Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow sorting Lifecycle graph bars #16542

Merged
merged 9 commits into from
Jul 31, 2023
16 changes: 8 additions & 8 deletions frontend/src/scenes/trends/trendsDataLogic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,24 @@ describe('trendsDataLogic', () => {
builtDataNodeLogic.actions.loadDataSuccess(insight)
}).toMatchValues({
indexedResults: [
expect.objectContaining({
count: 35346.0,
status: 'new',
id: 0,
seriesIndex: 0,
}),
expect.objectContaining({
count: -50255.0,
status: 'dormant',
id: 1,
id: 0,
seriesIndex: 1,
}),
expect.objectContaining({
count: 11612.0,
status: 'resurrecting',
id: 2,
id: 1,
seriesIndex: 3,
}),
expect.objectContaining({
count: 35346.0,
status: 'new',
id: 2,
seriesIndex: 0,
}),
],
})
})
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/scenes/trends/trendsDataLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,25 @@ export const trendsDataLogic = kea<trendsDataLogicType>([
indexedResults: [
(s) => [s.results, s.display, s.lifecycleFilter],
(results, display, lifecycleFilter): IndexedTrendResult[] => {
const defaultLifecyclesOrder = ['new', 'resurrecting', 'returning', 'dormant']
let indexedResults = results.map((result, index) => ({ ...result, seriesIndex: index }))
if (
display &&
(display === ChartDisplayType.ActionsBarValue || display === ChartDisplayType.ActionsPie)
) {
indexedResults.sort((a, b) => b.aggregated_value - a.aggregated_value)
} else if (lifecycleFilter && lifecycleFilter.toggledLifecycles) {
indexedResults = indexedResults.filter((result) =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
lifecycleFilter.toggledLifecycles!.includes(String(result.status) as LifecycleToggle)
} else if (lifecycleFilter) {
if (lifecycleFilter.toggledLifecycles) {
indexedResults = indexedResults.filter((result) =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
lifecycleFilter.toggledLifecycles!.includes(String(result.status) as LifecycleToggle)
)
}

indexedResults = indexedResults.sort(
(a, b) =>
defaultLifecyclesOrder.indexOf(String(b.status)) -
defaultLifecyclesOrder.indexOf(String(a.status))
)
}
return indexedResults.map((result, index) => ({ ...result, id: index }))
Expand Down