Add configuration types for widgets (#14717)
closes https://github.com/twentyhq/core-team-issues/issues/1532
This commit is contained in:
+13
-6
@@ -1,9 +1,8 @@
|
||||
import { GraphType } from '@/page-layout/mocks/mockWidgets';
|
||||
import { getDefaultWidgetData } from '@/page-layout/utils/getDefaultWidgetData';
|
||||
import { ChartSkeletonLoader } from '@/page-layout/widgets/graph/components/ChartSkeletonLoader';
|
||||
import { GraphWidgetNumberChart } from '@/page-layout/widgets/graph/graphWidgetNumberChart/components/GraphWidgetNumberChart';
|
||||
import { type GraphWidget } from '@/page-layout/widgets/graph/types/GraphWidget';
|
||||
import { lazy, Suspense } from 'react';
|
||||
import { GraphType, type PageLayoutWidget } from '~/generated-metadata/graphql';
|
||||
|
||||
const GraphWidgetBarChart = lazy(() =>
|
||||
import(
|
||||
@@ -38,14 +37,22 @@ const GraphWidgetGaugeChart = lazy(() =>
|
||||
);
|
||||
|
||||
type GraphWidgetRendererProps = {
|
||||
widget: GraphWidget;
|
||||
widget: PageLayoutWidget;
|
||||
};
|
||||
|
||||
export const GraphWidgetRenderer = ({ widget }: GraphWidgetRendererProps) => {
|
||||
const graphType = widget.configuration?.graphType;
|
||||
if (!widget.configuration || !('graphType' in widget.configuration)) {
|
||||
throw new Error(
|
||||
`Invalid configuration for widget ${widget.id}: missing graphType`,
|
||||
);
|
||||
}
|
||||
|
||||
const graphType = widget.configuration.graphType;
|
||||
|
||||
if (!Object.values(GraphType).includes(graphType)) {
|
||||
return null;
|
||||
throw new Error(
|
||||
`Unsupported graph type ${graphType} for widget ${widget.id}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data: any = getDefaultWidgetData(graphType);
|
||||
@@ -54,7 +61,7 @@ export const GraphWidgetRenderer = ({ widget }: GraphWidgetRendererProps) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (graphType as GraphType) {
|
||||
switch (graphType) {
|
||||
case GraphType.NUMBER:
|
||||
return (
|
||||
<GraphWidgetNumberChart
|
||||
|
||||
Reference in New Issue
Block a user