diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d4b274..45e76d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change history for ui-plugin-query-builder +## IN PROGRESS + +* [UIPQB-168](https://folio-org.atlassian.net/browse/UIPQB-168) Allow editing queries containing no fields. + ## [1.2.6](https://github.com/folio-org/ui-plugin-query-builder/tree/v1.2.6) (2024-12-11) * [UIPQB-128](https://folio-org.atlassian.net/browse/UIPQB-128) Invalid fields handling > Errors when query includes a deleted custom field. diff --git a/src/QueryBuilder/QueryBuilder/helpers/upgradeInitialValues.js b/src/QueryBuilder/QueryBuilder/helpers/upgradeInitialValues.js index 2481a05..0aded34 100644 --- a/src/QueryBuilder/QueryBuilder/helpers/upgradeInitialValues.js +++ b/src/QueryBuilder/QueryBuilder/helpers/upgradeInitialValues.js @@ -7,16 +7,25 @@ * queries edited/created here are the latest version, as we only have the latest version of entity types available. * In the future, it might be neat to send a request to /fqm/migrate if we see initialValues are out of date, but that's * outside the scope of UIPQB-125 as we already upgrade queries in the background in mod-lists. + * + * Returns undefined if there is no initial value (new query). */ export default function upgradeInitialValues(initialValues, entityType) { if (!initialValues) { - return initialValues; + return undefined; } const withoutVersion = { ...initialValues }; delete withoutVersion._version; + if (Object.keys(withoutVersion).length === 0) { + // if the query is {}, treat it as a new query + // (all add buttons are displayed on existing rows except for the "new list" state, so if we do + // not simulate this state, the user will be unable to add anything) + return undefined; + } + if (!entityType) { return withoutVersion; } diff --git a/src/QueryBuilder/QueryBuilder/helpers/upgradeInitialValues.test.js b/src/QueryBuilder/QueryBuilder/helpers/upgradeInitialValues.test.js index 301c45e..9fac8d2 100644 --- a/src/QueryBuilder/QueryBuilder/helpers/upgradeInitialValues.test.js +++ b/src/QueryBuilder/QueryBuilder/helpers/upgradeInitialValues.test.js @@ -10,13 +10,16 @@ describe('initial values legacy conversion', () => { [undefined, undefined], [null, {}], [undefined, {}], - [{}, null], - [{}, undefined], - ])('ignores initialValues=%s and entityType=%s', (initialValues, entityType) => { - expect(upgradeInitialValues(initialValues, entityType)).toStrictEqual(initialValues); + [{ _version: '1' }, null], + [{ _version: '1' }, undefined], + [{ _version: '1' }, null], + [{ _version: '1' }, undefined], + [{ _version: '1' }, {}], + ])('considers initialValues=%s and entityType=%s as a new query', (initialValues, entityType) => { + expect(upgradeInitialValues(initialValues, entityType)).toStrictEqual(undefined); }); - it.each([{}, { foo: '' }, { bar: '' }, { foo: '', bar: '' }])( + it.each([{ foo: '' }, { bar: '' }, { foo: '', bar: '' }])( 'processes but does not convert non-id columns in %s', (values) => { expect(upgradeInitialValues(values, ENTITY_TYPE)).toStrictEqual(values);