diff --git a/packages/ui/src/components/Drawer/Queues/JobsCount.tsx b/packages/ui/src/components/Drawer/Queues/JobsCount.tsx index ac7b188..f7f6e60 100644 --- a/packages/ui/src/components/Drawer/Queues/JobsCount.tsx +++ b/packages/ui/src/components/Drawer/Queues/JobsCount.tsx @@ -2,9 +2,13 @@ import React from 'react'; import type { JobStatus } from '@/typings/gql'; import JobStatusChip from '@/components/JobStatusChip'; import { makeStyles } from '@material-ui/core/styles'; +import StatusesIndicator from './QueueStatusesIndicator'; const useStyles = makeStyles({ root: { + position: 'relative', + }, + list: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', @@ -24,12 +28,15 @@ type TProps = { export default function QueueJobsCount(props: TProps) { const cls = useStyles(); return ( - +
+ + +
); } diff --git a/packages/ui/src/components/Drawer/Queues/Queue.tsx b/packages/ui/src/components/Drawer/Queues/Queue.tsx index b09c67d..e46b2e8 100644 --- a/packages/ui/src/components/Drawer/Queues/Queue.tsx +++ b/packages/ui/src/components/Drawer/Queues/Queue.tsx @@ -8,15 +8,11 @@ import PauseIcon from '@material-ui/icons/Pause'; import { makeStyles } from '@material-ui/core/styles'; import Badge from '@material-ui/core/Badge'; import Typography from '@material-ui/core/Typography'; -import { - useJobsCountArray, - useQueueWorkspaceLabel, - useShouldRenderStatusesPie, -} from './hooks'; -import StatusesPie from './QueueStatusesPie'; +import { useJobsCountArray, useQueueWorkspaceLabel } from './hooks'; const useStyles = makeStyles((theme) => ({ listItem: { + position: 'relative', paddingRight: theme.spacing(1), '& .MuiListItemIcon-root': { minWidth: 32, @@ -38,8 +34,6 @@ const DrawerQueue = (props: TProps) => { props.onSelect(id, workspaceLabel); }, [id, workspaceLabel]); const countArray = useJobsCountArray(props.queue.jobsCounts); - const shouldRenderStatusesPie = useShouldRenderStatusesPie(props.queue); - const shouldRenderListIcon = isPaused || shouldRenderStatusesPie; return ( { dense button > - {shouldRenderListIcon && ( + {isPaused && ( - {isPaused && ( - - - - - - )} - {shouldRenderStatusesPie && } + + + + + )} ({ + root: { + display: 'flex', + height: 3, + overflow: 'hidden', + marginTop: theme.spacing(0.5), + }, +})); + +type TProps = { + count: { status: JobStatus; count: number }[]; +}; +export default function QueueStatusesIndicator({ count }: TProps) { + const cls = useStyles(); + const palette = useJobStatusesPalette(); + const mapped = useMemo(() => { + const allJobsCount = sum(count.map(({ count }) => count)); + return count.map(({ count, status }) => ({ + width: MathUtils.mapNumberToPercent(count, 0, allJobsCount) + '%', + color: palette[status], + })); + }, [palette, count]); + return ( +
+ {mapped.map(({ width, color }, idx) => ( +
+ ))} +
+ ); +} diff --git a/packages/ui/src/components/Drawer/Queues/QueueStatusesPie.tsx b/packages/ui/src/components/Drawer/Queues/QueueStatusesPie.tsx deleted file mode 100644 index 4de80bc..0000000 --- a/packages/ui/src/components/Drawer/Queues/QueueStatusesPie.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { useJobStatusesPalette } from '@/components/JobStatusChip/hooks'; -import React from 'react'; -import * as Chart from 'recharts'; -import type { JobStatus } from '@/typings/gql'; - -const margin = { top: 0, left: 0, right: 5, bottom: 0 }; -const style: React.CSSProperties = { - pointerEvents: 'none', -}; -type TProps = { - count: { status: JobStatus; count: number }[]; -}; -export default function QueueStatusesPie(props: TProps) { - const palette = useJobStatusesPalette(); - return ( - - - {props.count.map((d, idx) => ( - - ))} - - - ); -} diff --git a/packages/ui/src/components/Drawer/Queues/hooks.ts b/packages/ui/src/components/Drawer/Queues/hooks.ts index 8d37383..1af0ff4 100644 --- a/packages/ui/src/components/Drawer/Queues/hooks.ts +++ b/packages/ui/src/components/Drawer/Queues/hooks.ts @@ -25,15 +25,3 @@ export const useMaybeGroupQueuesByPrefix = (queues: QueueFromQuery[]) => { } return groupBy(queues, 'keyPrefix'); }; - -export const useShouldRenderStatusesPie = (queue: QueueFromQuery): boolean => { - const pref = usePreferencesStore((state) => state.showStatusesPieInDrawer); - return useMemo(() => { - if (!pref || queue.isPaused) return false; - // show pie only if there are at least two different non zero statuses - const [firstCount, secondCount] = Object.values(queue.jobsCounts).sort( - (a, b) => b - a - ); - return firstCount > 0 && secondCount > 0; - }, [pref, queue.isPaused, queue.jobsCounts]); -};