Skip to content

Commit

Permalink
fix: support recordId with '/' in it.
Browse files Browse the repository at this point in the history
  • Loading branch information
ulion committed Apr 10, 2023
1 parent 7fc4ca4 commit 34f7b1c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/backend/actions/search/search-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export const SearchAction: Action<SearchActionResponse> = {
const { query } = request

const decorated = resource.decorate()
const titlePropertyName = request.query?.searchProperty ?? decorated.titleProperty().name()
const titlePropertyName = query?.searchProperty ?? decorated.searchProperty().name()

const {
sortBy = decorated.options?.sort?.sortBy || titlePropertyName,
sortBy = decorated.options?.sort?.sortBy
|| query?.searchProperty
|| decorated.titleProperty().name(),
direction = 'asc',
filters: customFilters = {},
perPage = 50,
Expand Down
11 changes: 11 additions & 0 deletions src/backend/decorators/resource/resource-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ class ResourceDecorator {
return record.get(this.titleProperty().name()) as string
}

/**
* Returns PropertyDecorator of a property which should be used to search.
* If searchProperty not set, use titleProperty as fallback
*
* @return {PropertyDecorator} PropertyDecorator of search property
*/
searchProperty(): PropertyDecorator {
return (this.options.searchProperty && this.getPropertyByKey(this.options.searchProperty))
|| this.titleProperty()
}

getHref(currentAdmin?: CurrentAdmin): string | null {
const { href } = this.options
if (href) {
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 @@ -105,6 +105,10 @@ export interface ResourceOptions {
direction: 'asc' | 'desc';
sortBy: string;
};
/**
* Property which should be used to search
*/
searchProperty?: string;
/**
* List of properties along with their options
*/
Expand Down
2 changes: 1 addition & 1 deletion src/backend/utils/build-feature/build-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function mergeActionHooks<T>(
return hooks.length ? { [key]: hooks } : {}
}

const basicOptions = ['id', 'href', 'parent', 'sort', 'navigation'] as const
const basicOptions = ['id', 'href', 'parent', 'sort', 'navigation', 'searchProperty'] as const
const listOptions = [
'listProperties', 'showProperties', 'editProperties', 'filterProperties',
] as const
Expand Down

0 comments on commit 34f7b1c

Please sign in to comment.