Skip to content

Commit

Permalink
Merge branch 'master' into Add-polling-mode-for-result-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeYvas authored Sep 27, 2024
2 parents 9921272 + 538882c commit 18965e4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [UIPQB-131](https://folio-org.atlassian.net/browse/UIPQB-131) Columns and empty area display in the list details page, when we refresh the page 1st time or duplicate the list
* [UIPQB-132](https://folio-org.atlassian.net/browse/UIPQB-132) Save not empty previews results and show it in test query
* [UIPQB-126](https://folio-org.atlassian.net/browse/UIPQB-126) Update date format in requests to UTC
* [UIPQB-125](https://folio-org.atlassian.net/browse/UIPQB-125) Add support for FQM _version

## [1.1.4](https://github.com/folio-org/ui-plugin-query-builder/tree/v1.1.4) (2024-04-02)

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
],
"pluginType": "query-builder",
"displayName": "ui-plugin-query-builder.meta.title",
"okapiInterfaces": {},
"okapiInterfaces": {
"fqm-query": "2.0"
},
"stripesDeps": [
"@folio/stripes-acq-components"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import { useRunQuery } from '../../../hooks/useRunQuery';
import { getSourceValue, useQuerySource } from '../../../hooks/useQuerySource';
import { queryBuilderModalPropTypes } from '../../propTypes';
import { QUERY_DETAILS_STATUSES, QUERY_KEYS } from '../../../constants/query';
import { useEntityType } from '../../../hooks/useEntityType';
import { useCancelQuery } from '../../../hooks/useCancelQuery';
import { useEntityType } from '../../../hooks/useEntityType';
import { useFqmVersion } from '../../../hooks/useFqmVersion';
import { useTestQuery } from '../../../hooks/useTestQuery';
import { getFieldOptions } from '../helpers/selectOptions';
import upgradeInitialValues from '../helpers/upgradeInitialValues';
Expand Down Expand Up @@ -62,6 +63,8 @@ export const QueryBuilderModal = ({
},
});

const fqmVersion = useFqmVersion();

const { cancelQuery } = useCancelQuery({ cancelQueryDataSource });

const initialValues = useMemo(
Expand Down Expand Up @@ -160,7 +163,7 @@ export const QueryBuilderModal = ({
const handleRun = async () => {
await runQuery({
queryId,
fqlQuery,
fqlQuery: { ...fqlQuery, _version: fqmVersion },
userFriendlyQuery: queryStr,
});

Expand Down
19 changes: 16 additions & 3 deletions src/QueryBuilder/QueryBuilder/helpers/upgradeInitialValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@
* Upgrades initial values to indirectly reference id columns (e.g. vendor_code instead of vendor_id).
* FQM used to previously require vendor_id, but this was changed in MODFQMMGR-151 to allow for better expression
* and to allow for more flexibility in the future.
*
* As part of UIPQB-125, we're stripping out the _version key from the initial values, too. We will assume that any
* 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.
*/
export default function upgradeInitialValues(initialValues, entityType) {
if (!initialValues || !entityType) {
if (!initialValues) {
return initialValues;
}

const withoutVersion = { ...initialValues };

delete withoutVersion._version;

if (!entityType) {
return withoutVersion;
}

const idColumnMapping = {};

entityType.columns.forEach((column) => {
Expand All @@ -18,10 +31,10 @@ export default function upgradeInitialValues(initialValues, entityType) {

const upgradedInitialValues = {};

Object.keys(initialValues).forEach((key) => {
Object.keys(withoutVersion).forEach((key) => {
const newKey = idColumnMapping[key] || key;

upgradedInitialValues[newKey] = initialValues[key];
upgradedInitialValues[newKey] = withoutVersion[key];
});

return upgradedInitialValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('initial values legacy conversion', () => {
[{}, null],
[{}, undefined],
])('ignores initialValues=%s and entityType=%s', (initialValues, entityType) => {
expect(upgradeInitialValues(initialValues, entityType)).toBe(initialValues);
expect(upgradeInitialValues(initialValues, entityType)).toStrictEqual(initialValues);
});

it.each([{}, { foo: '' }, { bar: '' }, { foo: '', bar: '' }])(
Expand All @@ -26,7 +26,8 @@ describe('initial values legacy conversion', () => {
);

it.each([
[{ idColumn: '' }, { foo: '' }],
[{ _version: '1', foo: '' }, { foo: '' }],
[{ _version: '1', idColumn: '' }, { foo: '' }],
[
{ idColumn: '', bar: '' },
{ foo: '', bar: '' },
Expand Down
2 changes: 2 additions & 0 deletions src/constants/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const QUERY_DETAILS_STATUSES = {
};

export const QUERY_KEYS = {
FQM_VERSION: 'FQM_VERSION',

QUERY_PLUGIN_CONTENT_DATA: 'QUERY_PLUGIN_CONTENT_DATA',
QUERY_PLUGIN_ENTITY_TYPE: 'QUERY_PLUGIN_ENTITY_TYPE',
QUERY_PLUGIN_PREVIEW_ENTITY_TYPE: 'QUERY_PLUGIN_PREVIEW_ENTITY_TYPE',
Expand Down
15 changes: 15 additions & 0 deletions src/hooks/useFqmVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useNamespace, useOkapiKy } from '@folio/stripes/core';
import { useQuery } from 'react-query';
import { QUERY_KEYS } from '../constants/query';

export function useFqmVersion() {
const ky = useOkapiKy();
const [queryKey] = useNamespace({ key: QUERY_KEYS.FQM_VERSION });

return (
useQuery({
queryKey: [queryKey],
queryFn: () => ky.get('fqm/version').text(),
}).data ?? '0'
);
}

0 comments on commit 18965e4

Please sign in to comment.