From 5802dbad525183ebd442a860d6c6b1e2666af4e1 Mon Sep 17 00:00:00 2001 From: UladzislauKutarkin <72550466+UladzislauKutarkin@users.noreply.github.com> Date: Fri, 27 Dec 2024 14:40:06 +0400 Subject: [PATCH] UIPQB-164: Columns are reset when user modifies query (#202) --- CHANGELOG.md | 3 ++- src/QueryBuilder/ResultViewer/ResultViewer.js | 1 + src/QueryBuilder/ResultViewer/ResultViewer.test.js | 4 ++-- src/hooks/useViewerCallbacks.js | 7 ++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98f97432..e20416b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ * [UIPQB-141](https://folio-org.atlassian.net/browse/UIPQB-141) Modal dialog focus inconsistencies across screenreaders. * [UIPQB-162](https://folio-org.atlassian.net/browse/UIPQB-162) Errors when query includes a modified custom field. -* [UIPQB-175](https://folio-org.atlassian.net/browse/UIPQB-175) Displays the "Smth went wrong" page, when the user clicks on "Select operator" dropdown and selects any of them, if there are deleted custom fields +* [UIPQB-175](https://folio-org.atlassian.net/browse/UIPQB-175) Displays the "Smth went wrong" page, when the user clicks on "Select operator" dropdown and selects any of them, if there are deleted custom fields. +* [UIPQB-164](https://folio-org.atlassian.net/browse/UIPQB-164) Columns are reset when user modifies query. ## [1.2.7](https://github.com/folio-org/ui-plugin-query-builder/tree/v1.2.7) (2024-12-26) diff --git a/src/QueryBuilder/ResultViewer/ResultViewer.js b/src/QueryBuilder/ResultViewer/ResultViewer.js index a1c0952a..3e7f9588 100644 --- a/src/QueryBuilder/ResultViewer/ResultViewer.js +++ b/src/QueryBuilder/ResultViewer/ResultViewer.js @@ -82,6 +82,7 @@ export const ResultViewer = ({ onPreviewShown, defaultLimit, forcedVisibleValues, + visibleColumns, }); // refresh functionality diff --git a/src/QueryBuilder/ResultViewer/ResultViewer.test.js b/src/QueryBuilder/ResultViewer/ResultViewer.test.js index dae2576d..0b18d9dd 100644 --- a/src/QueryBuilder/ResultViewer/ResultViewer.test.js +++ b/src/QueryBuilder/ResultViewer/ResultViewer.test.js @@ -76,8 +76,8 @@ describe('ResultViewer', () => { }); describe('Initial and visible columns setters', () => { - it.each([[], undefined])('should call both when no initial fields are provided (recordColumns=%s)', async (visibleColumns) => { - render(renderResultViewer({ visibleColumns })); + it.each([[], undefined])('should call both when no initial fields are provided (recordColumns=%s)', async () => { + render(renderResultViewer({ visibleColumns: ['user_id'] })); await waitFor(() => { expect(screen.queryByText('ui-plugin-query-builder.viewer.retrieving')).not.toBeInTheDocument(); diff --git a/src/hooks/useViewerCallbacks.js b/src/hooks/useViewerCallbacks.js index c27b3efb..ae591d1d 100644 --- a/src/hooks/useViewerCallbacks.js +++ b/src/hooks/useViewerCallbacks.js @@ -8,12 +8,17 @@ export const useViewerCallbacks = ({ currentRecordsCount, onPreviewShown, defaultLimit, + visibleColumns, }) => { useEffect(() => { if (defaultColumns.length !== 0) { onSetDefaultColumns?.(defaultColumns); - onSetDefaultVisibleColumns?.(defaultVisibleColumns); + const uniqueVisibleColumns = Array.from( + new Set([...defaultVisibleColumns, ...visibleColumns]), + ); + + onSetDefaultVisibleColumns?.(uniqueVisibleColumns); } }, [currentRecordsCount]);