16248 follow ups (#16262)
Follow ups on https://github.com/twentyhq/twenty/pull/16248
This commit is contained in:
+22
-15
@@ -1,7 +1,7 @@
|
||||
import { isNestedFieldDateType } from '@/page-layout/widgets/graph/utils/isNestedFieldDateType';
|
||||
import { isRelationNestedFieldDateKind } from '@/page-layout/widgets/graph/utils/isRelationNestedFieldDateKind';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
describe('isNestedFieldDateType', () => {
|
||||
describe('isRelationNestedFieldDateKind', () => {
|
||||
const companyObject = {
|
||||
id: 'company-id',
|
||||
nameSingular: 'company',
|
||||
@@ -19,25 +19,30 @@ describe('isNestedFieldDateType', () => {
|
||||
} as any;
|
||||
|
||||
it('returns true for a relation subfield that is a date type', () => {
|
||||
const result = isNestedFieldDateType(relationField, 'createdAt', [
|
||||
companyObject,
|
||||
]);
|
||||
|
||||
const result = isRelationNestedFieldDateKind({
|
||||
relationField: relationField,
|
||||
relationNestedFieldName: 'createdAt',
|
||||
objectMetadataItems: [companyObject],
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false when the nested subfield is not a date type', () => {
|
||||
const result = isNestedFieldDateType(relationField, 'name', [
|
||||
companyObject,
|
||||
]);
|
||||
const result = isRelationNestedFieldDateKind({
|
||||
relationField: relationField,
|
||||
relationNestedFieldName: 'name',
|
||||
objectMetadataItems: [companyObject],
|
||||
});
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false when subFieldName is missing', () => {
|
||||
const result = isNestedFieldDateType(relationField, undefined, [
|
||||
companyObject,
|
||||
]);
|
||||
const result = isRelationNestedFieldDateKind({
|
||||
relationField: relationField,
|
||||
relationNestedFieldName: undefined as string | undefined,
|
||||
objectMetadataItems: [companyObject],
|
||||
});
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
@@ -48,9 +53,11 @@ describe('isNestedFieldDateType', () => {
|
||||
type: FieldMetadataType.TEXT,
|
||||
} as any;
|
||||
|
||||
const result = isNestedFieldDateType(nonRelationField, 'createdAt', [
|
||||
companyObject,
|
||||
]);
|
||||
const result = isRelationNestedFieldDateKind({
|
||||
relationField: nonRelationField,
|
||||
relationNestedFieldName: 'createdAt',
|
||||
objectMetadataItems: [companyObject],
|
||||
});
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
import { type BarDatum } from '@nivo/bar';
|
||||
import { isNumber } from '@sniptt/guards';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
type ApplyCumulativeTransformToBarChartDataOptions = {
|
||||
@@ -18,7 +19,7 @@ export const applyCumulativeTransformToBarChartData = ({
|
||||
(accumulator, datum) => {
|
||||
const value = datum[aggregateKey];
|
||||
|
||||
if (typeof value === 'number') {
|
||||
if (isNumber(value)) {
|
||||
accumulator.runningTotal += value;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
import { type BarDatum } from '@nivo/bar';
|
||||
import { isNumber } from '@sniptt/guards';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
type ApplyCumulativeTransformToTwoDimensionalBarChartDataOptions = {
|
||||
@@ -24,7 +25,7 @@ export const applyCumulativeTransformToTwoDimensionalBarChartData = ({
|
||||
for (const key of keys) {
|
||||
const value = datum[key];
|
||||
|
||||
if (typeof value === 'number') {
|
||||
if (isNumber(value)) {
|
||||
accumulator.runningTotals[key] += value;
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -1,7 +1,7 @@
|
||||
import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { GRAPH_DEFAULT_DATE_GRANULARITY } from '@/page-layout/widgets/graph/constants/GraphDefaultDateGranularity.constant';
|
||||
import { getGroupByOrderBy } from '@/page-layout/widgets/graph/utils/getGroupByOrderBy';
|
||||
import { isNestedFieldDateType } from '@/page-layout/widgets/graph/utils/isNestedFieldDateType';
|
||||
import { isRelationNestedFieldDateKind } from '@/page-layout/widgets/graph/utils/isRelationNestedFieldDateKind';
|
||||
import {
|
||||
type AggregateOrderByWithGroupByField,
|
||||
type ObjectRecordOrderByForCompositeField,
|
||||
@@ -61,11 +61,11 @@ export const generateGroupByQueryVariablesFromBarOrLineChartConfiguration = ({
|
||||
|
||||
const isFieldXDate = isFieldMetadataDateKind(groupByFieldX.type);
|
||||
|
||||
const isFieldXNestedDate = isNestedFieldDateType(
|
||||
groupByFieldX,
|
||||
groupBySubFieldNameX,
|
||||
const isFieldXNestedDate = isRelationNestedFieldDateKind({
|
||||
relationField: groupByFieldX,
|
||||
relationNestedFieldName: groupBySubFieldNameX,
|
||||
objectMetadataItems,
|
||||
);
|
||||
});
|
||||
|
||||
const shouldApplyDateGranularityX = isFieldXDate || isFieldXNestedDate;
|
||||
|
||||
@@ -87,11 +87,11 @@ export const generateGroupByQueryVariablesFromBarOrLineChartConfiguration = ({
|
||||
if (isDefined(groupByFieldY)) {
|
||||
const isFieldYDate = isFieldMetadataDateKind(groupByFieldY.type);
|
||||
|
||||
const isFieldYNestedDate = isNestedFieldDateType(
|
||||
groupByFieldY,
|
||||
groupBySubFieldNameY,
|
||||
const isFieldYNestedDate = isRelationNestedFieldDateKind({
|
||||
relationField: groupByFieldY,
|
||||
relationNestedFieldName: groupBySubFieldNameY,
|
||||
objectMetadataItems,
|
||||
);
|
||||
});
|
||||
|
||||
const shouldApplyDateGranularityY = isFieldYDate || isFieldYNestedDate;
|
||||
|
||||
@@ -137,11 +137,11 @@ export const generateGroupByQueryVariablesFromBarOrLineChartConfiguration = ({
|
||||
) {
|
||||
const isFieldYDateForOrderBy = isFieldMetadataDateKind(groupByFieldY.type);
|
||||
|
||||
const isFieldYNestedDateForOrderBy = isNestedFieldDateType(
|
||||
groupByFieldY,
|
||||
groupBySubFieldNameY,
|
||||
const isFieldYNestedDateForOrderBy = isRelationNestedFieldDateKind({
|
||||
relationField: groupByFieldY,
|
||||
relationNestedFieldName: groupBySubFieldNameY,
|
||||
objectMetadataItems,
|
||||
);
|
||||
});
|
||||
|
||||
const shouldApplyDateGranularityYForOrderBy =
|
||||
isFieldYDateForOrderBy || isFieldYNestedDateForOrderBy;
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { GRAPH_DEFAULT_DATE_GRANULARITY } from '@/page-layout/widgets/graph/constants/GraphDefaultDateGranularity.constant';
|
||||
import { getGroupByOrderBy } from '@/page-layout/widgets/graph/utils/getGroupByOrderBy';
|
||||
import { isNestedFieldDateType } from '@/page-layout/widgets/graph/utils/isNestedFieldDateType';
|
||||
import { isRelationNestedFieldDateKind } from '@/page-layout/widgets/graph/utils/isRelationNestedFieldDateKind';
|
||||
import {
|
||||
type AggregateOrderByWithGroupByField,
|
||||
type ObjectRecordOrderByForCompositeField,
|
||||
@@ -48,11 +48,11 @@ export const generateGroupByQueryVariablesFromPieChartConfiguration = ({
|
||||
|
||||
const isFieldDate = isFieldMetadataDateKind(groupByField.type);
|
||||
|
||||
const isNestedDate = isNestedFieldDateType(
|
||||
groupByField,
|
||||
groupBySubFieldName,
|
||||
const isNestedDate = isRelationNestedFieldDateKind({
|
||||
relationField: groupByField,
|
||||
relationNestedFieldName: groupBySubFieldName,
|
||||
objectMetadataItems,
|
||||
);
|
||||
});
|
||||
|
||||
const shouldApplyDateGranularity = isFieldDate || isNestedDate;
|
||||
|
||||
|
||||
+13
-9
@@ -3,21 +3,25 @@ import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataI
|
||||
import { isFieldRelation } from '@/object-record/record-field/ui/types/guards/isFieldRelation';
|
||||
import { isDefined, isFieldMetadataDateKind } from 'twenty-shared/utils';
|
||||
|
||||
export const isNestedFieldDateType = (
|
||||
field: FieldMetadataItem,
|
||||
subFieldName: string | undefined,
|
||||
objectMetadataItems: ObjectMetadataItem[],
|
||||
): boolean => {
|
||||
if (!isDefined(subFieldName)) {
|
||||
export const isRelationNestedFieldDateKind = ({
|
||||
relationField,
|
||||
relationNestedFieldName,
|
||||
objectMetadataItems,
|
||||
}: {
|
||||
relationField: FieldMetadataItem;
|
||||
relationNestedFieldName: string | undefined;
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
}): boolean => {
|
||||
if (!isDefined(relationNestedFieldName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isFieldRelation(field)) {
|
||||
if (!isFieldRelation(relationField)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const targetObjectNameSingular =
|
||||
field.relation?.targetObjectMetadata?.nameSingular;
|
||||
relationField.relation?.targetObjectMetadata?.nameSingular;
|
||||
|
||||
if (!isDefined(targetObjectNameSingular)) {
|
||||
return false;
|
||||
@@ -31,7 +35,7 @@ export const isNestedFieldDateType = (
|
||||
return false;
|
||||
}
|
||||
|
||||
const nestedFieldName = subFieldName.split('.')[0];
|
||||
const nestedFieldName = relationNestedFieldName.split('.')[0];
|
||||
const nestedField = targetObjectMetadataItem.fields.find(
|
||||
(f) => f.name === nestedFieldName,
|
||||
);
|
||||
+9
-9
@@ -7,9 +7,9 @@ import { type LineChartSeries } from '@/page-layout/widgets/graph/graphWidgetLin
|
||||
import { type GroupByRawResult } from '@/page-layout/widgets/graph/types/GroupByRawResult';
|
||||
import { type RawDimensionValue } from '@/page-layout/widgets/graph/types/RawDimensionValue';
|
||||
import { filterGroupByResults } from '@/page-layout/widgets/graph/utils/filterGroupByResults';
|
||||
import { isRelationNestedFieldDateKind } from '@/page-layout/widgets/graph/utils/isRelationNestedFieldDateKind';
|
||||
import { transformOneDimensionalGroupByToLineChartData } from '@/page-layout/widgets/graph/utils/transformOneDimensionalGroupByToLineChartData';
|
||||
import { transformTwoDimensionalGroupByToLineChartData } from '@/page-layout/widgets/graph/utils/transformTwoDimensionalGroupByToLineChartData';
|
||||
import { isNestedFieldDateType } from '@/page-layout/widgets/graph/utils/isNestedFieldDateType';
|
||||
import { isDefined, isFieldMetadataDateKind } from 'twenty-shared/utils';
|
||||
import {
|
||||
AxisNameDisplay,
|
||||
@@ -127,11 +127,11 @@ export const transformGroupByDataToLineChartData = ({
|
||||
const showLegend = configuration.displayLegend ?? true;
|
||||
|
||||
const isDateField = isFieldMetadataDateKind(groupByFieldX.type);
|
||||
const isNestedDateField = isNestedFieldDateType(
|
||||
groupByFieldX,
|
||||
primaryAxisSubFieldName,
|
||||
const isNestedDateField = isRelationNestedFieldDateKind({
|
||||
relationField: groupByFieldX,
|
||||
relationNestedFieldName: primaryAxisSubFieldName,
|
||||
objectMetadataItems,
|
||||
);
|
||||
});
|
||||
|
||||
const primaryAxisDateGranularity =
|
||||
isDateField || isNestedDateField
|
||||
@@ -144,11 +144,11 @@ export const transformGroupByDataToLineChartData = ({
|
||||
|
||||
const isSecondaryNestedDateField =
|
||||
isDefined(groupByFieldY) &&
|
||||
isNestedFieldDateType(
|
||||
groupByFieldY,
|
||||
secondaryAxisSubFieldName,
|
||||
isRelationNestedFieldDateKind({
|
||||
relationField: groupByFieldY,
|
||||
relationNestedFieldName: secondaryAxisSubFieldName,
|
||||
objectMetadataItems,
|
||||
);
|
||||
});
|
||||
|
||||
const secondaryAxisDateGranularity =
|
||||
isSecondaryDateField || isSecondaryNestedDateField
|
||||
|
||||
Reference in New Issue
Block a user