fix(front): make all available fields available for editform (rebased on develop)
This commit is contained in:
parent
d936e330d6
commit
af58e94e73
|
@ -1,4 +1,4 @@
|
||||||
import type { Album, Track, Actor } from '~/types'
|
import type { Album, Artist, Content, Track, Actor } from '~/types'
|
||||||
|
|
||||||
import { i18n } from '~/init/locale'
|
import { i18n } from '~/init/locale'
|
||||||
|
|
||||||
|
@ -16,14 +16,25 @@ export interface EditableConfigField extends ConfigField {
|
||||||
id: EditObjectType
|
id: EditObjectType
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EditObject = (Partial<Album> | Partial<Track>) & { attributed_to: Actor }
|
export type EditObject = (Partial<Artist> | Partial<Album> | Partial<Track>) & { attributed_to: Actor }
|
||||||
export type EditObjectType = 'album' | 'track'
|
export type EditObjectType = 'artist' | 'album' | 'track'
|
||||||
type Configs = Record<EditObjectType, { fields: (EditableConfigField|ConfigField)[] }>
|
type Configs = Record<EditObjectType, { fields: (EditableConfigField|ConfigField)[] }>
|
||||||
|
|
||||||
|
const getContentValueRepr = (val: Content) => val.text
|
||||||
|
|
||||||
// TODO: Get params from typescript type somehow?
|
// TODO: Get params from typescript type somehow?
|
||||||
export default (): Configs => {
|
export default (): Configs => {
|
||||||
const { t } = i18n.global
|
const { t } = i18n.global
|
||||||
|
|
||||||
|
const description: ConfigField = {
|
||||||
|
id: 'description',
|
||||||
|
type: 'content',
|
||||||
|
required: true,
|
||||||
|
label: t('composables.moderation.useEditConfigs.description.label'),
|
||||||
|
getValue: (obj) => obj.description ?? { text: '', content_type: 'text/markdown' },
|
||||||
|
getValueRepr: getContentValueRepr
|
||||||
|
}
|
||||||
|
|
||||||
const cover: ConfigField = {
|
const cover: ConfigField = {
|
||||||
id: 'cover',
|
id: 'cover',
|
||||||
type: 'attachment',
|
type: 'attachment',
|
||||||
|
@ -37,15 +48,25 @@ export default (): Configs => {
|
||||||
type: 'tags',
|
type: 'tags',
|
||||||
required: true,
|
required: true,
|
||||||
label: t('composables.moderation.useEditConfigs.tags.label'),
|
label: t('composables.moderation.useEditConfigs.tags.label'),
|
||||||
getValue: (obj) => ({
|
getValue: (obj) => { return obj.tags },
|
||||||
current: obj.tags || [],
|
|
||||||
others: [],
|
|
||||||
custom: [],
|
|
||||||
}),
|
|
||||||
getValueRepr: (tags: string[]) => tags.slice().sort().join('\n')
|
getValueRepr: (tags: string[]) => tags.slice().sort().join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
artist: {
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
id: 'name',
|
||||||
|
type: 'text',
|
||||||
|
required: true,
|
||||||
|
label: t('composables.moderation.useEditConfigs.artist.name'),
|
||||||
|
getValue: (artist) => (artist as Artist).name
|
||||||
|
},
|
||||||
|
description,
|
||||||
|
cover,
|
||||||
|
tags
|
||||||
|
]
|
||||||
|
},
|
||||||
album: {
|
album: {
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
|
@ -55,9 +76,9 @@ export default (): Configs => {
|
||||||
label: t('composables.moderation.useEditConfigs.album.title'),
|
label: t('composables.moderation.useEditConfigs.album.title'),
|
||||||
getValue: (album) => (album as Album).title
|
getValue: (album) => (album as Album).title
|
||||||
},
|
},
|
||||||
|
description,
|
||||||
{
|
{
|
||||||
id: 'release_date',
|
id: 'release_date',
|
||||||
// TODO: Change type to date and offer date select input in form
|
|
||||||
type: 'text',
|
type: 'text',
|
||||||
required: false,
|
required: false,
|
||||||
label: t('composables.moderation.useEditConfigs.album.releaseDate'),
|
label: t('composables.moderation.useEditConfigs.album.releaseDate'),
|
||||||
|
@ -76,6 +97,7 @@ export default (): Configs => {
|
||||||
label: t('composables.moderation.useEditConfigs.track.title'),
|
label: t('composables.moderation.useEditConfigs.track.title'),
|
||||||
getValue: (track) => (track as Track).title
|
getValue: (track) => (track as Track).title
|
||||||
},
|
},
|
||||||
|
description,
|
||||||
cover,
|
cover,
|
||||||
{
|
{
|
||||||
id: 'position',
|
id: 'position',
|
||||||
|
|
Loading…
Reference in New Issue