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-168] Allow editing queries containing no fields #196

Merged
merged 2 commits into from
Dec 13, 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
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
Loading