Skip to content

Commit

Permalink
improve logic editor cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilReinking committed Oct 18, 2024
1 parent 564353d commit 809cdf6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ const isSaving = ref(false);
const { isShowingLogicEditor, block } = storeToRefs(store);
// on mount, backup the current logic to restore in case of cancel
store.backupLogic();
const save = async () => {
isSaving.value = true;
Expand All @@ -128,11 +131,13 @@ const save = async () => {
setTimeout(() => {
isSaving.value = false;
store.backupLogic();
store.hideLogicEditor();
}, 250);
};
const close = () => {
store.restoreLogic();
store.hideLogicEditor();
};
</script>
4 changes: 2 additions & 2 deletions resources/js/components/Factory/Sidebar/Storyboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
/>
</div>
</div>
<BlockLogicEdit />
<BlockLogicEditor />
</template>

<script setup lang="ts">
Expand All @@ -76,7 +76,7 @@ import BlockContainer from "./BlockContainer.vue";
import EmptyState from "@/components/EmptyState.vue";
import ScrollShadow from "@/components/ScrollShadow.vue";
import _throttle from "lodash/throttle";
import BlockLogicEdit from "@/components/Factory/Sidebar/BlockLogicEdit.vue";
import BlockLogicEditor from "@/components/Factory/Sidebar/BlockLogicEditor.vue";
const isLoaded = ref(false);
const store = useForm();
Expand Down
14 changes: 14 additions & 0 deletions resources/js/stores/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface LogicStore {
validation: ValidationError[];
isShowingLogicEditor: boolean;
hideRule: FormBlockLogic | null;
backup: FormBlockLogic[] | null;
}

export const operators: Array<{ key: Operator; label: string }> = [
Expand Down Expand Up @@ -44,6 +45,7 @@ export const useLogic = defineStore("logic", {
isShowingLogicEditor: false,
hideRule: null,
validation: [],
backup: null,
};
},

Expand All @@ -58,6 +60,18 @@ export const useLogic = defineStore("logic", {
this.isShowingLogicEditor = false;
},

backupLogic() {
this.backup = this.block?.logics ?? null;
},

restoreLogic() {
if (!this.block) {
return;
}

this.block.logics = this.backup ?? undefined;
},

addRule() {
if (!this.block) {
return;
Expand Down

0 comments on commit 809cdf6

Please sign in to comment.