Skip to content

feat(new): Add ability to set the newProperties #1721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/decorators/property/property-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default interface PropertyOptions {
show?: boolean;
list?: boolean;
edit?: boolean;
new?: boolean;
filter?: boolean;
};
/**
Expand Down
1 change: 1 addition & 0 deletions src/backend/decorators/resource/resource-decorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ describe('ResourceDecorator', function () {
'titleProperty',
'resourceActions',
'listProperties',
'newProperties',
'editProperties',
'showProperties',
'filterProperties',
Expand Down
5 changes: 4 additions & 1 deletion src/backend/decorators/resource/resource-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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')),
Expand Down
4 changes: 4 additions & 0 deletions src/backend/decorators/resource/resource-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export interface ResourceOptions {
* List of properties which should be visible on edit view
*/
editProperties?: Array<string>;
/**
* List of properties which should be visible on new view
*/
newProperties?: Array<string>;
/**
* List of properties which should be visible on the filter
*/
Expand Down
4 changes: 2 additions & 2 deletions src/backend/utils/build-feature/build-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function mergeActionHooks<T>(

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]
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/actions/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const New: FC<ActionProps> = (props) => {
record={record as RecordJSON}
/>
))
: resource.editProperties.map((property) => (
: resource.newProperties.map((property) => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might also need to update where to new in BasePropertyComponent and LayoutElementRenderer. new would then also have to be added to i. e. isVisible for properties etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The where is used to determine the component to render in BasePropertyComponent and we actually want to render the property with the edit component

<BasePropertyComponent
key={property.propertyPath}
where="edit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const resource = {
resourceActions: [],
listProperties: [booleanProperty, stringProperty],
editProperties: [booleanProperty, stringProperty],
newProperties: [booleanProperty, stringProperty],
showProperties: [booleanProperty, stringProperty],
filterProperties: [booleanProperty, stringProperty],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/components/spec/resource-json.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ factory.define<ResourceJSON>('ResourceJSON', Object, {
showProperties: [],
filterProperties: [],
editProperties: [],
newProperties: [],
})

factory.extend('ResourceJSON', 'ResourceJSON.full', {}, {
Expand All @@ -44,6 +45,7 @@ factory.extend('ResourceJSON', 'ResourceJSON.full', {}, {
listProperties: properties,
showProperties: properties,
editProperties: properties,
newProperties: properties,
filterProperties: properties,
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -108,6 +108,7 @@ export interface PropertyJSON {
components?: {
show?: string;
edit?: string;
new?: string;
filter?: string;
list?: string;
};
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/interfaces/resource-json.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export interface ResourceJSON {
* Properties which should be visible on the edit view
*/
editProperties: Array<BasePropertyJSON>;
/**
* Properties which should be visible on the edit new
*/
newProperties: Array<BasePropertyJSON>;
/**
* Properties which should be visible on the show view
*/
Expand Down