refactor: apply review suggestions
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -802,12 +802,28 @@ const _default: FrontendPlugin<
|
||||
}>;
|
||||
'page:catalog/entity': ExtensionDefinition<{
|
||||
config: {
|
||||
groups: Record<string, string | false> | undefined;
|
||||
groups:
|
||||
| Record<
|
||||
string,
|
||||
| false
|
||||
| {
|
||||
title: string;
|
||||
}
|
||||
>[]
|
||||
| undefined;
|
||||
} & {
|
||||
path: string | undefined;
|
||||
};
|
||||
configInput: {
|
||||
groups?: Record<string, string | false> | undefined;
|
||||
groups?:
|
||||
| Record<
|
||||
string,
|
||||
| false
|
||||
| {
|
||||
title: string;
|
||||
}
|
||||
>[]
|
||||
| undefined;
|
||||
} & {
|
||||
path?: string | undefined;
|
||||
};
|
||||
|
||||
@@ -198,9 +198,11 @@ describe('Index page', () => {
|
||||
Object.assign({ namespace: 'catalog' }, catalogEntityPage),
|
||||
{
|
||||
config: {
|
||||
groups: {
|
||||
documentation: 'Docs',
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
documentation: { title: 'Docs' },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -257,9 +259,11 @@ describe('Index page', () => {
|
||||
Object.assign({ namespace: 'catalog' }, catalogEntityPage),
|
||||
{
|
||||
config: {
|
||||
groups: {
|
||||
documentation: false,
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
documentation: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -360,9 +364,11 @@ describe('Index page', () => {
|
||||
Object.assign({ namespace: 'catalog' }, catalogEntityPage),
|
||||
{
|
||||
config: {
|
||||
groups: {
|
||||
docs: 'Docs',
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
docs: { title: 'Docs' },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -71,7 +71,14 @@ export const catalogEntityPage = PageBlueprint.makeWithOverrides({
|
||||
config: {
|
||||
schema: {
|
||||
groups: z =>
|
||||
z.record(z.string(), z.string().or(z.literal(false))).optional(),
|
||||
z
|
||||
.array(
|
||||
z.record(
|
||||
z.string(),
|
||||
z.literal(false).or(z.object({ title: z.string() })),
|
||||
),
|
||||
)
|
||||
.optional(),
|
||||
},
|
||||
},
|
||||
factory(originalFactory, { config, inputs }) {
|
||||
@@ -82,10 +89,17 @@ export const catalogEntityPage = PageBlueprint.makeWithOverrides({
|
||||
const { EntityLayout } = await import('./components/EntityLayout');
|
||||
|
||||
// config groups override default groups
|
||||
const groups: Record<string, string> = {
|
||||
...defaultEntityContentGroups,
|
||||
...config.groups,
|
||||
};
|
||||
const groups: Record<string, string> = config.groups?.length
|
||||
? config.groups.reduce<Record<string, string>>((rest, group) => {
|
||||
const [groupId, groupValue] = Object.entries(group)[0];
|
||||
return groupValue
|
||||
? {
|
||||
...rest,
|
||||
[groupId]: groupValue.title,
|
||||
}
|
||||
: rest;
|
||||
}, {})
|
||||
: defaultEntityContentGroups;
|
||||
|
||||
// the groups order is determined by the order of the contents
|
||||
// a group will appear in the order of the first item that belongs to it
|
||||
|
||||
Reference in New Issue
Block a user