1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-06 01:15:28 +02:00

fix: total flags and flags per user when all projects (#6787)

Fixes the flag stats flagsPerUser calculation and display value. 
Previously the calculation depended on project data which might not be
there with the permission changes

Closes #
[1-2255](https://linear.app/unleash/issue/1-2255/unable-to-render-total-number-of-flags-when-there-are-no-project-data)

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
andreas-unleash 2024-04-09 10:52:09 +03:00 committed by GitHub
parent e7a9f31eb4
commit 60262e5d0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,7 +12,11 @@ import { TimeToProduction } from './componentsStat/TimeToProduction/TimeToProduc
import { TimeToProductionChart } from './componentsChart/TimeToProductionChart/TimeToProductionChart';
import { MetricsSummaryChart } from './componentsChart/MetricsSummaryChart/MetricsSummaryChart';
import { UpdatesPerEnvironmentTypeChart } from './componentsChart/UpdatesPerEnvironmentTypeChart/UpdatesPerEnvironmentTypeChart';
import type { InstanceInsightsSchema } from 'openapi';
import type {
InstanceInsightsSchema,
InstanceInsightsSchemaFlags,
InstanceInsightsSchemaUsers,
} from 'openapi';
import type { GroupedDataByProject } from './hooks/useGroupedProjectTrends';
import { Box, styled } from '@mui/material';
import { allOption } from '../common/ProjectSelect/ProjectSelect';
@ -20,6 +24,7 @@ import type { VFC } from 'react';
import { chartInfo } from './chart-info';
interface IChartsProps {
flags: InstanceInsightsSchema['flags'];
flagTrends: InstanceInsightsSchema['flagTrends'];
projectsData: InstanceInsightsSchema['projectFlagTrends'];
groupedProjectsData: GroupedDataByProject<
@ -66,6 +71,7 @@ const ChartWidget = styled(Widget)(({ theme }) => ({
export const InsightsCharts: VFC<IChartsProps> = ({
projects,
flags,
users,
summary,
userTrends,
@ -78,6 +84,16 @@ export const InsightsCharts: VFC<IChartsProps> = ({
const showAllProjects = projects[0] === allOption.id;
const isOneProjectSelected = projects.length === 1;
function getFlagsPerUser(
flags: InstanceInsightsSchemaFlags,
users: InstanceInsightsSchemaUsers,
) {
const flagsPerUserCalculation = flags.total / users.total;
return Number.isNaN(flagsPerUserCalculation)
? 'N/A'
: flagsPerUserCalculation.toFixed(2);
}
return (
<>
<StyledGrid>
@ -122,9 +138,9 @@ export const InsightsCharts: VFC<IChartsProps> = ({
/>
<Widget {...chartInfo.totalFlags}>
<FlagStats
count={summary.total}
count={showAllProjects ? flags.total : summary.total}
flagsPerUser={
showAllProjects ? summary.flagsPerUser : ''
showAllProjects ? getFlagsPerUser(flags, users) : ''
}
/>
</Widget>