Skip to content

Commit

Permalink
scopePointerStore always checks for existing scope
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Nov 7, 2023
1 parent bbd004d commit 901e3bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions client/src/components/Workflow/Editor/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,12 @@ export default {
const response = await axios.post(`${getAppRoot()}workflow/save_workflow_as`, formData);
const newId = response.data;
if (!create) {
this.name = rename_name;
this.annotation = rename_annotation;
}
this.hasChanges = false;
await this.routeToWorkflow(newId);
} catch (e) {
this.onWorkflowError("Saving workflow failed, please contact an administrator.");
Expand Down Expand Up @@ -575,18 +581,9 @@ export default {
this.onUpdateStep(step);
},
async routeToWorkflow(id) {
const { addScopePointer, scope } = useScopePointerStore();
let pointedTo;
// the current workflow id might be pointing to existing stores
const originalPointed = scope(this.id);
if (originalPointed !== this.id) {
pointedTo = originalPointed;
} else {
pointedTo = this.id;
}
// map scoped stores to existing stores, before updating the id
addScopePointer(id, pointedTo);
const { addScopePointer } = useScopePointerStore();
addScopePointer(id, this.id);
this.id = id;
await this.onSave();
Expand Down Expand Up @@ -618,7 +615,6 @@ export default {
await this.routeToWorkflow(id);
} else {
// otherwise, use `save_as` endpoint to include steps, etc.
this.hasChanges = false;
await this.doSaveAs(true);
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/stores/scopePointerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useScopePointerStore = defineStore("scopePointerStore", () => {
const scopePointers = ref<Record<FromScopeId, ToScopeId | undefined>>({});

function addScopePointer(from: FromScopeId, to: ToScopeId) {
scopePointers.value[from] = to;
scopePointers.value[from] = scope.value(to);
}

const scope = computed(() => (scopeId: string) => scopePointers.value[scopeId] ?? scopeId);
Expand Down

0 comments on commit 901e3bb

Please sign in to comment.