refactor: apply review suggestions
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -4,7 +4,19 @@
|
||||
|
||||
Update the default entity page extension component to support grouping multiple entity content items in the same tab.
|
||||
|
||||
Disable a default group via configuration:
|
||||
Disable all default groups:
|
||||
|
||||
```diff
|
||||
# app-config.yaml
|
||||
app:
|
||||
extensions:
|
||||
# Pages
|
||||
+ - page:catalog/entity:
|
||||
+ config:
|
||||
+ groups: []
|
||||
```
|
||||
|
||||
Create a custom list of :
|
||||
|
||||
```diff
|
||||
# app-config.yaml
|
||||
@@ -14,32 +26,7 @@ app:
|
||||
+ - page:catalog/entity:
|
||||
+ config:
|
||||
+ groups:
|
||||
+ deployment: false
|
||||
```
|
||||
|
||||
Change a default group title via configuration:
|
||||
|
||||
```diff
|
||||
# app-config.yaml
|
||||
app:
|
||||
extensions:
|
||||
# Pages
|
||||
+ - page:catalog/entity:
|
||||
+ config:
|
||||
+ groups:
|
||||
+ deployment: Infrastructure # this is overriding the default group title
|
||||
```
|
||||
|
||||
Create a custom entity content group via configuration:
|
||||
|
||||
```diff
|
||||
# app-config.yaml
|
||||
app:
|
||||
extensions:
|
||||
# Pages
|
||||
+ - page:catalog/entity:
|
||||
+ config:
|
||||
+ groups:
|
||||
+ # <id>: <Title>
|
||||
+ custom: Custom
|
||||
+ # This array of groups completely replaces the default groups
|
||||
+ - custom:
|
||||
+ title: 'Custom'
|
||||
```
|
||||
|
||||
@@ -17,12 +17,13 @@ app:
|
||||
config:
|
||||
groups:
|
||||
# example disabling a default group
|
||||
development: false
|
||||
- development: false
|
||||
# example overriding a default group title
|
||||
documentation: Docs
|
||||
- documentation:
|
||||
title: Docs
|
||||
# example adding a new group
|
||||
# Format <GROUP_ID>: <GROUP_TITLE>
|
||||
custom: Custom
|
||||
- custom:
|
||||
title: Custom
|
||||
|
||||
# Entity page cards
|
||||
- entity-card:catalog/about
|
||||
|
||||
@@ -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