Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update references to view in widget when view is renamed #239

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
* (bluefox) jQui Toggle icon widget was migrated to react

### 2.9.4 (2023-12-04)
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
Loading