@finos/legend-data-cube
Version:
102 lines • 5.37 kB
JavaScript
import { jsx as _jsx } 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 { CODE_EDITOR_LANGUAGE } from '@finos/legend-code-editor';
import { DEFAULT_ALERT_WINDOW_CONFIG, LayoutConfiguration, WindowState, } from './DataCubeLayoutService.js';
import { Alert } from '../../components/core/DataCubeAlert.js';
import { editor as monacoEditorAPI, Uri } from 'monaco-editor';
import { DataCubeCodeCheckErrorAlert } from '../../components/core/DataCubeCodeCheckErrorAlert.js';
import { uuid } from '@finos/legend-shared';
import { DataCubeExecutionErrorAlert } from '../../components/core/DataCubeExecutionErrorAlert.js';
export var AlertType;
(function (AlertType) {
AlertType["ERROR"] = "ERROR";
AlertType["INFO"] = "INFO";
AlertType["SUCCESS"] = "SUCCESS";
AlertType["WARNING"] = "WARNING";
})(AlertType || (AlertType = {}));
export class DataCubeAlertService {
_logService;
_layoutService;
constructor(logService, layoutService) {
this._logService = logService;
this._layoutService = layoutService;
}
alert(options) {
const { message, type, text, actions, windowTitle, windowConfig } = options;
const window = new WindowState(new LayoutConfiguration(windowTitle ?? '', () => (_jsx(Alert, { type: type, message: message, text: text, actions: actions, onClose: () => this._layoutService.closeWindow(window) }))));
window.configuration.window = windowConfig ?? DEFAULT_ALERT_WINDOW_CONFIG;
this._layoutService.newWindow(window);
}
alertError(error, options) {
const { message, text, actions, windowTitle, windowConfig } = options;
const window = new WindowState(new LayoutConfiguration(windowTitle ?? 'Error', () => (_jsx(Alert, { type: AlertType.ERROR, message: message, text: text, actions: actions }))));
window.configuration.window = windowConfig ?? DEFAULT_ALERT_WINDOW_CONFIG;
this._layoutService.newWindow(window);
}
alertUnhandledError(error) {
this._logService.logUnhandledError(error);
this.alertError(error, {
message: error.message,
});
}
alertCodeCheckError(error, code, codePrefix, options) {
const { message, text, windowTitle, windowConfig } = options;
// correct the source information since we added prefix to the code
// and reveal error in the editor
if (error.sourceInformation) {
error.sourceInformation.startColumn -=
error.sourceInformation.startLine === 1 ? codePrefix.length : 0;
error.sourceInformation.endColumn -=
error.sourceInformation.endLine === 1 ? codePrefix.length : 0;
const editorModel = monacoEditorAPI.createModel(code, CODE_EDITOR_LANGUAGE.PURE, Uri.file(`/${uuid()}.pure`));
const fullRange = editorModel.getFullModelRange();
if (error.sourceInformation.startLine < 1 ||
(error.sourceInformation.startLine === 1 &&
error.sourceInformation.startColumn < 1) ||
error.sourceInformation.endLine > fullRange.endLineNumber ||
(error.sourceInformation.endLine === fullRange.endLineNumber &&
error.sourceInformation.endColumn > fullRange.endColumn)) {
error.sourceInformation.startColumn = fullRange.startColumn;
error.sourceInformation.startLine = fullRange.startLineNumber;
error.sourceInformation.endColumn = fullRange.endColumn;
error.sourceInformation.endLine = fullRange.endLineNumber;
}
const window = new WindowState(new LayoutConfiguration(windowTitle ?? 'Error', () => (_jsx(DataCubeCodeCheckErrorAlert, { editorModel: editorModel, error: error, message: message, text: text }))));
window.configuration.window = windowConfig ?? {
width: 500,
height: 400,
minWidth: 300,
minHeight: 300,
center: true,
};
this._layoutService.newWindow(window);
}
}
alertExecutionError(error, options) {
const { message, text, windowTitle, windowConfig } = options;
const window = new WindowState(new LayoutConfiguration(windowTitle ?? 'Error', () => (_jsx(DataCubeExecutionErrorAlert, { error: error, message: message, text: text, onClose: () => this._layoutService.closeWindow(window) }))));
window.configuration.window = windowConfig ?? {
width: 600,
height: 250, // leave some space to show debug content
minWidth: 500,
minHeight: 200,
center: true,
};
this._layoutService.newWindow(window);
}
}
//# sourceMappingURL=DataCubeAlertService.js.map