@antscorp/antsomi-ui 1.3.5-beta.420 → 1.3.5-beta.422

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.
@@ -13,6 +13,8 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  import React, { useMemo } from 'react';
14
14
  import { Resizable } from 'react-resizable';
15
15
  import { MIN_COLUMN_WIDTH } from '../../constants';
16
+ // Components
17
+ import { Typography } from '@antscorp/antsomi-ui/es/components/atoms';
16
18
  export const ResizableCell = props => {
17
19
  var _a;
18
20
  const { width, handleProps, disableResize, children, style, fixed, index, tableRef, onResize, onResizeStop, onClick = () => { } } = props, restProps = __rest(props, ["width", "handleProps", "disableResize", "children", "style", "fixed", "index", "tableRef", "onResize", "onResizeStop", "onClick"]);
@@ -20,7 +22,7 @@ export const ResizableCell = props => {
20
22
  const isResizing = React.useRef(false);
21
23
  // Memos
22
24
  const columnStyle = useMemo(() => (Object.assign(Object.assign({}, style), { zIndex: fixed ? 100 - (index || 0) : undefined })), [style, fixed, index]);
23
- const CellHeaderContent = children;
25
+ const CellHeaderContent = (React.createElement(Typography.Text, { ellipsis: { tooltip: true }, style: { width: '100%' } }, children));
24
26
  const isRowSelectionCol = (_a = props === null || props === void 0 ? void 0 : props.className) === null || _a === void 0 ? void 0 : _a.includes('antsomi-table-selection-column');
25
27
  if (isRowSelectionCol || !width || disableResize) {
26
28
  return (React.createElement("th", Object.assign({}, restProps, { style: columnStyle, onClick: onClick }), CellHeaderContent));
@@ -60,7 +60,7 @@ export const ToolbarActionButtons = memo(() => {
60
60
  `${label}`.toUpperCase()));
61
61
  // If customRender is exist then return custom render instead of render internal component
62
62
  if (customRender)
63
- return customRender(actionButton);
63
+ return actionButton;
64
64
  switch (key) {
65
65
  case 'SEARCH': {
66
66
  const _a = action, { addFilterInfo, onClickSearchItem, isAddFilterFromSearchItem } = _a, restOfAction = __rest(_a, ["addFilterInfo", "onClickSearchItem", "isAddFilterFromSearchItem"]);
@@ -10,7 +10,12 @@ interface TUseDataTableListing<TTableType = any> {
10
10
  pagination: PaginationProps;
11
11
  table: TableProps<TTableType>;
12
12
  search: TSearchActionButton;
13
+ /** @deprecated This selectedRowKeys is deprecated. Use selectedRow.keys instead. */
13
14
  selectedRowKeys: React.Key[];
15
+ selectedRow: {
16
+ keys: React.Key[];
17
+ rows: TTableType[];
18
+ };
14
19
  queries: {
15
20
  getTableListing: ReturnType<typeof useGetTableListing>;
16
21
  getModifyColumnList: ReturnType<typeof useGetModifyColumnList>;
@@ -27,6 +32,10 @@ type TState<TTableType = any> = {
27
32
  pagination: PaginationProps;
28
33
  table: TableProps<TTableType>;
29
34
  selectedRowKeys: React.Key[];
35
+ selectedRow: {
36
+ keys: React.Key[];
37
+ rows: TTableType[];
38
+ };
30
39
  searchValue?: string;
31
40
  sorter?: SorterResult<TTableType>;
32
41
  };
@@ -51,10 +51,15 @@ const initialState = {
51
51
  columnWidths: {},
52
52
  },
53
53
  selectedRowKeys: [],
54
+ selectedRow: {
55
+ keys: [],
56
+ rows: [],
57
+ },
54
58
  searchValue: '',
55
59
  sorter: {},
56
60
  };
57
61
  export function useDataTableListing(props) {
62
+ var _a, _b;
58
63
  // Props
59
64
  const { config, name = 'default', table: tableProps, search: searchProps, filter: filterProps, } = props || {};
60
65
  // Hooks
@@ -64,11 +69,11 @@ export function useDataTableListing(props) {
64
69
  // Variables
65
70
  const { env = appConfig === null || appConfig === void 0 ? void 0 : appConfig.env, auth = appConfig === null || appConfig === void 0 ? void 0 : appConfig.auth, api, object } = config;
66
71
  const { column: apiColumn, filter: apiFilter, listing: apiListing, search: apiSearch, } = api || {};
67
- const _a = apiColumn || {}, { url: columnUrl = `${COLUMN_DOMAIN[env || 'development']}/api/column`, enabled: enabledApiColumn = true } = _a, restOfApiColumnRequest = __rest(_a, ["url", "enabled"]);
68
- const _b = apiFilter || {}, { url: filterUrl = `${COLUMN_DOMAIN[env || 'development']}/api/filter`, enabled: enabledApiFilter = true } = _b, restOfApiFilterRequest = __rest(_b, ["url", "enabled"]);
69
- const _c = apiListing || {}, { url: listingUrl = '', enabled: enabledApiListing = true } = _c, restOfApiListingRequest = __rest(_c, ["url", "enabled"]);
70
- const _d = apiSearch || {}, { url: searchUrl = '', enabled: enabledApiSearch = true } = _d, restOfApiSearchRequest = __rest(_d, ["url", "enabled"]);
71
- const { filters, selectedFilterId, pagination, selectedRowKeys, searchValue, table, sorter } = state;
72
+ const _c = apiColumn || {}, { url: columnUrl = `${COLUMN_DOMAIN[env || 'development']}/api/column`, enabled: enabledApiColumn = true } = _c, restOfApiColumnRequest = __rest(_c, ["url", "enabled"]);
73
+ const _d = apiFilter || {}, { url: filterUrl = `${COLUMN_DOMAIN[env || 'development']}/api/filter`, enabled: enabledApiFilter = true } = _d, restOfApiFilterRequest = __rest(_d, ["url", "enabled"]);
74
+ const _e = apiListing || {}, { url: listingUrl = '', enabled: enabledApiListing = true } = _e, restOfApiListingRequest = __rest(_e, ["url", "enabled"]);
75
+ const _f = apiSearch || {}, { url: searchUrl = '', enabled: enabledApiSearch = true } = _f, restOfApiSearchRequest = __rest(_f, ["url", "enabled"]);
76
+ const { filters, selectedFilterId, pagination, selectedRowKeys, searchValue, table, sorter, selectedRow, } = state;
72
77
  const { externalFilters } = filterProps || {};
73
78
  const modifyColumnAuth = Object.assign(Object.assign({}, auth), { url: columnUrl });
74
79
  const filterAuth = Object.assign(Object.assign({}, auth), { url: filterUrl });
@@ -126,10 +131,13 @@ export function useDataTableListing(props) {
126
131
  enabled: enabledApiFilter,
127
132
  },
128
133
  });
134
+ // Variables
135
+ const { data: modifyColumnsData, isLoading: isModifyColumnsLoading } = getModifyColumnList || {};
136
+ const modifyColumnSelected = useDeepCompareMemo(() => { var _a; return ((_a = modifyColumnsData === null || modifyColumnsData === void 0 ? void 0 : modifyColumnsData.find(({ isLasted }) => +isLasted === 1)) === null || _a === void 0 ? void 0 : _a.modifyColId) || ''; }, [modifyColumnsData]);
129
137
  const getTableListing = useGetTableListing({
130
138
  args: {
131
139
  auth: listingAuth,
132
- params: Object.assign({ limit: pagination.pageSize, page: pagination.page, filter: JSON.stringify(mapFiltersToApiFilters([...(filters || []), ...(externalFilters || [])])) }, ((sorter === null || sorter === void 0 ? void 0 : sorter.order) &&
140
+ params: Object.assign({ limit: pagination.pageSize, page: pagination.page, filter: JSON.stringify(mapFiltersToApiFilters([...(filters || []), ...(externalFilters || [])])), columns: JSON.stringify(((_b = (_a = modifyColumnsData === null || modifyColumnsData === void 0 ? void 0 : modifyColumnsData.find(modifyColumnItem => modifyColumnItem.modifyColId === modifyColumnSelected)) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(col => { var _a; return (_a = col.metricCode) === null || _a === void 0 ? void 0 : _a.toUpperCase(); })) || []) }, ((sorter === null || sorter === void 0 ? void 0 : sorter.order) &&
133
141
  (sorter === null || sorter === void 0 ? void 0 : sorter.columnKey) && {
134
142
  sort: sorter.columnKey.toString(),
135
143
  az: SORT_MAP[sorter.order],
@@ -154,7 +162,6 @@ export function useDataTableListing(props) {
154
162
  });
155
163
  // Variables
156
164
  const { data: columnMetricsData } = getColumnMetrics || {};
157
- const { data: modifyColumnsData, isLoading: isModifyColumnsLoading } = getModifyColumnList || {};
158
165
  const { data: savedFiltersData } = getSavedFilterList || {};
159
166
  const { data: filterMetricsData } = getFilterMetricList || {};
160
167
  const { data: tableListing, isLoading: isTableListingLoading, isRefetching: isTableListingRefetching, refetch: refetchTableListing, } = getTableListing || {};
@@ -202,7 +209,6 @@ export function useDataTableListing(props) {
202
209
  removable: !MODIFY_COLUMN_DISABLE_REMOVE.includes(modifyName),
203
210
  metrics: columns === null || columns === void 0 ? void 0 : columns.map(({ metricCode, metricId }) => metricCode || metricId || -1),
204
211
  })).reverse()) || [], [modifyColumnsData]);
205
- const modifyColumnSelected = useDeepCompareMemo(() => { var _a; return ((_a = modifyColumnsData === null || modifyColumnsData === void 0 ? void 0 : modifyColumnsData.find(({ isLasted }) => +isLasted === 1)) === null || _a === void 0 ? void 0 : _a.modifyColId) || ''; }, [modifyColumnsData]);
206
212
  const filterMetrics = useDeepCompareMemo(() => {
207
213
  const serializeFilterMetrics = (metrics) => {
208
214
  const result = metrics.map(metric => {
@@ -322,7 +328,7 @@ export function useDataTableListing(props) {
322
328
  }, 500);
323
329
  }, [mapObject, refetchTableListing, updateModifyColumn]);
324
330
  const onApplyModifyColumn = useCallback((args) => __awaiter(this, void 0, void 0, function* () {
325
- var _e;
331
+ var _g;
326
332
  const { selectedMetrics, columnSetName, existColumnSet } = args || {};
327
333
  const flattenMetrics = flatTree(columnMetricsData, 'child');
328
334
  const selectedColumnMetrics = selectedMetrics
@@ -335,7 +341,7 @@ export function useDataTableListing(props) {
335
341
  exitModifyColumnId = (existColumnSet === null || existColumnSet === void 0 ? void 0 : existColumnSet.id) || '';
336
342
  if (columnSetName === '') {
337
343
  exitModifyColumnId =
338
- ((_e = modifyColumnsData === null || modifyColumnsData === void 0 ? void 0 : modifyColumnsData.find(modifyColumn => modifyColumn.modifyName === 'Custom')) === null || _e === void 0 ? void 0 : _e.modifyColId) || '';
344
+ ((_g = modifyColumnsData === null || modifyColumnsData === void 0 ? void 0 : modifyColumnsData.find(modifyColumn => modifyColumn.modifyName === 'Custom')) === null || _g === void 0 ? void 0 : _g.modifyColId) || '';
339
345
  }
340
346
  }
341
347
  /**
@@ -489,8 +495,8 @@ export function useDataTableListing(props) {
489
495
  columnWidths: table.columnWidths || {},
490
496
  rowSelection: {
491
497
  selectedRowKeys,
492
- onChange(selectedRowKeys) {
493
- setState(prev => (Object.assign(Object.assign({}, prev), { selectedRowKeys })));
498
+ onChange(selectedRowKeys, selectedRows) {
499
+ setState(prev => (Object.assign(Object.assign({}, prev), { selectedRowKeys, selectedRow: { keys: selectedRowKeys, rows: selectedRows } })));
494
500
  },
495
501
  },
496
502
  onChange: onChangeTable,
@@ -501,7 +507,9 @@ export function useDataTableListing(props) {
501
507
  });
502
508
  },
503
509
  },
510
+ /* Selected row */
504
511
  selectedRowKeys,
512
+ selectedRow,
505
513
  /* Search */
506
514
  search: Object.assign(Object.assign(Object.assign({ loading: isSearchListingLoading || isSearchListingFetching, searchList }, (!!(searchProps === null || searchProps === void 0 ? void 0 : searchProps.render) && {
507
515
  itemSearchRender(_item, index, node) {
@@ -25,7 +25,7 @@ export const DataTableTest = () => {
25
25
  // Variables
26
26
  const { tableCollapsed } = state;
27
27
  // Hooks
28
- const { modifyColumn, filter, pagination, table, search, selectedRowKeys } = useDataTableListing({
28
+ const { modifyColumn, filter, pagination, table, search, selectedRowKeys, selectedRow } = useDataTableListing({
29
29
  config: {
30
30
  // auth: {}, // Default is get from AppConfigProvider
31
31
  auth: {
@@ -91,6 +91,7 @@ export const DataTableTest = () => {
91
91
  // },
92
92
  },
93
93
  });
94
+ console.log('selectedRowKeys', selectedRowKeys, selectedRow.keys);
94
95
  // const { filter, pagination, table, modifyColumn } = useDataTableListing<ProjectSurvey>({
95
96
  // name: 'permission-account',
96
97
  // config: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.420",
3
+ "version": "1.3.5-beta.422",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",