Skip to content

Commit ea97b4a

Browse files
committed
feat: allow to set titleProperty in resource options
1 parent f40d897 commit ea97b4a

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/backend/decorators/property/property-options.interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ export default interface PropertyOptions {
3131
* Indicates if property should be treated as an ID
3232
*/
3333
isId?: boolean;
34+
3435
/**
3536
* One of given property should be treated as an "title property". Title property is "clickable"
3637
* when user sees the record in a list or show views.
38+
*
39+
* @deprecated Use ResourceOptions#titleProperty
3740
*/
3841
isTitle?: boolean;
3942

src/backend/decorators/resource/resource-decorator.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,15 @@ class ResourceDecorator {
246246
* @return {PropertyDecorator} PropertyDecorator of title property
247247
*/
248248
titleProperty(): PropertyDecorator {
249+
let titleProperty
250+
249251
const properties = Object.values(this.properties)
250-
const titleProperty = properties.find((p) => p.isTitle())
252+
if (this.options.titleProperty) {
253+
titleProperty = properties.find((p) => p.propertyPath === this.options.titleProperty)
254+
} else {
255+
titleProperty = properties.find((p) => p.isTitle())
256+
}
257+
251258
return titleProperty || properties[0]
252259
}
253260

src/backend/decorators/resource/resource-options.interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export interface ResourceOptions {
6969
* List of properties which should be visible on the filter
7070
*/
7171
filterProperties?: Array<string>;
72+
/**
73+
* Name of title property
74+
*/
75+
titleProperty?: string;
7276
/**
7377
* Where resource link in sidebar should redirect. Default to the list action.
7478
*/

src/backend/utils/build-feature/build-feature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function mergeActionHooks<T>(
3030
return hooks.length ? { [key]: hooks } : {}
3131
}
3232

33-
const basicOptions = ['id', 'href', 'parent', 'sort', 'navigation'] as const
33+
const basicOptions = ['id', 'href', 'parent', 'sort', 'navigation', 'titleProperty'] as const
3434
const listOptions = [
3535
'listProperties', 'showProperties', 'editProperties', 'filterProperties',
3636
] as const

0 commit comments

Comments
 (0)