Skip to content

Commit

Permalink
Allow for discarding of changes without leaving (#9644)
Browse files Browse the repository at this point in the history
* Allow for discarding of changes without leaving

* Update to use v-if for consistency

* Fix boolean logic

* Allow disabling of options

* Remove unused disabled prop
  • Loading branch information
licitdev authored and rijkvanzanten committed Dec 1, 2021
1 parent 5b1eec5 commit 1c64648
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
7 changes: 7 additions & 0 deletions app/src/modules/content/routes/item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
@save-and-stay="saveAndStay"
@save-and-add-new="saveAndAddNew"
@save-as-copy="saveAsCopyAndNavigate"
@discard-and-stay="discardAndStay"
/>
</template>
</v-button>
Expand Down Expand Up @@ -386,6 +387,7 @@ export default defineComponent({
saveAndStay,
saveAndAddNew,
saveAsCopyAndNavigate,
discardAndStay,
templateData,
templateDataLoading,
archiveTooltip,
Expand Down Expand Up @@ -507,6 +509,11 @@ export default defineComponent({
router.push(leaveTo.value);
}
function discardAndStay() {
edits.value = {};
confirmLeave.value = false;
}
function revert(values: Record<string, any>) {
edits.value = {
...edits.value,
Expand Down
11 changes: 10 additions & 1 deletion app/src/modules/files/routes/item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@

<template #append-outer>
<save-options
v-if="hasEdits === true || saveAllowed === true"
v-if="hasEdits === true && saveAllowed === true"
:disabled-options="['save-and-add-new']"
@save-and-stay="saveAndStay"
@save-as-copy="saveAsCopyAndNavigate"
@discard-and-stay="discardAndStay"
/>
</template>
</v-button>
Expand Down Expand Up @@ -328,6 +330,7 @@ export default defineComponent({
deleting,
saveAndStay,
saveAsCopyAndNavigate,
discardAndStay,
isBatch,
editActive,
revisionsDrawerDetail,
Expand Down Expand Up @@ -411,9 +414,15 @@ export default defineComponent({
function discardAndLeave() {
if (!leaveTo.value) return;
edits.value = {};
confirmLeave.value = false;
router.push(leaveTo.value);
}
function discardAndStay() {
edits.value = {};
confirmLeave.value = false;
}
function downloadFile() {
const filePath = addTokenToURL(getRootPath() + `assets/${props.primaryKey}?download`);
window.open(filePath, '_blank');
Expand Down
9 changes: 8 additions & 1 deletion app/src/modules/settings/routes/webhooks/item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@

<template #append-outer>
<save-options
:disabled="hasEdits === false"
v-if="hasEdits === true"
@save-and-stay="saveAndStay"
@save-and-add-new="saveAndAddNew"
@save-as-copy="saveAsCopyAndNavigate"
@discard-and-stay="discardAndStay"
/>
</template>
</v-button>
Expand Down Expand Up @@ -178,6 +179,7 @@ export default defineComponent({
saveAndStay,
saveAndAddNew,
saveAsCopyAndNavigate,
discardAndStay,
isBatch,
title,
validationErrors,
Expand Down Expand Up @@ -217,6 +219,11 @@ export default defineComponent({
confirmLeave.value = false;
router.push(leaveTo.value);
}
function discardAndStay() {
edits.value = {};
confirmLeave.value = false;
}
},
});
</script>
Expand Down
8 changes: 8 additions & 0 deletions app/src/modules/users/routes/item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
@save-and-stay="saveAndStay"
@save-and-add-new="saveAndAddNew"
@save-as-copy="saveAsCopyAndNavigate"
@discard-and-stay="discardAndStay"
/>
</template>
</v-button>
Expand Down Expand Up @@ -343,6 +344,7 @@ export default defineComponent({
saveAndStay,
saveAndAddNew,
saveAsCopyAndNavigate,
discardAndStay,
isBatch,
revisionsDrawerDetail,
previewLoading,
Expand Down Expand Up @@ -492,9 +494,15 @@ export default defineComponent({
function discardAndLeave() {
if (!leaveTo.value) return;
edits.value = {};
confirmLeave.value = false;
router.push(leaveTo.value);
}
function discardAndStay() {
edits.value = {};
confirmLeave.value = false;
}
async function toggleArchive() {
await archive();
Expand Down
20 changes: 12 additions & 8 deletions app/src/views/private/components/save-options/save-options.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<template>
<v-menu show-arrow :disabled="disabled">
<v-menu show-arrow>
<template #activator="{ toggle }">
<v-icon :class="{ disabled }" name="more_vert" clickable @click="toggle" />
</template>

<v-list>
<v-list-item :disabled="disabled" clickable @click="$emit('save-and-stay')">
<v-list-item v-if="!disabledOptions.includes('save-and-stay')" clickable @click="$emit('save-and-stay')">
<v-list-item-icon><v-icon name="check" /></v-list-item-icon>
<v-list-item-content>{{ t('save_and_stay') }}</v-list-item-content>
<v-list-item-hint>{{ translateShortcut(['meta', 's']) }}</v-list-item-hint>
</v-list-item>
<v-list-item :disabled="disabled" clickable @click="$emit('save-and-add-new')">
<v-list-item v-if="!disabledOptions.includes('save-and-add-new')" clickable @click="$emit('save-and-add-new')">
<v-list-item-icon><v-icon name="add" /></v-list-item-icon>
<v-list-item-content>{{ t('save_and_create_new') }}</v-list-item-content>
<v-list-item-hint>{{ translateShortcut(['meta', 'shift', 's']) }}</v-list-item-hint>
</v-list-item>
<v-list-item :disabled="disabled" clickable @click="$emit('save-as-copy')">
<v-list-item v-if="!disabledOptions.includes('save-as-copy')" clickable @click="$emit('save-as-copy')">
<v-list-item-icon><v-icon name="done_all" /></v-list-item-icon>
<v-list-item-content>{{ t('save_as_copy') }}</v-list-item-content>
</v-list-item>
<v-list-item v-if="!disabledOptions.includes('discard-and-stay')" clickable @click="$emit('discard-and-stay')">
<v-list-item-icon><v-icon name="undo" /></v-list-item-icon>
<v-list-item-content>{{ t('discard_changes') }}</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>
</template>
Expand All @@ -30,12 +34,12 @@ import translateShortcut from '@/utils/translate-shortcut';
export default defineComponent({
props: {
disabled: {
type: Boolean,
default: false,
disabledOptions: {
type: Array,
default: () => [],
},
},
emits: ['save-and-stay', 'save-and-add-new', 'save-as-copy'],
emits: ['save-and-stay', 'save-and-add-new', 'save-as-copy', 'discard-and-stay'],
setup() {
const { t } = useI18n();
Expand Down

0 comments on commit 1c64648

Please sign in to comment.