Skip to content

Commit

Permalink
added config list in the entity ref list
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish8689 committed Dec 18, 2024
1 parent 841eb02 commit 8753ee9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,21 @@ export const AdvanceSearchProvider = ({

Object.entries(res).forEach(([_, fields]) => {
if (Array.isArray(fields) && fields.length > 0) {
fields.forEach((field: { name: string; type: string }) => {
if (field.name && field.type) {
const { subfieldsKey, dataObject } =
advancedSearchClassBase.getCustomPropertiesSubFields(field);
subfields[subfieldsKey] = dataObject;
fields.forEach(
(field: {
name: string;
type: string;
customPropertyConfig: {
config: string | string[];
};
}) => {
if (field.name && field.type) {
const { subfieldsKey, dataObject } =
advancedSearchClassBase.getCustomPropertiesSubFields(field);
subfields[subfieldsKey] = dataObject;
}
}
});
);
}
});
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ export const TEXT_FIELD_OPERATORS = [
'is_null',
'is_not_null',
];

export const DATE_FIELD_OPERATORS = ['between', 'not_between'];

/**
* Generates a query builder tree with a group containing an empty rule
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
SelectFieldSettings,
} from 'react-awesome-query-builder';
import AntdConfig from 'react-awesome-query-builder/lib/config/antd';
import { TEXT_FIELD_OPERATORS } from '../constants/AdvancedSearch.constants';
import {
DATE_FIELD_OPERATORS,
TEXT_FIELD_OPERATORS,
} from '../constants/AdvancedSearch.constants';
import { EntityFields, SuggestionField } from '../enums/AdvancedSearch.enum';
import { SearchIndex } from '../enums/search.enum';
import { getAggregateFieldOptions } from '../rest/miscAPI';
Expand Down Expand Up @@ -796,42 +799,40 @@ class AdvancedSearchClassBase {
};
};

public getCustomPropertiesSubFields(field: { name: string; type: string }) {
public getCustomPropertiesSubFields(field: {
name: string;
type: string;
customPropertyConfig: {
config: string | string[];
};
}) {
{
switch (field.type) {
case 'array<entityReference>':
case 'entityReference':
return {
subfieldsKey: field.name + `.fullyQualifiedName`,
subfieldsKey: field.name + `.name`,
dataObject: {
type: 'select',
label: field.name,
fieldSettings: {
asyncFetch: advancedSearchClassBase.autocomplete({
searchIndex: [SearchIndex.USER, SearchIndex.TEAM],
entityField: EntityFields.DISPLAY_NAME_KEYWORD,
searchIndex: (
(field.customPropertyConfig.config ?? []) as string[]
).join(',') as SearchIndex,
entityField: EntityFields.NAME_KEYWORD,
}),
useAsyncSearch: true,
},
},
};
case 'date-cp': {
return {
subfieldsKey: field.name,
dataObject: {
type: 'date',
valueSources: ['value'],
operators: TEXT_FIELD_OPERATORS,
},
};
}
case 'date-cp':
case 'dateTime-cp': {
return {
subfieldsKey: field.name,
dataObject: {
type: 'datetime',
valueSources: ['value'],
operators: TEXT_FIELD_OPERATORS,
type: 'date',
operators: DATE_FIELD_OPERATORS,
},
};
}
Expand All @@ -840,8 +841,7 @@ class AdvancedSearchClassBase {
subfieldsKey: field.name,
dataObject: {
type: 'time',
valueSources: ['value'],
operators: TEXT_FIELD_OPERATORS,
operators: DATE_FIELD_OPERATORS,
},
};
}
Expand All @@ -851,9 +851,6 @@ class AdvancedSearchClassBase {
dataObject: {
type: 'text',
label: field.name,
fieldSettings: {
minimum_should_match: 1,
},
},
};
}
Expand Down

0 comments on commit 8753ee9

Please sign in to comment.