Skip to content

Commit

Permalink
Merge pull request #1549 from merico-dev/1548-when-deleting-a-view-it…
Browse files Browse the repository at this point in the history
…s-panels-are-deleted-but-not-their-layouts

1548 when deleting a view its panels are deleted but not their layouts
  • Loading branch information
GerilLeto authored Sep 30, 2024
2 parents 2fa3339 + b27fd13 commit dc067d5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/api",
"version": "13.42.3",
"version": "13.42.4",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/dashboard",
"version": "13.42.3",
"version": "13.42.4",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
5 changes: 5 additions & 0 deletions dashboard/src/dashboard-editor/model/layouts/layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export const LayoutsModel = types
layoutSet.removeByPanelID(panelID);
});
},
removeByPanelIDs(panelIDs: string[]) {
self.list.forEach((layoutSet) => {
layoutSet.removeByPanelIDs(panelIDs);
});
},
setCurrentLayoutWrapperWidth(v: number) {
self.currentLayoutWrapperWidth = v;
},
Expand Down
16 changes: 13 additions & 3 deletions dashboard/src/dashboard-editor/model/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PanelsModelInstance } from '../panels';

import { ViewDivisionConfigSnapshotIn, ViewMetaInstance, ViewModalConfigSnapshotIn } from '~/model';
import { ViewModel, ViewModelInstance } from './view';
import { LayoutsModelInstance } from '../layouts';

export const ViewsModel = types
.compose(
Expand Down Expand Up @@ -45,13 +46,20 @@ export const ViewsModel = types
} as const),
);
},
get contentModel() {
// @ts-expect-error getRoot type, reading panels
return getRoot(self).content;
},
}))
.actions((self) => ({
setIDOfVIE(id: string) {
self.idOfVIE = id;
self.visibleViewIDs.length = 0;
self.visibleViewIDs.push(id);
},
resetIDOfVIE() {
this.setIDOfVIE(self.current[0].id);
},
replace(current: Array<ViewRenderModelInstance>) {
self.current.replace(current);
},
Expand Down Expand Up @@ -88,11 +96,13 @@ export const ViewsModel = types
return;
}
const view = self.current[index];
// @ts-expect-error getRoot type, reading panels
const panels: PanelsModelInstance = getRoot(self).content.panels;
const panels: PanelsModelInstance = self.contentModel.panels;
const layouts: LayoutsModelInstance = self.contentModel.layouts;

panels.removeByIDs(view.panelIDs);
layouts.removeByPanelIDs(view.panelIDs);
self.current.splice(index, 1);
this.resetIDOfVIE();
},
replaceByIndex(index: number, replacement: ViewRenderModelInstance) {
self.current.splice(index, 1, replacement);
Expand All @@ -109,7 +119,7 @@ export const ViewsModel = types
return;
}
this.removeByID(self.idOfVIE);
this.setIDOfVIE(self.current[0].id);
this.resetIDOfVIE();
},
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ export const LayoutSetMeta = types
self.list.splice(i, 1);
}
},
removeByPanelIDs(panelIDs: string[]) {
while (panelIDs.length > 0) {
const id = panelIDs.pop();
if (id) {
this.removeByPanelID(id);
}
}
},
updateLayoutItem(item: Layout) {
const layoutItem = self.list.find((o) => o.id === item.i);
if (!layoutItem) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/root",
"version": "13.42.3",
"version": "13.42.4",
"private": true,
"workspaces": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion settings-form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/settings-form",
"version": "13.42.3",
"version": "13.42.4",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@devtable/website",
"private": true,
"license": "Apache-2.0",
"version": "13.42.3",
"version": "13.42.4",
"scripts": {
"dev": "vite",
"preview": "vite preview"
Expand Down

0 comments on commit dc067d5

Please sign in to comment.