Add sub-categories to affirmation categories
Add self-referential parent/child relation on AffirmationCategory for one-level hierarchy. Update AffirmationForm with two-level category and sub-category dropdowns, server actions with find-or-create hierarchy logic, AffirmationList with Parent
This commit is contained in:
@@ -96,7 +96,7 @@ const models: AdminModelConfig[] = [
|
||||
displayName: 'Affirmations',
|
||||
displayNameSingular: 'Affirmation',
|
||||
idType: 'String',
|
||||
include: { solfeggioFrequency: true, category: true },
|
||||
include: { solfeggioFrequency: true, category: { include: { parent: true } } },
|
||||
listFields: ['name', 'category.name', 'solfeggioFrequency.name', 'price'],
|
||||
searchFields: ['name', 'content'],
|
||||
formFields: ['name', 'content', 'solfeggioFrequencyId', 'categoryId', 'price'],
|
||||
@@ -152,13 +152,17 @@ const models: AdminModelConfig[] = [
|
||||
displayName: 'Affirmation Categories',
|
||||
displayNameSingular: 'Affirmation Category',
|
||||
idType: 'Int',
|
||||
include: { affirmations: true },
|
||||
listFields: ['name'],
|
||||
include: { affirmations: true, children: true, parent: true },
|
||||
listFields: ['name', 'parent.name'],
|
||||
searchFields: ['name'],
|
||||
formFields: ['name'],
|
||||
formFields: ['name', 'parentId'],
|
||||
readonlyFields: ['id'],
|
||||
fieldTypes: {
|
||||
name: 'String'
|
||||
name: 'String',
|
||||
parentId: 'Int'
|
||||
},
|
||||
relationOptions: {
|
||||
parentId: { model: 'AffirmationCategory', labelField: 'name', valueField: 'id' }
|
||||
},
|
||||
relatedRecords: [
|
||||
{
|
||||
@@ -167,6 +171,13 @@ const models: AdminModelConfig[] = [
|
||||
type: 'has-many',
|
||||
displayFields: ['name', 'price'],
|
||||
editSlug: 'affirmations'
|
||||
},
|
||||
{
|
||||
relationKey: 'children',
|
||||
label: 'Sub-categories',
|
||||
type: 'has-many',
|
||||
displayFields: ['name'],
|
||||
editSlug: 'affirmation-categories'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -25,7 +25,7 @@ export type AdminModelConfig = {
|
||||
displayName: string;
|
||||
displayNameSingular: string;
|
||||
idType: 'String' | 'Int';
|
||||
include?: Record<string, boolean>;
|
||||
include?: Record<string, boolean | { include: Record<string, boolean> }>;
|
||||
listFields: string[];
|
||||
searchFields: string[];
|
||||
formFields: string[];
|
||||
|
||||
Reference in New Issue
Block a user