-
-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: flag types used for project insights (#6607)
- Loading branch information
Showing
7 changed files
with
192 additions
and
29 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
36 changes: 36 additions & 0 deletions
36
frontend/src/component/project/Project/ProjectInsights/FlagTypesUsed/FlagTypesUsed.test.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,36 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
import type { ProjectOverviewSchema } from 'openapi'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import { FlagTypesUsed } from './FlagTypesUsed'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const setupApi = (overview: ProjectOverviewSchema) => { | ||
testServerRoute(server, '/api/admin/projects/default/overview', overview); | ||
}; | ||
|
||
test('Show outdated SDKs and apps using them', async () => { | ||
setupApi({ | ||
name: 'default', | ||
version: 2, | ||
featureTypeCounts: [ | ||
{ | ||
type: 'release', | ||
count: 57, | ||
}, | ||
], | ||
}); | ||
render( | ||
<Routes> | ||
<Route path={'/projects/:projectId'} element={<FlagTypesUsed />} /> | ||
</Routes>, | ||
{ | ||
route: '/projects/default', | ||
}, | ||
); | ||
|
||
await screen.findByText('Release'); | ||
await screen.findByText('57'); | ||
}); |
125 changes: 125 additions & 0 deletions
125
frontend/src/component/project/Project/ProjectInsights/FlagTypesUsed/FlagTypesUsed.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,125 @@ | ||
import { useMemo } from 'react'; | ||
import { styled, type SvgIconTypeMap, Typography } from '@mui/material'; | ||
import { getFeatureTypeIcons } from 'utils/getFeatureTypeIcons'; | ||
|
||
import type { OverridableComponent } from '@mui/material/OverridableComponent'; | ||
import { useRequiredPathParam } from 'hooks/useRequiredPathParam'; | ||
import useProjectOverview from 'hooks/api/getters/useProjectOverview/useProjectOverview'; | ||
|
||
export const StyledProjectInfoWidgetContainer = styled('div')(({ theme }) => ({ | ||
margin: '0', | ||
[theme.breakpoints.down('md')]: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
position: 'relative', | ||
}, | ||
})); | ||
|
||
export const StyledWidgetTitle = styled(Typography)(({ theme }) => ({ | ||
marginBottom: theme.spacing(2.5), | ||
})); | ||
|
||
export const StyledCount = styled('span')(({ theme }) => ({ | ||
fontSize: theme.typography.h2.fontSize, | ||
fontWeight: 'bold', | ||
color: theme.palette.text.primary, | ||
})); | ||
|
||
const StyledTypeCount = styled(StyledCount)(({ theme }) => ({ | ||
marginLeft: 'auto', | ||
fontWeight: theme.typography.fontWeightRegular, | ||
color: theme.palette.text.secondary, | ||
})); | ||
|
||
interface IFlagTypeRowProps { | ||
type: string; | ||
Icon: OverridableComponent<SvgIconTypeMap>; | ||
count: number; | ||
} | ||
|
||
const StyledParagraphGridRow = styled('div')(({ theme }) => ({ | ||
display: 'flex', | ||
gap: theme.spacing(1.5), | ||
width: '100%', | ||
margin: theme.spacing(1, 0), | ||
fontSize: theme.fontSizes.smallBody, | ||
color: theme.palette.text.secondary, | ||
alignItems: 'center', | ||
[theme.breakpoints.down('md')]: { | ||
margin: 0, | ||
}, | ||
})); | ||
|
||
const FlagTypesRow = ({ type, Icon, count }: IFlagTypeRowProps) => { | ||
const getTitleText = (str: string) => { | ||
return str.charAt(0).toUpperCase() + str.slice(1).replace('-', ' '); | ||
}; | ||
|
||
return ( | ||
<StyledParagraphGridRow data-loading> | ||
<Icon fontSize='small' data-loading /> | ||
<div>{getTitleText(type)}</div> | ||
<StyledTypeCount>{count}</StyledTypeCount> | ||
</StyledParagraphGridRow> | ||
); | ||
}; | ||
|
||
export const FlagTypesUsed = () => { | ||
const projectId = useRequiredPathParam('projectId'); | ||
const { project } = useProjectOverview(projectId); | ||
|
||
const { featureTypeCounts } = project; | ||
|
||
const featureTypeStats = useMemo(() => { | ||
const release = | ||
featureTypeCounts.find( | ||
(featureType) => featureType.type === 'release', | ||
)?.count || 0; | ||
|
||
const experiment = | ||
featureTypeCounts.find( | ||
(featureType) => featureType.type === 'experiment', | ||
)?.count || 0; | ||
|
||
const operational = | ||
featureTypeCounts.find( | ||
(featureType) => featureType.type === 'operational', | ||
)?.count || 0; | ||
|
||
const kill = | ||
featureTypeCounts.find( | ||
(featureType) => featureType.type === 'kill-switch', | ||
)?.count || 0; | ||
|
||
const permission = | ||
featureTypeCounts.find( | ||
(featureType) => featureType.type === 'permission', | ||
)?.count || 0; | ||
|
||
return { | ||
release, | ||
experiment, | ||
operational, | ||
'kill-switch': kill, | ||
permission, | ||
}; | ||
}, [featureTypeCounts]); | ||
|
||
return ( | ||
<StyledProjectInfoWidgetContainer> | ||
<StyledWidgetTitle variant='h3' data-loading> | ||
Flag types used | ||
</StyledWidgetTitle> | ||
{Object.keys(featureTypeStats).map((type) => ( | ||
<FlagTypesRow | ||
type={type} | ||
key={type} | ||
Icon={getFeatureTypeIcons(type)} | ||
count={ | ||
featureTypeStats[type as keyof typeof featureTypeStats] | ||
} | ||
/> | ||
))} | ||
</StyledProjectInfoWidgetContainer> | ||
); | ||
}; |
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