feat(admin): footer record actions, deletable flag, mail row states and diff styles
- FormView footer RecordActions when there is no preview; meta.deletable hides Delete - Partial fields reload after save and record actions; customized/outdated badges - .summer-diff kit and docs for codeeditor, mailpreview and footer actions Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,7 +4,15 @@ import { onBeforeRouteLeave, onBeforeRouteUpdate, useRoute, useRouter } from 'vu
|
||||
import { ArrowLeft, Trash2 } from '@lucide/vue'
|
||||
import { api } from '../api/client'
|
||||
import { parentFileRoutes } from '../api/files'
|
||||
import type { AdminRecord, ErrorEnvelope, FormView, RecordEnvelope, RecordMeta, RelationOption } from '../api/types'
|
||||
import type {
|
||||
AdminRecord,
|
||||
ErrorEnvelope,
|
||||
FormView,
|
||||
RecordAction,
|
||||
RecordEnvelope,
|
||||
RecordMeta,
|
||||
RelationOption,
|
||||
} from '../api/types'
|
||||
import { controllerIdFromParams, controllerPath } from '../app/controllerRoutes'
|
||||
import { shortcutHint } from '../app/hotkeys'
|
||||
import { currentLocale, message, t } from '../app/i18n'
|
||||
@@ -20,6 +28,7 @@ import {
|
||||
FORM_ENABLED_LOCALES,
|
||||
FORM_FEEDBACK,
|
||||
FORM_LOCALE,
|
||||
FORM_PARTIAL_RELOAD,
|
||||
FORM_PATCH,
|
||||
FORM_PERMISSION_LOCKS,
|
||||
FORM_REMEMBER_LABEL,
|
||||
@@ -28,6 +37,7 @@ import {
|
||||
FORM_VALUES,
|
||||
createUploadGate,
|
||||
} from '../components/form/formContext'
|
||||
import RecordActions from '../components/form/RecordActions.vue'
|
||||
import type { AdminDependentOptionsResult } from '../api/types'
|
||||
import { RELATION_MANAGER, needsRecord } from '../components/form/registry'
|
||||
import { applyTriggers } from '../components/form/trigger'
|
||||
@@ -91,6 +101,12 @@ const labels = ref<RecordMeta['labels']>({})
|
||||
const permissionLocks = ref<NonNullable<RecordMeta['permissionLocks']>>({})
|
||||
/** The controller's record title (meta.title, pact.FormRecordTitle); '' when it names none. */
|
||||
const recordTitle = ref('')
|
||||
/** Record actions from the show response (footer when there is no preview). */
|
||||
const actions = ref<RecordAction[]>([])
|
||||
/** When false, Delete is hidden; absent means true (existing controllers). */
|
||||
const deletable = ref(true)
|
||||
const acting = ref(false)
|
||||
const partialReload = ref(0)
|
||||
const errors = ref<Record<string, string[]>>({})
|
||||
// The text of a save the server refused with 403 (UI-SPEC S6). It is a
|
||||
// banner, not a toast: it stays readable until the next save attempt.
|
||||
@@ -248,6 +264,8 @@ function adopt(record: RecordEnvelope | undefined): void {
|
||||
labels.value = record.meta.labels ?? {}
|
||||
permissionLocks.value = record.meta.permissionLocks ?? {}
|
||||
recordTitle.value = record.meta.title ?? ''
|
||||
actions.value = record.meta.actions ?? []
|
||||
deletable.value = record.meta.deletable !== false
|
||||
}
|
||||
saved.value = snapshot(editablePayload(fields.value, values.value, mode, permissionLocks.value))
|
||||
}
|
||||
@@ -359,6 +377,7 @@ provide(FORM_ENABLED_LOCALES, computed(() => schemaEnabledLocales(schema.value?.
|
||||
provide(FORM_ASSETS, () => assetsReady)
|
||||
provide(FORM_PERMISSION_LOCKS, computed(() => permissionLocks.value))
|
||||
provide(FORM_TRIGGER_NOTES, computed(() => triggered.value.notes))
|
||||
provide(FORM_PARTIAL_RELOAD, partialReload)
|
||||
// The form's single polite live region (dependent dropdown clears, repeater
|
||||
// moves) and the feedback nested controls read: errors and notices by row
|
||||
// path, the confirm dialog (Phase 17, D-07, D-08).
|
||||
@@ -480,6 +499,7 @@ async function save(): Promise<RecordEnvelope | null> {
|
||||
// The save committed everything held against the session.
|
||||
pendingChanges.value = 0
|
||||
revision.value++
|
||||
partialReload.value++
|
||||
const savedText = message(schema.value.messages.saved, undefined, { name: recordName.value })
|
||||
// The toast repeats the notices, so a save that navigates away (save
|
||||
// and close) still tells the administrator what changed.
|
||||
@@ -543,6 +563,46 @@ async function onSaveAndNew(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const footerActions = computed(
|
||||
() => mode === 'update' && !singleton.value && !backToPreview.value && actions.value.length > 0,
|
||||
)
|
||||
const showDelete = computed(() => mode === 'update' && !singleton.value && deletable.value)
|
||||
const footerBusy = computed(() => busy.value || acting.value)
|
||||
|
||||
async function onActionDone(text: string): Promise<void> {
|
||||
showToast(text)
|
||||
if (recordId === null) {
|
||||
return
|
||||
}
|
||||
const result = await api.GET('/{vendor}/{plugin}/{controller}/{id}', {
|
||||
params: { path: { ...path, id: recordId } },
|
||||
})
|
||||
if (result.data) {
|
||||
adopt(result.data)
|
||||
partialReload.value++
|
||||
} else if (result.response.status === 404) {
|
||||
failed.value = true
|
||||
}
|
||||
}
|
||||
|
||||
async function onActionStale(): Promise<void> {
|
||||
// RecordActions already toasted action_stale; reload the record in place.
|
||||
if (recordId === null) {
|
||||
return
|
||||
}
|
||||
const result = await api.GET('/{vendor}/{plugin}/{controller}/{id}', {
|
||||
params: { path: { ...path, id: recordId } },
|
||||
})
|
||||
if (result.data) {
|
||||
adopt(result.data)
|
||||
partialReload.value++
|
||||
}
|
||||
}
|
||||
|
||||
function onActionGone(): void {
|
||||
failed.value = true
|
||||
}
|
||||
|
||||
async function onDelete(): Promise<void> {
|
||||
if (recordId === null || busy.value || !schema.value) {
|
||||
return
|
||||
@@ -678,27 +738,40 @@ void load()
|
||||
</template>
|
||||
|
||||
<footer
|
||||
class="fixed right-0 bottom-0 left-[var(--shell-offset,0px)] z-30 flex items-center gap-2.5 border-t border-border bg-surface px-8 py-3.5"
|
||||
class="fixed right-0 bottom-0 left-[var(--shell-offset,0px)] z-30 flex flex-wrap items-center gap-2.5 border-t border-border bg-surface px-8 py-3.5"
|
||||
>
|
||||
<Button
|
||||
v-if="mode === 'update' && !singleton"
|
||||
variant="danger"
|
||||
data-action="delete"
|
||||
:icon="Trash2"
|
||||
:disabled="busy || loading || !schema"
|
||||
@click="onDelete"
|
||||
>
|
||||
{{ t('backend::lang.form.delete') }}
|
||||
</Button>
|
||||
<div class="ml-auto flex items-center gap-2.5">
|
||||
<Button variant="ghost" data-action="cancel" hotkey="escape" @click="onLeave">{{ t('backend::lang.form.cancel') }}</Button>
|
||||
<div class="flex flex-wrap items-center gap-2.5">
|
||||
<Button
|
||||
v-if="showDelete"
|
||||
variant="danger"
|
||||
data-action="delete"
|
||||
:icon="Trash2"
|
||||
:disabled="footerBusy || loading || !schema"
|
||||
@click="onDelete"
|
||||
>
|
||||
{{ t('backend::lang.form.delete') }}
|
||||
</Button>
|
||||
<RecordActions
|
||||
v-if="footerActions && recordId !== null"
|
||||
:source="path"
|
||||
:record-id="recordId"
|
||||
:actions="actions"
|
||||
:disabled="footerBusy || loading || !schema"
|
||||
@busy="(running: boolean) => (acting = running)"
|
||||
@done="onActionDone"
|
||||
@stale="onActionStale"
|
||||
@gone="onActionGone"
|
||||
/>
|
||||
</div>
|
||||
<div class="ml-auto flex flex-wrap items-center gap-2.5">
|
||||
<Button variant="ghost" data-action="cancel" hotkey="escape" :disabled="footerBusy" @click="onLeave">{{ t('backend::lang.form.cancel') }}</Button>
|
||||
<Button
|
||||
v-if="mode === 'create'"
|
||||
variant="outline"
|
||||
data-action="save-new"
|
||||
hotkey="mod+shift+s"
|
||||
:title="shortcutHint(t('backend::lang.form.create_and_new'), 'mod+shift+s')"
|
||||
:disabled="busy || loading || !schema || activeUploads > 0"
|
||||
:disabled="footerBusy || loading || !schema || activeUploads > 0"
|
||||
@click="onSaveAndNew"
|
||||
>
|
||||
{{ t('backend::lang.form.create_and_new') }}
|
||||
@@ -708,7 +781,7 @@ void load()
|
||||
data-action="save-close"
|
||||
hotkey="mod+enter"
|
||||
:title="shortcutHint(t('backend::lang.form.save_and_close'), 'mod+enter')"
|
||||
:disabled="busy || loading || !schema || activeUploads > 0"
|
||||
:disabled="footerBusy || loading || !schema || activeUploads > 0"
|
||||
@click="onSaveAndClose"
|
||||
>
|
||||
{{ t('backend::lang.form.save_and_close') }}
|
||||
@@ -718,7 +791,7 @@ void load()
|
||||
data-action="save"
|
||||
hotkey="mod+s"
|
||||
:title="shortcutHint(t('backend::lang.form.save'), 'mod+s')"
|
||||
:disabled="busy || loading || !schema || activeUploads > 0"
|
||||
:disabled="footerBusy || loading || !schema || activeUploads > 0"
|
||||
@click="onSave"
|
||||
>
|
||||
{{ busy ? t('backend::lang.form.saving') : t('backend::lang.form.save') }}
|
||||
|
||||
@@ -106,6 +106,8 @@ const stateLabels = computed(() => ({
|
||||
deleted: message(messages.value?.rowStateDeleted),
|
||||
negative: message(messages.value?.rowStateNegative),
|
||||
disabled: message(messages.value?.rowStateDisabled),
|
||||
customized: message(messages.value?.rowStateCustomized),
|
||||
outdated: message(messages.value?.rowStateOutdated),
|
||||
}))
|
||||
// Declared bulk actions the admin may run (D-09), in declared order. The
|
||||
// built-in delete stays the toolbar button and is not part of the menu.
|
||||
|
||||
Reference in New Issue
Block a user