-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[Dashboards] add primary axis select gap fill for bar and line charts #17098
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0121a30
init
ehconitin 779c166
refactor: move select gap fill utilities to shared graph/utils
ehconitin 8474509
fix: remove select gap fill from pie chart
ehconitin 7d48f21
rename filteredResultsWithGaps to resultsWithAllGapsFilled
ehconitin 1737047
remove sorting from select gap fill utilities
ehconitin d1504d6
Merge remote-tracking branch 'upstream/main' into primary-axis-select…
ehconitin 22cfc65
lint
ehconitin e1755d6
only apply select gap fill to single select fields
ehconitin a7e3737
Merge remote-tracking branch 'upstream/main' into primary-axis-select…
ehconitin 0aa4778
Remove FillSelectGapsResult wrapper and fix dimension value typing
ehconitin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
5 changes: 5 additions & 0 deletions
5
packages/twenty-front/src/modules/page-layout/widgets/graph/types/FillSelectGapsResult.ts
This file contains hidden or 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,5 @@ | ||
| import { type GroupByRawResult } from '@/page-layout/widgets/graph/types/GroupByRawResult'; | ||
|
|
||
| export type FillSelectGapsResult = { | ||
| data: GroupByRawResult[]; | ||
| }; | ||
48 changes: 48 additions & 0 deletions
48
...ront/src/modules/page-layout/widgets/graph/utils/__tests__/createEmptySelectGroup.test.ts
This file contains hidden or 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,48 @@ | ||
| import { createEmptySelectGroup } from '@/page-layout/widgets/graph/utils/createEmptySelectGroup'; | ||
|
|
||
| describe('createEmptySelectGroup', () => { | ||
| it('creates record with correct groupByDimensionValues', () => { | ||
| const result = createEmptySelectGroup(['A'], ['count']); | ||
|
|
||
| expect(result.groupByDimensionValues).toEqual(['A']); | ||
| }); | ||
|
|
||
| it('initializes all aggregateKeys to 0', () => { | ||
| const result = createEmptySelectGroup(['A'], ['count']); | ||
|
|
||
| expect(result.count).toBe(0); | ||
| }); | ||
|
|
||
| it('handles empty aggregateKeys array', () => { | ||
| const result = createEmptySelectGroup(['A'], []); | ||
|
|
||
| expect(result).toEqual({ | ||
| groupByDimensionValues: ['A'], | ||
| }); | ||
| }); | ||
|
|
||
| it('handles multiple aggregate keys', () => { | ||
| const result = createEmptySelectGroup(['A'], ['count', 'sum', 'avg']); | ||
|
|
||
| expect(result).toEqual({ | ||
| groupByDimensionValues: ['A'], | ||
| count: 0, | ||
| sum: 0, | ||
| avg: 0, | ||
| }); | ||
| }); | ||
|
|
||
| it('handles null values in dimensionValues', () => { | ||
| const result = createEmptySelectGroup(['A', null], ['count']); | ||
|
|
||
| expect(result.groupByDimensionValues).toEqual(['A', null]); | ||
| expect(result.count).toBe(0); | ||
| }); | ||
|
|
||
| it('handles multiple dimension values', () => { | ||
| const result = createEmptySelectGroup(['A', 'X', 'Y'], ['count']); | ||
|
|
||
| expect(result.groupByDimensionValues).toEqual(['A', 'X', 'Y']); | ||
| expect(result.count).toBe(0); | ||
| }); | ||
| }); |
133 changes: 133 additions & 0 deletions
133
...t/src/modules/page-layout/widgets/graph/utils/__tests__/fillSelectGapsInChartData.test.ts
This file contains hidden or 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,133 @@ | ||
| import { fillSelectGapsInChartData } from '@/page-layout/widgets/graph/utils/fillSelectGapsInChartData'; | ||
|
|
||
| describe('fillSelectGapsInChartData', () => { | ||
| const selectOptions = [ | ||
| { id: '1', label: 'Option A', value: 'A', position: 0, color: 'green' }, | ||
| { id: '2', label: 'Option B', value: 'B', position: 1, color: 'blue' }, | ||
| { id: '3', label: 'Option C', value: 'C', position: 2, color: 'red' }, | ||
| ] as const; | ||
|
|
||
| describe('one-dimensional data', () => { | ||
| it('returns data unchanged when selectOptions is undefined', () => { | ||
| const data = [ | ||
| { groupByDimensionValues: ['A'], count: 5 }, | ||
| { groupByDimensionValues: ['B'], count: 3 }, | ||
| ]; | ||
|
|
||
| const result = fillSelectGapsInChartData({ | ||
| data, | ||
| selectOptions: undefined, | ||
| aggregateKeys: ['count'], | ||
| }); | ||
|
|
||
| expect(result.data).toEqual(data); | ||
| }); | ||
|
|
||
| it('returns data unchanged when selectOptions is null', () => { | ||
| const data = [ | ||
| { groupByDimensionValues: ['A'], count: 5 }, | ||
| { groupByDimensionValues: ['B'], count: 3 }, | ||
| ]; | ||
|
|
||
| const result = fillSelectGapsInChartData({ | ||
| data, | ||
| selectOptions: null, | ||
| aggregateKeys: ['count'], | ||
| }); | ||
|
|
||
| expect(result.data).toEqual(data); | ||
| }); | ||
|
|
||
| it('returns data unchanged when selectOptions is empty', () => { | ||
| const data = [ | ||
| { groupByDimensionValues: ['A'], count: 5 }, | ||
| { groupByDimensionValues: ['B'], count: 3 }, | ||
| ]; | ||
|
|
||
| const result = fillSelectGapsInChartData({ | ||
| data, | ||
| selectOptions: [], | ||
| aggregateKeys: ['count'], | ||
| }); | ||
|
|
||
| expect(result.data).toEqual(data); | ||
| }); | ||
|
|
||
| it('returns empty data unchanged', () => { | ||
| const result = fillSelectGapsInChartData({ | ||
| data: [], | ||
| selectOptions: [...selectOptions], | ||
| aggregateKeys: ['count'], | ||
| }); | ||
|
|
||
| expect(result.data).toEqual([]); | ||
| }); | ||
|
|
||
| it('fills missing select options with zero values', () => { | ||
| const data = [ | ||
| { groupByDimensionValues: ['A'], count: 5 }, | ||
| { groupByDimensionValues: ['C'], count: 3 }, | ||
| ]; | ||
|
|
||
| const result = fillSelectGapsInChartData({ | ||
| data, | ||
| selectOptions: [...selectOptions], | ||
| aggregateKeys: ['count'], | ||
| }); | ||
|
|
||
| expect(result.data).toHaveLength(3); | ||
| expect(result.data[0]).toEqual({ | ||
| groupByDimensionValues: ['A'], | ||
| count: 5, | ||
| }); | ||
| expect(result.data[1]).toEqual({ | ||
| groupByDimensionValues: ['B'], | ||
| count: 0, | ||
| }); | ||
| expect(result.data[2]).toEqual({ | ||
| groupByDimensionValues: ['C'], | ||
| count: 3, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('two-dimensional data', () => { | ||
| it('fills missing primary axis options for all secondary values', () => { | ||
| const data = [ | ||
| { groupByDimensionValues: ['A', 'X'], count: 5 }, | ||
| { groupByDimensionValues: ['C', 'X'], count: 3 }, | ||
| { groupByDimensionValues: ['A', 'Y'], count: 2 }, | ||
| ]; | ||
|
|
||
| const result = fillSelectGapsInChartData({ | ||
| data, | ||
| selectOptions: [...selectOptions], | ||
| aggregateKeys: ['count'], | ||
| hasSecondDimension: true, | ||
| }); | ||
|
|
||
| expect(result.data).toHaveLength(6); | ||
|
|
||
| expect( | ||
| result.data.filter((r) => r.groupByDimensionValues[0] === 'A'), | ||
| ).toHaveLength(2); | ||
| expect( | ||
| result.data.filter((r) => r.groupByDimensionValues[0] === 'B'), | ||
| ).toHaveLength(2); | ||
| expect( | ||
| result.data.filter((r) => r.groupByDimensionValues[0] === 'C'), | ||
| ).toHaveLength(2); | ||
|
|
||
| expect( | ||
| result.data.find( | ||
| (r) => | ||
| r.groupByDimensionValues[0] === 'B' && | ||
| r.groupByDimensionValues[1] === 'X', | ||
| ), | ||
| ).toEqual({ | ||
| groupByDimensionValues: ['B', 'X'], | ||
| count: 0, | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
88 changes: 88 additions & 0 deletions
88
...page-layout/widgets/graph/utils/__tests__/fillSelectGapsInOneDimensionalChartData.test.ts
This file contains hidden or 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,88 @@ | ||
| import { fillSelectGapsInOneDimensionalChartData } from '@/page-layout/widgets/graph/utils/fillSelectGapsInOneDimensionalChartData'; | ||
|
|
||
| describe('fillSelectGapsInOneDimensionalChartData', () => { | ||
| const selectOptions = [ | ||
| { id: '1', label: 'Option A', value: 'A', position: 0, color: 'green' }, | ||
| { id: '2', label: 'Option B', value: 'B', position: 1, color: 'blue' }, | ||
| { id: '3', label: 'Option C', value: 'C', position: 2, color: 'red' }, | ||
| ] as const; | ||
|
|
||
| it('fills missing select options with zero values', () => { | ||
| const data = [ | ||
| { groupByDimensionValues: ['A'], count: 5 }, | ||
| { groupByDimensionValues: ['C'], count: 3 }, | ||
| ]; | ||
|
|
||
| const result = fillSelectGapsInOneDimensionalChartData({ | ||
| data, | ||
| selectOptions: [...selectOptions], | ||
| aggregateKeys: ['count'], | ||
| }); | ||
|
|
||
| expect(result.data).toHaveLength(3); | ||
| expect(result.data[0]).toEqual({ | ||
| groupByDimensionValues: ['A'], | ||
| count: 5, | ||
| }); | ||
| expect(result.data[1]).toEqual({ | ||
| groupByDimensionValues: ['B'], | ||
| count: 0, | ||
| }); | ||
| expect(result.data[2]).toEqual({ | ||
| groupByDimensionValues: ['C'], | ||
| count: 3, | ||
| }); | ||
| }); | ||
|
|
||
| it('preserves existing data values', () => { | ||
| const data = [ | ||
| { groupByDimensionValues: ['A'], count: 10, sum: 100 }, | ||
| { groupByDimensionValues: ['B'], count: 20, sum: 200 }, | ||
| { groupByDimensionValues: ['C'], count: 30, sum: 300 }, | ||
| ]; | ||
|
|
||
| const result = fillSelectGapsInOneDimensionalChartData({ | ||
| data, | ||
| selectOptions: [...selectOptions], | ||
| aggregateKeys: ['count', 'sum'], | ||
| }); | ||
|
|
||
| expect(result.data).toHaveLength(3); | ||
| expect(result.data).toEqual(data); | ||
| }); | ||
|
|
||
| it('preserves selectOptions order', () => { | ||
| const data = [ | ||
| { groupByDimensionValues: ['C'], count: 3 }, | ||
| { groupByDimensionValues: ['A'], count: 5 }, | ||
| ]; | ||
|
|
||
| const result = fillSelectGapsInOneDimensionalChartData({ | ||
| data, | ||
| selectOptions: [...selectOptions], | ||
| aggregateKeys: ['count'], | ||
| }); | ||
|
|
||
| expect(result.data).toHaveLength(3); | ||
| expect(result.data[0].groupByDimensionValues[0]).toBe('A'); | ||
| expect(result.data[1].groupByDimensionValues[0]).toBe('B'); | ||
| expect(result.data[2].groupByDimensionValues[0]).toBe('C'); | ||
| }); | ||
|
|
||
| it('works with multiple aggregate keys', () => { | ||
| const data = [{ groupByDimensionValues: ['A'], count: 5, sum: 100 }]; | ||
|
|
||
| const result = fillSelectGapsInOneDimensionalChartData({ | ||
| data, | ||
| selectOptions: [...selectOptions], | ||
| aggregateKeys: ['count', 'sum'], | ||
| }); | ||
|
|
||
| expect(result.data).toHaveLength(3); | ||
| expect(result.data[1]).toEqual({ | ||
| groupByDimensionValues: ['B'], | ||
| count: 0, | ||
| sum: 0, | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.