Skip to content

Commit 72546ad

Browse files
committed
fix(files_versions): Migrate version name dialog from NcModal to NcDialog
* Resolves nextcloud/viewer#2390 Make the version name dialog a real dialog instead of a modal. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 003bf4b commit 72546ad

File tree

3 files changed

+121
-109
lines changed

3 files changed

+121
-109
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
<template>
6+
<NcDialog :buttons="dialogButtons"
7+
content-classes="version-label-modal"
8+
is-form
9+
:open="open"
10+
size="normal"
11+
:name="t('files_versions', 'Name this version')"
12+
@update:open="$emit('update:open', $event)"
13+
@submit="setVersionLabel(editedVersionLabel)">
14+
<NcTextField ref="labelInput"
15+
class="version-label-modal__input"
16+
:label="t('files_versions', 'Version name')"
17+
:placeholder="t('files_versions', 'Version name')"
18+
:value.sync="editedVersionLabel" />
19+
20+
<p class="version-label-modal__info">
21+
{{ t('files_versions', 'Named versions are persisted, and excluded from automatic cleanups when your storage quota is full.') }}
22+
</p>
23+
</NcDialog>
24+
</template>
25+
26+
<script lang="ts">
27+
import { t } from '@nextcloud/l10n'
28+
import { defineComponent } from 'vue'
29+
import svgCheck from '@mdi/svg/svg/check.svg?raw'
30+
31+
import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'
32+
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
33+
34+
type Focusable = Vue & { focus: () => void }
35+
36+
export default defineComponent({
37+
name: 'VersionLabelDialog',
38+
components: {
39+
NcDialog,
40+
NcTextField,
41+
},
42+
props: {
43+
open: {
44+
type: Boolean,
45+
default: false,
46+
},
47+
versionLabel: {
48+
type: String,
49+
default: '',
50+
},
51+
},
52+
data() {
53+
return {
54+
editedVersionLabel: '',
55+
}
56+
},
57+
computed: {
58+
dialogButtons() {
59+
return [
60+
{
61+
label: t('files_versions', 'Remove version name'),
62+
type: 'error',
63+
nativeType: 'reset',
64+
callback: () => { this.setVersionLabel('') },
65+
},
66+
{
67+
label: t('files_versions', 'Save version name'),
68+
type: 'primary',
69+
nativeType: 'submit',
70+
icon: svgCheck,
71+
},
72+
]
73+
},
74+
},
75+
watch: {
76+
versionLabel: {
77+
immediate: true,
78+
handler(label) {
79+
this.editedVersionLabel = label ?? ''
80+
},
81+
},
82+
open: {
83+
immediate: true,
84+
handler(open) {
85+
if (open) {
86+
this.$nextTick(() => (this.$refs.labelInput as Focusable).focus())
87+
}
88+
this.editedVersionLabel = this.versionLabel
89+
},
90+
},
91+
},
92+
methods: {
93+
setVersionLabel(label: string) {
94+
this.$emit('label-update', label)
95+
},
96+
97+
t,
98+
},
99+
})
100+
</script>
101+
102+
<style scoped lang="scss">
103+
.version-label-modal {
104+
&__info {
105+
color: var(--color-text-maxcontrast);
106+
margin-block: calc(3 * var(--default-grid-baseline));
107+
}
108+
109+
&__input {
110+
margin-block-start: calc(2 * var(--default-grid-baseline));
111+
}
112+
}
113+
</style>

apps/files_versions/src/components/VersionLabelForm.vue

Lines changed: 0 additions & 99 deletions
This file was deleted.

apps/files_versions/src/views/VersionTab.vue

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,34 @@
2828
</template>
2929
<NcLoadingIcon v-if="loading" slot="loader" class="files-list-viewer__loader" />
3030
</VirtualScrolling>
31-
<NcModal v-if="showVersionLabelForm"
32-
:title="t('files_versions', 'Name this version')"
33-
@close="showVersionLabelForm = false">
34-
<VersionLabelForm :version-label="editedVersion.label" @label-update="handleLabelUpdate" />
35-
</NcModal>
31+
<VersionLabelDialog v-if="editedVersion"
32+
:open.sync="showVersionLabelForm"
33+
:version-label="editedVersion.label"
34+
@label-update="handleLabelUpdate" />
3635
</div>
3736
</template>
3837

3938
<script>
4039
import path from 'path'
4140
4241
import { showError, showSuccess } from '@nextcloud/dialogs'
43-
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
4442
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
4543
import { getCurrentUser } from '@nextcloud/auth'
4644
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
47-
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
45+
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
4846
4947
import { fetchVersions, deleteVersion, restoreVersion, setVersionLabel } from '../utils/versions.ts'
5048
import Version from '../components/Version.vue'
5149
import VirtualScrolling from '../components/VirtualScrolling.vue'
52-
import VersionLabelForm from '../components/VersionLabelForm.vue'
50+
import VersionLabelDialog from '../components/VersionLabelDialog.vue'
5351
5452
export default {
5553
name: 'VersionTab',
5654
components: {
5755
Version,
5856
VirtualScrolling,
59-
VersionLabelForm,
57+
VersionLabelDialog,
6058
NcLoadingIcon,
61-
NcModal,
6259
},
6360
mixins: [
6461
isMobile,
@@ -71,6 +68,7 @@ export default {
7168
versions: [],
7269
loading: false,
7370
showVersionLabelForm: false,
71+
editedVersion: null,
7472
}
7573
},
7674
computed: {

0 commit comments

Comments
 (0)