diff --git a/src/components/Dashboard/Tiles/Widgets/WidgetsEditModal.tsx b/src/components/Dashboard/Tiles/Widgets/WidgetsEditModal.tsx index d28d5cf44..b5714c805 100644 --- a/src/components/Dashboard/Tiles/Widgets/WidgetsEditModal.tsx +++ b/src/components/Dashboard/Tiles/Widgets/WidgetsEditModal.tsx @@ -24,6 +24,7 @@ import { useColorTheme } from '../../../../tools/color'; export type WidgetEditModalInnerProps = { widgetId: string; options: IWidget['properties']; + widgetOptions: IWidget['properties']; }; type IntegrationOptionsValueType = IWidget['properties'][string]; @@ -35,7 +36,11 @@ export const WidgetsEditModal = ({ }: ContextModalProps) => { const { t } = useTranslation([`modules/${innerProps.widgetId}`, 'common']); const [moduleProperties, setModuleProperties] = useState(innerProps.options); - const items = Object.entries(moduleProperties ?? {}) as [string, IntegrationOptionsValueType][]; + // const items = Object.entries(moduleProperties ?? {}) as [string, IntegrationOptionsValueType][]; + const items = Object.entries(innerProps.widgetOptions ?? {}) as [ + string, + IntegrationOptionsValueType + ][]; // Find the Key in the "Widgets" Object that matches the widgetId const currentWidgetDefinition = Widgets[innerProps.widgetId as keyof typeof Widgets]; @@ -79,8 +84,9 @@ export const WidgetsEditModal = ({ return ( - {items.map(([key, value], index) => { + {items.map(([key, defaultValue], index) => { const option = (currentWidgetDefinition as any).options[key] as IWidgetOptionValue; + const value = moduleProperties[key] ?? defaultValue; if (!option) { return ( @@ -176,7 +182,6 @@ function WidgetOptionTypeSwitch( { const { t } = useTranslation(`modules/${integration}`); if (!widget) return null; + // Match widget.id with WidgetsDefinitions + // First get the keys + const keys = Object.keys(WidgetsDefinitions); + // Then find the key that matches the widget.id + const widgetDefinition = keys.find((key) => key === widget.id); + // Then get the widget definition + const widgetDefinitionObject = + WidgetsDefinitions[widgetDefinition as keyof typeof WidgetsDefinitions]; const handleDeleteClick = () => { openContextModalGeneric({ @@ -50,6 +59,8 @@ export const WidgetsMenu = ({ integration, widget }: WidgetsMenuProps) => { innerProps: { widgetId: integration, options: widget.properties, + // Cast as the right type for the correct widget + widgetOptions: widgetDefinitionObject.options as any, }, }); };