@finos/legend-data-cube
Version:
90 lines • 3.26 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 { makeObservable, observable, action, computed } from 'mobx';
import { guaranteeNonNullable } from '@finos/legend-shared';
import { _findCol, _sortByColName } from '../../core/model/DataCubeColumn.js';
export class DataCubeEditorColumnsSelectorColumnState {
name;
type;
constructor(name, type) {
this.name = name;
this.type = type;
}
}
export class DataCubeEditorColumnsSelectorState {
_editor;
selectedColumns = [];
availableColumnsSearchText = '';
selectedColumnsSearchText = '';
onChange;
constructor(editor, options) {
makeObservable(this, {
availableColumns: computed,
availableColumnsForDisplay: computed,
selectedColumnsForDisplay: computed,
selectedColumns: observable,
setSelectedColumns: action,
availableColumnsSearchText: observable,
setAvailableColumnsSearchText: action,
selectedColumnsSearchText: observable,
setSelectedColumnsSearchText: action,
});
this._editor = editor;
this.onChange = options?.onChange;
}
get availableColumnsForDisplay() {
return this.availableColumns
.filter((column) => !_findCol(this.selectedColumns, column.name))
.sort(_sortByColName);
}
get selectedColumnsForDisplay() {
return this.selectedColumns;
}
setSelectedColumns(val) {
// NOTE: since we have a list of columns available which we treat as
// "templates" to select from, we need to clone these columns in order
// to avoid modifying the original available columns
this.selectedColumns = val.map((col) => this.cloneColumn(col));
this.onChange?.(this);
}
setAvailableColumnsSearchText(val) {
this.availableColumnsSearchText = val;
}
setSelectedColumnsSearchText(val) {
this.selectedColumnsSearchText = val;
}
getColumn(colName) {
return guaranteeNonNullable(_findCol(this.availableColumns, colName), `Can't find column '${colName}'`);
}
}
export class DataCubeEditorColumnsSelectorSortColumnState extends DataCubeEditorColumnsSelectorColumnState {
onChange;
direction;
constructor(name, type, direction, onChange) {
super(name, type);
makeObservable(this, {
direction: observable,
setDirection: action,
});
this.direction = direction;
this.onChange = onChange;
}
setDirection(val) {
this.direction = val;
this.onChange?.();
}
}
//# sourceMappingURL=DataCubeEditorColumnsSelectorState.js.map