Create fields widget (#16403)
https://github.com/user-attachments/assets/b150815a-5d54-4d4a-b984-20dcf7b29aa7
This commit is contained in:
committed by
GitHub
parent
7b98804ec1
commit
fd54a2af5c
+2
-4
@@ -1,10 +1,8 @@
|
||||
import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import {
|
||||
type PageLayoutWidget,
|
||||
type RatioAggregateConfig,
|
||||
} from '~/generated/graphql';
|
||||
import { type RatioAggregateConfig } from '~/generated/graphql';
|
||||
|
||||
const fieldExists = (
|
||||
fieldId: string | undefined | null,
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
|
||||
import { assertIsDefinedOrThrow } from 'twenty-shared/utils';
|
||||
import { type AggregateChartConfiguration } from '~/generated/graphql';
|
||||
|
||||
type AssertAggregateChartWidgetOrThrow = (
|
||||
widget: PageLayoutWidget,
|
||||
) => asserts widget is PageLayoutWidget & {
|
||||
objectMetadataId: string;
|
||||
configuration: AggregateChartConfiguration;
|
||||
};
|
||||
|
||||
export const assertAggregateChartWidgetOrThrow: AssertAggregateChartWidgetOrThrow =
|
||||
(widget: PageLayoutWidget) => {
|
||||
assertIsDefinedOrThrow(
|
||||
widget.objectMetadataId,
|
||||
new Error('Widget objectMetadataId is required'),
|
||||
);
|
||||
|
||||
if (widget.configuration?.__typename !== 'AggregateChartConfiguration') {
|
||||
throw new Error(
|
||||
`Expected AggregateChartConfiguration but got ${widget.configuration?.__typename}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
|
||||
import { assertIsDefinedOrThrow } from 'twenty-shared/utils';
|
||||
import { type BarChartConfiguration } from '~/generated/graphql';
|
||||
|
||||
type AssertBarChartWidgetOrThrow = (
|
||||
widget: PageLayoutWidget,
|
||||
) => asserts widget is PageLayoutWidget & {
|
||||
objectMetadataId: string;
|
||||
configuration: BarChartConfiguration;
|
||||
};
|
||||
|
||||
export const assertBarChartWidgetOrThrow: AssertBarChartWidgetOrThrow = (
|
||||
widget: PageLayoutWidget,
|
||||
) => {
|
||||
assertIsDefinedOrThrow(
|
||||
widget.objectMetadataId,
|
||||
new Error('Widget objectMetadataId is required'),
|
||||
);
|
||||
|
||||
if (widget.configuration?.__typename !== 'BarChartConfiguration') {
|
||||
throw new Error(
|
||||
`Expected BarChartConfiguration but got ${widget.configuration?.__typename}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
|
||||
import { assertIsDefinedOrThrow } from 'twenty-shared/utils';
|
||||
import { type LineChartConfiguration } from '~/generated/graphql';
|
||||
|
||||
type AssertLineChartWidgetOrThrow = (
|
||||
widget: PageLayoutWidget,
|
||||
) => asserts widget is PageLayoutWidget & {
|
||||
objectMetadataId: string;
|
||||
configuration: LineChartConfiguration;
|
||||
};
|
||||
|
||||
export const assertLineChartWidgetOrThrow: AssertLineChartWidgetOrThrow = (
|
||||
widget: PageLayoutWidget,
|
||||
) => {
|
||||
assertIsDefinedOrThrow(
|
||||
widget.objectMetadataId,
|
||||
new Error('Widget objectMetadataId is required'),
|
||||
);
|
||||
|
||||
if (widget.configuration?.__typename !== 'LineChartConfiguration') {
|
||||
throw new Error(
|
||||
`Expected LineChartConfiguration but got ${widget.configuration?.__typename}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
|
||||
import { assertIsDefinedOrThrow } from 'twenty-shared/utils';
|
||||
import { type PieChartConfiguration } from '~/generated/graphql';
|
||||
|
||||
type AssertPieChartWidgetOrThrow = (
|
||||
widget: PageLayoutWidget,
|
||||
) => asserts widget is PageLayoutWidget & {
|
||||
objectMetadataId: string;
|
||||
configuration: PieChartConfiguration;
|
||||
};
|
||||
|
||||
export const assertPieChartWidgetOrThrow: AssertPieChartWidgetOrThrow = (
|
||||
widget: PageLayoutWidget,
|
||||
) => {
|
||||
assertIsDefinedOrThrow(
|
||||
widget.objectMetadataId,
|
||||
new Error('Widget objectMetadataId is required'),
|
||||
);
|
||||
|
||||
if (widget.configuration?.__typename !== 'PieChartConfiguration') {
|
||||
throw new Error(
|
||||
`Expected PieChartConfiguration but got ${widget.configuration?.__typename}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user