UNPKG

@skbkontur/db-viewer-ui

Version:

Database Viewer with custom configuration

93 lines 7.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ObjectTableLayoutHeader = void 0; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const NetDownloadIcon16Regular_1 = require("@skbkontur/icons/NetDownloadIcon16Regular"); const SettingsGearIcon16Regular_1 = require("@skbkontur/icons/SettingsGearIcon16Regular"); const UiFilterFunnelIcon16Regular_1 = require("@skbkontur/icons/UiFilterFunnelIcon16Regular"); const XCircleIcon16Regular_1 = require("@skbkontur/icons/XCircleIcon16Regular"); const react_stack_layout_1 = require("@skbkontur/react-stack-layout"); const react_ui_1 = require("@skbkontur/react-ui"); const difference_1 = tslib_1.__importDefault(require("lodash/difference")); const react_1 = tslib_1.__importDefault(require("react")); const PropertyMetaInformationUtils_1 = require("../../Domain/Objects/PropertyMetaInformationUtils"); const FieldSelector_1 = require("../FieldSelector/FieldSelector"); const CountOfRecordsSelector_1 = require("./CountOfRecordsSelector"); const DownloadLimitModal_1 = require("./DownloadLimitModal"); const FilterModal_1 = require("./FilterModal"); const ObjectTableLayoutHeader_styles_1 = require("./ObjectTableLayoutHeader.styles"); const Spinner_1 = require("./Spinner"); class ObjectTableLayoutHeader extends react_1.default.Component { constructor() { super(...arguments); Object.defineProperty(this, "state", { enumerable: true, configurable: true, writable: true, value: { showFilterModal: false, modalEditingConditions: [], } }); Object.defineProperty(this, "handleOpenFilterModal", { enumerable: true, configurable: true, writable: true, value: () => { this.setState({ showFilterModal: true }); } }); Object.defineProperty(this, "handleCloseFilterModal", { enumerable: true, configurable: true, writable: true, value: () => { this.setState({ showFilterModal: false }); } }); Object.defineProperty(this, "handleApplyFilter", { enumerable: true, configurable: true, writable: true, value: () => { this.props.onChange({ conditions: this.state.modalEditingConditions.filter(x => x.value != null && x.value.trim() !== ""), offset: 0, }); this.setState({ showFilterModal: false }); } }); } componentDidMount() { this.setState({ modalEditingConditions: this.props.query.conditions || [], }); } componentDidUpdate(prevProps) { const { query, showModalFilter } = this.props; if (query.conditions !== prevProps.query.conditions || showModalFilter !== prevProps.showModalFilter) { this.setState({ showFilterModal: showModalFilter, modalEditingConditions: this.props.query.conditions || [], }); } } render() { const { query, allowReadAll, properties, onChange, onDownloadClick, onDownloadAbort, downloading, showDownloadModal, downloadCount, } = this.props; const { showFilterModal, modalEditingConditions } = this.state; const allowCloseModal = allowReadAll || PropertyMetaInformationUtils_1.PropertyMetaInformationUtils.hasFilledRequiredFields(query.conditions || [], properties); return ((0, jsx_runtime_1.jsxs)(react_stack_layout_1.RowStack, { baseline: true, block: true, gap: 2, style: { flexWrap: "wrap" }, children: [(0, jsx_runtime_1.jsx)(react_stack_layout_1.Fit, { className: ObjectTableLayoutHeader_styles_1.jsStyles.filter(), children: (0, jsx_runtime_1.jsx)(react_ui_1.Link, { icon: (0, jsx_runtime_1.jsx)(UiFilterFunnelIcon16Regular_1.UiFilterFunnelIcon16Regular, {}), onClick: this.handleOpenFilterModal, "data-tid": "OpenFilter", children: "\u0424\u0438\u043B\u044C\u0442\u0440\u0430\u0446\u0438\u044F" }) }), (0, jsx_runtime_1.jsx)(react_stack_layout_1.Fit, { className: ObjectTableLayoutHeader_styles_1.jsStyles.countSelector(), children: (0, jsx_runtime_1.jsx)(CountOfRecordsSelector_1.CountOfRecordsSelector, { count: query.count, onChange: value => onChange({ count: value }) }) }), (0, jsx_runtime_1.jsx)(react_stack_layout_1.Fit, { children: (0, jsx_runtime_1.jsx)(react_ui_1.Link, { icon: (0, jsx_runtime_1.jsx)(XCircleIcon16Regular_1.XCircleIcon16Regular, {}), onClick: () => onChange(null), "data-tid": "ClearFilter", children: "\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C \u0444\u0438\u043B\u044C\u0442\u0440" }) }), (0, jsx_runtime_1.jsx)(react_stack_layout_1.Fit, { children: (0, jsx_runtime_1.jsx)(react_ui_1.Tooltip, { render: () => this.renderFieldSelectorTooltipContent(), pos: "bottom right", trigger: "click", children: (0, jsx_runtime_1.jsx)(react_ui_1.Link, { icon: (0, jsx_runtime_1.jsx)(SettingsGearIcon16Regular_1.SettingsGearIcon16Regular, {}), "data-tid": "FieldSettings", children: "\u041D\u0430\u0441\u0442\u0440\u043E\u0438\u0442\u044C \u043F\u043E\u043B\u044F" }) }) }), (0, jsx_runtime_1.jsx)(react_stack_layout_1.Fit, { children: (0, jsx_runtime_1.jsx)(react_ui_1.Link, { icon: downloading ? (0, jsx_runtime_1.jsx)(Spinner_1.Spinner, {}) : (0, jsx_runtime_1.jsx)(NetDownloadIcon16Regular_1.NetDownloadIcon16Regular, {}), onClick: onDownloadClick, disabled: downloading, "data-tid": "DownloadLink", children: "\u0412\u044B\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0432\u0441\u0451 \u0432 Excel" }) }), showFilterModal && ((0, jsx_runtime_1.jsx)(FilterModal_1.FilterModal, { allowClose: allowCloseModal, onClose: this.handleCloseFilterModal, modalEditingConditions: modalEditingConditions, tableColumns: properties.filter(x => x.isSearchable), onChangeFilter: x => this.setState({ modalEditingConditions: x }), onApplyFilter: this.handleApplyFilter })), showDownloadModal && downloadCount && ((0, jsx_runtime_1.jsx)(DownloadLimitModal_1.DownloadLimitModal, { countLimit: downloadCount.countLimit, onDownloadAbort: onDownloadAbort }))] })); } renderFieldSelectorTooltipContent() { const { query, properties, onChange } = this.props; const { hiddenColumns } = query; if (properties.length === 0) { return null; } const fields = properties.map(x => ({ name: x.name, caption: x.name })); return ((0, jsx_runtime_1.jsx)(FieldSelector_1.FieldSelector, { showSelectAllButton: true, "data-tid": "ColumnSelector", fieldDefinitions: fields, hiddenFields: hiddenColumns, onShowField: fieldNames => onChange({ hiddenColumns: (0, difference_1.default)(hiddenColumns, fieldNames) }), onHideField: fieldNames => onChange({ hiddenColumns: [...hiddenColumns, ...fieldNames] }) })); } } exports.ObjectTableLayoutHeader = ObjectTableLayoutHeader; //# sourceMappingURL=ObjectTableLayoutHeader.js.map