-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
401 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...es/ui/src/results/ResultHistory/ResultHistoryChronological/ResultHistoryChronological.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useState } from 'react'; | ||
import clsx from 'clsx'; | ||
|
||
import { ClobbrUIResult } from 'models/ClobbrUIResult'; | ||
|
||
import { ButtonBase } from '@mui/material'; | ||
|
||
import { getResultStats } from 'results/ResultStats/ResultStats'; | ||
import { orderBy } from 'lodash-es'; | ||
import { ResultHistoryChronologicalItem } from './ResultHistoryChronologicalItem'; | ||
|
||
export const ResultHistoryChronological = ({ | ||
results, | ||
maximumResults | ||
}: { | ||
results: Array<ClobbrUIResult>; | ||
maximumResults: number; | ||
}) => { | ||
const [numberOfResultsToShow, setNumberOfResultsToShow] = | ||
useState(maximumResults); | ||
|
||
const resultsToShow = orderBy(results, 'startDate', 'desc').slice( | ||
0, | ||
numberOfResultsToShow | ||
); | ||
const someResultsNotShown = results.length > resultsToShow.length; | ||
|
||
const showMoreResults = () => { | ||
setNumberOfResultsToShow(numberOfResultsToShow + 10); | ||
}; | ||
|
||
const chronologicalResultsWithStats = resultsToShow.map((result) => { | ||
const successfulLogs = result.logs.filter((log) => !log.failed); | ||
|
||
return { | ||
result, | ||
successPct: (successfulLogs.length * 100) / result.iterations, | ||
stats: getResultStats(result) || [] | ||
}; | ||
}); | ||
|
||
return ( | ||
<div> | ||
<div className={clsx('relative flex flex-col gap-4')}> | ||
{chronologicalResultsWithStats.map(({ result, successPct }, index) => { | ||
return ( | ||
<ResultHistoryChronologicalItem | ||
key={result.id} | ||
index={index} | ||
result={result} | ||
successPct={successPct} | ||
/> | ||
); | ||
})} | ||
</div> | ||
|
||
{someResultsNotShown ? ( | ||
<div className="w-full bg-white/20 dark:bg-black/20 hover:bg-gray-200/40 hover:dark:bg-black/40 transition-all flex justify-center rounded-md"> | ||
<ButtonBase | ||
onClick={showMoreResults} | ||
className="text-xs w-full !p-1.5" | ||
> | ||
Show more | ||
</ButtonBase> | ||
</div> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.