Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Oct 14, 2024
1 parent 3d4a6f6 commit e4c7256
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 40 deletions.
59 changes: 20 additions & 39 deletions src/scenes/Dashboard/ProgressReportsWidget/ProgressReportsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DataGridPro,
DataGridProProps as DataGridProps,
GridColDef,
GridRenderCellParams as RenderCellParams,
} from '@mui/x-data-grid-pro';
import { merge } from 'lodash';
import { useMemo } from 'react';
Expand All @@ -24,7 +25,6 @@ import {
useDataGridSource,
} from '~/components/Grid';
import { Link } from '~/components/Routing';
import { ProgressSummaryFragment } from '../../ProgressReports/Detail/ProgressReportDetail.graphql';
import { ExpansionCell } from './ExpansionCell';
import {
ProgressReportsDataGridRowFragment as ProgressReport,
Expand Down Expand Up @@ -103,7 +103,18 @@ export const ProgressReportsColumnMap = {
minWidth: 200,
sortable: false,
filterable: false,
renderCell: ({ value }) => <CumulativeProgressColumn value={value} />,
renderCell: ({
value,
}: RenderCellParams<
ProgressReport,
ProgressReport['cumulativeSummary']
>) => (
<Box sx={{ my: 1, display: 'flex', gap: 2 }}>
<Metric label="Planned" value={value?.planned} />
<Metric label="Actual" value={value?.actual} />
<Metric label="Variance" value={value?.variance} />
</Box>
),
},
teamNews: {
headerName: 'Team News',
Expand Down Expand Up @@ -222,41 +233,11 @@ export const ProgressReportsGrid = ({
);
};

const CumulativeProgressColumn = ({
value,
}: {
value: ProgressSummaryFragment | null;
}) => {
const progressData = {
Planned: value?.planned,
Actual: value?.actual,
Variance: value?.variance,
};

return (
<Box
sx={{
my: 1,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'left',
gap: 2,
}}
>
{Object.entries(progressData).map(([label, data]) =>
cumulativeProgressData(label, data)
)}
</Box>
);
};

const cumulativeProgressData = (label: string, data: number | undefined) => {
const displayValue = data === undefined ? '—' : `${(data * 100).toFixed(1)}%`;

return (
<Box sx={{ textAlign: 'left' }}>
<Typography variant="body2">{displayValue}</Typography>
<Typography variant="body2">{label}</Typography>
const Metric = ({ label, value }: { label: string; value?: number }) => (
<Typography variant="body2">
<Box color={value ? undefined : 'text.disabled'}>
{value === undefined ? '—' : `${(value * 100).toFixed(1)}%`}
</Box>
);
};
<div>{label}</div>
</Typography>
);
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ fragment progressReportsDataGridRow on ProgressReport {
}
}
cumulativeSummary {
...ProgressSummary
planned
actual
variance
}
teamNews {
items {
Expand Down

0 comments on commit e4c7256

Please sign in to comment.