Skip to content

Commit

Permalink
Fix flows editing existing operations (#13713)
Browse files Browse the repository at this point in the history
* Use immediate watcher instead of prop based ref default val

Fixes #13702

* Make it happy

* I'll be damned, it wasn't my stupidity after all
  • Loading branch information
rijkvanzanten committed Jun 3, 2022
1 parent 2f8c9ac commit 96f2da5
Show file tree
Hide file tree
Showing 5 changed files with 2,994 additions and 1,160 deletions.
18 changes: 9 additions & 9 deletions app/package.json
Expand Up @@ -70,8 +70,8 @@
"@types/ms": "0.7.31",
"@types/qrcode": "1.4.1",
"@types/wellknown": "0.5.1",
"@vitejs/plugin-vue": "1.10.0",
"@vue/compiler-sfc": "3.2.22",
"@vitejs/plugin-vue": "2.3.3",
"@vue/compiler-sfc": "3.2.36",
"apexcharts": "3.30.0",
"axios": "0.24.0",
"base-64": "1.0.0",
Expand All @@ -97,20 +97,20 @@
"mitt": "3.0.0",
"nanoid": "3.1.30",
"p-queue": "7.1.0",
"pinia": "2.0.4",
"pinia": "2.0.14",
"prettier": "2.4.1",
"pretty-ms": "7.0.1",
"qrcode": "1.4.4",
"rimraf": "3.0.2",
"sass": "1.43.4",
"tinymce": "5.10.2",
"ts-jest": "27.1.3",
"typescript": "4.5.2",
"vite": "2.6.14",
"vite-plugin-md": "0.11.4",
"vue": "3.2.22",
"vue-i18n": "9.1.9",
"vue-router": "4.0.12",
"typescript": "4.7.3",
"vite": "2.9.9",
"vite-plugin-md": "0.14.0",
"vue": "3.2.36",
"vue-i18n": "9.1.10",
"vue-router": "4.0.15",
"vuedraggable": "4.1.0",
"wellknown": "0.5.0"
}
Expand Down
12 changes: 9 additions & 3 deletions app/src/composables/use-edits-guard/use-edits-guard.ts
@@ -1,7 +1,11 @@
import { ref, Ref, onBeforeMount, onBeforeUnmount } from 'vue';
import { ref, Ref, onBeforeMount, onBeforeUnmount, unref } from 'vue';
import { onBeforeRouteUpdate, onBeforeRouteLeave, NavigationGuard, useRoute } from 'vue-router';

export function useEditsGuard(hasEdits: Ref<boolean>) {
type EditsGuardOptions = {
ignorePrefix?: string | Ref<string>;
};

export function useEditsGuard(hasEdits: Ref<boolean>, opts?: EditsGuardOptions) {
const { path } = useRoute();

const confirmLeave = ref(false);
Expand All @@ -16,7 +20,9 @@ export function useEditsGuard(hasEdits: Ref<boolean>) {
};

const editsGuard: NavigationGuard = (to) => {
if (hasEdits.value && !to.path.startsWith(path)) {
const matchesPathPrefix = opts?.ignorePrefix ? to.path.startsWith(unref(opts.ignorePrefix)) : false;

if (hasEdits.value && !to.path.startsWith(path) && !matchesPathPrefix) {
confirmLeave.value = true;
leaveTo.value = to.fullPath;
return false;
Expand Down
Expand Up @@ -100,6 +100,7 @@ const options = ref<Record<string, any>>(props.operation?.options ?? {});
const operationType = ref<string | undefined>(props.operation?.type);
const operationKey = ref<string | null>(props.operation?.key ?? null);
const operationName = ref<string | null>(props.operation?.name ?? null);
const saving = ref(false);
const isOperationKeyUnique = computed(
Expand All @@ -113,6 +114,19 @@ const saveDisabled = computed(() => {
return !operationType.value || !isOperationKeyUnique.value;
});
watch(
() => props.operation,
(operation) => {
if (!operation) return;
options.value = operation.options;
operationType.value = operation.type;
operationKey.value = operation.key;
operationName.value = operation.name;
},
{ immediate: true, deep: true }
);
watch(operationType, () => {
options.value = {};
});
Expand Down
12 changes: 10 additions & 2 deletions app/src/modules/settings/routes/flows/flow.vue
Expand Up @@ -168,7 +168,7 @@
</v-dialog>
<router-view
:operation="panels.find((panel) => panel.id === props.operationId)"
:operation="currentOperation"
:existing-operation-keys="exitingOperationKeys"
:flow="flow"
@save="stageOperation"
Expand Down Expand Up @@ -316,6 +316,12 @@ const panels = computed(() => {
return panels;
});
const currentOperation = computed(() => {
return panels.value.find((panel) => {
return panel.id === props.operationId;
});
});
const parentPanels = computed(() => {
const parents = panels.value.reduce<Record<string, ParentInfo>>((acc, panel) => {
if (panel.resolve)
Expand Down Expand Up @@ -649,7 +655,9 @@ function getNearAttachment(pos: Vector2) {
const hasEdits = computed(() => stagedPanels.value.length > 0 || panelsToBeDeleted.value.length > 0);
const { confirmLeave, leaveTo } = useEditsGuard(hasEdits);
const { confirmLeave, leaveTo } = useEditsGuard(hasEdits, {
ignorePrefix: computed(() => `/settings/flows/${props.primaryKey}/`),
});
const confirmCancel = ref(false);
Expand Down

0 comments on commit 96f2da5

Please sign in to comment.