Skip to content

Commit

Permalink
Fix: applying a new view while looking at it
Browse files Browse the repository at this point in the history
  • Loading branch information
jobelenus committed Dec 20, 2024
1 parent 7a8bc8b commit 06aeb98
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
22 changes: 20 additions & 2 deletions app/web/src/pages/WorkspaceSinglePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ import {
VormInput,
} from "@si/vue-lib/design-system";
import { useChangeSetsStore } from "@/store/change_sets.store";
import { useViewsStore } from "@/store/views.store";
import { useWorkspacesStore } from "@/store/workspaces.store";
import { useAuthStore } from "@/store/auth.store";
import AppLayout from "@/components/layout/AppLayout.vue";
Expand Down Expand Up @@ -191,13 +192,30 @@ function handleUrlChange() {
const changeSetId = route.params.changeSetId as string | undefined;
if ([undefined, "null", "undefined", "auto"].includes(changeSetId ?? "")) {
const id = changeSetsStore.getAutoSelectedChangeSetId();
const newChangeSetId =
id === false || id === changeSetsStore.headChangeSetId ? "head" : id;
const viewId = route.params.viewId as string | undefined;
if (viewId) {
const viewStore = useViewsStore(newChangeSetId);
if (!viewStore.viewsById[viewId]) {
delete route.params.viewId;
const defaultView =
viewStore.viewList.find((v) => v.id === viewId) ||
viewStore.viewList[0];
if (viewStore.outlinerViewId === viewId)
viewStore.outlinerViewId = defaultView?.id ?? null;
if (viewStore.selectedViewId === viewId)
if (defaultView?.id) viewStore.selectView(defaultView.id);
else viewStore.clearSelectedView();
}
}
router.replace({
name: route.name, // eslint-disable-line @typescript-eslint/no-non-null-assertion
params: {
...route.params,
changeSetId:
id === false || id === changeSetsStore.headChangeSetId ? "head" : id,
changeSetId: newChangeSetId,
},
query: { ...route.query },
});
Expand Down
7 changes: 7 additions & 0 deletions app/web/src/store/views.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,13 @@ export const useViewsStore = (forceChangeSetId?: ChangeSetId) => {
// to begin, and then adjust it via delta when things move
this.sockets = view.sockets;
},
clearSelectedView() {
this.selectedViewId = null;
this.sockets = {};
this.components = {};
this.groups = {};
this.viewNodes = {};
},
async selectView(id: ViewId) {
const view = this.viewsById[id];
if (view) {
Expand Down

0 comments on commit 06aeb98

Please sign in to comment.