feat(quick-261016-nqk): admin heads form and preview with meta.title (G-18.1-4)
This commit is contained in:
@@ -78,6 +78,8 @@ const recordId = mode === 'update' ? Number(route.params.id) : null
|
|||||||
const schema = ref<FormView | null>(null)
|
const schema = ref<FormView | null>(null)
|
||||||
const values = ref<AdminRecord>({})
|
const values = ref<AdminRecord>({})
|
||||||
const labels = ref<RecordMeta['labels']>({})
|
const labels = ref<RecordMeta['labels']>({})
|
||||||
|
/** The controller's record title (meta.title, pact.FormRecordTitle); '' when it names none. */
|
||||||
|
const recordTitle = ref('')
|
||||||
const errors = ref<Record<string, string[]>>({})
|
const errors = ref<Record<string, string[]>>({})
|
||||||
// The text of a save the server refused with 403 (UI-SPEC S6). It is a
|
// 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.
|
// banner, not a toast: it stays readable until the next save attempt.
|
||||||
@@ -157,8 +159,10 @@ const panelFields = computed(() => {
|
|||||||
return fields.value.filter((field) => tabOf(field) === key)
|
return fields.value.filter((field) => tabOf(field) === key)
|
||||||
})
|
})
|
||||||
|
|
||||||
/** The record's display name: the first text-like field's value, in schema order. */
|
/** The record's display name: the controller's title, else the first text-like field's value, in schema order. */
|
||||||
const recordName = computed(() =>
|
const recordName = computed(
|
||||||
|
() =>
|
||||||
|
recordTitle.value ||
|
||||||
recordDisplayName(schema.value?.fields, values.value, schemaEnabledLocales(schema.value?.meta)),
|
recordDisplayName(schema.value?.fields, values.value, schemaEnabledLocales(schema.value?.meta)),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -217,6 +221,7 @@ function adopt(record: RecordEnvelope | undefined): void {
|
|||||||
}
|
}
|
||||||
values.value = next
|
values.value = next
|
||||||
labels.value = record.meta.labels ?? {}
|
labels.value = record.meta.labels ?? {}
|
||||||
|
recordTitle.value = record.meta.title ?? ''
|
||||||
}
|
}
|
||||||
saved.value = snapshot(editablePayload(fields.value, values.value, mode))
|
saved.value = snapshot(editablePayload(fields.value, values.value, mode))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ const recordPath = `${listPath}/${recordId}`
|
|||||||
const schema = ref<FormView | null>(null)
|
const schema = ref<FormView | null>(null)
|
||||||
const values = ref<AdminRecord>({})
|
const values = ref<AdminRecord>({})
|
||||||
const labels = ref<RecordMeta['labels']>({})
|
const labels = ref<RecordMeta['labels']>({})
|
||||||
|
/** The controller's record title (meta.title, pact.FormRecordTitle); '' when it names none. */
|
||||||
|
const recordTitle = ref('')
|
||||||
const actions = ref<RecordAction[]>([])
|
const actions = ref<RecordAction[]>([])
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const failed = ref(false)
|
const failed = ref(false)
|
||||||
@@ -112,8 +114,10 @@ const panelFields = computed(() => {
|
|||||||
return fields.value.filter((field) => tabOf(field) === key)
|
return fields.value.filter((field) => tabOf(field) === key)
|
||||||
})
|
})
|
||||||
|
|
||||||
/** The record's display name: the first text-like field's value, in schema order. */
|
/** The record's display name: the controller's title, else the first text-like field's value, in schema order. */
|
||||||
const recordName = computed(() =>
|
const recordName = computed(
|
||||||
|
() =>
|
||||||
|
recordTitle.value ||
|
||||||
recordDisplayName(schema.value?.fields, values.value, schemaEnabledLocales(schema.value?.meta)),
|
recordDisplayName(schema.value?.fields, values.value, schemaEnabledLocales(schema.value?.meta)),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -146,6 +150,7 @@ async function loadRecord(): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
values.value = { ...result.data.data }
|
values.value = { ...result.data.data }
|
||||||
labels.value = result.data.meta.labels ?? {}
|
labels.value = result.data.meta.labels ?? {}
|
||||||
|
recordTitle.value = result.data.meta.title ?? ''
|
||||||
actions.value = result.data.meta.actions ?? []
|
actions.value = result.data.meta.actions ?? []
|
||||||
return true
|
return true
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -623,6 +623,14 @@ describe('password and preset on the form (UI-SPEC S7, D-19, D-27 G7)', () => {
|
|||||||
expect(editor(wrapper, 'slug').element.value).toBe('ada-lovelace')
|
expect(editor(wrapper, 'slug').element.value).toBe('ada-lovelace')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("titles a record by the controller's meta.title when it sends one, and publishes it as the crumb", async () => {
|
||||||
|
const record = clone(rosterRecordFixture)
|
||||||
|
;(record.meta as { title?: string }).title = 'Person #1 (Ada)'
|
||||||
|
const { wrapper } = await mountApp('/acme/roster/people/1', people({ [`GET ${PERSON}`]: { body: record } }))
|
||||||
|
expect(wrapper.find('h1').text()).toBe('Person #1 (Ada)')
|
||||||
|
expect(recordCrumb.value).toBe('Person #1 (Ada)')
|
||||||
|
})
|
||||||
|
|
||||||
it('titles a record by the default locale of an mltext first field, and publishes it as the crumb', async () => {
|
it('titles a record by the default locale of an mltext first field, and publishes it as the crumb', async () => {
|
||||||
const record = clone(rosterRecordFixture)
|
const record = clone(rosterRecordFixture)
|
||||||
record.data.name = { en: 'Ada Lovelace', pl: 'Ada Lovelace PL' }
|
record.data.name = { en: 'Ada Lovelace', pl: 'Ada Lovelace PL' }
|
||||||
|
|||||||
@@ -139,6 +139,19 @@ describe('preview view (UI-SPEC S3, D-11)', () => {
|
|||||||
expect(recordCrumb.value).toBe('Ada Lovelace')
|
expect(recordCrumb.value).toBe('Ada Lovelace')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("heads the record by the controller's meta.title when it sends one, before the first text field", async () => {
|
||||||
|
const { wrapper } = await mountApp(
|
||||||
|
PREVIEW,
|
||||||
|
routes({
|
||||||
|
[`GET ${RECORD}`]: recordWith((record) => {
|
||||||
|
;(record.meta as { title?: string }).title = 'Person #1 (Ada)'
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
expect(wrapper.find('h1').text()).toBe('Person #1 (Ada)')
|
||||||
|
expect(recordCrumb.value).toBe('Person #1 (Ada)')
|
||||||
|
})
|
||||||
|
|
||||||
it('shows the muted dash for an empty value and the label of a relation, never its id', async () => {
|
it('shows the muted dash for an empty value and the label of a relation, never its id', async () => {
|
||||||
const { wrapper } = await mountApp(PREVIEW, routes({ [`GET ${RECORD}`]: recordWith((record) => (record.data.joined_ip = null)) }))
|
const { wrapper } = await mountApp(PREVIEW, routes({ [`GET ${RECORD}`]: recordWith((record) => (record.data.joined_ip = null)) }))
|
||||||
expect(wrapper.find('[data-preview-field="joined_ip"] [data-empty]').text()).toBe('—')
|
expect(wrapper.find('[data-preview-field="joined_ip"] [data-empty]').text()).toBe('—')
|
||||||
|
|||||||
Reference in New Issue
Block a user