Skip to content

Commit

Permalink
[UIPQB-132] Add useLastNotEmptyValue hook (#147)
Browse files Browse the repository at this point in the history
* Add useLastNotEmptyValue hook

* Update CHANGELOG.md
  • Loading branch information
SergeYvas authored Sep 13, 2024
1 parent ec0ae37 commit cadafd1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [UIPQB-119](https://folio-org.atlassian.net/browse/UIPQB-119) Filter column names
* [UIPQB-79](https://folio-org.atlassian.net/browse/UIPQB-79) Update available operators for arrays
* [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

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

Expand Down
7 changes: 5 additions & 2 deletions src/QueryBuilder/ResultViewer/ResultViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useAsyncDataSource } from '../../hooks/useAsyncDataSource';
import { usePagination } from '../../hooks/usePagination';
import { useViewerRefresh } from '../../hooks/useViewerRefresh';
import { useViewerCallbacks } from '../../hooks/useViewerCallbacks';
import { useLastNotEmptyValue } from '../../hooks/useLastNotEmptyValue';

export const ResultViewer = ({
showPagination = true,
Expand Down Expand Up @@ -66,6 +67,8 @@ export const ResultViewer = ({
forcedVisibleValues,
});

const lastNotEmptyContent = useLastNotEmptyValue(contentData, []);

const isListLoading = isContentDataFetching || isContentDataLoading || isEntityTypeLoading || refreshInProgress;
const currentRecordsCount = contentData?.length || 0;

Expand Down Expand Up @@ -98,7 +101,7 @@ export const ResultViewer = ({
<Row between="xs">
<Col xs={10}>
<Headline size="large" margin="none" tag="h3">
{isListLoading ?
{isListLoading && !totalRecords ?
intl.formatMessage({ id: 'ui-plugin-query-builder.result.inProgress' })
:
headline?.({
Expand Down Expand Up @@ -135,7 +138,7 @@ export const ResultViewer = ({
) : (
<MultiColumnList
data-testid="results-viewer-table"
contentData={contentData}
contentData={lastNotEmptyContent}
columnMapping={columnMapping}
formatter={formatter}
columnWidths={columnWidths}
Expand Down
14 changes: 14 additions & 0 deletions src/hooks/useLastNotEmptyValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useEffect, useState } from 'react';
import { isEmpty } from 'lodash';

export const useLastNotEmptyValue = (value, defaultValue) => {
const [lastNotEmptyValue, setLastNotEmptyValue] = useState(defaultValue);

useEffect(() => {
if (!isEmpty(value)) {
setLastNotEmptyValue(value);
}
}, [value]);

return lastNotEmptyValue;
};

0 comments on commit cadafd1

Please sign in to comment.