@mailstep/design-system 0.6.14 → 0.6.16
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 +7 -6
- package/ui/Blocks/CommonGrid/components/ControlButtons/ControlButtons.d.ts +3 -2
- package/ui/Blocks/CommonGrid/components/ControlButtons/ControlButtons.js +14 -43
- package/ui/Blocks/CommonGrid/components/QuickFilter/QuickFilter.d.ts +5 -1
- package/ui/Blocks/CommonGrid/components/QuickFilter/QuickFilter.js +19 -3
- package/ui/Blocks/CommonGrid/hooks/useQuickFilter.d.ts +27 -0
- package/ui/Blocks/CommonGrid/hooks/useQuickFilter.js +87 -0
- package/ui/index.es.js +3091 -3015
- package/ui/index.umd.js +118 -114
- package/ui/utils/CheckDeviceWidth/checkDeviceWidth.d.ts +3 -0
- package/ui/utils/CheckDeviceWidth/checkDeviceWidth.js +17 -0
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
};
|
|
23
23
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
24
|
import useGetGridHeight from './hooks/useGetGridHeight';
|
|
25
|
-
import { useEffect, useMemo } from 'react';
|
|
25
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
26
26
|
import { getFilters, GRID_MIN_ROWS, rowHeight } from './utils';
|
|
27
27
|
import useEditReadAsColumn from './hooks/useEditReadAsColumn';
|
|
28
28
|
import { useModal } from '../Modal/hooks/useModal';
|
|
@@ -42,7 +42,8 @@ import { Settings2 } from '../../Elements/Icon/icons/Settings2';
|
|
|
42
42
|
var StyledCommonGrid = function (props) {
|
|
43
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, quickFilter = props.quickFilter, floatingButtonProps = props.floatingButtonProps, queryRowsParam = props.queryRowsParam, customPaginationHandler = props.customPaginationHandler, passDownProps = __rest(props, ["optimizeFilters", "extraControlButtons", "eshopSelect", "onBatchAction", "processCheckedValues", "processCheckedValuesTitle", "hideControlButtons", "quickFilter", "floatingButtonProps", "queryRowsParam", "customPaginationHandler"]);
|
|
44
44
|
var gridActions = passDownProps.gridActions, gridSelectors = passDownProps.gridSelectors, rowsData = passDownProps.rowsData, actionColumnDefinition = passDownProps.actionColumnDefinition;
|
|
45
|
-
var _b =
|
|
45
|
+
var _b = useState(false), displayManageColumnButton = _b[0], setDisplayManageColumnButton = _b[1];
|
|
46
|
+
var _c = useGetGridHeight(), gridHeight = _c.gridHeight, gridRef = _c.gridRef, paginationRef = _c.paginationRef;
|
|
46
47
|
useEffect(function () {
|
|
47
48
|
var _a;
|
|
48
49
|
if (!queryRowsParam && gridHeight && gridHeight > 0) {
|
|
@@ -54,13 +55,13 @@ var StyledCommonGrid = function (props) {
|
|
|
54
55
|
var modifiedPassDownProps = useEditReadAsColumn(passDownProps);
|
|
55
56
|
var filters = useMemo(function () { return getFilters(optimizeFilters); }, [optimizeFilters]);
|
|
56
57
|
var columns = modifiedPassDownProps.columnsDefinitions;
|
|
57
|
-
var
|
|
58
|
-
var
|
|
58
|
+
var _d = useModal(), openManageColumnForm = _d.onOpen, manageColumnFormVisible = _d.isOpen, onClose = _d.onClose;
|
|
59
|
+
var _e = useManageColumn({
|
|
59
60
|
columns: columns,
|
|
60
61
|
gridActions: gridActions,
|
|
61
62
|
gridSelectors: gridSelectors,
|
|
62
63
|
onClose: onClose,
|
|
63
|
-
}), columnsConfigValues =
|
|
64
|
-
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, quickFilter: quickFilter, displayColumnsDefinitions: displayColumnsDefinitions, filters: filters })), _jsx(StyledColumnButton, { type: "button", variant: "ghost", appearance: "primary", iconLeft: _jsx(Settings2, {}), onClick: openManageColumnForm, children: _jsx(H6, { variant: "semiBold", mt: 0, mb: 0, children: _jsx(Trans, { id: "manageColumn.title", message: "Manage column" }) }) })] }) }), _jsx(CommonGridWithStyles, __assign({}, passDownProps, modifiedPassDownProps, { filters: filters, gridRef: gridRef, height: gridHeight, floatingButtonProps: floatingButtonProps, handleDragEnd: handleDragEnd(false), displayColumnsDefinitions: displayColumnsDefinitions, hasColouredRows: true }))] }), _jsx(HidePrint, { children: _jsxs(BottomWrapper, { ref: paginationRef, isFixed: !!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, customPaginationHandler: customPaginationHandler, radius: window.innerWidth < 768 ? 3 : 5, rate: window.innerWidth < 768 ? 1 : 4 }), _jsx(TablePagination, { gridActions: gridActions, gridSelectors: gridSelectors, customPaginationHandler: customPaginationHandler })] })] }) }), manageColumnFormVisible && (_jsx(Modal, { title: _jsx(Trans, { id: "manageColumn.title", message: "Manage columns" }), onClose: onCloseForm, onCancel: onCloseForm, 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: manageColumnsFormDefinitions, columnsConfigValues: columnsConfigValues, setColumnsConfigOptions: setColumnsConfigOptions, handleDragEnd: handleDragEnd(true) }) }))] }));
|
|
64
|
+
}), columnsConfigValues = _e.columnsConfigValues, setColumnsConfigOptions = _e.setColumnsConfigOptions, onConfirmForm = _e.onConfirmForm, resetColumnConfig = _e.resetColumnConfig, handleDragEnd = _e.handleDragEnd, onCloseForm = _e.onCloseForm, displayColumnsDefinitions = _e.displayColumnsDefinitions, manageColumnsFormDefinitions = _e.manageColumnsFormDefinitions;
|
|
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, quickFilter: quickFilter, displayColumnsDefinitions: displayColumnsDefinitions, filters: filters, setDisplayManageColumnButton: setDisplayManageColumnButton })), displayManageColumnButton && (_jsx(StyledColumnButton, { type: "button", variant: "ghost", appearance: "primary", iconLeft: _jsx(Settings2, {}), onClick: openManageColumnForm, children: _jsx(H6, { variant: "semiBold", mt: 0, mb: 0, children: _jsx(Trans, { id: "manageColumn.title", message: "Manage column" }) }) }))] }) }), _jsx(CommonGridWithStyles, __assign({}, passDownProps, modifiedPassDownProps, { filters: filters, gridRef: gridRef, height: gridHeight, floatingButtonProps: floatingButtonProps, handleDragEnd: handleDragEnd(false), displayColumnsDefinitions: displayColumnsDefinitions, hasColouredRows: true }))] }), _jsx(HidePrint, { children: _jsxs(BottomWrapper, { ref: paginationRef, isFixed: !!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, customPaginationHandler: customPaginationHandler, radius: window.innerWidth < 768 ? 3 : 5, rate: window.innerWidth < 768 ? 1 : 4 }), _jsx(TablePagination, { gridActions: gridActions, gridSelectors: gridSelectors, customPaginationHandler: customPaginationHandler })] })] }) }), manageColumnFormVisible && (_jsx(Modal, { title: _jsx(Trans, { id: "manageColumn.title", message: "Manage columns" }), onClose: onCloseForm, onCancel: onCloseForm, 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: manageColumnsFormDefinitions, columnsConfigValues: columnsConfigValues, setColumnsConfigOptions: setColumnsConfigOptions, handleDragEnd: handleDragEnd(true) }) }))] }));
|
|
65
66
|
};
|
|
66
67
|
export default StyledCommonGrid;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CommonGridProps, GridActionsType, GridSelectorsType, ColumnDefinition, FiltersConfig } from '../../types';
|
|
2
|
+
import { Dispatch } from 'react';
|
|
2
3
|
export declare const Row: import("styled-components").StyledComponent<"div", import("@xstyled/system").Theme, {}, never>;
|
|
3
4
|
type Props = {
|
|
4
|
-
columns?: CommonGridProps['columnsDefinitions'];
|
|
5
5
|
extraControlButtons: CommonGridProps['extraControlButtons'];
|
|
6
6
|
eshopSelect: CommonGridProps['extraControlButtons'];
|
|
7
7
|
gridActions: GridActionsType;
|
|
@@ -9,6 +9,7 @@ type Props = {
|
|
|
9
9
|
quickFilter?: CommonGridProps['quickFilter'];
|
|
10
10
|
displayColumnsDefinitions?: ColumnDefinition<string>[];
|
|
11
11
|
filters?: FiltersConfig;
|
|
12
|
+
setDisplayManageColumnButton: Dispatch<React.SetStateAction<boolean>>;
|
|
12
13
|
};
|
|
13
|
-
declare const ControlButtons: ({ extraControlButtons, eshopSelect, gridActions, gridSelectors, quickFilter, displayColumnsDefinitions, filters, }: Props) => JSX.Element;
|
|
14
|
+
declare const ControlButtons: ({ extraControlButtons, eshopSelect, gridActions, gridSelectors, quickFilter, displayColumnsDefinitions, filters, setDisplayManageColumnButton, }: Props) => JSX.Element;
|
|
14
15
|
export default ControlButtons;
|
|
@@ -3,63 +3,34 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
3
3
|
return cooked;
|
|
4
4
|
};
|
|
5
5
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
7
6
|
import styled, { x } from '@xstyled/styled-components';
|
|
8
7
|
import { Trans } from '@lingui/react';
|
|
9
8
|
import ExtraControlButtons from '../ExtraControlButtons';
|
|
10
9
|
import { ExtraControlButtonPosition, } from '../../types';
|
|
11
10
|
import Button from '../../../../Elements/Button/Button';
|
|
12
11
|
import { i18n } from '@lingui/core';
|
|
13
|
-
import { useAddFilter } from '../../hooks/useAddFilter';
|
|
14
|
-
import { createFilterType } from '../../utils';
|
|
15
|
-
import { isObject } from 'lodash';
|
|
16
12
|
import QuickFilter from '../QuickFilter';
|
|
13
|
+
import useQuickFilter from '../../hooks/useQuickFilter';
|
|
14
|
+
import { useEffect } from 'react';
|
|
17
15
|
export var Row = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n position: sticky;\n left: 20px;\n"], ["\n display: flex;\n position: sticky;\n left: 20px;\n"])));
|
|
18
|
-
var defaultVoidFunction = function () {
|
|
19
|
-
var args = [];
|
|
20
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
21
|
-
args[_i] = arguments[_i];
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
};
|
|
25
16
|
var ControlButtons = function (_a) {
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var filterType = createFilterType(searchedColumnsDefinitions || {});
|
|
35
|
-
var filtersDefaultComparator = (_c = filters === null || filters === void 0 ? void 0 : filters[filterType].defaultExtraProps) === null || _c === void 0 ? void 0 : _c.defaultComparator;
|
|
36
|
-
var searchComparator = (quickFilterValues && quickFilterValues.comparator) || filtersDefaultComparator;
|
|
37
|
-
var filtersOn = !!filter && Object.values(filter).some(function (item) { var _a; return ((_a = item.value) === null || _a === void 0 ? void 0 : _a.value) !== '' && item.value !== ''; });
|
|
17
|
+
var extraControlButtons = _a.extraControlButtons, eshopSelect = _a.eshopSelect, gridActions = _a.gridActions, gridSelectors = _a.gridSelectors, _b = _a.quickFilter, quickFilter = _b === void 0 ? '' : _b, displayColumnsDefinitions = _a.displayColumnsDefinitions, filters = _a.filters, setDisplayManageColumnButton = _a.setDisplayManageColumnButton;
|
|
18
|
+
var _c = useQuickFilter({
|
|
19
|
+
gridActions: gridActions,
|
|
20
|
+
gridSelectors: gridSelectors,
|
|
21
|
+
quickFilter: quickFilter,
|
|
22
|
+
displayColumnsDefinitions: displayColumnsDefinitions,
|
|
23
|
+
filters: filters,
|
|
24
|
+
}), searchedValue = _c.searchedValue, translatedValue = _c.translatedValue, onChangeInputValue = _c.onChangeInputValue, onClear = _c.onClear, onResetFilters = _c.onResetFilters, onDisplayInput = _c.onDisplayInput, displayInput = _c.displayInput, isMobileInputView = _c.isMobileInputView, filter = _c.filter;
|
|
38
25
|
useEffect(function () {
|
|
39
|
-
|
|
40
|
-
}, [
|
|
41
|
-
var
|
|
42
|
-
setSearchedValue(e.target.value);
|
|
43
|
-
var value = {
|
|
44
|
-
comparator: searchComparator,
|
|
45
|
-
value: e.target.value,
|
|
46
|
-
};
|
|
47
|
-
searchedColumnsDefinitions && handleAddFilter(value, searchedColumnsDefinitions);
|
|
48
|
-
}, [setSearchedValue, searchComparator, handleAddFilter, searchedColumnsDefinitions]);
|
|
49
|
-
var onResetFilters = useCallback(function () {
|
|
50
|
-
resetFilters === null || resetFilters === void 0 ? void 0 : resetFilters();
|
|
51
|
-
setSearchedValue === null || setSearchedValue === void 0 ? void 0 : setSearchedValue('');
|
|
52
|
-
}, []);
|
|
53
|
-
var translatedValue = searchedColumnsDefinitions &&
|
|
54
|
-
isObject(searchedColumnsDefinitions === null || searchedColumnsDefinitions === void 0 ? void 0 : searchedColumnsDefinitions.title) &&
|
|
55
|
-
'props' in (searchedColumnsDefinitions === null || searchedColumnsDefinitions === void 0 ? void 0 : searchedColumnsDefinitions.title) &&
|
|
56
|
-
((_d = searchedColumnsDefinitions.title) === null || _d === void 0 ? void 0 : _d.props) &&
|
|
57
|
-
i18n._({ id: (_f = (_e = searchedColumnsDefinitions.title) === null || _e === void 0 ? void 0 : _e.props) === null || _f === void 0 ? void 0 : _f.id, message: (_g = searchedColumnsDefinitions.title) === null || _g === void 0 ? void 0 : _g.props.message });
|
|
26
|
+
setDisplayManageColumnButton(!isMobileInputView);
|
|
27
|
+
}, [isMobileInputView, setDisplayManageColumnButton]);
|
|
28
|
+
var filtersOn = !!filter && Object.values(filter).some(function (item) { var _a; return ((_a = item.value) === null || _a === void 0 ? void 0 : _a.value) !== '' && item.value !== ''; });
|
|
58
29
|
return (_jsxs(Row, { children: [quickFilter && (_jsx(QuickFilter, { searchedValue: searchedValue, placeholderText: i18n._({
|
|
59
30
|
id: 'controlButtons.searchPlaceholder',
|
|
60
31
|
message: "Search ".concat(translatedValue, " ..."),
|
|
61
32
|
values: { translatedValue: translatedValue },
|
|
62
|
-
}), onChange: onChangeInputValue })), eshopSelect && (_jsx(x.div, { children: _jsx(ExtraControlButtons, { extraControlButtons: eshopSelect, targetPosition: ExtraControlButtonPosition.TopRight }) })), _jsx(ExtraControlButtons, { extraControlButtons: extraControlButtons, targetPosition: ExtraControlButtonPosition.TopLeft }), _jsx(x.div, { children: filtersOn && (_jsx(Button, { type: "button", onClick: onResetFilters, variant: "default", appearance: "secondary", "data-cy": "resetFiltersBtn", children: _jsx(Trans, { id: "dataGrid.buttonClearSettings", message: "Reset filters" }) })) })] }));
|
|
33
|
+
}), onChange: onChangeInputValue, onClear: onClear, onClick: onDisplayInput, displayInput: displayInput, isMobileInputView: isMobileInputView })), eshopSelect && (_jsx(x.div, { children: _jsx(ExtraControlButtons, { extraControlButtons: eshopSelect, targetPosition: ExtraControlButtonPosition.TopRight }) })), _jsx(ExtraControlButtons, { extraControlButtons: extraControlButtons, targetPosition: ExtraControlButtonPosition.TopLeft }), _jsx(x.div, { children: filtersOn && (_jsx(Button, { type: "button", onClick: onResetFilters, variant: "default", appearance: "secondary", "data-cy": "resetFiltersBtn", children: _jsx(Trans, { id: "dataGrid.buttonClearSettings", message: "Reset filters" }) })) })] }));
|
|
63
34
|
};
|
|
64
35
|
export default ControlButtons;
|
|
65
36
|
var templateObject_1;
|
|
@@ -3,6 +3,10 @@ type QuickFilterProps = {
|
|
|
3
3
|
searchedValue: string;
|
|
4
4
|
placeholderText?: string;
|
|
5
5
|
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
displayInput: boolean;
|
|
8
|
+
onClear: () => void;
|
|
9
|
+
isMobileInputView?: boolean;
|
|
6
10
|
};
|
|
7
|
-
declare const QuickFilter: ({ searchedValue, placeholderText, onChange }: QuickFilterProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
declare const QuickFilter: ({ searchedValue, placeholderText, onChange, onClick, displayInput, onClear, isMobileInputView, }: QuickFilterProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
12
|
export default QuickFilter;
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
+
return cooked;
|
|
4
|
+
};
|
|
1
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
6
|
import Input from '../../../../Forms/Input';
|
|
3
|
-
import { x } from '@xstyled/styled-components';
|
|
7
|
+
import styled, { x } from '@xstyled/styled-components';
|
|
8
|
+
import Button from '../../../../Elements/Button';
|
|
9
|
+
var StyledInput = styled(Input)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: ", ";\n z-index: ", ";\n width: ", ";\n"], ["\n position: ", ";\n z-index: ", ";\n width: ", ";\n"])), function (_a) {
|
|
10
|
+
var isMobileInputView = _a.isMobileInputView;
|
|
11
|
+
return (isMobileInputView ? 'absolute' : 'relative');
|
|
12
|
+
}, function (_a) {
|
|
13
|
+
var isMobileInputView = _a.isMobileInputView;
|
|
14
|
+
return (isMobileInputView ? '3' : '1');
|
|
15
|
+
}, function (_a) {
|
|
16
|
+
var isMobileInputView = _a.isMobileInputView;
|
|
17
|
+
return (isMobileInputView ? '90vw' : 'auto');
|
|
18
|
+
});
|
|
4
19
|
var QuickFilter = function (_a) {
|
|
5
|
-
var searchedValue = _a.searchedValue, placeholderText = _a.placeholderText, onChange = _a.onChange;
|
|
6
|
-
return (_jsx(x.div, { mr: "12px", children: _jsx(
|
|
20
|
+
var searchedValue = _a.searchedValue, placeholderText = _a.placeholderText, onChange = _a.onChange, onClick = _a.onClick, displayInput = _a.displayInput, onClear = _a.onClear, isMobileInputView = _a.isMobileInputView;
|
|
21
|
+
return (_jsx(x.div, { mr: "12px", children: displayInput ? (_jsx(StyledInput, { icon: "search", type: "text", value: searchedValue, placeholder: placeholderText, onChange: onChange, variant: "gray", onClear: onClear, isMobileInputView: isMobileInputView })) : (_jsx(Button, { variant: "icon", appearance: "secondary", icon: "search", onClick: onClick })) }));
|
|
7
22
|
};
|
|
8
23
|
export default QuickFilter;
|
|
24
|
+
var templateObject_1;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
|
+
import { ColumnDefinition, CommonGridProps, FiltersConfig, GridActionsType, GridSelectorsType } from '../types';
|
|
3
|
+
type Props = {
|
|
4
|
+
gridActions: GridActionsType;
|
|
5
|
+
gridSelectors: GridSelectorsType;
|
|
6
|
+
quickFilter?: CommonGridProps['quickFilter'];
|
|
7
|
+
filter?: CommonGridProps['gridSelectors']['filter'];
|
|
8
|
+
displayColumnsDefinitions?: ColumnDefinition<string>[];
|
|
9
|
+
filters?: FiltersConfig;
|
|
10
|
+
};
|
|
11
|
+
declare const useQuickFilter: ({ gridActions, gridSelectors, quickFilter, displayColumnsDefinitions, filters }: Props) => {
|
|
12
|
+
searchedValue: string;
|
|
13
|
+
translatedValue: any;
|
|
14
|
+
onChangeInputValue: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
15
|
+
onResetFilters: () => void;
|
|
16
|
+
onDisplayInput: () => void;
|
|
17
|
+
displayInput: boolean;
|
|
18
|
+
onClear: () => void;
|
|
19
|
+
isMobileInputView: boolean;
|
|
20
|
+
filter: {
|
|
21
|
+
[column: string]: {
|
|
22
|
+
value: any;
|
|
23
|
+
filterProps: import("../types").FilterProps;
|
|
24
|
+
};
|
|
25
|
+
} | undefined;
|
|
26
|
+
};
|
|
27
|
+
export default useQuickFilter;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { useCheckDeviceWidth } from '../../../utils/CheckDeviceWidth/checkDeviceWidth';
|
|
3
|
+
import { createFilterType } from '../utils';
|
|
4
|
+
import { useAddFilter } from './useAddFilter';
|
|
5
|
+
import { isObject } from 'lodash';
|
|
6
|
+
import { i18n } from '@lingui/core';
|
|
7
|
+
var defaultVoidFunction = function () {
|
|
8
|
+
var args = [];
|
|
9
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
10
|
+
args[_i] = arguments[_i];
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
var useQuickFilter = function (_a) {
|
|
15
|
+
var _b, _c, _d, _e, _f, _g;
|
|
16
|
+
var gridActions = _a.gridActions, gridSelectors = _a.gridSelectors, quickFilter = _a.quickFilter, displayColumnsDefinitions = _a.displayColumnsDefinitions, filters = _a.filters;
|
|
17
|
+
var resetFilters = gridActions.resetFilters, _h = gridActions.addFilter, addFilter = _h === void 0 ? defaultVoidFunction : _h;
|
|
18
|
+
var filter = gridSelectors.filter;
|
|
19
|
+
var isMobile = useCheckDeviceWidth().isMobile;
|
|
20
|
+
var _j = useState(''), searchedValue = _j[0], setSearchedValue = _j[1];
|
|
21
|
+
var _k = useState(false), displayInput = _k[0], setDisplayInput = _k[1];
|
|
22
|
+
var handleAddFilter = useAddFilter(addFilter);
|
|
23
|
+
var quickFilterValues = quickFilter ? (_b = filter === null || filter === void 0 ? void 0 : filter[quickFilter]) === null || _b === void 0 ? void 0 : _b.value : undefined;
|
|
24
|
+
var searchedColumnsDefinitions = (displayColumnsDefinitions === null || displayColumnsDefinitions === void 0 ? void 0 : displayColumnsDefinitions.find(function (item) { return item.name === quickFilter; })) || null;
|
|
25
|
+
var filterType = createFilterType(searchedColumnsDefinitions || {});
|
|
26
|
+
var filtersDefaultComparator = ((_c = filters === null || filters === void 0 ? void 0 : filters[filterType].defaultExtraProps) === null || _c === void 0 ? void 0 : _c.defaultComparator) || 'eq';
|
|
27
|
+
var searchComparator = (quickFilterValues && quickFilterValues.comparator) || filtersDefaultComparator;
|
|
28
|
+
var isMobileInputView = isMobile && displayInput;
|
|
29
|
+
useEffect(function () {
|
|
30
|
+
if (quickFilterValues) {
|
|
31
|
+
setSearchedValue(quickFilterValues.value);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
setSearchedValue('');
|
|
35
|
+
}
|
|
36
|
+
}, [quickFilterValues, quickFilter, setSearchedValue]);
|
|
37
|
+
useEffect(function () {
|
|
38
|
+
if (isMobile) {
|
|
39
|
+
setDisplayInput(false);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
setDisplayInput(true);
|
|
43
|
+
}
|
|
44
|
+
}, [isMobile]);
|
|
45
|
+
var onChangeInputValue = useCallback(function (e) {
|
|
46
|
+
setSearchedValue(e.target.value);
|
|
47
|
+
var value = {
|
|
48
|
+
comparator: searchComparator,
|
|
49
|
+
value: e.target.value,
|
|
50
|
+
};
|
|
51
|
+
searchedColumnsDefinitions && handleAddFilter(value, searchedColumnsDefinitions);
|
|
52
|
+
}, [setSearchedValue, searchComparator, handleAddFilter, searchedColumnsDefinitions]);
|
|
53
|
+
var onClear = useCallback(function () {
|
|
54
|
+
setSearchedValue('');
|
|
55
|
+
onChangeInputValue({ target: { value: '' } });
|
|
56
|
+
if (isMobile) {
|
|
57
|
+
setDisplayInput(false);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
setDisplayInput(true);
|
|
61
|
+
}
|
|
62
|
+
}, [setSearchedValue, isMobile, onChangeInputValue, setDisplayInput]);
|
|
63
|
+
var onDisplayInput = useCallback(function () {
|
|
64
|
+
setDisplayInput(true);
|
|
65
|
+
}, []);
|
|
66
|
+
var onResetFilters = useCallback(function () {
|
|
67
|
+
resetFilters === null || resetFilters === void 0 ? void 0 : resetFilters();
|
|
68
|
+
setSearchedValue === null || setSearchedValue === void 0 ? void 0 : setSearchedValue('');
|
|
69
|
+
}, [resetFilters, setSearchedValue]);
|
|
70
|
+
var translatedValue = searchedColumnsDefinitions &&
|
|
71
|
+
isObject(searchedColumnsDefinitions === null || searchedColumnsDefinitions === void 0 ? void 0 : searchedColumnsDefinitions.title) &&
|
|
72
|
+
'props' in (searchedColumnsDefinitions === null || searchedColumnsDefinitions === void 0 ? void 0 : searchedColumnsDefinitions.title) &&
|
|
73
|
+
((_d = searchedColumnsDefinitions.title) === null || _d === void 0 ? void 0 : _d.props) &&
|
|
74
|
+
i18n._({ id: (_f = (_e = searchedColumnsDefinitions.title) === null || _e === void 0 ? void 0 : _e.props) === null || _f === void 0 ? void 0 : _f.id, message: (_g = searchedColumnsDefinitions.title) === null || _g === void 0 ? void 0 : _g.props.message });
|
|
75
|
+
return {
|
|
76
|
+
searchedValue: searchedValue,
|
|
77
|
+
translatedValue: translatedValue,
|
|
78
|
+
onChangeInputValue: onChangeInputValue,
|
|
79
|
+
onResetFilters: onResetFilters,
|
|
80
|
+
onDisplayInput: onDisplayInput,
|
|
81
|
+
displayInput: displayInput,
|
|
82
|
+
onClear: onClear,
|
|
83
|
+
isMobileInputView: isMobileInputView,
|
|
84
|
+
filter: filter,
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export default useQuickFilter;
|