|
| 1 | +<!-- |
| 2 | + SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | +--> |
| 5 | +<template> |
| 6 | + <div class="permission-editor"> |
| 7 | + <!-- Cap notice: shown when some permissions are not grantable --> |
| 8 | + <NcNoteCard v-if="notice" type="info"> |
| 9 | + {{ notice }} |
| 10 | + </NcNoteCard> |
| 11 | + |
| 12 | + <NcSelect |
| 13 | + :modelValue="selectedPreset" |
| 14 | + :clearable="false" |
| 15 | + :searchable="false" |
| 16 | + :inputLabel="presetLabel" |
| 17 | + :hideLabel="hideLabel" |
| 18 | + :options="presetOptions" |
| 19 | + class="permission-editor__preset" |
| 20 | + :placeholder="t('Custom permissions')" |
| 21 | + @update:modelValue="(option) => emit('presetChange', option)" /> |
| 22 | + |
| 23 | + <!-- Fine-grained toggles, shown while the custom entry is selected --> |
| 24 | + <Transition name="expand"> |
| 25 | + <div v-if="showPermissions" ref="permissionsEl" class="permission-editor__permissions"> |
| 26 | + <div class="permission-editor__permissions-inner"> |
| 27 | + <NcFormBox> |
| 28 | + <NcFormBoxSwitch |
| 29 | + v-for="permission in permissions" |
| 30 | + :key="permission.class" |
| 31 | + :label="permission.display_name" |
| 32 | + :description="permission.hint ?? undefined" |
| 33 | + :disabled="permission.available === false" |
| 34 | + :error="permissionErrors[permission.class]" |
| 35 | + :modelValue="permission.enabled" |
| 36 | + @update:modelValue="(enabled) => emit('permissionToggle', permission, enabled)" /> |
| 37 | + </NcFormBox> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + </Transition> |
| 41 | + |
| 42 | + <NcNoteCard v-if="presetError" type="error"> |
| 43 | + {{ presetError }} |
| 44 | + </NcNoteCard> |
| 45 | + </div> |
| 46 | +</template> |
| 47 | + |
| 48 | +<script setup lang="ts"> |
| 49 | +import type { PresetOption } from '../composables/useRecipientPermissions.ts' |
| 50 | +import type { SharingPermission } from '../types/api.ts' |
| 51 | +
|
| 52 | +import { nextTick, ref, watch } from 'vue' |
| 53 | +import NcFormBox from '@nextcloud/vue/components/NcFormBox' |
| 54 | +import NcFormBoxSwitch from '@nextcloud/vue/components/NcFormBoxSwitch' |
| 55 | +import NcNoteCard from '@nextcloud/vue/components/NcNoteCard' |
| 56 | +import NcSelect from '@nextcloud/vue/components/NcSelect' |
| 57 | +import { t } from '../utils/l10n.ts' |
| 58 | +
|
| 59 | +/** A permission toggle; `available === false` disables it (over the cap). */ |
| 60 | +export type EditablePermission = SharingPermission & { available?: boolean } |
| 61 | +
|
| 62 | +const props = withDefaults(defineProps<{ |
| 63 | + /** Preset dropdown options */ |
| 64 | + presetOptions: PresetOption[] |
| 65 | + /** The currently selected preset option */ |
| 66 | + selectedPreset: PresetOption | null |
| 67 | + /** Whether the fine-grained toggles are shown (custom preset) */ |
| 68 | + showPermissions: boolean |
| 69 | + /** The permission toggles */ |
| 70 | + permissions: EditablePermission[] |
| 71 | + /** Backend errors per permission class */ |
| 72 | + permissionErrors?: Record<string, string> |
| 73 | + /** Backend error for the preset selection */ |
| 74 | + presetError?: string | null |
| 75 | + /** Info notice shown above the editor (e.g. the permission cap) */ |
| 76 | + notice?: string | null |
| 77 | + /** Label for the preset select */ |
| 78 | + presetLabel?: string |
| 79 | + /** Hide the preset select label */ |
| 80 | + hideLabel?: boolean |
| 81 | +}>(), { |
| 82 | + permissionErrors: () => ({}), |
| 83 | + presetError: null, |
| 84 | + notice: null, |
| 85 | + presetLabel: undefined, |
| 86 | + hideLabel: false, |
| 87 | +}) |
| 88 | +
|
| 89 | +const emit = defineEmits<{ |
| 90 | + (e: 'presetChange', option: PresetOption | null): void |
| 91 | + (e: 'permissionToggle', permission: SharingPermission, enabled: boolean): void |
| 92 | +}>() |
| 93 | +
|
| 94 | +const permissionsEl = ref<HTMLElement | null>(null) |
| 95 | +
|
| 96 | +// Reveal the toggles once they appear, they are below the fold in the dialog. |
| 97 | +watch(() => props.showPermissions, async (shown) => { |
| 98 | + if (!shown) { |
| 99 | + return |
| 100 | + } |
| 101 | + await nextTick() |
| 102 | + permissionsEl.value?.scrollIntoView({ behavior: 'smooth', block: 'nearest' }) |
| 103 | +}) |
| 104 | +</script> |
| 105 | + |
| 106 | +<style scoped lang="scss"> |
| 107 | +.permission-editor { |
| 108 | + display: flex; |
| 109 | + flex-direction: column; |
| 110 | + gap: calc(var(--default-grid-baseline) * 3); |
| 111 | +
|
| 112 | + &__permissions { |
| 113 | + display: grid; |
| 114 | + grid-template-rows: 1fr; |
| 115 | + } |
| 116 | +
|
| 117 | + &__permissions-inner { |
| 118 | + overflow: hidden; |
| 119 | + } |
| 120 | +} |
| 121 | +
|
| 122 | +.expand-enter-active, |
| 123 | +.expand-leave-active { |
| 124 | + transition: grid-template-rows 0.2s ease-in-out; |
| 125 | +} |
| 126 | +
|
| 127 | +.expand-enter-from, |
| 128 | +.expand-leave-to { |
| 129 | + grid-template-rows: 0fr; |
| 130 | +} |
| 131 | +
|
| 132 | +@media (prefers-reduced-motion: reduce) { |
| 133 | + .expand-enter-active, |
| 134 | + .expand-leave-active { |
| 135 | + transition: none; |
| 136 | + } |
| 137 | +} |
| 138 | +</style> |
0 commit comments