Create typeguards for widget configurations (#16627)

We checked for widget types by doing `configuration?.__typename ===
'LineChartConfiguration'` which made the code difficult to read.

In this PR, I introduce type guards for each widget type.

Note: the configuration type is `WidgetConfiguration |
FieldsConfiguration` for now but should be changed to
`WidgetConfiguration` when @Devessier adds FieldsConfiguration to the
backend type `WidgetConfiguration`.
This commit is contained in:
Raphaël Bosi
2025-12-17 17:48:34 +01:00
committed by GitHub
parent a560e8ac83
commit b0e256221a
40 changed files with 530 additions and 135 deletions
@@ -0,0 +1,11 @@
import { type FieldsConfiguration } from '@/page-layout/types/FieldsConfiguration';
import {
type LineChartConfiguration,
type WidgetConfiguration,
} from '~/generated/graphql';
export const isLineChartConfiguration = (
configuration: WidgetConfiguration | FieldsConfiguration | null | undefined,
): configuration is LineChartConfiguration => {
return configuration?.__typename === 'LineChartConfiguration';
};