Skip to content
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

UIPQB-128: Invalid fields handling > Errors when query includes a deleted custom field #193

Merged
merged 3 commits into from
Dec 4, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* [UIPQB-159](https://folio-org.atlassian.net/browse/UIPQB-159) [Lists] Empty columns are displaying when the user duplicates the list and the refresh is in progress
* [UIPQB-160](https://folio-org.atlassian.net/browse/UIPQB-160) [QB] Update the text in the query builder after 3 attempts result in 500 errors.
* [UIPQB-128](https://folio-org.atlassian.net/browse/UIPQB-128) Invalid fields handling > Errors when query includes a deleted custom field.

## [1.2.4](https://github.com/folio-org/ui-plugin-query-builder/tree/v1.2.4) (2024-11-27)

Expand Down
20 changes: 20 additions & 0 deletions src/QueryBuilder/QueryBuilder/helpers/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@ const getFormattedSourceField = async ({ item, intl, booleanOptions, fieldOption

if (operator) {
const fieldItem = fieldOptions.find(f => f.value === field);
const defaultItem = fieldOptions[0];

// Exceptional case, when queried field were deleted
if (!fieldItem) {
return {
boolean: { options: booleanOptions, current: boolean },
field: { options: fieldOptions, current: field, dataType: defaultItem?.dataType },
operator: {
dataType: defaultItem?.dataType,
options: getOperatorOptions({
dataType: defaultItem?.dataType,
hasSourceOrValues: defaultItem?.value || defaultItem?.source,
intl,
}),
current: '',
},
value: { current: '', source: defaultItem?.source, options: defaultItem?.values },
};
}

const { dataType, values, source } = fieldItem;
const hasSourceOrValues = values || source;
let formattedValue;
Expand Down
54 changes: 54 additions & 0 deletions src/QueryBuilder/QueryBuilder/helpers/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,60 @@ describe('mongoQueryToSource()', () => {

expect(result).toEqual(initial);
});

it('should handle case when queried field is deleted', async () => {
const initialValuesUpdated = {
$and: [
{ user_first_name: { $eq: 'value' } },
{ delegate_languages: { $empty: true } },
],
};

const defaultField = fieldOptions[0];

const result = await mongoQueryToSource({
initialValues: initialValuesUpdated,
booleanOptions,
fieldOptions,
intl: { formatMessage: jest.fn() },
getParamsSource: jest.fn(),
});

expect(result).toEqual([
{
boolean: { options: booleanOptions, current: '$and' },
field: {
options: fieldOptions,
current: 'user_first_name',
dataType: 'stringType',
},
operator: {
dataType: 'stringType',
options: expect.any(Array),
current: '==',
},
value: { current: 'value', source: undefined, options: undefined },
},
{
boolean: { options: booleanOptions, current: '$and' },
field: {
options: fieldOptions,
current: 'delegate_languages',
dataType: defaultField?.dataType,
},
operator: {
dataType: defaultField?.dataType,
options: expect.any(Array),
current: '',
},
value: {
current: '',
source: defaultField?.source,
options: defaultField?.values,
},
},
]);
});
});

describe('isQueryValid', () => {
Expand Down
Loading