UNPKG

@finos/legend-data-cube

Version:
67 lines 2.67 kB
/** * 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 { action, computed, makeObservable, observable } from 'mobx'; import {} from '../../core/DataCubeSnapshot.js'; import { DataCubeEditorMutableColumnConfiguration } from './DataCubeEditorMutableConfiguration.js'; import { at, guaranteeNonNullable, } from '@finos/legend-shared'; import { _findCol } from '../../core/model/DataCubeColumn.js'; export class DataCubeEditorColumnPropertiesPanelState { _view; columns = []; selectedColumnName; showAdvancedSettings = false; constructor(editor) { makeObservable(this, { columns: observable, setColumns: action, selectedColumnName: observable, setSelectedColumnName: action, selectedColumn: computed, showAdvancedSettings: observable, setShowAdvancedSettings: action, applySnaphot: action, }); this._view = editor.view; } getColumnConfiguration(colName) { return guaranteeNonNullable(_findCol(this.columns, colName), `Can't find configuration for column '${colName}'`); } setColumns(val) { this.columns = val; } setSelectedColumnName(val) { this.selectedColumnName = val; } get selectedColumn() { return _findCol(this.columns, this.selectedColumnName); } setShowAdvancedSettings(val) { this.showAdvancedSettings = val; } applySnaphot(snapshot, configuration) { this.setColumns(snapshot.data.configuration.columns.map((column) => DataCubeEditorMutableColumnConfiguration.create(column, snapshot, this._view.engine.aggregateOperations))); if (!this.selectedColumn && this.columns.length) { this.setSelectedColumnName(at(this.columns, 0).name); } } buildSnapshot(newSnapshot, baseSnapshot) { newSnapshot.data.configuration = { ...newSnapshot.data.configuration, columns: this.columns.map((column) => column.serialize()), }; } } //# sourceMappingURL=DataCubeEditorColumnPropertiesPanelState.js.map