Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: chart info naming bug fix (#6660)
Rename param Signed-off-by: andreas-unleash <andreas@getunleash.ai>
- Loading branch information
1 parent
2f7580e
commit 9233d4c
Showing
7 changed files
with
119 additions
and
106 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
48 changes: 0 additions & 48 deletions
48
frontend/src/component/executiveDashboard/hooks/useAvgTimeToProduction.test.ts
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
frontend/src/component/executiveDashboard/hooks/useAvgTimeToProduction.ts
This file was deleted.
Oops, something went wrong.
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
63 changes: 63 additions & 0 deletions
63
frontend/src/component/executiveDashboard/hooks/useMedianTimeToProduction.test.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,63 @@ | ||
import { useMedianTimeToProduction } from './useMedianTimeToProduction'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
describe('useMedianTimeToProduction', () => { | ||
test('returns 0 when projectsData is empty', () => { | ||
const projectsData = {}; | ||
const { result } = renderHook(() => | ||
useMedianTimeToProduction(projectsData), | ||
); | ||
expect(result.current).toBe(0); | ||
}); | ||
|
||
test('calculates median time to production correctly with even number of projects', () => { | ||
const projectsData = { | ||
project1: [ | ||
{ timeToProduction: 10, date: '2023-01-01' }, | ||
{ timeToProduction: 20, date: '2023-02-01' }, | ||
], | ||
project2: [ | ||
{ timeToProduction: 15, date: '2023-01-15' }, | ||
{ timeToProduction: 25, date: '2023-02-15' }, | ||
], | ||
project3: [{ timeToProduction: 30, date: '2023-01-20' }], | ||
} as any; | ||
const { result } = renderHook(() => | ||
useMedianTimeToProduction(projectsData), | ||
); | ||
// With sorted timeToProductions [10, 15, 20, 25, 30], median is the middle value, 20. | ||
expect(result.current).toBe(20); | ||
}); | ||
|
||
test('calculates median time to production correctly with odd number of projects', () => { | ||
const projectsData = { | ||
project1: [ | ||
{ timeToProduction: 10, date: '2023-01-01' }, | ||
{ timeToProduction: 20, date: '2023-02-01' }, | ||
], | ||
project2: [{ timeToProduction: 15, date: '2023-01-15' }], | ||
} as any; | ||
const { result } = renderHook(() => | ||
useMedianTimeToProduction(projectsData), | ||
); | ||
// With sorted timeToProductions [10, 15, 20], median is the middle value, 15. | ||
expect(result.current).toBe(15); | ||
}); | ||
|
||
test('correctly handles all valid time to production values', () => { | ||
const projectsData = { | ||
project1: [{ timeToProduction: 10, date: '2023-01-01' }], | ||
project2: [{ timeToProduction: 25, date: '2023-01-10' }], | ||
project3: [{ date: '2023-01-15' }], | ||
project4: [ | ||
{ timeToProduction: 30, date: '2023-02-01' }, | ||
{ timeToProduction: 20, date: '2023-02-02' }, | ||
], | ||
} as any; | ||
const { result } = renderHook(() => | ||
useMedianTimeToProduction(projectsData), | ||
); | ||
// With sorted timeToProductions [10, 20, 25, 30], the median is the average of 20 and 25, i.e., 22.5. | ||
expect(result.current).toBe(22.5); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
frontend/src/component/executiveDashboard/hooks/useMedianTimeToProduction.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,43 @@ | ||
import { useMemo } from 'react'; | ||
import type { | ||
ExecutiveSummarySchema, | ||
ExecutiveSummarySchemaProjectFlagTrendsItem, | ||
} from 'openapi'; | ||
import type { GroupedDataByProject } from './useGroupedProjectTrends'; | ||
|
||
const validTrend = (trend: ExecutiveSummarySchemaProjectFlagTrendsItem) => | ||
Boolean(trend) && Boolean(trend.timeToProduction); | ||
|
||
export const useMedianTimeToProduction = ( | ||
projectsData: GroupedDataByProject< | ||
ExecutiveSummarySchema['projectFlagTrends'] | ||
>, | ||
) => | ||
useMemo(() => { | ||
const timesToProduction: number[] = []; | ||
|
||
Object.values(projectsData).forEach((trends) => { | ||
trends.forEach((trend) => { | ||
if (validTrend(trend)) { | ||
timesToProduction.push(trend.timeToProduction!); | ||
} | ||
}); | ||
}); | ||
|
||
if (timesToProduction.length === 0) { | ||
return 0; | ||
} | ||
|
||
timesToProduction.sort((a, b) => a - b); | ||
|
||
const midIndex = Math.floor(timesToProduction.length / 2); | ||
|
||
const median = | ||
timesToProduction.length % 2 === 0 | ||
? (timesToProduction[midIndex - 1] + | ||
timesToProduction[midIndex]) / | ||
2 | ||
: timesToProduction[midIndex]; | ||
|
||
return median; | ||
}, [projectsData]); |