The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(dashboard): keep the Not Set group when gap-filling select and da… (#28825)
Arnav Singh08da201356af
diff --git a/packages/twenty-server/src/modules/dashboard/chart-data/utils/__tests__/fill-date-gaps.util.spec.ts b/packages/twenty-server/src/modules/dashboard/chart-data/utils/__tests__/fill-date-gaps.util.spec.tsindex ec542a95893..29c6533e30b 100644--- a/packages/twenty-server/src/modules/dashboard/chart-data/utils/__tests__/fill-date-gaps.util.spec.ts+++ b/packages/twenty-server/src/modules/dashboard/chart-data/utils/__tests__/fill-date-gaps.util.spec.ts@@ -347,3 +347,58 @@ describe('fillDateGapsTwoDimensional', () => {});});});++describe('fillDateGaps with records that have no value', () => {+ it('should keep the null group after the filled dates', () => {+ const result = fillDateGaps({+ data: [+ { groupByDimensionValues: ['2024-01-01'], aggregateValue: 1 },+ { groupByDimensionValues: ['2024-01-03'], aggregateValue: 2 },+ { groupByDimensionValues: [null], aggregateValue: 7 },+ ],+ dateGranularity: ObjectRecordGroupByDateGranularity.DAY,+ });++ expect(result.data).toEqual([+ { groupByDimensionValues: ['2024-01-01'], aggregateValue: 1 },+ { groupByDimensionValues: ['2024-01-02'], aggregateValue: 0 },+ { groupByDimensionValues: ['2024-01-03'], aggregateValue: 2 },+ { groupByDimensionValues: [null], aggregateValue: 7 },+ ]);+ });++ it('should keep the null group in descending order', () => {+ const result = fillDateGaps({+ data: [+ { groupByDimensionValues: ['2024-01-02'], aggregateValue: 1 },+ { groupByDimensionValues: [null], aggregateValue: 7 },+ ],+ dateGranularity: ObjectRecordGroupByDateGranularity.DAY,+ isDescOrder: true,+ });++ expect(result.data).toEqual([+ { groupByDimensionValues: ['2024-01-02'], aggregateValue: 1 },+ { groupByDimensionValues: [null], aggregateValue: 7 },+ ]);+ });++ it('should keep the null group for every secondary value', () => {+ const result = fillDateGapsTwoDimensional({+ data: [+ { groupByDimensionValues: ['2024-01-01', 'X'], aggregateValue: 1 },+ { groupByDimensionValues: ['2024-01-02', 'X'], aggregateValue: 3 },+ { groupByDimensionValues: [null, 'X'], aggregateValue: 4 },+ { groupByDimensionValues: [null, 'Y'], aggregateValue: 2 },+ ],+ dateGranularity: ObjectRecordGroupByDateGranularity.DAY,+ });++ expect(result.data).toEqual([+ { groupByDimensionValues: ['2024-01-01', 'X'], aggregateValue: 1 },+ { groupByDimensionValues: ['2024-01-02', 'X'], aggregateValue: 3 },+ { groupByDimensionValues: [null, 'X'], aggregateValue: 4 },+ { groupByDimensionValues: [null, 'Y'], aggregateValue: 2 },+ ]);+ });+});diff --git a/packages/twenty-server/src/modules/dashboard/chart-data/utils/__tests__/fill-select-gaps.util.spec.ts b/packages/twenty-server/src/modules/dashboard/chart-data/utils/__tests__/fill-select-gaps.util.spec.tsindex d76c25af2a6..3f189f61cde 100644--- a/packages/twenty-server/src/modules/dashboard/chart-data/utils/__tests__/fill-select-gaps.util.spec.ts+++ b/packages/twenty-server/src/modules/dashboard/chart-data/utils/__tests__/fill-select-gaps.util.spec.ts@@ -342,3 +342,44 @@ describe('fillSelectGapsTwoDimensional', () => {});});});++describe('fillSelectGaps with records that have no value', () => {+ const selectOptions = [+ { value: 'TODO', label: 'Todo', position: 0 },+ { value: 'DONE', label: 'Done', position: 1 },+ ];++ it('should keep the null group after the filled options', () => {+ const result = fillSelectGaps({+ data: [+ { groupByDimensionValues: ['TODO'], aggregateValue: 4 },+ { groupByDimensionValues: [null], aggregateValue: 7 },+ ],+ selectOptions,+ });++ expect(result).toEqual([+ { groupByDimensionValues: ['TODO'], aggregateValue: 4 },+ { groupByDimensionValues: ['DONE'], aggregateValue: 0 },+ { groupByDimensionValues: [null], aggregateValue: 7 },+ ]);+ });++ it('should keep the null group for every secondary value', () => {+ const result = fillSelectGapsTwoDimensional({+ data: [+ { groupByDimensionValues: ['TODO', 'X'], aggregateValue: 5 },+ { groupByDimensionValues: [null, 'X'], aggregateValue: 2 },+ { groupByDimensionValues: [null, 'Y'], aggregateValue: 1 },+ ],+ selectOptions,+ });++ expect(result).toEqual([+ { groupByDimensionValues: ['TODO', 'X'], aggregateValue: 5 },+ { groupByDimensionValues: ['DONE', 'X'], aggregateValue: 0 },+ { groupByDimensionValues: [null, 'X'], aggregateValue: 2 },+ { groupByDimensionValues: [null, 'Y'], aggregateValue: 1 },+ ]);+ });+});diff --git a/packages/twenty-server/src/modules/dashboard/chart-data/utils/fill-date-gaps.util.ts b/packages/twenty-server/src/modules/dashboard/chart-data/utils/fill-date-gaps.util.tsindex 13237b93547..1239c857338 100644--- a/packages/twenty-server/src/modules/dashboard/chart-data/utils/fill-date-gaps.util.ts+++ b/packages/twenty-server/src/modules/dashboard/chart-data/utils/fill-date-gaps.util.ts@@ -36,11 +36,13 @@ export const fillDateGaps = ({const existingDateGroupsMap = new Map<string, GroupByRawResult>();const parsedDates: Temporal.PlainDate[] = [];+ const notSetGroups: GroupByRawResult[] = [];for (const item of data) {const dateValue = item.groupByDimensionValues?.[0];if (!isDefined(dateValue)) {+ notSetGroups.push(item);continue;}@@ -85,7 +87,7 @@ export const fillDateGaps = ({};});- return { data: filledData, wasTruncated };+ return { data: [...filledData, ...notSetGroups], wasTruncated };};type FillDateGapsTwoDimensionalParams = {@@ -112,12 +114,14 @@ export const fillDateGapsTwoDimensional = ({const existingDateGroupsMap = new Map<string, GroupByRawResult>();const parsedDates: Temporal.PlainDate[] = [];+ const notSetGroups: GroupByRawResult[] = [];const uniqueSecondDimensionValues = new Set<unknown>();for (const item of data) {const dateValue = item.groupByDimensionValues?.[0];if (!isDefined(dateValue)) {+ notSetGroups.push(item);continue;}@@ -171,5 +175,5 @@ export const fillDateGapsTwoDimensional = ({}),);- return { data: filledData, wasTruncated };+ return { data: [...filledData, ...notSetGroups], wasTruncated };};diff --git a/packages/twenty-server/src/modules/dashboard/chart-data/utils/fill-select-gaps.util.ts b/packages/twenty-server/src/modules/dashboard/chart-data/utils/fill-select-gaps.util.tsindex e2b3e491fa6..43e728b9cf2 100644--- a/packages/twenty-server/src/modules/dashboard/chart-data/utils/fill-select-gaps.util.ts+++ b/packages/twenty-server/src/modules/dashboard/chart-data/utils/fill-select-gaps.util.ts@@ -21,12 +21,15 @@ export const fillSelectGaps = ({}const existingGroupsMap = new Map<string, GroupByRawResult>();+ const notSetGroups: GroupByRawResult[] = [];for (const item of data) {const dimensionValue = item.groupByDimensionValues?.[0];if (isDefined(dimensionValue)) {existingGroupsMap.set(String(dimensionValue), item);+ } else {+ notSetGroups.push(item);}}@@ -43,7 +46,7 @@ export const fillSelectGaps = ({};});- return filledData;+ return [...filledData, ...notSetGroups];};type FillSelectGapsTwoDimensionalParams = {@@ -65,6 +68,7 @@ export const fillSelectGapsTwoDimensional = ({const existingGroupsMap = new Map<string, GroupByRawResult>();const uniqueSecondDimensionValues = new Set<unknown>();+ const notSetGroups: GroupByRawResult[] = [];for (const item of data) {const primaryValue = item.groupByDimensionValues?.[0];@@ -75,6 +79,8 @@ export const fillSelectGapsTwoDimensional = ({existingGroupsMap.set(key, item);uniqueSecondDimensionValues.add(secondaryValue);+ } else {+ notSetGroups.push(item);}}@@ -94,5 +100,5 @@ export const fillSelectGapsTwoDimensional = ({}),);- return filledData;+ return [...filledData, ...notSetGroups];};