Skip to content

Commit

Permalink
update references to view in widget when view is renamed
Browse files Browse the repository at this point in the history
- closes #118
  • Loading branch information
foxriver76 committed Dec 5, 2023
1 parent a574c2c commit d8eed9a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

### 2.9.4 (2023-12-04)
* (foxriver76) fixed issues with display width
Expand Down
51 changes: 47 additions & 4 deletions src/src/Toolbar/ViewsManager/ViewDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d8eed9a

Please sign in to comment.