@antscorp/antsomi-ui 1.3.5-beta.622 → 1.3.5-beta.624
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/es/components/molecules/AccountSelection/AccountListing.js +1 -1
- package/es/components/molecules/AccountSelection/AccountSelection.js +1 -1
- package/es/components/organism/DataTable/hooks/useDataTableListing/types.d.ts +4 -0
- package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.js +44 -19
- package/es/components/template/TemplateListing/components/CategoryListing/styled.js +3 -0
- package/package.json +1 -1
|
@@ -44,5 +44,5 @@ export const AccountListing = React.forwardRef((props, ref) => {
|
|
|
44
44
|
accountData.filter(account => !(recentData === null || recentData === void 0 ? void 0 : recentData.value.includes(account.userId)) &&
|
|
45
45
|
searchStringQuery(account.userName, searchValue)).map(account => (React.createElement(AccountItem, { key: account.userId, userName: account.userName, userId: account.userId, onClick: handleSelectAccount, isSelected: +currentAccount === account.userId })))))),
|
|
46
46
|
showAllAccount ? (React.createElement(Text, { className: `all-account ${isAllAccount ? 'is-selected' : ''}`, onClick: () => handleSelectAccount('all') },
|
|
47
|
-
React.createElement("strong", null, "All
|
|
47
|
+
React.createElement("strong", null, "All accounts"))) : null));
|
|
48
48
|
});
|
|
@@ -31,7 +31,7 @@ export const AccountSelection = props => {
|
|
|
31
31
|
useEffect(() => {
|
|
32
32
|
var _a;
|
|
33
33
|
const newLabel = currentAccount === 'all'
|
|
34
|
-
? 'All
|
|
34
|
+
? 'All accounts'
|
|
35
35
|
: ((_a = accountData === null || accountData === void 0 ? void 0 : accountData.find(account => account.userId === +currentAccount)) === null || _a === void 0 ? void 0 : _a.userName) || '';
|
|
36
36
|
setInputLabel(newLabel);
|
|
37
37
|
}, [currentAccount, accountData]);
|
|
@@ -41,6 +41,8 @@ export type TConfig<TTableType = any> = {
|
|
|
41
41
|
type: number;
|
|
42
42
|
objectId: number;
|
|
43
43
|
};
|
|
44
|
+
/** Disable local storage cache */
|
|
45
|
+
disabledCache?: boolean;
|
|
44
46
|
};
|
|
45
47
|
type TGeneralTableColumnType<TTableType> = Omit<ColumnType<TTableType>, 'render'> & {
|
|
46
48
|
link?: ((record: TTableType) => string) | string;
|
|
@@ -104,6 +106,8 @@ export interface UseDataTableListingProps<TTableType = any, TSearchType = any> {
|
|
|
104
106
|
};
|
|
105
107
|
search?: TSearchProps<TSearchType>;
|
|
106
108
|
filter?: {
|
|
109
|
+
/** Init default filters, this filter will show in UI instead of external filters */
|
|
110
|
+
defaultFilters?: FilterItem[];
|
|
107
111
|
externalFilters?: FilterItem[];
|
|
108
112
|
includeDataType?: boolean;
|
|
109
113
|
matchesAny?: {
|
|
@@ -78,14 +78,14 @@ export function useDataTableListing(props) {
|
|
|
78
78
|
// State
|
|
79
79
|
const [state, setState] = useState(initialState);
|
|
80
80
|
// Variables
|
|
81
|
-
const { env = appConfig === null || appConfig === void 0 ? void 0 : appConfig.env, auth = appConfig === null || appConfig === void 0 ? void 0 : appConfig.auth, api, object } = config;
|
|
81
|
+
const { env = appConfig === null || appConfig === void 0 ? void 0 : appConfig.env, auth = appConfig === null || appConfig === void 0 ? void 0 : appConfig.auth, api, object, disabledCache } = config;
|
|
82
82
|
const { column: apiColumn, filter: apiFilter, listing: apiListing, search: apiSearch, matchesAny: apiMatchesAny, } = api || {};
|
|
83
83
|
const _d = apiColumn || {}, { url: columnUrl = `${COLUMN_DOMAIN[env || 'development']}/api/column`, enabled: enabledApiColumn = true } = _d, restOfApiColumnRequest = __rest(_d, ["url", "enabled"]);
|
|
84
84
|
const _e = apiFilter || {}, { url: filterUrl = `${COLUMN_DOMAIN[env || 'development']}/api/filter`, enabled: enabledApiFilter = true } = _e, restOfApiFilterRequest = __rest(_e, ["url", "enabled"]);
|
|
85
85
|
const _f = apiListing || {}, { url: listingUrl = '', enabled: enabledApiListing = true } = _f, restOfApiListingRequest = __rest(_f, ["url", "enabled"]);
|
|
86
86
|
const _g = apiSearch || {}, { url: searchUrl = '', enabled: enabledApiSearch = true } = _g, restOfApiSearchRequest = __rest(_g, ["url", "enabled"]);
|
|
87
87
|
const { filters, selectedFilterId, pagination, selectedRowKeys, searchValue, table, sorter, selectedRow, selectedFilterItem, expandedRowKeys, groupBy, modeView, } = state;
|
|
88
|
-
const { externalFilters, includeDataType = false, matchesAny, formatFilterValue, } = filterProps || {};
|
|
88
|
+
const { externalFilters, defaultFilters, includeDataType = false, matchesAny, formatFilterValue, } = filterProps || {};
|
|
89
89
|
const { sortDirectionKey = 'az', mainColumnKey, expandColumnKey, expandable } = tableProps || {};
|
|
90
90
|
const { itemProps: gridViewItemProps } = gridViewProps || {};
|
|
91
91
|
const { columnKeys: groupByColumnKeys, defaultSelectedKey: groupByDefaultSelectedKey } = groupByProps || {};
|
|
@@ -325,12 +325,21 @@ export function useDataTableListing(props) {
|
|
|
325
325
|
}
|
|
326
326
|
return children;
|
|
327
327
|
}, [expandColumnKey, expandable, expandedRowKeys, mainColumnKey]);
|
|
328
|
+
const handleUpdateLocalStorage = useCallback((dataTableLocalStorage) => {
|
|
329
|
+
if (disabledCache) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const localStorageValues = parseJSONFromLocalStorage(localStorageKey) || {};
|
|
333
|
+
// Set Local Storage
|
|
334
|
+
localStorage.setItem(localStorageKey, JSON.stringify(Object.assign(Object.assign({}, localStorageValues), dataTableLocalStorage)));
|
|
335
|
+
}, [disabledCache, localStorageKey]);
|
|
328
336
|
const handleUpdateGroupBy = useCallback((groupBy) => {
|
|
329
337
|
const localStorageValues = parseJSONFromLocalStorage(localStorageKey) || {};
|
|
330
338
|
setState(prev => (Object.assign(Object.assign({}, prev), { groupBy: Object.assign(Object.assign({}, prev.groupBy), groupBy) })));
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
339
|
+
handleUpdateLocalStorage({
|
|
340
|
+
groupBy: Object.assign(Object.assign({}, localStorageValues.groupBy), groupBy),
|
|
341
|
+
});
|
|
342
|
+
}, [handleUpdateLocalStorage, localStorageKey]);
|
|
334
343
|
const tableColumns = useDeepCompareMemo(() => {
|
|
335
344
|
let data = [];
|
|
336
345
|
const { columns } = tableProps || {};
|
|
@@ -478,6 +487,10 @@ export function useDataTableListing(props) {
|
|
|
478
487
|
*/
|
|
479
488
|
useDeepCompareEffect(() => {
|
|
480
489
|
const { filter, pagination, table, sorter, groupBy } = localStorageValues || {};
|
|
490
|
+
// If disabled cache then do nothing
|
|
491
|
+
if (disabledCache) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
481
494
|
if (!isEmpty(filter)) {
|
|
482
495
|
const { filters, selectedFilterId } = filter || {};
|
|
483
496
|
setState(prev => (Object.assign(Object.assign({}, prev), { selectedFilterId,
|
|
@@ -575,30 +588,33 @@ export function useDataTableListing(props) {
|
|
|
575
588
|
const localStorageValues = parseJSONFromLocalStorage(localStorageKey) || {};
|
|
576
589
|
// Set State
|
|
577
590
|
setState(prev => (Object.assign(Object.assign({}, prev), { pagination: Object.assign(Object.assign({}, prev.pagination), pagination) })));
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
591
|
+
handleUpdateLocalStorage({
|
|
592
|
+
pagination: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.pagination), pagination),
|
|
593
|
+
});
|
|
594
|
+
}, [handleUpdateLocalStorage, localStorageKey]);
|
|
581
595
|
const handleUpdateFilter = useCallback((filter) => {
|
|
582
596
|
const localStorageValues = parseJSONFromLocalStorage(localStorageKey) || {};
|
|
583
597
|
// Set State
|
|
584
598
|
setState(prev => (Object.assign(Object.assign(Object.assign({}, prev), filter), { pagination: Object.assign(Object.assign({}, prev.pagination), { page: 1 }) })));
|
|
585
|
-
|
|
586
|
-
|
|
599
|
+
handleUpdateLocalStorage({
|
|
600
|
+
filter: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.filter), filter),
|
|
587
601
|
// Reset page to 1
|
|
588
|
-
pagination: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.pagination), { page: 1 })
|
|
589
|
-
|
|
602
|
+
pagination: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.pagination), { page: 1 }),
|
|
603
|
+
});
|
|
604
|
+
}, [handleUpdateLocalStorage, localStorageKey]);
|
|
590
605
|
const handleUpdateTable = useCallback((table) => {
|
|
591
606
|
const localStorageValues = parseJSONFromLocalStorage(localStorageKey) || {};
|
|
592
607
|
setState(prev => (Object.assign(Object.assign({}, prev), { table: Object.assign(Object.assign({}, prev.table), table) })));
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
608
|
+
handleUpdateLocalStorage({
|
|
609
|
+
table: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.table), table),
|
|
610
|
+
});
|
|
611
|
+
}, [handleUpdateLocalStorage, localStorageKey]);
|
|
596
612
|
const handleUpdateSorter = useCallback((sorter) => {
|
|
597
|
-
const localStorageValues = parseJSONFromLocalStorage(localStorageKey) || {};
|
|
598
613
|
setState(prev => (Object.assign(Object.assign({}, prev), { sorter })));
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
614
|
+
handleUpdateLocalStorage({
|
|
615
|
+
sorter,
|
|
616
|
+
});
|
|
617
|
+
}, [handleUpdateLocalStorage]);
|
|
602
618
|
/* Filter */
|
|
603
619
|
const onChangeFilters = useCallback((filters) => {
|
|
604
620
|
handleUpdateFilter({
|
|
@@ -689,6 +705,15 @@ export function useDataTableListing(props) {
|
|
|
689
705
|
fetchNextPage();
|
|
690
706
|
}
|
|
691
707
|
}, [fetchNextPage, isFetchingNextPage]);
|
|
708
|
+
// Handle Effects
|
|
709
|
+
/**
|
|
710
|
+
* Update filters from default filters
|
|
711
|
+
* */
|
|
712
|
+
useDeepCompareEffect(() => {
|
|
713
|
+
if (defaultFilters) {
|
|
714
|
+
handleUpdateFilter({ filters: defaultFilters || [] });
|
|
715
|
+
}
|
|
716
|
+
}, [defaultFilters, handleUpdateFilter]);
|
|
692
717
|
return {
|
|
693
718
|
/* Modify Column */
|
|
694
719
|
modifyColumn: {
|