@blaze-cms/plugin-data-ui 0.146.0-node18-tooltips.48 → 0.146.0-node18-core-styles-tooltips.60
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 +174 -39
- package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +0 -1
- package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -1
- package/lib/components/EntityManager/Entity/Entity.js +5 -5
- package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
- package/lib/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js +1 -1
- package/lib/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js.map +1 -1
- package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +0 -1
- package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -1
- package/lib/components/EntityManager/Entity/SideBarRelations/index.js +5 -5
- package/lib/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/create/submit.js +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/create/submit.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/delete/delete.js +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/delete/delete.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/shared/publish.js +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/shared/publish.js.map +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/update/submit.js +1 -1
- package/lib/components/EntityManager/Entity/actions-handlers/update/submit.js.map +1 -1
- package/lib/components/EntityManager/EntityManager.js +3 -3
- package/lib/components/EntityManager/EntityManager.js.map +1 -1
- package/lib/components/EntityManager/utils/entity.js +1 -1
- package/lib/components/EntityManager/utils/entity.js.map +1 -1
- package/lib/components/EntityManager/utils/entityAvailableActions.js +2 -2
- package/lib/components/EntityManager/utils/entityAvailableActions.js.map +1 -1
- package/lib/components/InfoBoxes/InfoBoxes.js +0 -1
- package/lib/components/InfoBoxes/InfoBoxes.js.map +1 -1
- package/lib/components/InfoBoxes/container/InfoBoxContainer.js +1 -1
- package/lib/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -1
- package/lib/components/InfoBoxes/helpers/build-dynamic-query.js +0 -1
- package/lib/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -1
- package/lib/components/ListingTable/ListingTable.js +7 -7
- package/lib/components/ListingTable/ListingTable.js.map +1 -1
- package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js +1 -1
- package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
- package/lib/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +327 -0
- package/lib/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js.map +1 -0
- package/lib/components/ListingTable/SearchFilter/SearchContainer.js +111 -79
- package/lib/components/ListingTable/SearchFilter/SearchContainer.js.map +1 -1
- package/lib/components/ListingTable/SearchFilter/SearchFilter.js +1 -1
- package/lib/components/ListingTable/SearchFilter/SearchFilter.js.map +1 -1
- package/lib/components/ListingTable/SearchFilter/helpers.js +0 -1
- package/lib/components/ListingTable/SearchFilter/helpers.js.map +1 -1
- package/lib/components/ListingTable/TableActions/TableActions.js.map +1 -1
- package/lib/components/ListingTable/service/index.js +1 -2
- package/lib/components/ListingTable/service/index.js.map +1 -1
- package/lib/components/Tabs/index.js +1 -1
- package/lib/components/Tabs/index.js.map +1 -1
- package/lib/index.js +5 -5
- package/lib/index.js.map +1 -1
- package/lib/utils/add-content-menu-items.js +1 -1
- package/lib/utils/add-content-menu-items.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/EntityHeader/EntityHeader.js.map +1 -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.map +1 -1
- package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/actions-handlers/create/submit.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/actions-handlers/shared/publish.js.map +1 -1
- package/lib-es/components/EntityManager/EntityManager.js.map +1 -1
- package/lib-es/components/EntityManager/utils/entity.js.map +1 -1
- package/lib-es/components/EntityManager/utils/query.js.map +1 -1
- package/lib-es/components/InfoBoxes/InfoBoxTooltip.js.map +1 -1
- package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -1
- package/lib-es/components/InfoBoxes/hooks/useData.js.map +1 -1
- package/lib-es/components/InfoBoxes/presentational/InfoBox.js.map +1 -1
- package/lib-es/components/InfoBoxes/presentational/InfoBoxLabel.js.map +1 -1
- package/lib-es/components/ListingTable/ListingTable.js.map +1 -1
- package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
- package/lib-es/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +171 -0
- package/lib-es/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js.map +1 -0
- package/lib-es/components/ListingTable/SearchFilter/SearchContainer.js +18 -1
- package/lib-es/components/ListingTable/SearchFilter/SearchContainer.js.map +1 -1
- package/lib-es/components/ListingTable/SearchFilter/helpers.js.map +1 -1
- package/lib-es/components/ListingTable/SearchFilter/querys.js.map +1 -1
- package/lib-es/components/ListingTable/mappers/populate-rows.js.map +1 -1
- package/lib-es/components/ListingTable/service/index.js.map +1 -1
- package/lib-es/index.js +2 -2
- package/lib-es/index.js.map +1 -1
- package/lib-es/utils/add-content-menu-items.js.map +1 -1
- package/lib-es/utils/build-create-entity-mutation.js.map +1 -1
- package/lib-es/utils/build-delete-entity-mutation.js.map +1 -1
- package/lib-es/utils/build-listing-query.js.map +1 -1
- package/lib-es/utils/build-update-data-query.js.map +1 -1
- package/lib-es/utils/build-update-publish-unpublish-mutation.js.map +1 -1
- package/package.json +10 -10
- package/src/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +158 -0
- package/src/components/ListingTable/SearchFilter/SearchContainer.js +35 -2
|
@@ -0,0 +1,158 @@
|
|
|
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: !checked,
|
|
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
|
+
}) => onChange(id, value);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<MultiSelect
|
|
130
|
+
label={label}
|
|
131
|
+
name={id}
|
|
132
|
+
data={{ data: currentData, filterBy: ['name'], identification: 'id', keyValue: 'name' }}
|
|
133
|
+
limit={SELECTION_LIMIT}
|
|
134
|
+
onChange={interceptOnSearchChange}
|
|
135
|
+
getSelected={getSelected}
|
|
136
|
+
onItemsRendered={onItemsRenderedIntercept}
|
|
137
|
+
required={false}
|
|
138
|
+
checkedPreviewCount={1}
|
|
139
|
+
formatMoreLabel={count => `${count} more`}
|
|
140
|
+
isDynamic
|
|
141
|
+
/>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
RelationMultiSelectFilter.propTypes = {
|
|
146
|
+
id: PropTypes.string.isRequired,
|
|
147
|
+
label: PropTypes.string,
|
|
148
|
+
entityIdentifier: PropTypes.string.isRequired,
|
|
149
|
+
selectedIds: PropTypes.array,
|
|
150
|
+
onChange: PropTypes.func.isRequired
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
RelationMultiSelectFilter.defaultProps = {
|
|
154
|
+
label: '',
|
|
155
|
+
selectedIds: []
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export default RelationMultiSelectFilter;
|
|
@@ -16,6 +16,7 @@ import { getStringTypeProps } from '@blaze-cms/utils';
|
|
|
16
16
|
|
|
17
17
|
import { BsArrowCounterclockwise, BsSearch } from 'react-icons/bs';
|
|
18
18
|
import { updateListFilters, buildQueryFields, getTidyLabel } from './helpers';
|
|
19
|
+
import RelationMultiSelectFilter from './RelationMultiSelectFilter';
|
|
19
20
|
import { NOOP_QUERY } from './querys';
|
|
20
21
|
import { ENTER_KEY, DEFAULT_FILTER_OPTION_LABEL } from '../../../constants';
|
|
21
22
|
|
|
@@ -57,6 +58,16 @@ const SearchContainer = ({
|
|
|
57
58
|
[multiSelectFiltersToDisplay]
|
|
58
59
|
);
|
|
59
60
|
|
|
61
|
+
const relationMultiSelectFilters = useMemo(
|
|
62
|
+
() => multiSelectFiltersToDisplay.filter(([, config]) => config && config.relation),
|
|
63
|
+
[multiSelectFiltersToDisplay]
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const nonRelationMultiSelectFilters = useMemo(
|
|
67
|
+
() => multiSelectFiltersToDisplay.filter(([, config]) => !config || !config.relation),
|
|
68
|
+
[multiSelectFiltersToDisplay]
|
|
69
|
+
);
|
|
70
|
+
|
|
60
71
|
const { keywordSearchProperties, keywordSearchLabels } = useMemo(() => {
|
|
61
72
|
const labels = [];
|
|
62
73
|
const properties = [];
|
|
@@ -70,8 +81,9 @@ const SearchContainer = ({
|
|
|
70
81
|
}, [keywordFiltersToUse]);
|
|
71
82
|
|
|
72
83
|
const { gqlFields, rawQuery } = useMemo(
|
|
73
|
-
() =>
|
|
74
|
-
|
|
84
|
+
() =>
|
|
85
|
+
buildQueryFields([...selectFiltersToDisplay, ...nonRelationMultiSelectFilters], schema.id),
|
|
86
|
+
[selectFiltersToDisplay, nonRelationMultiSelectFilters, schema.id]
|
|
75
87
|
);
|
|
76
88
|
|
|
77
89
|
const action = displayAggregations
|
|
@@ -492,6 +504,27 @@ const SearchContainer = ({
|
|
|
492
504
|
);
|
|
493
505
|
})}
|
|
494
506
|
|
|
507
|
+
{relationMultiSelectFilters.map(([property, config]) => {
|
|
508
|
+
const entityIdentifier =
|
|
509
|
+
resolveEntityIdentifier(property, config) || config.relation?.entityIdentifier;
|
|
510
|
+
|
|
511
|
+
if (!entityIdentifier) return null;
|
|
512
|
+
|
|
513
|
+
return (
|
|
514
|
+
<div
|
|
515
|
+
className="search-container__select-wrapper"
|
|
516
|
+
key={`relation-multiselect-${property}`}>
|
|
517
|
+
<RelationMultiSelectFilter
|
|
518
|
+
id={property}
|
|
519
|
+
label={config.label || config.relation.label}
|
|
520
|
+
entityIdentifier={entityIdentifier}
|
|
521
|
+
selectedIds={selectedFilters[property] || []}
|
|
522
|
+
onChange={handleMultiSelect}
|
|
523
|
+
/>
|
|
524
|
+
</div>
|
|
525
|
+
);
|
|
526
|
+
})}
|
|
527
|
+
|
|
495
528
|
<div className="search-container__reset-button">
|
|
496
529
|
<span role="button" onClick={handleReset}>
|
|
497
530
|
<BsArrowCounterclockwise />
|