@mailstep/design-system 0.6.89-beta.2 → 0.6.90
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/README.md +0 -2
- package/package.json +1 -2
- package/ui/Blocks/CommonGrid/CommonGridContainer.js +11 -11
- package/ui/Blocks/CommonGrid/HoC/withReduxActions.js +2 -1
- package/ui/Blocks/CommonGrid/components/ControlButtons/ControlButtons.d.ts +5 -1
- package/ui/Blocks/CommonGrid/components/ControlButtons/ControlButtons.js +19 -6
- package/ui/Blocks/CommonGrid/components/GridModals/index.d.ts +22 -0
- package/ui/Blocks/CommonGrid/components/GridModals/index.js +27 -0
- package/ui/Blocks/CommonGrid/components/HeadCell.d.ts +1 -1
- package/ui/Blocks/CommonGrid/components/HeadCell.js +6 -4
- package/ui/Blocks/CommonGrid/components/HeadRow.d.ts +1 -1
- package/ui/Blocks/CommonGrid/components/HeadRow.js +4 -4
- package/ui/Blocks/CommonGrid/components/ManageColumnForm/ManageColumnForm.d.ts +2 -2
- package/ui/Blocks/CommonGrid/components/ManageColumnForm/ManageColumnForm.js +4 -4
- package/ui/Blocks/CommonGrid/components/PresetsModalBody/index.d.ts +16 -0
- package/ui/Blocks/CommonGrid/components/PresetsModalBody/index.js +31 -0
- package/ui/Blocks/CommonGrid/hooks/useCreatePreset.d.ts +19 -0
- package/ui/Blocks/CommonGrid/hooks/useCreatePreset.js +52 -0
- package/ui/Blocks/CommonGrid/hooks/useDeletePreset.d.ts +17 -0
- package/ui/Blocks/CommonGrid/hooks/useDeletePreset.js +45 -0
- package/ui/Blocks/CommonGrid/hooks/usePresetFileHandlers.d.ts +13 -0
- package/ui/Blocks/CommonGrid/hooks/usePresetFileHandlers.js +68 -0
- package/ui/Blocks/CommonGrid/hooks/usePresetsState.d.ts +9 -0
- package/ui/Blocks/CommonGrid/hooks/usePresetsState.js +13 -0
- package/ui/Blocks/CommonGrid/hooks/useSelectPreset.d.ts +15 -0
- package/ui/Blocks/CommonGrid/hooks/useSelectPreset.js +47 -0
- package/ui/Blocks/CommonGrid/store/index.d.ts +3 -1
- package/ui/Blocks/CommonGrid/store/index.js +89 -89
- package/ui/Blocks/CommonGrid/storybook/stories/complexWithPaginationAndRedux.stories.js +1 -1
- package/ui/Blocks/CommonGrid/types.d.ts +4 -0
- package/ui/Blocks/CommonGrid/utils/constants.d.ts +1 -0
- package/ui/Blocks/CommonGrid/utils/constants.js +1 -0
- package/ui/Elements/Button/styles.js +2 -2
- package/ui/Elements/Tag/palletes.js +3 -0
- package/ui/index.es.js +17910 -17094
- package/ui/index.umd.js +777 -778
- package/ui/utils/translations.js +1 -1
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailstep/design-system",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.90",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./ui/index.js",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"deploy": "npm run build && npm publish ./build",
|
|
18
18
|
"dev": "yarn storybook",
|
|
19
19
|
"test": "echo \"The tests are still waiting to be written, but it seems like they're really good at procrastinating!\"",
|
|
20
|
-
"chromatic": "npx chromatic --project-token=chpt_cbebab21ab70358 --exit-zero-on-changes",
|
|
21
20
|
"lint": "eslint src/**/*.{js,jsx,ts,tsx,json}"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
@@ -20,29 +20,28 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
24
|
import { useEffect, useMemo, useState } from 'react';
|
|
25
25
|
import { Pagination } from '../../Elements/Pagination';
|
|
26
26
|
import HidePrint from '../HidePrint/HidePrint';
|
|
27
|
-
import Modal from '../Modal';
|
|
28
27
|
import { useModal } from '../Modal/hooks/useModal';
|
|
29
28
|
import ActionHead from './components/ActionHead';
|
|
30
29
|
import ControlButtons from './components/ControlButtons';
|
|
31
|
-
import
|
|
30
|
+
import { GridModals } from './components/GridModals';
|
|
32
31
|
import TablePagination from './components/TablePagination';
|
|
33
32
|
import useEditReadAsColumn from './hooks/useEditReadAsColumn';
|
|
34
33
|
import useGetGridHeight from './hooks/useGetGridHeight';
|
|
35
34
|
import useManageColumn from './hooks/useManageColumn';
|
|
36
|
-
import {
|
|
35
|
+
import { usePresetState } from './hooks/usePresetsState';
|
|
37
36
|
import { x } from '@xstyled/styled-components';
|
|
38
37
|
import { CommonGridWithStyles, BottomWrapper, CommonGridWrap, ContentContainer, StyledButtonStrip } from './styles';
|
|
39
38
|
import { getFilters, GRID_MIN_ROWS, rowHeight } from './utils';
|
|
40
39
|
var CommonGridContainer = function (props) {
|
|
41
40
|
var _a;
|
|
42
|
-
var _b = props.optimizeFilters, optimizeFilters = _b === void 0 ? false : _b, extraControlButtons = props.extraControlButtons, onBatchAction = props.onBatchAction, processCheckedValues = props.processCheckedValues, processCheckedValuesTitle = props.processCheckedValuesTitle, hideControlButtons = props.hideControlButtons, quickFilter = props.quickFilter, floatingButtonProps = props.floatingButtonProps, queryRowsParam = props.queryRowsParam, customPaginationHandler = props.customPaginationHandler, _c = props.autoHeight, autoHeight = _c === void 0 ? true : _c, passDownProps = __rest(props, ["optimizeFilters", "extraControlButtons", "onBatchAction", "processCheckedValues", "processCheckedValuesTitle", "hideControlButtons", "quickFilter", "floatingButtonProps", "queryRowsParam", "customPaginationHandler", "autoHeight"]);
|
|
41
|
+
var _b = props.optimizeFilters, optimizeFilters = _b === void 0 ? false : _b, extraControlButtons = props.extraControlButtons, onBatchAction = props.onBatchAction, processCheckedValues = props.processCheckedValues, processCheckedValuesTitle = props.processCheckedValuesTitle, hideControlButtons = props.hideControlButtons, quickFilter = props.quickFilter, floatingButtonProps = props.floatingButtonProps, queryRowsParam = props.queryRowsParam, customPaginationHandler = props.customPaginationHandler, _c = props.autoHeight, autoHeight = _c === void 0 ? true : _c, gridName = props.gridName, _d = props.withPresets, withPresets = _d === void 0 ? true : _d, passDownProps = __rest(props, ["optimizeFilters", "extraControlButtons", "onBatchAction", "processCheckedValues", "processCheckedValuesTitle", "hideControlButtons", "quickFilter", "floatingButtonProps", "queryRowsParam", "customPaginationHandler", "autoHeight", "gridName", "withPresets"]);
|
|
43
42
|
var gridActions = passDownProps.gridActions, gridSelectors = passDownProps.gridSelectors, rowsData = passDownProps.rowsData, actionColumnDefinition = passDownProps.actionColumnDefinition;
|
|
44
|
-
var
|
|
45
|
-
var
|
|
43
|
+
var _e = useState(false), displayManageColumnButton = _e[0], setDisplayManageColumnButton = _e[1];
|
|
44
|
+
var _f = useGetGridHeight(), gridHeight = _f.gridHeight, gridRef = _f.gridRef, paginationRef = _f.paginationRef;
|
|
46
45
|
useEffect(function () {
|
|
47
46
|
var _a;
|
|
48
47
|
if (!queryRowsParam && gridHeight && gridHeight > 0) {
|
|
@@ -56,13 +55,14 @@ var CommonGridContainer = function (props) {
|
|
|
56
55
|
var modifiedPassDownProps = useEditReadAsColumn(passDownProps);
|
|
57
56
|
var filters = useMemo(function () { return getFilters(optimizeFilters); }, [optimizeFilters]);
|
|
58
57
|
var columns = modifiedPassDownProps.columnsDefinitions;
|
|
59
|
-
var
|
|
60
|
-
var
|
|
58
|
+
var _g = useModal(), openManageColumnForm = _g.onOpen, manageColumnFormVisible = _g.isOpen, onClose = _g.onClose;
|
|
59
|
+
var _h = useManageColumn({
|
|
61
60
|
columns: columns,
|
|
62
61
|
gridActions: gridActions,
|
|
63
62
|
gridSelectors: gridSelectors,
|
|
64
63
|
onClose: onClose
|
|
65
|
-
}), columnsConfigValues =
|
|
66
|
-
|
|
64
|
+
}), columnsConfigValues = _h.columnsConfigValues, setColumnsConfigOptions = _h.setColumnsConfigOptions, onConfirmForm = _h.onConfirmForm, resetColumnConfig = _h.resetColumnConfig, handleDragEnd = _h.handleDragEnd, onCloseForm = _h.onCloseForm, displayColumnsDefinitions = _h.displayColumnsDefinitions, manageColumnsFormDefinitions = _h.manageColumnsFormDefinitions;
|
|
65
|
+
var _j = usePresetState(), isPresetsModalOpen = _j.isPresetsModalOpen, onClosePresetsModal = _j.onClosePresetsModal, onOpenPresetsModal = _j.onOpenPresetsModal, setSelectedPresetName = _j.setSelectedPresetName, selectedPresetName = _j.selectedPresetName;
|
|
66
|
+
return (_jsxs(_Fragment, { children: [_jsxs(ContentContainer, { children: [_jsxs(CommonGridWrap, { children: [_jsx(HidePrint, { children: _jsx(StyledButtonStrip, { className: "buttonsStrip", children: _jsx(ControlButtons, { hideControlButtons: hideControlButtons, extraControlButtons: extraControlButtons, gridActions: gridActions, gridSelectors: gridSelectors, quickFilter: quickFilter, displayColumnsDefinitions: displayColumnsDefinitions, filters: filters, setDisplayManageColumnButton: setDisplayManageColumnButton, displayManageColumnButton: displayManageColumnButton, openManageColumnForm: openManageColumnForm, onOpenPresetsModal: onOpenPresetsModal, selectedPresetName: selectedPresetName, withPresets: withPresets, gridName: gridName }) }) }), _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 || !!((_a = actionColumnDefinition === null || actionColumnDefinition === void 0 ? void 0 : actionColumnDefinition.actionOptions) === null || _a === void 0 ? void 0 : _a.length)) && (_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 })] })] }) })] }), _jsx(GridModals, { manageColumnFormVisible: manageColumnFormVisible, onCloseForm: onCloseForm, resetColumnConfig: resetColumnConfig, onConfirmForm: onConfirmForm, manageColumnsFormDefinitions: manageColumnsFormDefinitions, columnsConfigValues: columnsConfigValues, setColumnsConfigOptions: setColumnsConfigOptions, handleDragEnd: handleDragEnd(true), gridName: gridName, gridActions: gridActions, gridSelectors: gridSelectors, onClosePresetsModal: onClosePresetsModal, isPresetsModalOpen: isPresetsModalOpen, selectedPresetName: selectedPresetName, setSelectedPresetName: setSelectedPresetName })] }));
|
|
67
67
|
};
|
|
68
68
|
export default CommonGridContainer;
|
|
@@ -23,12 +23,13 @@ var withReduxActions = function (gridName, prefix) {
|
|
|
23
23
|
setPage: actions.setPage,
|
|
24
24
|
setRowsPerPage: actions.setRowsPerPage,
|
|
25
25
|
addFilter: actions.addFilter,
|
|
26
|
+
setFilters: actions.setFilters,
|
|
26
27
|
resetFilters: actions.resetFilters,
|
|
27
28
|
addSorting: actions.addSorting,
|
|
28
29
|
clearSettings: actions.clearSettings,
|
|
29
30
|
setColumnWidth: actions.setColumnWidth,
|
|
30
31
|
resetGrid: actions.resetGrid,
|
|
31
|
-
setColumnsOrder: actions.setColumnsOrder
|
|
32
|
+
setColumnsOrder: actions.setColumnsOrder
|
|
32
33
|
}, dispatch),
|
|
33
34
|
_a);
|
|
34
35
|
});
|
|
@@ -11,6 +11,10 @@ type Props = {
|
|
|
11
11
|
displayManageColumnButton?: boolean;
|
|
12
12
|
openManageColumnForm?: () => void;
|
|
13
13
|
setDisplayManageColumnButton: Dispatch<React.SetStateAction<boolean>>;
|
|
14
|
+
onOpenPresetsModal: () => void;
|
|
15
|
+
gridName?: string;
|
|
16
|
+
selectedPresetName: string;
|
|
17
|
+
withPresets?: boolean;
|
|
14
18
|
};
|
|
15
|
-
declare const ControlButtons: ({ extraControlButtons, gridActions, gridSelectors, quickFilter, displayColumnsDefinitions, filters, hideControlButtons, displayManageColumnButton, openManageColumnForm, setDisplayManageColumnButton }: Props) => JSX.Element;
|
|
19
|
+
declare const ControlButtons: ({ extraControlButtons, gridActions, gridSelectors, quickFilter, displayColumnsDefinitions, filters, hideControlButtons, displayManageColumnButton, openManageColumnForm, setDisplayManageColumnButton, onOpenPresetsModal, gridName, selectedPresetName, withPresets }: Props) => JSX.Element;
|
|
16
20
|
export default ControlButtons;
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
1
12
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
13
|
import { useEffect } from 'react';
|
|
3
14
|
import Button from '../../../../Elements/Button/Button';
|
|
4
15
|
import { Settings2 } from '../../../../Elements/Icon/icons/Settings2';
|
|
5
16
|
import { H6 } from '../../../../Elements/Typography';
|
|
17
|
+
import Tag from '../../../../Elements/Tag/Tag';
|
|
18
|
+
import { palletes } from '../../../../Elements/Tag/palletes';
|
|
6
19
|
import useQuickFilter from '../../hooks/useQuickFilter';
|
|
7
20
|
import { ExtraControlButtonPosition } from '../../types';
|
|
8
21
|
import ExtraControlButtons from '../ExtraControlButtons';
|
|
@@ -12,7 +25,7 @@ import { Trans } from '@lingui/react';
|
|
|
12
25
|
import { x } from '@xstyled/styled-components';
|
|
13
26
|
import { ControlButtonsContainer, Left, Right, StyledColumnButton } from './styles';
|
|
14
27
|
var ControlButtons = function (_a) {
|
|
15
|
-
var extraControlButtons = _a.extraControlButtons, gridActions = _a.gridActions, gridSelectors = _a.gridSelectors, _b = _a.quickFilter, quickFilter = _b === void 0 ? '' : _b, displayColumnsDefinitions = _a.displayColumnsDefinitions, filters = _a.filters, hideControlButtons = _a.hideControlButtons, displayManageColumnButton = _a.displayManageColumnButton, openManageColumnForm = _a.openManageColumnForm, setDisplayManageColumnButton = _a.setDisplayManageColumnButton;
|
|
28
|
+
var extraControlButtons = _a.extraControlButtons, gridActions = _a.gridActions, gridSelectors = _a.gridSelectors, _b = _a.quickFilter, quickFilter = _b === void 0 ? '' : _b, displayColumnsDefinitions = _a.displayColumnsDefinitions, filters = _a.filters, hideControlButtons = _a.hideControlButtons, displayManageColumnButton = _a.displayManageColumnButton, openManageColumnForm = _a.openManageColumnForm, setDisplayManageColumnButton = _a.setDisplayManageColumnButton, onOpenPresetsModal = _a.onOpenPresetsModal, gridName = _a.gridName, selectedPresetName = _a.selectedPresetName, withPresets = _a.withPresets;
|
|
16
29
|
var _c = useQuickFilter({
|
|
17
30
|
gridActions: gridActions,
|
|
18
31
|
gridSelectors: gridSelectors,
|
|
@@ -24,10 +37,10 @@ var ControlButtons = function (_a) {
|
|
|
24
37
|
setDisplayManageColumnButton(!isMobileInputView);
|
|
25
38
|
}, [isMobileInputView, setDisplayManageColumnButton]);
|
|
26
39
|
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 !== ''; });
|
|
27
|
-
return (_jsxs(ControlButtonsContainer, { children: [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
return (_jsxs(ControlButtonsContainer, { children: [_jsxs(Left, { children: [!hideControlButtons && (_jsxs(_Fragment, { children: [quickFilter && (_jsx(QuickFilter, { searchedValue: searchedValue, placeholderText: i18n._({
|
|
41
|
+
id: 'controlButtons.searchPlaceholder',
|
|
42
|
+
message: "Search ".concat(translatedValue, " ..."),
|
|
43
|
+
values: { translatedValue: translatedValue }
|
|
44
|
+
}), onChange: onChangeInputValue, onClear: onClear, onClick: onDisplayInput, displayInput: displayInput, isMobileInputView: isMobileInputView, alwaysShowClear: isMobile })), _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" }) })) })] })), withPresets && gridName && (_jsxs(_Fragment, { children: [_jsx(x.div, { mx: "12px", children: _jsx(Button, { onClick: onOpenPresetsModal, type: "button", variant: "default", appearance: "tertiary", children: _jsx(Trans, { id: "dataGrid.presets.title", message: "Presets" }) }) }), selectedPresetName && (_jsx(Tag, __assign({ size: "medium" }, palletes.redWhite, { children: _jsx(H6, { mt: 0, mb: 0, variant: "semiBold", children: selectedPresetName }) })))] }))] }), _jsxs(Right, { children: [_jsx(ExtraControlButtons, { extraControlButtons: extraControlButtons, targetPosition: ExtraControlButtonPosition.TopRight }), 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" }) }) }))] })] }));
|
|
32
45
|
};
|
|
33
46
|
export default ControlButtons;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { type FC } from 'react';
|
|
2
|
+
import { DropResult } from 'react-beautiful-dnd';
|
|
3
|
+
import { ColumnConfig, ColumnDefinition, GridActionsType, GridSelectorsType } from '../../types';
|
|
4
|
+
type ModalsProps = {
|
|
5
|
+
manageColumnFormVisible: boolean;
|
|
6
|
+
onCloseForm: () => void;
|
|
7
|
+
resetColumnConfig: () => void;
|
|
8
|
+
onConfirmForm: () => void;
|
|
9
|
+
manageColumnsFormDefinitions: ColumnDefinition[];
|
|
10
|
+
columnsConfigValues: string[];
|
|
11
|
+
setColumnsConfigOptions: (value: React.SetStateAction<Record<string, ColumnConfig | {}>>) => void;
|
|
12
|
+
handleDragEnd: (item: DropResult) => void;
|
|
13
|
+
gridName?: string;
|
|
14
|
+
gridSelectors: GridSelectorsType;
|
|
15
|
+
gridActions: GridActionsType;
|
|
16
|
+
isPresetsModalOpen: boolean;
|
|
17
|
+
onClosePresetsModal: () => void;
|
|
18
|
+
selectedPresetName: string;
|
|
19
|
+
setSelectedPresetName: (value: string) => void;
|
|
20
|
+
};
|
|
21
|
+
export declare const GridModals: FC<ModalsProps>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Input } from '../../../../Forms/Input/Input';
|
|
3
|
+
import { Modal } from '../../../Modal/Modal';
|
|
4
|
+
import { useCreatePreset } from '../../hooks/useCreatePreset';
|
|
5
|
+
import { useDeletePreset } from '../../hooks/useDeletePreset';
|
|
6
|
+
import { usePresetFileHandlers } from '../../hooks/usePresetFileHandlers';
|
|
7
|
+
import { useSelectPreset } from '../../hooks/useSelectPreset';
|
|
8
|
+
import ManageColumnForm from '../ManageColumnForm';
|
|
9
|
+
import { PresetsModalBody } from '../PresetsModalBody';
|
|
10
|
+
import { Trans } from '@lingui/react';
|
|
11
|
+
export var GridModals = function (_a) {
|
|
12
|
+
var manageColumnFormVisible = _a.manageColumnFormVisible, onCloseForm = _a.onCloseForm, resetColumnConfig = _a.resetColumnConfig, onConfirmForm = _a.onConfirmForm, manageColumnsFormDefinitions = _a.manageColumnsFormDefinitions, columnsConfigValues = _a.columnsConfigValues, setColumnsConfigOptions = _a.setColumnsConfigOptions, handleDragEnd = _a.handleDragEnd, gridName = _a.gridName, gridSelectors = _a.gridSelectors, gridActions = _a.gridActions, isPresetsModalOpen = _a.isPresetsModalOpen, onClosePresetsModal = _a.onClosePresetsModal, selectedPresetName = _a.selectedPresetName, setSelectedPresetName = _a.setSelectedPresetName;
|
|
13
|
+
var _b = useSelectPreset({
|
|
14
|
+
gridName: gridName,
|
|
15
|
+
gridActions: gridActions,
|
|
16
|
+
setSelectedPresetName: setSelectedPresetName,
|
|
17
|
+
onClosePresetsModal: onClosePresetsModal,
|
|
18
|
+
filters: gridSelectors.filter
|
|
19
|
+
}), gridPresets = _b.gridPresets, setGridPresets = _b.setGridPresets, handleSelectPreset = _b.handleSelectPreset;
|
|
20
|
+
var _c = useCreatePreset({ gridName: gridName, setGridPresets: setGridPresets, onClosePresetsModal: onClosePresetsModal, setSelectedPresetName: setSelectedPresetName, filters: gridSelectors.filter }), isCreatePresetModalOpen = _c.isCreatePresetModalOpen, handleCloseCreatePresetModal = _c.handleCloseCreatePresetModal, onOpenCreatePresetModal = _c.onOpenCreatePresetModal, handleCreatePreset = _c.handleCreatePreset, presetName = _c.presetName, handleChangePresetName = _c.handleChangePresetName;
|
|
21
|
+
var _d = useDeletePreset({ gridName: gridName, selectedPresetName: selectedPresetName, setGridPresets: setGridPresets, setSelectedPresetName: setSelectedPresetName }), handleOpenDeletePresetModal = _d.handleOpenDeletePresetModal, handleDeletePreset = _d.handleDeletePreset, onCloseDeletePresetModal = _d.onCloseDeletePresetModal, presetNameToDelete = _d.presetNameToDelete, isDeletePresetModalOpen = _d.isDeletePresetModalOpen;
|
|
22
|
+
var _e = usePresetFileHandlers({
|
|
23
|
+
gridName: gridName,
|
|
24
|
+
setGridPresets: setGridPresets
|
|
25
|
+
}), fileInputRef = _e.fileInputRef, handleImportPresets = _e.handleImportPresets, handleExportPresets = _e.handleExportPresets, handleImportButtonClick = _e.handleImportButtonClick;
|
|
26
|
+
return (_jsxs(_Fragment, { children: [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 }) })), _jsx(Modal, { isShown: isPresetsModalOpen, title: _jsx(Trans, { id: "dataGrid.presets.title", message: "Presets" }), onClose: onClosePresetsModal, width: "narrow", children: _jsx(PresetsModalBody, { onOpenCreatePresetModal: onOpenCreatePresetModal, gridPresets: gridPresets, handleSelectPreset: handleSelectPreset, handleOpenDeletePresetModal: handleOpenDeletePresetModal, selectedPresetName: selectedPresetName, handleExportPresets: handleExportPresets, handleImportPresets: handleImportPresets, handleImportButtonClick: handleImportButtonClick, fileInputRef: fileInputRef, filters: gridSelectors.filter }) }), _jsx(Modal, { isShown: isCreatePresetModalOpen, title: _jsx(Trans, { id: "dataGrid.createPreset.title", message: "Create preset" }), onCancel: handleCloseCreatePresetModal, onConfirm: handleCreatePreset, isConfirmDisabled: !presetName, width: "narrow", children: _jsx(Input, { type: "text", onChange: handleChangePresetName, value: presetName, label: _jsx(Trans, { id: "dataGrid.createPreset.title", message: "Preset name" }) }) }), _jsx(Modal, { isShown: isDeletePresetModalOpen, title: _jsx(Trans, { id: "dataGrid.deletePreset.title", message: "Delete preset" }), onCancel: onCloseDeletePresetModal, onConfirm: handleDeletePreset, isConfirmDisabled: !presetNameToDelete, width: "narrow", children: _jsxs(_Fragment, { children: [_jsx(Trans, { id: "dataGrid.deletePreset.confirm", message: "Are you sure you want to delete preset" }), " \"", presetNameToDelete, "\" ?"] }) })] }));
|
|
27
|
+
};
|
|
@@ -23,5 +23,5 @@ type Props = {
|
|
|
23
23
|
sticky?: boolean;
|
|
24
24
|
stickTo?: StickTo;
|
|
25
25
|
};
|
|
26
|
-
declare const _default: React.MemoExoticComponent<({ title, name, isSortable, systemName, onAddSort, sortValue, hasResize, onResizeOver, onResizeOut, innerRef, isDragging, draggableProps, dragHandleProps, flexBasis, flexGrow, flexShrink, handleResizeDrag, group, sticky, stickTo
|
|
26
|
+
declare const _default: React.MemoExoticComponent<({ title, name, isSortable, systemName, onAddSort, sortValue, hasResize, onResizeOver, onResizeOut, innerRef, isDragging, draggableProps, dragHandleProps, flexBasis, flexGrow, flexShrink, handleResizeDrag, group, sticky, stickTo }: Props) => JSX.Element>;
|
|
27
27
|
export default _default;
|
|
@@ -15,11 +15,11 @@ var __assign = (this && this.__assign) || function () {
|
|
|
15
15
|
};
|
|
16
16
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
17
|
import React from 'react';
|
|
18
|
+
import { getGroupClassNames, getStickyCollClassNames } from '../utils';
|
|
18
19
|
import styled from '@xstyled/styled-components';
|
|
19
|
-
import { Cell } from './Table';
|
|
20
20
|
import ColumnTitle from './ColumnTitle';
|
|
21
21
|
import Resize from './Resize';
|
|
22
|
-
import {
|
|
22
|
+
import { Cell } from './Table';
|
|
23
23
|
var DraggableCell = styled(Cell)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background-color: ", ";\n"], ["\n background-color: ", ";\n"])), function (_a) {
|
|
24
24
|
var $isDragging = _a.$isDragging;
|
|
25
25
|
return ($isDragging ? 'transparentRed' : 'transparent');
|
|
@@ -29,12 +29,14 @@ var HeadCell = function (_a) {
|
|
|
29
29
|
var onResize = React.useCallback(function (width) {
|
|
30
30
|
handleResizeDrag === null || handleResizeDrag === void 0 ? void 0 : handleResizeDrag(name, width);
|
|
31
31
|
}, [handleResizeDrag, name]);
|
|
32
|
-
var style = React.useMemo(function () { return (__assign({}, draggableProps === null || draggableProps === void 0 ? void 0 : draggableProps.style
|
|
32
|
+
var style = React.useMemo(function () { return (__assign({}, draggableProps === null || draggableProps === void 0 ? void 0 : draggableProps.style
|
|
33
|
+
// position: 'relative', // this is needed so that resizer is visible. TODO solve in better way (adjusting width of headers and moving resizer one level up ??)
|
|
34
|
+
)); }, [draggableProps]);
|
|
33
35
|
var onSetSort = React.useCallback(function (value) {
|
|
34
36
|
onAddSort && onAddSort(systemName || name, value);
|
|
35
37
|
}, [onAddSort, systemName, name]);
|
|
36
38
|
var cellClassName = "cell".concat(getStickyCollClassNames(!!sticky, stickTo), " ").concat(getGroupClassNames(group));
|
|
37
|
-
return (_jsxs(DraggableCell, __assign({}, draggableProps, dragHandleProps, { style: style, flexBasis: flexBasis, flexGrow: flexGrow, flexShrink: flexShrink,
|
|
39
|
+
return (_jsxs(DraggableCell, __assign({}, draggableProps, dragHandleProps, { style: style, flexBasis: flexBasis, flexGrow: flexGrow, flexShrink: flexShrink, ref: innerRef, "$isDragging": isDragging, className: cellClassName, children: [_jsx(ColumnTitle, { title: title, isSortable: isSortable, onSetSort: onSetSort, sortValue: sortValue }), hasResize && onResizeOut && onResizeOver && (_jsx(Resize, { onResize: onResize, onResizeOver: onResizeOver, onResizeOut: onResizeOut }))] })));
|
|
38
40
|
};
|
|
39
41
|
export default React.memo(HeadCell);
|
|
40
42
|
var templateObject_1;
|
|
@@ -11,5 +11,5 @@ type HeadRowProps = {
|
|
|
11
11
|
handleDragEnd: (item: DropResult) => void;
|
|
12
12
|
groups: Group[];
|
|
13
13
|
};
|
|
14
|
-
declare const HeadRow: ({ columns, actionColumn, onAddSort, handleDragEnd, sortingValues, displayColumnsWidth, columnLayout, handleResizeDrag, groups
|
|
14
|
+
declare const HeadRow: ({ columns, actionColumn, onAddSort, handleDragEnd, sortingValues, displayColumnsWidth, columnLayout, handleResizeDrag, groups }: HeadRowProps) => JSX.Element;
|
|
15
15
|
export default HeadRow;
|
|
@@ -11,10 +11,10 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import React, { useEffect, useState } from 'react';
|
|
14
|
-
import { DragDropContext, Droppable, Draggable
|
|
15
|
-
import { Row, Cell } from './Table';
|
|
16
|
-
import HeadCell from './HeadCell';
|
|
14
|
+
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
|
|
17
15
|
import { getActionCellSizeProps, getCellSizeProps, getSortName } from '../utils';
|
|
16
|
+
import HeadCell from './HeadCell';
|
|
17
|
+
import { Row, Cell } from './Table';
|
|
18
18
|
var getStickyComponent = function (columns, stickyTo, displayColumnsWidth) {
|
|
19
19
|
var _a;
|
|
20
20
|
return (_a = columns === null || columns === void 0 ? void 0 : columns.filter(function (item) { return item.sticky && item.stickTo === stickyTo; })) === null || _a === void 0 ? void 0 : _a.map(function (column) { return (_jsx(HeadCell, __assign({ name: column.name, systemName: column.systemName, isSortable: false, hasResize: false, isDragging: false, sortValue: null }, getCellSizeProps(column, displayColumnsWidth[column.name]), { title: column.title, sticky: column.sticky, stickTo: column.stickTo }), column.name)); });
|
|
@@ -34,7 +34,7 @@ var HeadRow = function (_a) {
|
|
|
34
34
|
setIsDragDisabled(false);
|
|
35
35
|
}, [setIsDragDisabled]);
|
|
36
36
|
var displayReadEditCell = ((_b = actionColumn === null || actionColumn === void 0 ? void 0 : actionColumn.actionOptions) === null || _b === void 0 ? void 0 : _b.length) || (actionColumn === null || actionColumn === void 0 ? void 0 : actionColumn.canRowEdit) || (actionColumn === null || actionColumn === void 0 ? void 0 : actionColumn.canRowRead) || (actionColumn === null || actionColumn === void 0 ? void 0 : actionColumn.forceCheckboxes);
|
|
37
|
-
return (_jsx(_Fragment, { children: showUIElements && (_jsx(DragDropContext, { onDragEnd: handleDragEnd, children: _jsx(Droppable, { droppableId: "droppable", direction: "horizontal", isDropDisabled: isDragDisabled, children: function (droppableProvided) { return (_jsxs(Row, __assign({ className: "headRow", accountForScrollbar: false, innerRef: droppableProvided.innerRef }, droppableProvided.droppableProps, { children: [actionColumn && (_jsxs(_Fragment, { children: [displayReadEditCell && (_jsx(Cell, { className: "cell", style: Object.assign(__assign({}, getActionCellSizeProps(actionColumn))) })), (actionColumn === null || actionColumn === void 0 ? void 0 : actionColumn.addRowNumbers) && (_jsx(Cell, { className: "cell", style: Object.assign(__assign({}, getActionCellSizeProps(actionColumn))) }))] })), getStickyComponent(columns, 'left', displayColumnsWidth), columns
|
|
37
|
+
return (_jsx(_Fragment, { children: showUIElements && (_jsx(DragDropContext, { onDragEnd: handleDragEnd, children: _jsx(Droppable, { droppableId: "droppable", direction: "horizontal", isDropDisabled: isDragDisabled, isCombineEnabled: false, ignoreContainerClipping: true, children: function (droppableProvided) { return (_jsxs(Row, __assign({ className: "headRow", accountForScrollbar: false, innerRef: droppableProvided.innerRef }, droppableProvided.droppableProps, { children: [actionColumn && (_jsxs(_Fragment, { children: [displayReadEditCell && (_jsx(Cell, { className: "cell", style: Object.assign(__assign({}, getActionCellSizeProps(actionColumn))) })), (actionColumn === null || actionColumn === void 0 ? void 0 : actionColumn.addRowNumbers) && (_jsx(Cell, { className: "cell", style: Object.assign(__assign({}, getActionCellSizeProps(actionColumn))) }))] })), getStickyComponent(columns, 'left', displayColumnsWidth), columns
|
|
38
38
|
.filter(function (item) { return !item.sticky; })
|
|
39
39
|
.map(function (column, key) { return (_jsx(Draggable, { draggableId: column.name, index: key, isDragDisabled: isDragDisabled || column.sticky, children: function (draggableProvided, snapshot) {
|
|
40
40
|
var _a;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ColumnConfig, CommonGridProps } from '../../types';
|
|
3
2
|
import { DropResult } from 'react-beautiful-dnd';
|
|
3
|
+
import { ColumnConfig, CommonGridProps } from '../../types';
|
|
4
4
|
type ManageColumnProps = {
|
|
5
5
|
columns?: CommonGridProps['columnsDefinitions'];
|
|
6
6
|
columnsConfigValues?: string[];
|
|
@@ -9,5 +9,5 @@ type ManageColumnProps = {
|
|
|
9
9
|
}>) => void;
|
|
10
10
|
handleDragEnd: (item: DropResult) => void;
|
|
11
11
|
};
|
|
12
|
-
declare const ManageColumnForm: ({ columns, columnsConfigValues, setColumnsConfigOptions, handleDragEnd
|
|
12
|
+
declare const ManageColumnForm: ({ columns, columnsConfigValues, setColumnsConfigOptions, handleDragEnd }: ManageColumnProps) => JSX.Element;
|
|
13
13
|
export default ManageColumnForm;
|
|
@@ -11,11 +11,11 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { useCallback, useState } from 'react';
|
|
14
|
-
import {
|
|
15
|
-
import { ActionRow } from './components/ActionRow';
|
|
14
|
+
import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd';
|
|
16
15
|
import { Input } from '../../../../Forms/Input/Input';
|
|
16
|
+
import { ActionRow } from './components/ActionRow';
|
|
17
17
|
import { i18n } from '@lingui/core';
|
|
18
|
-
import {
|
|
18
|
+
import { x } from '@xstyled/styled-components';
|
|
19
19
|
var ManageColumnForm = function (_a) {
|
|
20
20
|
var columns = _a.columns, columnsConfigValues = _a.columnsConfigValues, setColumnsConfigOptions = _a.setColumnsConfigOptions, handleDragEnd = _a.handleDragEnd;
|
|
21
21
|
var _b = useState(''), searchedValue = _b[0], setSearchedValue = _b[1];
|
|
@@ -25,7 +25,7 @@ var ManageColumnForm = function (_a) {
|
|
|
25
25
|
var clear = useCallback(function () {
|
|
26
26
|
setSearchedValue('');
|
|
27
27
|
}, [setSearchedValue]);
|
|
28
|
-
return (_jsxs(x.div, { children: [_jsx(Input, { icon: "search", type: "text", value: searchedValue, placeholder: i18n._({ id: 'manageColumn.searchPlaceholder', message: 'Find column...' }), onChange: onChangeInputValue, onClear: clear, variant: "gray" }), _jsx(DragDropContext, { onDragEnd: handleDragEnd, children: _jsx(Droppable, { droppableId: "droppable", direction: "vertical", children: function (droppableProvided) { return (_jsx(x.div, __assign({ h: "400px", overflowY: "scroll", mt: "20px", ref: droppableProvided.innerRef }, droppableProvided.droppableProps, { children: columns === null || columns === void 0 ? void 0 : columns.map(function (column, index) {
|
|
28
|
+
return (_jsxs(x.div, { children: [_jsx(Input, { icon: "search", type: "text", value: searchedValue, placeholder: i18n._({ id: 'manageColumn.searchPlaceholder', message: 'Find column...' }), onChange: onChangeInputValue, onClear: clear, variant: "gray" }), _jsx(DragDropContext, { onDragEnd: handleDragEnd, children: _jsx(Droppable, { droppableId: "droppable", direction: "vertical", isCombineEnabled: false, ignoreContainerClipping: false, children: function (droppableProvided) { return (_jsx(x.div, __assign({ h: "400px", overflowY: "scroll", mt: "20px", ref: droppableProvided.innerRef }, droppableProvided.droppableProps, { children: columns === null || columns === void 0 ? void 0 : columns.map(function (column, index) {
|
|
29
29
|
return (_jsx(Draggable, { draggableId: column.name, index: index, isDragDisabled: !!searchedValue, children: function (draggableProvided, snapshot) { return (_jsx(ActionRow, { column: column, innerRef: draggableProvided.innerRef, columnsConfigValues: columnsConfigValues, setColumnsConfigOptions: setColumnsConfigOptions, searchedValue: searchedValue, draggableProps: draggableProvided.draggableProps, dragHandleProps: draggableProvided.dragHandleProps }, index)); } }, column.name));
|
|
30
30
|
}) }))); } }) })] }));
|
|
31
31
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ChangeEvent, type FC, MouseEvent, RefObject } from 'react';
|
|
2
|
+
import { Filtering } from '../../types';
|
|
3
|
+
type PresetsModalBodyProps = {
|
|
4
|
+
onOpenCreatePresetModal: () => void;
|
|
5
|
+
gridPresets: Record<string, Record<string, any>>;
|
|
6
|
+
handleSelectPreset: (presetName: string, filters: Filtering) => () => void;
|
|
7
|
+
handleOpenDeletePresetModal: (presetName: string) => (e: MouseEvent) => void;
|
|
8
|
+
selectedPresetName: string;
|
|
9
|
+
handleExportPresets: () => void;
|
|
10
|
+
handleImportButtonClick: () => void;
|
|
11
|
+
handleImportPresets: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
12
|
+
fileInputRef: RefObject<HTMLInputElement>;
|
|
13
|
+
filters?: Filtering;
|
|
14
|
+
};
|
|
15
|
+
export declare const PresetsModalBody: FC<PresetsModalBodyProps>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useMemo } from 'react';
|
|
14
|
+
import Button from '../../../../Elements/Button/Button';
|
|
15
|
+
import { Cancel } from '../../../../Elements/Icon/icons/Cancel';
|
|
16
|
+
import Tag from '../../../../Elements/Tag/Tag';
|
|
17
|
+
import { palletes } from '../../../../Elements/Tag/palletes';
|
|
18
|
+
import { H6 } from '../../../../Elements/Typography/Typography';
|
|
19
|
+
import { Trans } from '@lingui/react';
|
|
20
|
+
import { x } from '@xstyled/styled-components';
|
|
21
|
+
import isEmpty from 'lodash/isEmpty';
|
|
22
|
+
export var PresetsModalBody = function (_a) {
|
|
23
|
+
var onOpenCreatePresetModal = _a.onOpenCreatePresetModal, gridPresets = _a.gridPresets, handleSelectPreset = _a.handleSelectPreset, handleOpenDeletePresetModal = _a.handleOpenDeletePresetModal, selectedPresetName = _a.selectedPresetName, handleExportPresets = _a.handleExportPresets, handleImportButtonClick = _a.handleImportButtonClick, handleImportPresets = _a.handleImportPresets, fileInputRef = _a.fileInputRef, filters = _a.filters;
|
|
24
|
+
var presets = useMemo(function () { return Object.entries(gridPresets || {}); }, [gridPresets]);
|
|
25
|
+
var hasPresets = !!(presets === null || presets === void 0 ? void 0 : presets.length);
|
|
26
|
+
return (_jsxs(x.div, { children: [_jsx(x.div, { display: "flex", rowGap: "12px", children: hasPresets ? (presets === null || presets === void 0 ? void 0 : presets.map(function (_a, index) {
|
|
27
|
+
var presetName = _a[0], filters = _a[1];
|
|
28
|
+
var isSelected = presetName === selectedPresetName;
|
|
29
|
+
return (_jsxs(Tag, __assign({ size: "big", onClick: handleSelectPreset(presetName, filters) }, (isSelected ? palletes.redWhite : palletes.redRed), { pointer: true, children: [_jsx(H6, { mt: 0, mb: 0, variant: "semiBold", children: presetName }), _jsx(x.div, { ml: "12px", h: "fit-content", onClick: handleOpenDeletePresetModal(presetName), children: _jsx(Cancel, { fill: isSelected ? 'white' : '#DB2B19' }) })] }), "".concat(presetName, "_").concat(index)));
|
|
30
|
+
})) : (_jsx(Trans, { id: "dataGrid.noPresets.title", message: "No presets available" })) }), _jsx(x.input, { type: "file", accept: ".json", onChange: handleImportPresets, ref: fileInputRef, display: "none" }), _jsxs(x.div, { display: "flex", mt: "34px", gap: "12px", justifyContent: "space-between", children: [_jsxs(x.div, { display: "flex", gap: "12px", children: [hasPresets && (_jsx(Button, { onClick: handleExportPresets, type: "button", appearance: "secondary", children: _jsx(Trans, { id: "dataGrid.exportPreset.title", message: "Export presets" }) })), _jsx(Button, { onClick: handleImportButtonClick, type: "button", appearance: "secondary", children: _jsx(Trans, { id: "dataGrid.importPreset.title", message: "Import presets" }) })] }), _jsx(Button, { type: "button", onClick: onOpenCreatePresetModal, disabled: isEmpty(filters), children: _jsx(Trans, { id: "dataGrid.createNewPreset.title", message: "Create new preset" }) })] })] }));
|
|
31
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
|
+
import { Filtering } from '../types';
|
|
3
|
+
type Props = {
|
|
4
|
+
gridName?: string;
|
|
5
|
+
filters?: Filtering;
|
|
6
|
+
onClosePresetsModal: () => void;
|
|
7
|
+
setSelectedPresetName: (value: string) => void;
|
|
8
|
+
setGridPresets: (data: Record<string, Filtering>) => void;
|
|
9
|
+
};
|
|
10
|
+
type HookType = (props: Props) => {
|
|
11
|
+
isCreatePresetModalOpen: boolean;
|
|
12
|
+
onOpenCreatePresetModal: () => void;
|
|
13
|
+
handleCloseCreatePresetModal: () => void;
|
|
14
|
+
presetName: string;
|
|
15
|
+
handleChangePresetName: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
16
|
+
handleCreatePreset: () => void;
|
|
17
|
+
};
|
|
18
|
+
export declare const useCreatePreset: HookType;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { useCallback, useState } from 'react';
|
|
13
|
+
import { useModal } from '../../Modal/hooks/useModal';
|
|
14
|
+
import { presetsLocalStorageKey } from '../utils/constants';
|
|
15
|
+
import isEmpty from 'lodash/isEmpty';
|
|
16
|
+
import { useEvent } from './useEvent';
|
|
17
|
+
export var useCreatePreset = function (_a) {
|
|
18
|
+
var gridName = _a.gridName, filters = _a.filters, onClosePresetsModal = _a.onClosePresetsModal, setSelectedPresetName = _a.setSelectedPresetName, setGridPresets = _a.setGridPresets;
|
|
19
|
+
var _b = useModal(), isCreatePresetModalOpen = _b.isOpen, onOpenCreatePresetModal = _b.onOpen, onCloseCreatePresetModal = _b.onClose;
|
|
20
|
+
var _c = useState(''), presetName = _c[0], setPresetName = _c[1];
|
|
21
|
+
var handleChangePresetName = useCallback(function (event) {
|
|
22
|
+
setPresetName(event.target.value);
|
|
23
|
+
}, []);
|
|
24
|
+
var handleCloseCreatePresetModal = useCallback(function () {
|
|
25
|
+
setPresetName('');
|
|
26
|
+
onCloseCreatePresetModal();
|
|
27
|
+
}, []);
|
|
28
|
+
var handleCreatePreset = useEvent(function () {
|
|
29
|
+
var _a;
|
|
30
|
+
var _b;
|
|
31
|
+
setPresetName('');
|
|
32
|
+
onCloseCreatePresetModal();
|
|
33
|
+
onClosePresetsModal();
|
|
34
|
+
if (isEmpty(filters) || !gridName)
|
|
35
|
+
return;
|
|
36
|
+
var presetsAsString = localStorage.getItem(presetsLocalStorageKey);
|
|
37
|
+
var presets = presetsAsString ? JSON.parse(presetsAsString) : {};
|
|
38
|
+
var updatedPresets = __assign({}, presets);
|
|
39
|
+
updatedPresets[gridName] = __assign(__assign({}, ((_b = updatedPresets[gridName]) !== null && _b !== void 0 ? _b : {})), (_a = {}, _a[presetName] = filters, _a));
|
|
40
|
+
setGridPresets(updatedPresets[gridName]);
|
|
41
|
+
setSelectedPresetName(presetName);
|
|
42
|
+
localStorage.setItem(presetsLocalStorageKey, JSON.stringify(updatedPresets));
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
isCreatePresetModalOpen: isCreatePresetModalOpen,
|
|
46
|
+
onOpenCreatePresetModal: onOpenCreatePresetModal,
|
|
47
|
+
handleCloseCreatePresetModal: handleCloseCreatePresetModal,
|
|
48
|
+
presetName: presetName,
|
|
49
|
+
handleChangePresetName: handleChangePresetName,
|
|
50
|
+
handleCreatePreset: handleCreatePreset
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MouseEvent } from 'react';
|
|
2
|
+
import { Filtering } from '../types';
|
|
3
|
+
type Props = {
|
|
4
|
+
gridName?: string;
|
|
5
|
+
selectedPresetName: string;
|
|
6
|
+
setGridPresets: (data: Record<string, Filtering>) => void;
|
|
7
|
+
setSelectedPresetName: (value: string) => void;
|
|
8
|
+
};
|
|
9
|
+
type HookType = (props: Props) => {
|
|
10
|
+
handleOpenDeletePresetModal: (presetName: string) => (e: MouseEvent) => void;
|
|
11
|
+
isDeletePresetModalOpen: boolean;
|
|
12
|
+
handleDeletePreset: () => void;
|
|
13
|
+
onCloseDeletePresetModal: () => void;
|
|
14
|
+
presetNameToDelete?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const useDeletePreset: HookType;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { useCallback } from 'react';
|
|
13
|
+
import { useModal } from '../../Modal/hooks/useModal';
|
|
14
|
+
import { presetsLocalStorageKey } from '../utils/constants';
|
|
15
|
+
export var useDeletePreset = function (_a) {
|
|
16
|
+
var selectedPresetName = _a.selectedPresetName, gridName = _a.gridName, setGridPresets = _a.setGridPresets, setSelectedPresetName = _a.setSelectedPresetName;
|
|
17
|
+
var _b = useModal(), isDeletePresetModalOpen = _b.isOpen, onOpenDeletePresetModal = _b.onOpen, onCloseDeletePresetModal = _b.onClose, presetNameToDelete = _b.data;
|
|
18
|
+
var handleOpenDeletePresetModal = useCallback(function (presetName) { return function (e) {
|
|
19
|
+
if (!presetName)
|
|
20
|
+
return;
|
|
21
|
+
e.stopPropagation();
|
|
22
|
+
onOpenDeletePresetModal(presetName);
|
|
23
|
+
}; }, [selectedPresetName]);
|
|
24
|
+
var handleDeletePreset = useCallback(function () {
|
|
25
|
+
if (!gridName || !presetNameToDelete)
|
|
26
|
+
return;
|
|
27
|
+
var presetsAsString = localStorage.getItem(presetsLocalStorageKey);
|
|
28
|
+
var presets = presetsAsString ? JSON.parse(presetsAsString) : {};
|
|
29
|
+
var updatedPresets = __assign({}, presets);
|
|
30
|
+
delete updatedPresets[gridName][presetNameToDelete];
|
|
31
|
+
setGridPresets(updatedPresets[gridName]);
|
|
32
|
+
localStorage.setItem(presetsLocalStorageKey, JSON.stringify(updatedPresets));
|
|
33
|
+
if (selectedPresetName === presetNameToDelete) {
|
|
34
|
+
setSelectedPresetName('');
|
|
35
|
+
}
|
|
36
|
+
onCloseDeletePresetModal();
|
|
37
|
+
}, [gridName, presetNameToDelete]);
|
|
38
|
+
return {
|
|
39
|
+
handleOpenDeletePresetModal: handleOpenDeletePresetModal,
|
|
40
|
+
isDeletePresetModalOpen: isDeletePresetModalOpen,
|
|
41
|
+
handleDeletePreset: handleDeletePreset,
|
|
42
|
+
onCloseDeletePresetModal: onCloseDeletePresetModal,
|
|
43
|
+
presetNameToDelete: presetNameToDelete
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChangeEvent, RefObject } from 'react';
|
|
2
|
+
type FileHandlersProps = {
|
|
3
|
+
gridName?: string;
|
|
4
|
+
setGridPresets: (data: Record<string, any>) => void;
|
|
5
|
+
};
|
|
6
|
+
type HookType = (props: FileHandlersProps) => {
|
|
7
|
+
handleExportPresets: () => void;
|
|
8
|
+
handleImportPresets: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
9
|
+
handleImportButtonClick: () => void;
|
|
10
|
+
fileInputRef: RefObject<HTMLInputElement>;
|
|
11
|
+
};
|
|
12
|
+
export declare const usePresetFileHandlers: HookType;
|
|
13
|
+
export {};
|