@mailstep/design-system 0.5.0-beta.24 → 0.5.0-beta.25
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/package.json +1 -1
- package/ui/Blocks/CommonGrid/CommonGridContainer.js +2 -2
- package/ui/Blocks/CommonGrid/components/ActionHead/ActionHead.d.ts +3 -3
- package/ui/Blocks/CommonGrid/components/ActionHead/ActionHead.js +4 -3
- package/ui/Blocks/CommonGrid/components/ColumnFilterCell.js +1 -1
- package/ui/Blocks/CommonGrid/components/FilterRow.js +1 -1
- package/ui/Blocks/CommonGrid/hooks/useAddFilter.d.ts +4 -0
- package/ui/Blocks/CommonGrid/hooks/useAddFilter.js +14 -0
- package/ui/Blocks/CommonGrid/hooks/useGridActionTrigger.d.ts +8 -0
- package/ui/Blocks/CommonGrid/hooks/useGridActionTrigger.js +25 -0
- package/ui/Blocks/CommonGrid/hooks/useToggleAllCheckbox.d.ts +8 -0
- package/ui/Blocks/CommonGrid/hooks/useToggleAllCheckbox.js +15 -0
- package/ui/Blocks/CommonGrid/index.d.ts +2 -2
- package/ui/Blocks/CommonGrid/index.js +2 -2
- package/ui/Blocks/CommonGrid/storybook/stories/complexWithPaginationAndRedux.stories.js +1 -1
- package/ui/Blocks/CommonGrid/types.d.ts +2 -2
- package/ui/index.es.js +6731 -6737
- package/ui/index.umd.js +308 -308
- package/ui/Blocks/CommonGrid/utils/public.d.ts +0 -16
- package/ui/Blocks/CommonGrid/utils/public.js +0 -52
package/package.json
CHANGED
|
@@ -40,7 +40,7 @@ import Modal from '../Modal';
|
|
|
40
40
|
import ManageColumnForm from './components/ManageColumnForm';
|
|
41
41
|
import { Trans } from '@lingui/react';
|
|
42
42
|
var StyledCommonGrid = function (props) {
|
|
43
|
-
var _a = props.optimizeFilters, optimizeFilters = _a === void 0 ? false : _a, extraControlButtons = props.extraControlButtons, eshopSelect = props.eshopSelect, onBatchAction = props.onBatchAction,
|
|
43
|
+
var _a = props.optimizeFilters, optimizeFilters = _a === void 0 ? false : _a, extraControlButtons = props.extraControlButtons, eshopSelect = props.eshopSelect, onBatchAction = props.onBatchAction, processCheckedValues = props.processCheckedValues, processCheckedValuesTitle = props.processCheckedValuesTitle, hideControlButtons = props.hideControlButtons, floatingButtonProps = props.floatingButtonProps, passDownProps = __rest(props, ["optimizeFilters", "extraControlButtons", "eshopSelect", "onBatchAction", "processCheckedValues", "processCheckedValuesTitle", "hideControlButtons", "floatingButtonProps"]);
|
|
44
44
|
var gridActions = passDownProps.gridActions, gridSelectors = passDownProps.gridSelectors, rowsData = passDownProps.rowsData, actionColumnDefinition = passDownProps.actionColumnDefinition;
|
|
45
45
|
var rowHeight = 40;
|
|
46
46
|
var _b = useGetGridHeight(), gridHeight = _b.gridHeight, gridRef = _b.gridRef, paginationRef = _b.paginationRef;
|
|
@@ -62,6 +62,6 @@ var StyledCommonGrid = function (props) {
|
|
|
62
62
|
gridSelectors: gridSelectors,
|
|
63
63
|
onClose: onClose,
|
|
64
64
|
}), columnsConfigValues = _d.columnsConfigValues, setColumnsConfigOptions = _d.setColumnsConfigOptions, onConfirmForm = _d.onConfirmForm, resetColumnConfig = _d.resetColumnConfig;
|
|
65
|
-
return (_jsxs(ContentContainer, { children: [_jsxs(CommonGridWrap, { children: [_jsx(HidePrint, { children: _jsxs(StyledButtonStrip, { className: "buttonsStrip", children: [!hideControlButtons && (_jsx(ControlButtons, { extraControlButtons: extraControlButtons, gridActions: gridActions, gridSelectors: gridSelectors, eshopSelect: eshopSelect })), _jsx(StyledColumnButton, { type: "button", appearance: "ghost", icon: _jsx(Rows, {}), onClick: openManageColumnForm, children: _jsx(H6, { children: _jsx(Trans, { id: "manageColumn.title", message: "Manage column" }) }) })] }) }), _jsx(CommonGridWithStyles, __assign({}, passDownProps, modifiedPassDownProps, { filters: filters, gridRef: gridRef, hasColouredRows: true, floatingButtonProps: floatingButtonProps }))] }), _jsx(HidePrint, { children: _jsxs(BottomWrapper, { ref: paginationRef, isAbsolute: !!gridHeight, children: [
|
|
65
|
+
return (_jsxs(ContentContainer, { children: [_jsxs(CommonGridWrap, { children: [_jsx(HidePrint, { children: _jsxs(StyledButtonStrip, { className: "buttonsStrip", children: [!hideControlButtons && (_jsx(ControlButtons, { extraControlButtons: extraControlButtons, gridActions: gridActions, gridSelectors: gridSelectors, eshopSelect: eshopSelect })), _jsx(StyledColumnButton, { type: "button", appearance: "ghost", icon: _jsx(Rows, {}), onClick: openManageColumnForm, children: _jsx(H6, { children: _jsx(Trans, { id: "manageColumn.title", message: "Manage column" }) }) })] }) }), _jsx(CommonGridWithStyles, __assign({}, passDownProps, modifiedPassDownProps, { filters: filters, gridRef: gridRef, hasColouredRows: true, floatingButtonProps: floatingButtonProps }))] }), _jsx(HidePrint, { children: _jsxs(BottomWrapper, { ref: paginationRef, isAbsolute: !!gridHeight, children: [processCheckedValues && (_jsx(ActionHead, { rowsData: rowsData, onBatchAction: onBatchAction, gridActions: gridActions, gridSelectors: gridSelectors, actionColumn: actionColumnDefinition, processCheckedValues: processCheckedValues, processCheckedValuesTitle: processCheckedValuesTitle })), _jsxs(x.div, { display: "flex", justifyContent: "center", alignItems: "center", className: "paginatorWrapper", w: "100%", h: window.innerWidth > 1204 ? '60px' : '32px', children: [_jsx(Pagination, { page: gridSelectors === null || gridSelectors === void 0 ? void 0 : gridSelectors.page, itemCount: passDownProps === null || passDownProps === void 0 ? void 0 : passDownProps.totalRowsCount, itemPerPage: (gridSelectors === null || gridSelectors === void 0 ? void 0 : gridSelectors.rowsPerPage) || 10, onPageChange: gridActions === null || gridActions === void 0 ? void 0 : gridActions.setPage }), _jsx(TablePagination, { gridActions: gridActions, gridSelectors: gridSelectors })] })] }) }), manageColumnFormVisible && (_jsx(Modal, { title: _jsx(Trans, { id: "manageColumn.title", message: "Manage columns" }), onClose: onClose, onCancel: onClose, onExtraAction: resetColumnConfig, onConfirm: onConfirmForm, width: "auto", minWidth: "350px", hasFooter: true, extraActionLabel: _jsx(Trans, { id: "dataGrid.buttonClearConfig", message: "Reset config" }), cancelLabel: _jsx(Trans, { id: "form.buttonCancel", message: "Cancel" }), confirmLabel: _jsx(Trans, { id: "form.buttonConfirm", message: "Confirm" }), children: _jsx(ManageColumnForm, { columns: columns, columnsConfigValues: columnsConfigValues, setColumnsConfigOptions: setColumnsConfigOptions }) }))] }));
|
|
66
66
|
};
|
|
67
67
|
export default StyledCommonGrid;
|
|
@@ -5,8 +5,8 @@ type Props = {
|
|
|
5
5
|
actionColumn?: ActionColumn;
|
|
6
6
|
onBatchAction?: OnBatchActionFn;
|
|
7
7
|
rowsData: RowProps[];
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
processCheckedValues?: () => void;
|
|
9
|
+
processCheckedValuesTitle?: string;
|
|
10
10
|
};
|
|
11
|
-
declare const ActionHead: ({ gridActions, gridSelectors, actionColumn, onBatchAction, rowsData,
|
|
11
|
+
declare const ActionHead: ({ gridActions, gridSelectors, actionColumn, onBatchAction, rowsData, processCheckedValues, processCheckedValuesTitle, }: Props) => JSX.Element;
|
|
12
12
|
export default ActionHead;
|
|
@@ -6,10 +6,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
import { useCallback, useMemo } from 'react';
|
|
7
7
|
import styled from '@xstyled/styled-components';
|
|
8
8
|
import { Trans } from '@lingui/react';
|
|
9
|
-
import { useGridActionTrigger, useToggleAllCheckbox } from '../../utils/public';
|
|
10
9
|
import { Button } from '../../../../Elements/Button';
|
|
11
10
|
import ButtonMore from '../ButtonMore/ButtonMore';
|
|
12
11
|
import { i18n } from '@lingui/core';
|
|
12
|
+
import { useToggleAllCheckbox } from '../../hooks/useToggleAllCheckbox';
|
|
13
|
+
import { useGridActionTrigger } from '../../hooks/useGridActionTrigger';
|
|
13
14
|
var Wrap = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n width: 100%;\n margin-right: 2;\n gap: 24px;\n background-color: red;\n position: relative;\n"], ["\n display: flex;\n align-items: center;\n width: 100%;\n margin-right: 2;\n gap: 24px;\n background-color: red;\n position: relative;\n"])));
|
|
14
15
|
var ActionsWrap = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n position: absolute;\n bottom: 32px;\n left: 50%;\n transform: translate(-50%);\n width: 596px;\n padding: 12px 24px;\n border-radius: 10px;\n background-color: #fff;\n box-shadow: dropShadow;\n z-index: 2;\n"], ["\n position: absolute;\n bottom: 32px;\n left: 50%;\n transform: translate(-50%);\n width: 596px;\n padding: 12px 24px;\n border-radius: 10px;\n background-color: #fff;\n box-shadow: dropShadow;\n z-index: 2;\n"])));
|
|
15
16
|
var StyledText = styled.span(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n font-size: 14px;\n line-height: 18px;\n color: blue2;\n font-weight: 600;\n"], ["\n font-size: 14px;\n line-height: 18px;\n color: blue2;\n font-weight: 600;\n"])));
|
|
@@ -17,7 +18,7 @@ var ContentWrap = styled.div(templateObject_4 || (templateObject_4 = __makeTempl
|
|
|
17
18
|
var ButtonsWrap = styled.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n margin-left: 10px;\n\n & > * {\n margin-left: 10px;\n }\n"], ["\n display: flex;\n align-items: center;\n margin-left: 10px;\n\n & > * {\n margin-left: 10px;\n }\n"])));
|
|
18
19
|
var ActionHead = function (_a) {
|
|
19
20
|
var _b;
|
|
20
|
-
var gridActions = _a.gridActions, gridSelectors = _a.gridSelectors, actionColumn = _a.actionColumn, onBatchAction = _a.onBatchAction, rowsData = _a.rowsData,
|
|
21
|
+
var gridActions = _a.gridActions, gridSelectors = _a.gridSelectors, actionColumn = _a.actionColumn, onBatchAction = _a.onBatchAction, rowsData = _a.rowsData, processCheckedValues = _a.processCheckedValues, processCheckedValuesTitle = _a.processCheckedValuesTitle;
|
|
21
22
|
var handleUxChange = (gridActions || {}).handleUxChange;
|
|
22
23
|
var _c = (gridSelectors || {}).uxState, uxState = _c === void 0 ? {} : _c;
|
|
23
24
|
var _d = useToggleAllCheckbox(rowsData, uxState, handleUxChange), checked = _d[0], toggleCheckbox = _d[1];
|
|
@@ -43,7 +44,7 @@ var ActionHead = function (_a) {
|
|
|
43
44
|
id: 'dataGrid.checkedRowsCount',
|
|
44
45
|
message: "Selected {checkedRowsCount} items",
|
|
45
46
|
values: { checkedRowsCount: checkedRowsCount },
|
|
46
|
-
}) }), _jsxs(ButtonsWrap, { children: [_jsx(Button, { type: "button", onClick: checkAll, appearance: "secondaryLg", "data-cy": "checkAllBtn", disabled: checked, children: _jsx(Trans, { id: "dataGrid.checkAll", message: "Check all" }) }),
|
|
47
|
+
}) }), _jsxs(ButtonsWrap, { children: [_jsx(Button, { type: "button", onClick: checkAll, appearance: "secondaryLg", "data-cy": "checkAllBtn", disabled: checked, children: _jsx(Trans, { id: "dataGrid.checkAll", message: "Check all" }) }), processCheckedValues && (_jsx(Button, { type: "button", onClick: processCheckedValues, appearance: "primary", "data-cy": "exportBtn", disabled: !rowsData.length, children: processCheckedValuesTitle ? (processCheckedValuesTitle) : (_jsx(Trans, { id: "dataGrid.actionOptions.export", message: "Export" })) })), ((_b = actionColumn === null || actionColumn === void 0 ? void 0 : actionColumn.actionOptions) === null || _b === void 0 ? void 0 : _b.length) && (_jsx(ButtonMore, { items: actionsOptions, disabled: !enabledActions.length || !rowsData.length, dropdownPosition: "top" }))] })] }) })) }));
|
|
47
48
|
};
|
|
48
49
|
export default ActionHead;
|
|
49
50
|
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
|
|
@@ -13,7 +13,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
13
13
|
import React from 'react';
|
|
14
14
|
import { x } from '@xstyled/styled-components';
|
|
15
15
|
import { Cell } from './Table';
|
|
16
|
-
import { useAddFilter } from '../
|
|
16
|
+
import { useAddFilter } from '../hooks/useAddFilter';
|
|
17
17
|
import { createFilterType, getStickyCollClassNames } from '../utils';
|
|
18
18
|
import { getCellSizeProps, getGroupClassNames } from '../utils';
|
|
19
19
|
import OverlayComponent from './FilterDropdown';
|
|
@@ -16,7 +16,7 @@ import throttle from 'lodash/throttle';
|
|
|
16
16
|
import ColumnFilterCell from './ColumnFilterCell';
|
|
17
17
|
import { Row, Cell } from './Table';
|
|
18
18
|
import { getActionCellSizeProps, getFilterName } from '../utils';
|
|
19
|
-
import { useToggleAllCheckbox } from '../
|
|
19
|
+
import { useToggleAllCheckbox } from '../hooks/useToggleAllCheckbox';
|
|
20
20
|
import Toggle from '../../../Elements/Toggle/Toggle';
|
|
21
21
|
var FilterRow = function (_a) {
|
|
22
22
|
var _b, _c;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { createFilterType, getFilterName } from '../utils';
|
|
3
|
+
export var useAddFilter = function (onChange) {
|
|
4
|
+
return useCallback(function (value, column) {
|
|
5
|
+
if (onChange) {
|
|
6
|
+
var filterProps = {
|
|
7
|
+
type: createFilterType(column),
|
|
8
|
+
filterExtraProps: column.filterExtraProps || {},
|
|
9
|
+
computedValue: column.getFilterCriteria ? column.getFilterCriteria(value) : null,
|
|
10
|
+
};
|
|
11
|
+
onChange(getFilterName(column), value, filterProps);
|
|
12
|
+
}
|
|
13
|
+
}, [onChange]);
|
|
14
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RowProps, UxState, ActionColumn, OnBatchActionFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* hook for action selection and trigger
|
|
4
|
+
* returns [subset of actions that are enabled, onSelect(value) - param1: selected action value]
|
|
5
|
+
*/
|
|
6
|
+
type GridActionTriggerRet = [Required<ActionColumn>['actionOptions'], (value: any) => void];
|
|
7
|
+
export declare const useGridActionTrigger: (rowsData: RowProps[], uxState: UxState, actionOptions?: ActionColumn['actionOptions'], onBatchAction?: OnBatchActionFn) => GridActionTriggerRet;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useMemo, useCallback } from 'react';
|
|
2
|
+
import find from 'lodash/find';
|
|
3
|
+
export var useGridActionTrigger = function (rowsData, uxState, actionOptions, onBatchAction) {
|
|
4
|
+
if (actionOptions === void 0) { actionOptions = []; }
|
|
5
|
+
var actionRows = useMemo(function () {
|
|
6
|
+
return (rowsData || []).filter(function (row) { var _a; return (_a = uxState.checkedRows) === null || _a === void 0 ? void 0 : _a[row.id]; });
|
|
7
|
+
}, [uxState, rowsData]);
|
|
8
|
+
var enabledActions = useMemo(function () {
|
|
9
|
+
var actionsOptions = actionOptions || [];
|
|
10
|
+
return actionsOptions.filter(function (action) {
|
|
11
|
+
if (action.isEnabled) {
|
|
12
|
+
return action.isEnabled(actionRows);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return uxState.checkedRows && find(uxState.checkedRows, Boolean);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}, [uxState, actionRows, actionOptions]);
|
|
19
|
+
var handleBatchAction = useCallback(function (value) {
|
|
20
|
+
var actionsOptions = actionOptions || [];
|
|
21
|
+
var action = actionsOptions.find(function (option) { return option.value == value; });
|
|
22
|
+
action && onBatchAction && onBatchAction(action, actionRows);
|
|
23
|
+
}, [actionOptions, onBatchAction, actionRows]);
|
|
24
|
+
return [enabledActions, handleBatchAction];
|
|
25
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RowProps, GridActionsType, UxState } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* hook for checkbox that select and unselects all row
|
|
4
|
+
* returns [checked state, toggleAllHandler()] for checkbox
|
|
5
|
+
*/
|
|
6
|
+
type ToggleAllCheckboxRet = [boolean, () => void];
|
|
7
|
+
export declare const useToggleAllCheckbox: (rowsData: RowProps[], uxState: UxState, handleUxChange?: GridActionsType['handleUxChange']) => ToggleAllCheckboxRet;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useMemo, useCallback } from 'react';
|
|
2
|
+
export var useToggleAllCheckbox = function (rowsData, uxState, handleUxChange) {
|
|
3
|
+
var allChecked = useMemo(function () { return (rowsData || []).length >= 1 && rowsData.every(function (row) { var _a; return (_a = uxState.checkedRows) === null || _a === void 0 ? void 0 : _a[row.id]; }); }, [rowsData, uxState.checkedRows]);
|
|
4
|
+
var toggleAllHandler = useCallback(function () {
|
|
5
|
+
var checkedRows = {};
|
|
6
|
+
// if check all is not check, we check all
|
|
7
|
+
if (!allChecked && rowsData) {
|
|
8
|
+
rowsData.forEach(function (row) {
|
|
9
|
+
checkedRows[row.id] = true;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
handleUxChange && handleUxChange('checkedRows', checkedRows);
|
|
13
|
+
}, [handleUxChange, rowsData, allChecked]);
|
|
14
|
+
return [allChecked, toggleAllHandler];
|
|
15
|
+
};
|
|
@@ -3,8 +3,8 @@ import withReduxActions from './HoC/withReduxActions';
|
|
|
3
3
|
import reducer, { actionPrefix, createActions, createSelectors, createFullSelector, actionTypes } from './store';
|
|
4
4
|
import useFloatingButton from './hooks/useFloatingButton';
|
|
5
5
|
import * as Types from './types';
|
|
6
|
-
import * as utils from './utils/public';
|
|
7
6
|
export * from './StandardButtons';
|
|
8
7
|
export * from './components/gridCells';
|
|
8
|
+
import { useAddFilter } from './hooks/useAddFilter';
|
|
9
9
|
export default CommonGrid;
|
|
10
|
-
export { withReduxActions, reducer, actionPrefix, actionTypes, createActions, createSelectors, createFullSelector, Types,
|
|
10
|
+
export { withReduxActions, reducer, actionPrefix, actionTypes, createActions, createSelectors, createFullSelector, Types, useFloatingButton, useAddFilter, };
|
|
@@ -3,8 +3,8 @@ import withReduxActions from './HoC/withReduxActions';
|
|
|
3
3
|
import reducer, { actionPrefix, createActions, createSelectors, createFullSelector, actionTypes } from './store';
|
|
4
4
|
import useFloatingButton from './hooks/useFloatingButton';
|
|
5
5
|
import * as Types from './types';
|
|
6
|
-
import * as utils from './utils/public';
|
|
7
6
|
export * from './StandardButtons';
|
|
8
7
|
export * from './components/gridCells';
|
|
8
|
+
import { useAddFilter } from './hooks/useAddFilter';
|
|
9
9
|
export default CommonGrid;
|
|
10
|
-
export { withReduxActions, reducer, actionPrefix, actionTypes, createActions, createSelectors, createFullSelector, Types,
|
|
10
|
+
export { withReduxActions, reducer, actionPrefix, actionTypes, createActions, createSelectors, createFullSelector, Types, useFloatingButton, useAddFilter, };
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { ReduxGrid, createRandomData, enumValues, gridDummyActions } from '../utils/utils';
|
|
4
4
|
import { onRowEditClick, onRowReadClick, onRowAction, onBatchAction } from '../utils/actions';
|
|
5
5
|
import { filters } from '../utils/filters';
|
|
6
|
-
import { useAddFilter } from '../../
|
|
6
|
+
import { useAddFilter } from '../../hooks/useAddFilter';
|
|
7
7
|
import withReduxActions from '../../HoC/withReduxActions';
|
|
8
8
|
import { columnDefinitions, enumColumn } from '../utils/columnDefinition';
|
|
9
9
|
import withRedux from '../utils/withRedux';
|
|
@@ -294,8 +294,8 @@ export type Group = {
|
|
|
294
294
|
export type GridProps = Omit<CommonGridProps, 'filters'> & {
|
|
295
295
|
optimizeFilters?: boolean;
|
|
296
296
|
eshopSelect?: CommonGridProps['extraControlButtons'];
|
|
297
|
-
|
|
298
|
-
|
|
297
|
+
processCheckedValues?: () => void;
|
|
298
|
+
processCheckedValuesTitle?: string;
|
|
299
299
|
hideControlButtons?: boolean;
|
|
300
300
|
};
|
|
301
301
|
export type PageGridProps = Omit<GridProps, 'rowsData' | 'totalRowsCount' | 'columnsDefinitions' | 'actionColumnDefinition' | 'hideColumnConfig' | 'minColumnWidth' | 'columnLayout'>;
|