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:
+11
@@ -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';
|
||||
};
|
||||
Reference in New Issue
Block a user