Skip to content

Commit

Permalink
fix: total flags and flags per user when all projects (#6787)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
andreas-unleash committed Apr 9, 2024
1 parent e7a9f31 commit 60262e5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions frontend/src/component/insights/InsightsCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ 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';
import type { VFC } from 'react';
import { chartInfo } from './chart-info';

interface IChartsProps {
flags: InstanceInsightsSchema['flags'];
flagTrends: InstanceInsightsSchema['flagTrends'];
projectsData: InstanceInsightsSchema['projectFlagTrends'];
groupedProjectsData: GroupedDataByProject<
Expand Down Expand Up @@ -66,6 +71,7 @@ const ChartWidget = styled(Widget)(({ theme }) => ({

export const InsightsCharts: VFC<IChartsProps> = ({
projects,
flags,
users,
summary,
userTrends,
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 60262e5

Please sign in to comment.