Skip to content

Commit aa51aab

Browse files
authored
Refactor: field type and operators for enum custom properties (#24906)
1 parent 055acb3 commit aa51aab

3 files changed

Lines changed: 81 additions & 2 deletions

File tree

openmetadata-ui/src/main/resources/ui/src/constants/AdvancedSearch.constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ export const TEXT_FIELD_DESCRIPTION_OPERATORS = [
318318
'is_not_null',
319319
];
320320

321+
export const MULTISELECT_FIELD_OPERATORS = [
322+
'multiselect_contains',
323+
'multiselect_not_contains',
324+
'multiselect_equals',
325+
'multiselect_not_equals',
326+
];
327+
321328
export const RANGE_FIELD_OPERATORS = ['between', 'not_between'];
322329

323330
export const LIST_VALUE_OPERATORS = ['select_equals', 'select_not_equals'];

openmetadata-ui/src/main/resources/ui/src/utils/AdvancedSearchClassBase.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
* See the License for the specific language governing permissions and
1111
* limitations under the License.
1212
*/
13+
import { MULTISELECT_FIELD_OPERATORS } from '../constants/AdvancedSearch.constants';
1314
import { EntityFields } from '../enums/AdvancedSearch.enum';
1415
import { SearchIndex } from '../enums/search.enum';
16+
import { CustomPropertySummary } from '../rest/metadataTypeAPI.interface';
1517
import { AdvancedSearchClassBase } from './AdvancedSearchClassBase';
18+
import { getCustomPropertyAdvanceSearchEnumOptions } from './AdvancedSearchUtils';
19+
import { getEntityName } from './EntityUtils';
1620

1721
jest.mock('../rest/miscAPI', () => ({
1822
getAggregateFieldOptions: jest.fn().mockImplementation(() =>
@@ -26,6 +30,14 @@ jest.mock('./JSONLogicSearchClassBase', () => ({
2630
getQueryBuilderFields: jest.fn(),
2731
}));
2832

33+
jest.mock('./EntityUtils', () => ({
34+
getEntityName: jest.fn(),
35+
}));
36+
37+
jest.mock('./AdvancedSearchUtils', () => ({
38+
getCustomPropertyAdvanceSearchEnumOptions: jest.fn(),
39+
}));
40+
2941
describe('AdvancedSearchClassBase', () => {
3042
let advancedSearchClassBase: AdvancedSearchClassBase;
3143

@@ -198,3 +210,62 @@ describe('getEntitySpecificQueryBuilderFields', () => {
198210
expect(Object.keys(result)).toEqual([]);
199211
});
200212
});
213+
214+
describe('getCustomPropertiesSubFields', () => {
215+
let advancedSearchClassBase: AdvancedSearchClassBase;
216+
const mockGetEntityName = getEntityName as jest.Mock;
217+
const mockGetCustomPropertyAdvanceSearchEnumOptions =
218+
getCustomPropertyAdvanceSearchEnumOptions as jest.Mock;
219+
220+
beforeEach(() => {
221+
advancedSearchClassBase = new AdvancedSearchClassBase();
222+
jest.clearAllMocks();
223+
});
224+
225+
it('should return correct configuration for enum type custom property', () => {
226+
const mockField = {
227+
name: 'statusField',
228+
type: 'enum',
229+
customPropertyConfig: {
230+
config: {
231+
values: ['ACTIVE', 'INACTIVE', 'PENDING'],
232+
},
233+
},
234+
};
235+
236+
const mockLabel = 'Status Field';
237+
const mockEnumOptions = [
238+
{ value: 'ACTIVE', title: 'Active' },
239+
{ value: 'INACTIVE', title: 'Inactive' },
240+
{ value: 'PENDING', title: 'Pending' },
241+
];
242+
243+
mockGetEntityName.mockReturnValue(mockLabel);
244+
mockGetCustomPropertyAdvanceSearchEnumOptions.mockReturnValue(
245+
mockEnumOptions
246+
);
247+
248+
const result = advancedSearchClassBase.getCustomPropertiesSubFields(
249+
mockField as CustomPropertySummary
250+
);
251+
252+
expect(mockGetEntityName).toHaveBeenCalledWith(mockField);
253+
expect(mockGetCustomPropertyAdvanceSearchEnumOptions).toHaveBeenCalledWith([
254+
'ACTIVE',
255+
'INACTIVE',
256+
'PENDING',
257+
]);
258+
259+
expect(result).toEqual({
260+
subfieldsKey: 'statusField',
261+
dataObject: {
262+
type: 'multiselect',
263+
label: mockLabel,
264+
operators: MULTISELECT_FIELD_OPERATORS,
265+
fieldSettings: {
266+
listValues: mockEnumOptions,
267+
},
268+
},
269+
});
270+
});
271+
});

openmetadata-ui/src/main/resources/ui/src/utils/AdvancedSearchClassBase.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { debounce, isEmpty, sortBy, toLower } from 'lodash';
2424
import { CustomPropertyEnumConfig } from '../components/Explore/AdvanceSearchProvider/AdvanceSearchProvider.interface';
2525
import {
2626
LIST_VALUE_OPERATORS,
27+
MULTISELECT_FIELD_OPERATORS,
2728
NULL_CHECK_OPERATORS,
2829
RANGE_FIELD_OPERATORS,
2930
SEARCH_INDICES_WITH_COLUMNS_FIELD,
@@ -1248,9 +1249,9 @@ class AdvancedSearchClassBase {
12481249
return {
12491250
subfieldsKey: field.name,
12501251
dataObject: {
1251-
type: 'select',
1252+
type: 'multiselect',
12521253
label,
1253-
operators: LIST_VALUE_OPERATORS,
1254+
operators: MULTISELECT_FIELD_OPERATORS,
12541255
fieldSettings: {
12551256
listValues: getCustomPropertyAdvanceSearchEnumOptions(
12561257
(field.customPropertyConfig?.config as CustomPropertyEnumConfig)

0 commit comments

Comments
 (0)