Skip to content

Commit

Permalink
[UIPQB-168] Allow editing queries containing no fields (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncovercash authored Dec 13, 2024
1 parent 3414815 commit e46fed8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
11 changes: 10 additions & 1 deletion src/QueryBuilder/QueryBuilder/helpers/upgradeInitialValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e46fed8

Please sign in to comment.