37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { deepCopy } from 'src/utilities/dom'
|
|
|
|
import type { GalleryEntry, GalleryEntryInheritedProperties } from './gallery'
|
|
|
|
export const getTitleFromEntryOrId = (entry: GalleryEntry, id: string) => (
|
|
entry.title !== undefined
|
|
? entry.title === '' || entry.title === null
|
|
? 'untitled'
|
|
: entry.title
|
|
: id
|
|
)
|
|
|
|
export const amendVariantsWithDefaults = (entry: GalleryEntry) => {
|
|
const variants = deepCopy(entry.variants)
|
|
if (!!variants) {
|
|
Object.keys(variants).forEach(id => _amendVariantWithDefaults(entry, variants[id]))
|
|
}
|
|
|
|
return variants
|
|
}
|
|
|
|
export const _amendVariantWithDefaults = (parent: GalleryEntryInheritedProperties, variant: GalleryEntryInheritedProperties) => {
|
|
if (variant.title === undefined && (!!parent.title || parent.title === null || parent.title === '')) {
|
|
variant.title = parent.title
|
|
}
|
|
if (!variant.description && !!parent.description) {
|
|
variant.description = parent.description
|
|
}
|
|
if (variant.warning === undefined && !!parent.warning) {
|
|
variant.warning = parent.warning
|
|
}
|
|
if (!variant.fields && !!parent.fields) {
|
|
variant.fields = parent.fields
|
|
}
|
|
|
|
return variant
|
|
}
|