mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01: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:
		
							parent
							
								
									e7a9f31eb4
								
							
						
					
					
						commit
						60262e5d0b
					
				| @ -12,7 +12,11 @@ import { TimeToProduction } from './componentsStat/TimeToProduction/TimeToProduc | |||||||
| import { TimeToProductionChart } from './componentsChart/TimeToProductionChart/TimeToProductionChart'; | import { TimeToProductionChart } from './componentsChart/TimeToProductionChart/TimeToProductionChart'; | ||||||
| import { MetricsSummaryChart } from './componentsChart/MetricsSummaryChart/MetricsSummaryChart'; | import { MetricsSummaryChart } from './componentsChart/MetricsSummaryChart/MetricsSummaryChart'; | ||||||
| import { UpdatesPerEnvironmentTypeChart } from './componentsChart/UpdatesPerEnvironmentTypeChart/UpdatesPerEnvironmentTypeChart'; | 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 type { GroupedDataByProject } from './hooks/useGroupedProjectTrends'; | ||||||
| import { Box, styled } from '@mui/material'; | import { Box, styled } from '@mui/material'; | ||||||
| import { allOption } from '../common/ProjectSelect/ProjectSelect'; | import { allOption } from '../common/ProjectSelect/ProjectSelect'; | ||||||
| @ -20,6 +24,7 @@ import type { VFC } from 'react'; | |||||||
| import { chartInfo } from './chart-info'; | import { chartInfo } from './chart-info'; | ||||||
| 
 | 
 | ||||||
| interface IChartsProps { | interface IChartsProps { | ||||||
|  |     flags: InstanceInsightsSchema['flags']; | ||||||
|     flagTrends: InstanceInsightsSchema['flagTrends']; |     flagTrends: InstanceInsightsSchema['flagTrends']; | ||||||
|     projectsData: InstanceInsightsSchema['projectFlagTrends']; |     projectsData: InstanceInsightsSchema['projectFlagTrends']; | ||||||
|     groupedProjectsData: GroupedDataByProject< |     groupedProjectsData: GroupedDataByProject< | ||||||
| @ -66,6 +71,7 @@ const ChartWidget = styled(Widget)(({ theme }) => ({ | |||||||
| 
 | 
 | ||||||
| export const InsightsCharts: VFC<IChartsProps> = ({ | export const InsightsCharts: VFC<IChartsProps> = ({ | ||||||
|     projects, |     projects, | ||||||
|  |     flags, | ||||||
|     users, |     users, | ||||||
|     summary, |     summary, | ||||||
|     userTrends, |     userTrends, | ||||||
| @ -78,6 +84,16 @@ export const InsightsCharts: VFC<IChartsProps> = ({ | |||||||
|     const showAllProjects = projects[0] === allOption.id; |     const showAllProjects = projects[0] === allOption.id; | ||||||
|     const isOneProjectSelected = projects.length === 1; |     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 ( |     return ( | ||||||
|         <> |         <> | ||||||
|             <StyledGrid> |             <StyledGrid> | ||||||
| @ -122,9 +138,9 @@ export const InsightsCharts: VFC<IChartsProps> = ({ | |||||||
|                 /> |                 /> | ||||||
|                 <Widget {...chartInfo.totalFlags}> |                 <Widget {...chartInfo.totalFlags}> | ||||||
|                     <FlagStats |                     <FlagStats | ||||||
|                         count={summary.total} |                         count={showAllProjects ? flags.total : summary.total} | ||||||
|                         flagsPerUser={ |                         flagsPerUser={ | ||||||
|                             showAllProjects ? summary.flagsPerUser : '' |                             showAllProjects ? getFlagsPerUser(flags, users) : '' | ||||||
|                         } |                         } | ||||||
|                     /> |                     /> | ||||||
|                 </Widget> |                 </Widget> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user