@blaze-cms/plugin-data-ui 0.146.0-node18.1 → 0.146.0-rc-eagle-3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -12
- package/README.md +64 -0
- package/lib/components/EntityDataListing/EntityDataListing.js +21 -19
- package/lib/components/EntityDataListing/EntityDataListing.js.map +1 -1
- package/lib/components/EntityDataListing/index.js +2 -3
- package/lib/components/EntityDataListing/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +18 -20
- package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -1
- package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js +2 -3
- package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/Entity.js +290 -452
- package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
- package/lib/components/EntityManager/Entity/EntityHeader/EntityHeader.js +62 -66
- package/lib/components/EntityManager/Entity/EntityHeader/EntityHeader.js.map +1 -1
- package/lib/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js +34 -50
- package/lib/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js.map +1 -1
- package/lib/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/index.js +2 -3
- package/lib/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/EntityHeader/index.js +2 -3
- package/lib/components/EntityManager/Entity/EntityHeader/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +20 -26
- package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +1 -1
- package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +20 -18
- package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -1
- package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +34 -32
- package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -1
- package/lib/components/EntityManager/Entity/SideBarRelations/index.js +105 -150
- package/lib/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +24 -24
- package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/create/index.js +2 -3
- package/lib/components/EntityManager/Entity/actions-handlers/create/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/create/submit.js +34 -59
- package/lib/components/EntityManager/Entity/actions-handlers/create/submit.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/delete/delete.js +29 -45
- package/lib/components/EntityManager/Entity/actions-handlers/delete/delete.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/delete/index.js +2 -3
- package/lib/components/EntityManager/Entity/actions-handlers/delete/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/index.js +7 -8
- package/lib/components/EntityManager/Entity/actions-handlers/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/shared/index.js +2 -3
- package/lib/components/EntityManager/Entity/actions-handlers/shared/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/shared/publish.js +36 -57
- package/lib/components/EntityManager/Entity/actions-handlers/shared/publish.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/update/index.js +2 -3
- package/lib/components/EntityManager/Entity/actions-handlers/update/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/update/submit.js +47 -66
- package/lib/components/EntityManager/Entity/actions-handlers/update/submit.js.map +1 -1
- package/lib/components/EntityManager/Entity/index.js +2 -3
- package/lib/components/EntityManager/Entity/index.js.map +1 -1
- package/lib/components/EntityManager/EntityManager.js +92 -166
- package/lib/components/EntityManager/EntityManager.js.map +1 -1
- package/lib/components/EntityManager/index.js +2 -3
- package/lib/components/EntityManager/index.js.map +1 -1
- package/lib/components/EntityManager/utils/RecordEditContext/index.js +3 -4
- package/lib/components/EntityManager/utils/RecordEditContext/index.js.map +1 -1
- package/lib/components/EntityManager/utils/data-mappers.js +34 -46
- package/lib/components/EntityManager/utils/data-mappers.js.map +1 -1
- package/lib/components/EntityManager/utils/entity.js +36 -75
- package/lib/components/EntityManager/utils/entity.js.map +1 -1
- package/lib/components/EntityManager/utils/entityAvailableActions.js +51 -110
- package/lib/components/EntityManager/utils/entityAvailableActions.js.map +1 -1
- package/lib/components/EntityManager/utils/is-form-empty.js +6 -10
- package/lib/components/EntityManager/utils/is-form-empty.js.map +1 -1
- package/lib/components/EntityManager/utils/query.js +17 -10
- package/lib/components/EntityManager/utils/query.js.map +1 -1
- package/lib/components/InfoBoxes/InfoBoxTooltip.js +43 -0
- package/lib/components/InfoBoxes/InfoBoxTooltip.js.map +1 -0
- package/lib/components/InfoBoxes/InfoBoxes.js +19 -20
- package/lib/components/InfoBoxes/InfoBoxes.js.map +1 -1
- package/lib/components/InfoBoxes/container/InfoBoxContainer.js +27 -38
- package/lib/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -1
- package/lib/components/InfoBoxes/helpers/build-dynamic-query.js +21 -17
- package/lib/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -1
- package/lib/components/InfoBoxes/hooks/useData.js +33 -30
- package/lib/components/InfoBoxes/hooks/useData.js.map +1 -1
- package/lib/components/InfoBoxes/hooks/useInfoBox.js +10 -10
- package/lib/components/InfoBoxes/hooks/useInfoBox.js.map +1 -1
- package/lib/components/InfoBoxes/index.js +2 -3
- package/lib/components/InfoBoxes/index.js.map +1 -1
- package/lib/components/InfoBoxes/presentational/InfoBox.js +28 -32
- package/lib/components/InfoBoxes/presentational/InfoBox.js.map +1 -1
- package/lib/components/InfoBoxes/presentational/InfoBoxLabel.js +11 -12
- package/lib/components/InfoBoxes/presentational/InfoBoxLabel.js.map +1 -1
- package/lib/components/InfoBoxes/presentational/InfoBoxValue.js +12 -12
- package/lib/components/InfoBoxes/presentational/InfoBoxValue.js.map +1 -1
- package/lib/components/ListingTable/ListingTable.js +164 -303
- package/lib/components/ListingTable/ListingTable.js.map +1 -1
- package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js +62 -40
- package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
- package/lib/components/ListingTable/ListingTableContent/index.js +2 -3
- package/lib/components/ListingTable/ListingTableContent/index.js.map +1 -1
- package/lib/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +182 -0
- package/lib/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js.map +1 -0
- package/lib/components/ListingTable/SearchFilter/SearchContainer.js +505 -0
- package/lib/components/ListingTable/SearchFilter/SearchContainer.js.map +1 -0
- package/lib/components/ListingTable/SearchFilter/SearchFilter.js +53 -0
- package/lib/components/ListingTable/SearchFilter/SearchFilter.js.map +1 -0
- package/lib/components/ListingTable/SearchFilter/helpers.js +138 -0
- package/lib/components/ListingTable/SearchFilter/helpers.js.map +1 -0
- package/lib/components/ListingTable/SearchFilter/querys.js +13 -0
- package/lib/components/ListingTable/SearchFilter/querys.js.map +1 -0
- package/lib/components/ListingTable/TableActions/TableActions.js +27 -31
- package/lib/components/ListingTable/TableActions/TableActions.js.map +1 -1
- package/lib/components/ListingTable/TableActions/index.js +2 -3
- package/lib/components/ListingTable/TableActions/index.js.map +1 -1
- package/lib/components/ListingTable/index.js +2 -3
- package/lib/components/ListingTable/index.js.map +1 -1
- package/lib/components/ListingTable/mappers/populate-rows.js +104 -120
- package/lib/components/ListingTable/mappers/populate-rows.js.map +1 -1
- package/lib/components/ListingTable/service/index.js +66 -84
- package/lib/components/ListingTable/service/index.js.map +1 -1
- package/lib/components/Tabs/index.js +27 -42
- package/lib/components/Tabs/index.js.map +1 -1
- package/lib/components/hooks/useCallbackDebounce.js +5 -9
- package/lib/components/hooks/useCallbackDebounce.js.map +1 -1
- package/lib/constants.js +31 -29
- package/lib/constants.js.map +1 -1
- package/lib/icons/ContentIcon.js +17 -20
- package/lib/icons/ContentIcon.js.map +1 -1
- package/lib/icons/SettingsIcon.js +12 -15
- package/lib/icons/SettingsIcon.js.map +1 -1
- package/lib/icons/TaxonomyIcon.js +15 -18
- package/lib/icons/TaxonomyIcon.js.map +1 -1
- package/lib/icons/UsersIcon.js +11 -14
- package/lib/icons/UsersIcon.js.map +1 -1
- package/lib/icons/index.js +8 -9
- package/lib/icons/index.js.map +1 -1
- package/lib/index.js +88 -121
- package/lib/index.js.map +1 -1
- package/lib/utils/add-content-menu-items.js +67 -93
- package/lib/utils/add-content-menu-items.js.map +1 -1
- package/lib/utils/build-create-entity-mutation.js +5 -18
- package/lib/utils/build-create-entity-mutation.js.map +1 -1
- package/lib/utils/build-delete-entity-mutation.js +11 -8
- package/lib/utils/build-delete-entity-mutation.js.map +1 -1
- package/lib/utils/build-listing-query.js +20 -17
- package/lib/utils/build-listing-query.js.map +1 -1
- package/lib/utils/build-update-data-query.js +15 -9
- package/lib/utils/build-update-data-query.js.map +1 -1
- package/lib/utils/build-update-publish-unpublish-mutation.js +15 -8
- package/lib/utils/build-update-publish-unpublish-mutation.js.map +1 -1
- package/lib/utils/get-default-query-params.js +23 -10
- package/lib/utils/get-default-query-params.js.map +1 -1
- package/lib/utils/hoc/withContext.js +4 -6
- package/lib/utils/hoc/withContext.js.map +1 -1
- package/lib/utils/hooks/useToggle.js +4 -12
- package/lib/utils/hooks/useToggle.js.map +1 -1
- package/lib/utils/index.js +2 -3
- package/lib/utils/index.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/Entity.js +23 -30
- package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js +6 -1
- package/lib-es/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +2 -0
- package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js +26 -7
- package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +8 -2
- package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/actions-handlers/create/submit.js +4 -14
- package/lib-es/components/EntityManager/Entity/actions-handlers/create/submit.js.map +1 -1
- package/lib-es/components/EntityManager/utils/entity.js +8 -5
- package/lib-es/components/EntityManager/utils/entity.js.map +1 -1
- package/lib-es/components/InfoBoxes/InfoBoxTooltip.js +36 -0
- package/lib-es/components/InfoBoxes/InfoBoxTooltip.js.map +1 -0
- package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js +2 -0
- package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -1
- package/lib-es/components/InfoBoxes/presentational/InfoBox.js +4 -1
- package/lib-es/components/InfoBoxes/presentational/InfoBox.js.map +1 -1
- package/lib-es/components/ListingTable/ListingTable.js +12 -11
- package/lib-es/components/ListingTable/ListingTable.js.map +1 -1
- package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js +34 -16
- package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
- package/lib-es/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +173 -0
- package/lib-es/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js.map +1 -0
- package/lib-es/components/ListingTable/SearchFilter/SearchContainer.js +496 -0
- package/lib-es/components/ListingTable/SearchFilter/SearchContainer.js.map +1 -0
- package/lib-es/components/ListingTable/SearchFilter/SearchFilter.js +44 -0
- package/lib-es/components/ListingTable/SearchFilter/SearchFilter.js.map +1 -0
- package/lib-es/components/ListingTable/SearchFilter/helpers.js +127 -0
- package/lib-es/components/ListingTable/SearchFilter/helpers.js.map +1 -0
- package/lib-es/components/ListingTable/SearchFilter/querys.js +8 -0
- package/lib-es/components/ListingTable/SearchFilter/querys.js.map +1 -0
- package/lib-es/components/ListingTable/mappers/populate-rows.js +3 -0
- package/lib-es/components/ListingTable/mappers/populate-rows.js.map +1 -1
- package/lib-es/components/ListingTable/service/index.js +3 -2
- package/lib-es/components/ListingTable/service/index.js.map +1 -1
- package/lib-es/components/Tabs/index.js +6 -7
- package/lib-es/components/Tabs/index.js.map +1 -1
- package/lib-es/constants.js +4 -1
- package/lib-es/constants.js.map +1 -1
- package/lib-es/index.js +12 -3
- package/lib-es/index.js.map +1 -1
- package/lib-es/utils/build-create-entity-mutation.js +5 -19
- package/lib-es/utils/build-create-entity-mutation.js.map +1 -1
- package/lib-es/utils/build-listing-query.js +4 -4
- package/lib-es/utils/build-listing-query.js.map +1 -1
- package/lib-es/utils/get-default-query-params.js +17 -5
- package/lib-es/utils/get-default-query-params.js.map +1 -1
- package/lib-es/utils/hoc/withContext.js +1 -1
- package/lib-es/utils/hoc/withContext.js.map +1 -1
- package/package.json +21 -17
- package/src/components/EntityManager/Entity/Entity.js +35 -40
- package/src/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js +8 -1
- package/src/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +2 -0
- package/src/components/EntityManager/Entity/SideBarRelations/index.js +51 -17
- package/src/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +5 -3
- package/src/components/EntityManager/Entity/actions-handlers/create/submit.js +4 -11
- package/src/components/EntityManager/utils/entity.js +11 -6
- package/src/components/InfoBoxes/InfoBoxTooltip.js +32 -0
- package/src/components/InfoBoxes/helpers/build-dynamic-query.js +2 -0
- package/src/components/InfoBoxes/presentational/InfoBox.js +4 -2
- package/src/components/ListingTable/ListingTable.js +13 -18
- package/src/components/ListingTable/ListingTableContent/ListingTableContent.js +43 -25
- package/src/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +160 -0
- package/src/components/ListingTable/SearchFilter/SearchContainer.js +553 -0
- package/src/components/ListingTable/SearchFilter/SearchFilter.js +41 -0
- package/src/components/ListingTable/SearchFilter/helpers.js +146 -0
- package/src/components/ListingTable/SearchFilter/querys.js +9 -0
- package/src/components/ListingTable/mappers/populate-rows.js +3 -0
- package/src/components/ListingTable/service/index.js +2 -2
- package/src/components/Tabs/index.js +17 -21
- package/src/constants.js +9 -1
- package/src/index.js +11 -7
- package/src/utils/build-create-entity-mutation.js +5 -28
- package/src/utils/build-listing-query.js +4 -4
- package/src/utils/get-default-query-params.js +21 -9
- package/src/utils/hoc/withContext.js +5 -4
- package/babel.config.js +0 -3
- package/jest.config.js +0 -5
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
2
|
import Table from '@blaze-react/table';
|
|
3
3
|
import Pagination from '@blaze-react/pagination';
|
|
4
|
-
|
|
5
4
|
import PropTypes from 'prop-types';
|
|
6
5
|
import { withRouter } from 'react-router-dom';
|
|
7
6
|
|
|
@@ -13,34 +12,53 @@ const ListingTableContent = ({
|
|
|
13
12
|
currentPage,
|
|
14
13
|
totalItems
|
|
15
14
|
}) => {
|
|
15
|
+
const ref = useRef(null);
|
|
16
16
|
const displayTable = tableData && tableData.rows && !!tableData.rows.length;
|
|
17
17
|
const { isEnquiry } = tableData;
|
|
18
18
|
const className = `page__content${isEnquiry ? ' array-table' : ''}`;
|
|
19
19
|
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
// set table head to match body column widths to handle dynamic content
|
|
22
|
+
if (ref.current && displayTable) {
|
|
23
|
+
const tableHeadCells = ref.current.querySelectorAll('.table-head .table-cell');
|
|
24
|
+
const firstRowCells = ref.current.querySelectorAll(
|
|
25
|
+
'.table-body .table-row:first-child .table-cell'
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
firstRowCells.forEach((element, i) => {
|
|
29
|
+
const styles = window.getComputedStyle(element);
|
|
30
|
+
|
|
31
|
+
if (tableHeadCells[i]) {
|
|
32
|
+
tableHeadCells[i].style.flex = styles.flex;
|
|
33
|
+
tableHeadCells[i].style['justify-content'] = styles['justify-content'];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}, [tableData, displayTable]);
|
|
38
|
+
|
|
39
|
+
if (displayTable) {
|
|
40
|
+
return (
|
|
41
|
+
<div ref={ref} className={className}>
|
|
42
|
+
<Table
|
|
43
|
+
onSort={onSort}
|
|
44
|
+
data={tableData}
|
|
45
|
+
onSelect={handleSelect}
|
|
46
|
+
data-testid="listing-table-content"
|
|
47
|
+
/>
|
|
48
|
+
<Pagination
|
|
49
|
+
visiblePages={10}
|
|
50
|
+
totalItems={totalItems}
|
|
51
|
+
currentPage={currentPage}
|
|
52
|
+
onPageChange={handleOnPageChange}
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
20
58
|
return (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<Table
|
|
25
|
-
onSort={onSort}
|
|
26
|
-
data={tableData}
|
|
27
|
-
checkboxes={!isEnquiry}
|
|
28
|
-
onSelect={handleSelect}
|
|
29
|
-
data-testid="listing-table-content"
|
|
30
|
-
/>
|
|
31
|
-
<Pagination
|
|
32
|
-
visiblePages={10}
|
|
33
|
-
totalItems={totalItems}
|
|
34
|
-
currentPage={currentPage}
|
|
35
|
-
onPageChange={handleOnPageChange}
|
|
36
|
-
/>
|
|
37
|
-
</div>
|
|
38
|
-
) : (
|
|
39
|
-
<span className="table-no-results" data-testid="no-results">
|
|
40
|
-
No results
|
|
41
|
-
</span>
|
|
42
|
-
)}
|
|
43
|
-
</>
|
|
59
|
+
<span className="table-no-results" data-testid="no-results">
|
|
60
|
+
No results
|
|
61
|
+
</span>
|
|
44
62
|
);
|
|
45
63
|
};
|
|
46
64
|
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import React, { useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import MultiSelect from '@blaze-react/multiselect';
|
|
4
|
+
import debounce from 'lodash.debounce';
|
|
5
|
+
import unionBy from 'lodash.unionby';
|
|
6
|
+
import { useApolloClient } from '@apollo/client';
|
|
7
|
+
import {
|
|
8
|
+
getQuery,
|
|
9
|
+
getDynamicQuery,
|
|
10
|
+
getAdminRecordSearch,
|
|
11
|
+
buildLabel
|
|
12
|
+
} from '@blaze-cms/admin-ui-utils';
|
|
13
|
+
|
|
14
|
+
const DEBOUNCE_TIME = 500;
|
|
15
|
+
const SEARCH_LOAD_OFFSET = 10;
|
|
16
|
+
const SELECTION_LIMIT = 10;
|
|
17
|
+
|
|
18
|
+
const shouldLoadMore = (searchTerm, stopIndex, currentDataLength) =>
|
|
19
|
+
searchTerm &&
|
|
20
|
+
stopIndex > SEARCH_LOAD_OFFSET &&
|
|
21
|
+
stopIndex >= currentDataLength - SEARCH_LOAD_OFFSET;
|
|
22
|
+
|
|
23
|
+
const RelationMultiSelectFilter = ({ id, label, entityIdentifier, selectedIds, onChange }) => {
|
|
24
|
+
const client = useApolloClient();
|
|
25
|
+
const [schema, setSchema] = useState(null);
|
|
26
|
+
const [data, setData] = useState([]);
|
|
27
|
+
const [searchTerm, setSearchTerm] = useState('');
|
|
28
|
+
|
|
29
|
+
const { displayProperties } = schema || {};
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
let active = true;
|
|
33
|
+
(async () => {
|
|
34
|
+
try {
|
|
35
|
+
const { data: { getEntitySchemas = [] } = {} } = await client.query({
|
|
36
|
+
query: getQuery('GET_ENTITY_SCHEMA'),
|
|
37
|
+
variables: { identifier: entityIdentifier }
|
|
38
|
+
});
|
|
39
|
+
const [relationSchema] = getEntitySchemas;
|
|
40
|
+
if (active && relationSchema) setSchema(relationSchema);
|
|
41
|
+
} catch {
|
|
42
|
+
if (active) setSchema(null);
|
|
43
|
+
}
|
|
44
|
+
})();
|
|
45
|
+
return () => {
|
|
46
|
+
active = false;
|
|
47
|
+
};
|
|
48
|
+
}, [client, entityIdentifier]);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!schema || !selectedIds.length) return undefined;
|
|
52
|
+
let active = true;
|
|
53
|
+
(async () => {
|
|
54
|
+
try {
|
|
55
|
+
const { data: { result = [] } = {} } = await client.query({
|
|
56
|
+
query: getDynamicQuery('GET_ALL_ENTITIES')(schema),
|
|
57
|
+
variables: {
|
|
58
|
+
where: { id: { _in: selectedIds } },
|
|
59
|
+
sort: [{ property: 'name', direction: 'asc' }]
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (active && result.length) setData(prev => unionBy([...prev, ...result], 'id'));
|
|
63
|
+
} catch {
|
|
64
|
+
// ignore - selected chips will fall back to id-only display
|
|
65
|
+
}
|
|
66
|
+
})();
|
|
67
|
+
return () => {
|
|
68
|
+
active = false;
|
|
69
|
+
};
|
|
70
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
71
|
+
}, [schema]);
|
|
72
|
+
|
|
73
|
+
const onSearch = useMemo(
|
|
74
|
+
() => (schema ? getAdminRecordSearch(schema, client) : null),
|
|
75
|
+
[schema, client]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const currentData = useMemo(
|
|
79
|
+
() =>
|
|
80
|
+
data.map(option => {
|
|
81
|
+
const checked = selectedIds.includes(option.id);
|
|
82
|
+
return {
|
|
83
|
+
...option,
|
|
84
|
+
checked,
|
|
85
|
+
show: true,
|
|
86
|
+
name: buildLabel(displayProperties, option)
|
|
87
|
+
};
|
|
88
|
+
}),
|
|
89
|
+
[data, selectedIds, displayProperties]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const interceptOnSearchChange = debounce(async ({ value }) => {
|
|
93
|
+
setSearchTerm(value);
|
|
94
|
+
if (!onSearch) return;
|
|
95
|
+
const result = await onSearch({ event: { value }, currentValue: selectedIds });
|
|
96
|
+
if (!result) return;
|
|
97
|
+
setData(prev => {
|
|
98
|
+
const selected = prev.filter(item => selectedIds.includes(item.id));
|
|
99
|
+
const newOnes = result.filter(item => !selectedIds.includes(item.id));
|
|
100
|
+
return unionBy([...selected, ...newOnes], 'id');
|
|
101
|
+
});
|
|
102
|
+
}, DEBOUNCE_TIME);
|
|
103
|
+
|
|
104
|
+
const scrollHook = debounce(async ({ stopIndex }) => {
|
|
105
|
+
if (!onSearch) return;
|
|
106
|
+
const currentDataLength = data.length - selectedIds.length;
|
|
107
|
+
if (!shouldLoadMore(searchTerm, stopIndex, currentDataLength)) return;
|
|
108
|
+
const result = await onSearch({
|
|
109
|
+
event: { value: searchTerm },
|
|
110
|
+
currentValue: selectedIds,
|
|
111
|
+
currentOffset: currentDataLength
|
|
112
|
+
});
|
|
113
|
+
if (!result || !result.length) return;
|
|
114
|
+
setData(prev => unionBy([...prev, ...result], 'id'));
|
|
115
|
+
}, DEBOUNCE_TIME);
|
|
116
|
+
|
|
117
|
+
const onItemsRenderedIntercept = async event => {
|
|
118
|
+
if (!onSearch) return;
|
|
119
|
+
scrollHook(event);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const getSelected = ({
|
|
123
|
+
event: {
|
|
124
|
+
target: { value }
|
|
125
|
+
}
|
|
126
|
+
}) => {
|
|
127
|
+
onChange(id, value);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<MultiSelect
|
|
132
|
+
label={label}
|
|
133
|
+
name={id}
|
|
134
|
+
data={{ data: currentData, filterBy: ['name'], identification: 'id', keyValue: 'name' }}
|
|
135
|
+
limit={SELECTION_LIMIT}
|
|
136
|
+
onChange={interceptOnSearchChange}
|
|
137
|
+
getSelected={getSelected}
|
|
138
|
+
onItemsRendered={onItemsRenderedIntercept}
|
|
139
|
+
required={false}
|
|
140
|
+
checkedPreviewCount={1}
|
|
141
|
+
formatMoreLabel={count => `${count} more`}
|
|
142
|
+
isDynamic
|
|
143
|
+
/>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
RelationMultiSelectFilter.propTypes = {
|
|
148
|
+
id: PropTypes.string.isRequired,
|
|
149
|
+
label: PropTypes.string,
|
|
150
|
+
entityIdentifier: PropTypes.string.isRequired,
|
|
151
|
+
selectedIds: PropTypes.array,
|
|
152
|
+
onChange: PropTypes.func.isRequired
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
RelationMultiSelectFilter.defaultProps = {
|
|
156
|
+
label: '',
|
|
157
|
+
selectedIds: []
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export default RelationMultiSelectFilter;
|