diff --git a/README.md b/README.md index 85d82ff6..3e43df09 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,7 @@ E.g., if it was used in a menu and the menu is red, the circle would be red. ## Changelog ### **WORK IN PROGRESS** * (foxriver76) fixed crash case if signals are used +* (foxriver76) update references to view in widget when view is renamed * (bluefox) jQui Toggle icon widget was migrated to react ### 2.9.4 (2023-12-04) diff --git a/src/src/Toolbar/ViewsManager/ViewDialog.tsx b/src/src/Toolbar/ViewsManager/ViewDialog.tsx index 335fffd3..8cca833a 100644 --- a/src/src/Toolbar/ViewsManager/ViewDialog.tsx +++ b/src/src/Toolbar/ViewsManager/ViewDialog.tsx @@ -66,11 +66,54 @@ const ViewDialog = (props: ViewDialogProps) => { props.dialogCallback?.cb(props.dialogName); }; + interface RenameReferencesOptions { + /** The project to rename references in */ + project: Project; + /** The view name to rename */ + oldViewName: string; + } + + /** + * Rename the references to this view + * This currently affects View in Widget (8) + * + * @param options the project to rename the references in and the old view name + */ + const renameReferences = (options: RenameReferencesOptions) => { + const { project, oldViewName } = options; + + for (const [viewName, view] of Object.entries(project)) { + if (viewName === '___settings') { + continue; + } + + for (const widget of Object.values(view.widgets)) { + if (widget.tpl === 'tplContainerView') { + if (widget.data.contains_view === oldViewName) { + widget.data.contains_view = props.dialogName; + } + } + + if (widget.tpl === 'tplStatefulContainerView8') { + for (const [key, val] of Object.entries(widget.data)) { + if (key.startsWith('contains_view') && val === oldViewName) { + widget.data[key] = props.dialogName; + } + } + } + } + } + }; + const renameView = async () => { - const view = props.dialogView || props.selectedView; - const project = JSON.parse(JSON.stringify(store.getState().visProject)); - project[props.dialogName] = project[view]; - delete project[view]; + const oldViewName = props.dialogView || props.selectedView; + const project = deepClone(store.getState().visProject); + project[props.dialogName] = project[oldViewName]; + delete project[oldViewName]; + + // Rename view where applicable + renameReferences({ project, oldViewName }); + await props.changeProject(project); await props.changeView(props.dialogName); props.setDialog(null);