UNPKG

@finos/legend-data-cube

Version:
76 lines 6.59 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; /** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { observer } from 'mobx-react-lite'; import { DataCubeIcon } from '@finos/legend-art'; import { FormButton, FormCheckbox, FormNumberInput, FormTextInput, } from './DataCubeFormUtils.js'; import { useDataCube } from '../DataCubeProvider.js'; import { DataCubeSettingGroup, DataCubeSettingType, } from '../../stores/services/DataCubeSettingService.js'; import { guaranteeIsBoolean, guaranteeIsNumber, guaranteeIsString, } from '@finos/legend-shared'; import { runInAction } from 'mobx'; const DataCubeSettingEntryDisplay = observer((props) => { const { configuration } = props; const dataCube = useDataCube(); const panel = dataCube.settingService; switch (configuration.type) { case DataCubeSettingType.BOOLEAN: { const value = guaranteeIsBoolean(panel.currentValues.get(configuration.key)); return (_jsxs("div", { className: "my-2", children: [_jsx("div", { className: "font-medium", children: configuration.title }), _jsx("div", { className: "flex pr-2", children: _jsx(FormCheckbox, { label: configuration.description, checked: value, onChange: () => { runInAction(() => { panel.currentValues.set(configuration.key, !value); }); } }) })] })); } case DataCubeSettingType.NUMERIC: { const value = guaranteeIsNumber(panel.currentValues.get(configuration.key)); const defaultValue = configuration.defaultValue; return (_jsxs("div", { className: "my-2", children: [_jsx("div", { className: "font-medium", children: configuration.title }), _jsx("div", { className: "mb-1.5 text-sm text-neutral-700", children: configuration.description }), _jsx(FormNumberInput, { className: "w-20 text-sm", min: configuration.numericValueMin, step: configuration.numericValueStep, max: configuration.numericValueMax, defaultValue: defaultValue, value: value, setValue: (newValue) => { runInAction(() => { panel.currentValues.set(configuration.key, newValue ?? defaultValue); }); } })] })); } case DataCubeSettingType.STRING: { const value = guaranteeIsString(panel.currentValues.get(configuration.key)); return (_jsxs("div", { className: "my-2", children: [_jsx("div", { className: "font-medium", children: configuration.title }), _jsx("div", { className: "mb-1.5 text-sm text-neutral-700", children: configuration.description }), _jsx(FormTextInput, { className: "w-80 text-sm", value: value, onChange: (event) => { runInAction(() => { panel.currentValues.set(configuration.key, event.target.value); }); } })] })); } case DataCubeSettingType.ACTION: { return (_jsxs("div", { className: "my-2", children: [_jsx("div", { className: "font-medium", children: configuration.title }), _jsx("div", { className: "mb-1.5 text-sm text-neutral-700", children: configuration.description }), _jsx("div", { className: "flex pr-2", children: _jsx(FormButton, { compact: true, onClick: () => configuration.action?.(dataCube.api, undefined), children: "Run Action" }) })] })); } default: return null; } }); export const DataCubeSettingsPanel = observer(() => { const dataCube = useDataCube(); const panel = dataCube.settingService; const configurations = Array.from(panel.configurations.values()).toSorted((a, b) => a.title.localeCompare(b.title)); return (_jsxs(_Fragment, { children: [_jsx("div", { className: "h-[calc(100%_-_40px)] w-full p-2 pb-0", children: _jsxs("div", { className: "h-full w-full select-none overflow-auto border border-neutral-300 bg-white p-2", children: [_jsx("div", { className: "mt-1 flex h-5", children: _jsxs("div", { className: "flex h-full", children: [_jsx("div", { className: "flex h-5 items-center text-xl font-medium", children: _jsx(DataCubeIcon.Table, {}) }), _jsx("div", { className: "ml-1 flex h-5 items-center text-xl font-medium", children: "Grid" })] }) }), configurations .filter((setting) => setting.group === DataCubeSettingGroup.GRID) .map((configuration) => (_jsx(DataCubeSettingEntryDisplay, { configuration: configuration }, configuration.key))), _jsx("div", { className: "my-2 h-[1px] w-full bg-neutral-200" }), _jsx("div", { className: "mt-1 flex h-5", children: _jsxs("div", { className: "flex h-full", children: [_jsx("div", { className: "flex h-5 items-center text-xl font-medium", children: _jsx(DataCubeIcon.Debug, {}) }), _jsx("div", { className: "ml-1 flex h-5 items-center text-xl font-medium", children: "Debug" })] }) }), configurations .filter((setting) => setting.group === DataCubeSettingGroup.DEBUG) .map((configuration) => (_jsx(DataCubeSettingEntryDisplay, { configuration: configuration }, configuration.key)))] }) }), _jsxs("div", { className: "flex h-10 items-center justify-end px-2", children: [_jsx(FormButton, { onClick: () => panel.restoreDefaultValues(), disabled: !panel.allowRestoreDefaultValues, children: "Restore Default Settings" }), _jsx(FormButton, { className: "ml-2", onClick: () => { panel.display.close(); }, children: "Cancel" }), _jsx(FormButton, { className: "ml-2", onClick: () => panel.save(dataCube.api), children: "Apply" }), _jsx(FormButton, { className: "ml-2", onClick: () => { panel.save(dataCube.api); panel.display.close(); }, children: "OK" })] })] })); }); //# sourceMappingURL=DataCubeSettingsPanel.js.map