@finos/legend-data-cube
Version:
55 lines • 2.77 kB
JavaScript
/**
* 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 { uniqBy } from '@finos/legend-shared';
import { DataCubeColumnKind } from '../../core/DataCubeQueryEngine.js';
import {} from '../../core/DataCubeSnapshot.js';
import { _findCol, _toCol } from '../../core/model/DataCubeColumn.js';
import { DataCubeEditorColumnsSelectorColumnState, DataCubeEditorColumnsSelectorState, } from './DataCubeEditorColumnsSelectorState.js';
export class DataCubeEditorVerticalPivotColumnsSelectorState extends DataCubeEditorColumnsSelectorState {
cloneColumn(column) {
return new DataCubeEditorColumnsSelectorColumnState(column.name, column.type);
}
get availableColumns() {
return this._editor.columnProperties.columns
.filter((column) => column.kind === DataCubeColumnKind.DIMENSION &&
// exclude group-level extended columns
!_findCol(this._editor.groupExtendColumns, column.name) &&
// exclude pivot columns
!_findCol(this._editor.horizontalPivots.selector.selectedColumns, column.name))
.map((col) => new DataCubeEditorColumnsSelectorColumnState(col.name, col.type));
}
}
export class DataCubeEditorVerticalPivotsPanelState {
selector;
constructor(editor) {
this.selector = new DataCubeEditorVerticalPivotColumnsSelectorState(editor);
}
adaptPropagatedChanges() {
this.selector.setSelectedColumns(this.selector.selectedColumns.filter((column) => _findCol(this.selector.availableColumns, column.name)));
}
applySnaphot(snapshot, configuration) {
this.selector.setSelectedColumns((snapshot.data.groupBy?.columns ?? []).map((col) => new DataCubeEditorColumnsSelectorColumnState(col.name, col.type)));
}
buildSnapshot(newSnapshot, baseSnapshot) {
newSnapshot.data.groupBy = this.selector.selectedColumns.length
? {
columns: this.selector.selectedColumns.map(_toCol),
}
: undefined;
newSnapshot.data.selectColumns = uniqBy([...newSnapshot.data.selectColumns, ...this.selector.selectedColumns], (col) => col.name).map(_toCol);
}
}
//# sourceMappingURL=DataCubeEditorVerticalPivotsPanelState.js.map