-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the project health widget to the edb: <img width="1243" alt="Skjermbilde 2024-01-31 kl 12 16 23" src="https://github.com/Unleash/unleash/assets/16081982/7df1e4dc-3245-4c30-bb9e-f21e90697392">
- Loading branch information
1 parent
fcb8bf6
commit 79e86e1
Showing
5 changed files
with
75 additions
and
10 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
51 changes: 51 additions & 0 deletions
51
frontend/src/component/executiveDashboard/ProjectHealthChart/ProjectHealthChart.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,51 @@ | ||
import { useMemo, type VFC } from 'react'; | ||
import 'chartjs-adapter-date-fns'; | ||
import { useTheme } from '@mui/material'; | ||
import { | ||
ExecutiveSummarySchema, | ||
ExecutiveSummarySchemaProjectFlagTrendsItem, | ||
} from 'openapi'; | ||
import { LineChart } from '../LineChart/LineChart'; | ||
import { getRandomColor } from '../executive-dashboard-utils'; | ||
|
||
interface IFlagsProjectChartProps { | ||
projectFlagTrends: ExecutiveSummarySchema['projectFlagTrends']; | ||
} | ||
|
||
export const ProjectHealthChart: VFC<IFlagsProjectChartProps> = ({ | ||
projectFlagTrends, | ||
}) => { | ||
const theme = useTheme(); | ||
|
||
const data = useMemo(() => { | ||
const groupedFlagTrends = projectFlagTrends.reduce< | ||
Record<string, ExecutiveSummarySchemaProjectFlagTrendsItem[]> | ||
>((groups, item) => { | ||
if (!groups[item.project]) { | ||
groups[item.project] = []; | ||
} | ||
groups[item.project].push(item); | ||
return groups; | ||
}, {}); | ||
|
||
const datasets = Object.entries(groupedFlagTrends).map( | ||
([project, trends]) => { | ||
const color = getRandomColor(); | ||
return { | ||
label: project, | ||
data: trends.map((item) => item.health || 0), | ||
borderColor: color, | ||
backgroundColor: color, | ||
fill: true, | ||
}; | ||
}, | ||
); | ||
|
||
return { | ||
labels: projectFlagTrends.map((item) => item.date), | ||
datasets, | ||
}; | ||
}, [theme, projectFlagTrends]); | ||
|
||
return <LineChart data={data} />; | ||
}; |
9 changes: 9 additions & 0 deletions
9
frontend/src/component/executiveDashboard/executive-dashboard-utils.ts
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,9 @@ | ||
// TODO: Replace this function with something more tailored to our color palette | ||
export const getRandomColor = () => { | ||
const letters = '0123456789ABCDEF'; | ||
let color = '#'; | ||
for (let i = 0; i < 6; i++) { | ||
color += letters[Math.floor(Math.random() * 16)]; | ||
} | ||
return color; | ||
}; |