From 5bf48e7f06a99290070aadd14a8a01ebbde8cb92 Mon Sep 17 00:00:00 2001 From: Christophe Carvalho Vilas-Boas Date: Fri, 6 Dec 2024 18:30:42 +0100 Subject: [PATCH 1/3] feat(new): Add ability to set the newProperties the same way we set the editProperties --- src/backend/decorators/resource/resource-decorator.spec.ts | 1 + src/backend/decorators/resource/resource-decorator.ts | 3 +++ src/backend/decorators/resource/resource-options.interface.ts | 4 ++++ src/backend/utils/build-feature/build-feature.ts | 4 ++-- src/frontend/components/actions/new.tsx | 2 +- .../components/property-type/base-property-component.doc.md | 1 + src/frontend/components/spec/resource-json.factory.ts | 2 ++ src/frontend/interfaces/resource-json.interface.ts | 4 ++++ 8 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/backend/decorators/resource/resource-decorator.spec.ts b/src/backend/decorators/resource/resource-decorator.spec.ts index 15852fcb7..05e7ed8e8 100644 --- a/src/backend/decorators/resource/resource-decorator.spec.ts +++ b/src/backend/decorators/resource/resource-decorator.spec.ts @@ -264,6 +264,7 @@ describe('ResourceDecorator', function () { 'titleProperty', 'resourceActions', 'listProperties', + 'newProperties', 'editProperties', 'showProperties', 'filterProperties', diff --git a/src/backend/decorators/resource/resource-decorator.ts b/src/backend/decorators/resource/resource-decorator.ts index d2e6a9115..ac616489e 100644 --- a/src/backend/decorators/resource/resource-decorator.ts +++ b/src/backend/decorators/resource/resource-decorator.ts @@ -318,6 +318,9 @@ class ResourceDecorator { editProperties: this.getProperties({ where: 'edit', }).map((property) => property.toJSON('edit')), + newProperties: this.getProperties({ + where: 'new', + }).map((property) => property.toJSON('new')), showProperties: this.getProperties({ where: 'show', }).map((property) => property.toJSON('show')), diff --git a/src/backend/decorators/resource/resource-options.interface.ts b/src/backend/decorators/resource/resource-options.interface.ts index b66e99889..b70ee600e 100644 --- a/src/backend/decorators/resource/resource-options.interface.ts +++ b/src/backend/decorators/resource/resource-options.interface.ts @@ -66,6 +66,10 @@ export interface ResourceOptions { * List of properties which should be visible on edit view */ editProperties?: Array; + /** + * List of properties which should be visible on new view + */ + newProperties?: Array; /** * List of properties which should be visible on the filter */ diff --git a/src/backend/utils/build-feature/build-feature.ts b/src/backend/utils/build-feature/build-feature.ts index 28e705c48..e314db0d5 100644 --- a/src/backend/utils/build-feature/build-feature.ts +++ b/src/backend/utils/build-feature/build-feature.ts @@ -32,7 +32,7 @@ function mergeActionHooks( const basicOptions = ['id', 'href', 'parent', 'sort', 'navigation', 'titleProperty', 'translations'] as const const listOptions = [ - 'listProperties', 'showProperties', 'editProperties', 'filterProperties', + 'listProperties', 'showProperties', 'editProperties', 'newProperties', 'filterProperties', ] as const type BasicOption = typeof basicOptions[number] @@ -54,7 +54,7 @@ const hasMissingKeys: MissingKeys = {} as const * Merges 2 ResourceOptions together. Used by features * * - 'id', 'href', 'parent', 'sort' from `newOptions` override `oldOptions` - * - 'listProperties', 'showProperties', 'editProperties', 'filterProperties' + * - 'listProperties', 'showProperties', 'editProperties', 'newProperties', 'filterProperties' * are joined and made unique * - all 'properties' from `newOptions` override properties from `oldOptions` * - all 'actions' with their parameters from `newOptions` override `oldOptions` diff --git a/src/frontend/components/actions/new.tsx b/src/frontend/components/actions/new.tsx index 75e4ff0d8..6e0910b42 100644 --- a/src/frontend/components/actions/new.tsx +++ b/src/frontend/components/actions/new.tsx @@ -87,7 +87,7 @@ const New: FC = (props) => { record={record as RecordJSON} /> )) - : resource.editProperties.map((property) => ( + : resource.newProperties.map((property) => ( ('ResourceJSON', Object, { showProperties: [], filterProperties: [], editProperties: [], + newProperties: [], }) factory.extend('ResourceJSON', 'ResourceJSON.full', {}, { @@ -44,6 +45,7 @@ factory.extend('ResourceJSON', 'ResourceJSON.full', {}, { listProperties: properties, showProperties: properties, editProperties: properties, + newProperties: properties, filterProperties: properties, } }, diff --git a/src/frontend/interfaces/resource-json.interface.ts b/src/frontend/interfaces/resource-json.interface.ts index a937dddd3..79abeda60 100644 --- a/src/frontend/interfaces/resource-json.interface.ts +++ b/src/frontend/interfaces/resource-json.interface.ts @@ -57,6 +57,10 @@ export interface ResourceJSON { * Properties which should be visible on the edit view */ editProperties: Array; + /** + * Properties which should be visible on the edit new + */ + newProperties: Array; /** * Properties which should be visible on the show view */ From 8b474a637890674b1296d75398c8677d4baab6d6 Mon Sep 17 00:00:00 2001 From: Christophe Carvalho Vilas-Boas Date: Sat, 7 Dec 2024 10:14:02 +0100 Subject: [PATCH 2/3] feat(new): Add new to PropertyPlace --- .../interfaces/property-json/property-json.interface.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/frontend/interfaces/property-json/property-json.interface.ts b/src/frontend/interfaces/property-json/property-json.interface.ts index e6484ce25..635e3a0dd 100644 --- a/src/frontend/interfaces/property-json/property-json.interface.ts +++ b/src/frontend/interfaces/property-json/property-json.interface.ts @@ -1,6 +1,6 @@ import { PropertyType } from '../../../backend/adapters/property/base-property.js' -export type PropertyPlace = 'show' | 'list' | 'edit' | 'filter'; +export type PropertyPlace = 'show' | 'list' | 'edit' | 'new' | 'filter'; /** * JSON representation of a Property. @@ -108,6 +108,7 @@ export interface PropertyJSON { components?: { show?: string; edit?: string; + new?: string; filter?: string; list?: string; }; From b1b7669cacd1234d7b8f8704a95ed28e8740ab02 Mon Sep 17 00:00:00 2001 From: Christophe Carvalho Vilas-Boas Date: Sat, 7 Dec 2024 10:19:35 +0100 Subject: [PATCH 3/3] feat(new): Update documentation where PropertyPlace is used --- src/backend/decorators/property/property-decorator.ts | 2 +- src/backend/decorators/resource/resource-decorator.ts | 2 +- src/frontend/components/property-type/base-property-props.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/decorators/property/property-decorator.ts b/src/backend/decorators/property/property-decorator.ts index 858187171..0fc174d20 100644 --- a/src/backend/decorators/property/property-decorator.ts +++ b/src/backend/decorators/property/property-decorator.ts @@ -172,7 +172,7 @@ export class PropertyDecorator { /** * Indicates if given property should be visible * - * @param {'list' | 'edit' | 'show' | 'filter'} where + * @param {'list' | 'edit' | 'new' | 'show' | 'filter'} where */ isVisible(where: PropertyPlace): boolean { if (typeof this.options.isVisible === 'object' && this.options.isVisible !== null) { diff --git a/src/backend/decorators/resource/resource-decorator.ts b/src/backend/decorators/resource/resource-decorator.ts index ac616489e..95b326f5f 100644 --- a/src/backend/decorators/resource/resource-decorator.ts +++ b/src/backend/decorators/resource/resource-decorator.ts @@ -135,7 +135,7 @@ class ResourceDecorator { * Returns list of all properties which will be visible in given place (where) * * @param {Object} options - * @param {String} options.where one of: 'list', 'show', 'edit', 'filter' + * @param {String} options.where one of: 'list', 'show', 'edit', 'new', 'filter' * @param {String} [options.max] maximum number of properties returned where there are * no overrides in the options * diff --git a/src/frontend/components/property-type/base-property-props.ts b/src/frontend/components/property-type/base-property-props.ts index db51f4cda..9760ad9db 100644 --- a/src/frontend/components/property-type/base-property-props.ts +++ b/src/frontend/components/property-type/base-property-props.ts @@ -71,7 +71,7 @@ export type BasePropertyProps = { */ filter?: any; /** - * Where given property should be rendered. Either of 'show' | 'list' | 'edit' | 'filter'. + * Where given property should be rendered. Either of 'show' | 'list' | 'edit' | 'new' | 'filter'. */ where: PropertyPlace; }