@finos/legend-extension-dsl-data-space
Version:
Legend extension for Data Space DSL
148 lines • 6.89 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 { NAVIGATION_ZONE_SEPARATOR, } from '@finos/legend-application';
import {} from '@finos/legend-graph';
import { action, computed, makeObservable, observable } from 'mobx';
import {} from '../graph-manager/action/analytics/DataSpaceAnalysis.js';
import { PURE_DATA_SPACE_INFO_PROFILE_PATH, PURE_DATA_SPACE_INFO_PROFILE_VERIFIED_STEREOTYPE, } from '../graph-manager/DSL_DataSpace_PureGraphManagerPlugin.js';
import { DataSpaceViewerModelsDocumentationState } from './DataSpaceModelsDocumentationState.js';
import { DataSpaceViewerDiagramViewerState } from './DataSpaceViewerDiagramViewerState.js';
import { DATA_SPACE_WIKI_PAGE_SECTIONS, DataSpaceLayoutState, } from './DataSpaceLayoutState.js';
import { DATA_SPACE_VIEWER_ACTIVITY_MODE, generateAnchorForActivity, } from './DataSpaceViewerNavigation.js';
import { DataAccessState } from '@finos/legend-query-builder';
import { DEFAULT_LEGEND_AI_CONFIG, } from '@finos/legend-lego/legend-ai';
import { DataSpaceQuickStartState } from './DataSpaceQuickStartState.js';
import { DataSpaceViewerExecutableState } from './DataSpaceViewerExecutableState.js';
export class DataSpaceViewerState {
applicationStore;
graphManagerState;
layoutState;
dataSpaceAnalysisResult;
groupId;
artifactId;
versionId;
retrieveGraphData;
queryDataSpace;
viewProject;
viewSDLCProject;
onZoneChange;
queryClass;
openServiceQuery;
onQuickStartTabChange;
diagramViewerState;
modelsDocumentationState;
quickStartState;
legendAIConfig;
executableStates = [];
currentActivity = DATA_SPACE_VIEWER_ACTIVITY_MODE.DESCRIPTION;
currentDataAccessState;
currentExecutionContext;
currentRuntime;
constructor(applicationStore, graphManagerState, groupId, artifactId, versionId, dataSpaceAnalysisResult, actions) {
makeObservable(this, {
currentActivity: observable,
currentExecutionContext: observable,
currentRuntime: observable,
currentDataAccessState: observable,
executableStates: observable,
legendAIConfig: observable,
isVerified: computed,
setCurrentActivity: action,
setCurrentExecutionContext: action,
setCurrentRuntime: action,
});
this.applicationStore = applicationStore;
this.graphManagerState = graphManagerState;
this.layoutState = new DataSpaceLayoutState(this);
this.dataSpaceAnalysisResult = dataSpaceAnalysisResult;
this.executableStates = this.dataSpaceAnalysisResult.executables.map((exec) => new DataSpaceViewerExecutableState(this, exec));
this.groupId = groupId;
this.artifactId = artifactId;
this.versionId = versionId;
this.retrieveGraphData = actions.retrieveGraphData;
this.queryDataSpace = actions.queryDataSpace;
this.viewProject = actions.viewProject;
this.viewSDLCProject = actions.viewSDLCProject;
this.onZoneChange = actions.onZoneChange;
this.queryClass = actions.queryClass;
this.openServiceQuery = actions.openServiceQuery;
this.onQuickStartTabChange = actions.onQuickStartTabChange;
this.currentExecutionContext =
dataSpaceAnalysisResult.defaultExecutionContext;
this.currentRuntime = this.currentExecutionContext.defaultRuntime;
this.currentDataAccessState = new DataAccessState(this.applicationStore, this.graphManagerState, {
initialDatasets: this.currentExecutionContext.datasets,
mapping: this.currentExecutionContext.mapping.path,
runtime: this.currentExecutionContext.defaultRuntime.path,
getQuery: async () => undefined,
graphData: this.retrieveGraphData(),
});
this.modelsDocumentationState = new DataSpaceViewerModelsDocumentationState(this);
this.diagramViewerState = new DataSpaceViewerDiagramViewerState(this);
this.quickStartState = new DataSpaceQuickStartState(this);
this.legendAIConfig = DEFAULT_LEGEND_AI_CONFIG;
}
get isVerified() {
return Boolean(this.dataSpaceAnalysisResult.stereotypes.find((stereotype) => stereotype.profile === PURE_DATA_SPACE_INFO_PROFILE_PATH &&
stereotype.value === PURE_DATA_SPACE_INFO_PROFILE_VERIFIED_STEREOTYPE));
}
setCurrentActivity(val) {
this.currentActivity = val;
}
setCurrentExecutionContext(val) {
this.currentExecutionContext = val;
this.currentRuntime = val.defaultRuntime;
this.currentDataAccessState = new DataAccessState(this.applicationStore, this.graphManagerState, {
initialDatasets: val.datasets,
mapping: val.mapping.path,
runtime: val.defaultRuntime.path,
getQuery: async () => undefined,
graphData: this.retrieveGraphData(),
});
}
setCurrentRuntime(val) {
this.currentRuntime = val;
}
syncZoneWithNavigation(zone) {
this.layoutState.setCurrentNavigationZone(zone);
this.onZoneChange?.(zone);
}
changeZone(zone, force = false) {
if (force) {
this.layoutState.setCurrentNavigationZone('');
}
if (zone !== this.layoutState.currentNavigationZone) {
const zoneChunks = zone.split(NAVIGATION_ZONE_SEPARATOR);
const activityChunk = zoneChunks[0];
const matchingActivity = Object.values(DATA_SPACE_VIEWER_ACTIVITY_MODE).find((activity) => generateAnchorForActivity(activity) === activityChunk);
if (activityChunk && matchingActivity) {
if (DATA_SPACE_WIKI_PAGE_SECTIONS.includes(matchingActivity)) {
this.layoutState.setWikiPageAnchorToNavigate({
anchor: zone,
});
}
this.setCurrentActivity(matchingActivity);
this.onZoneChange?.(zone);
this.layoutState.setCurrentNavigationZone(zone);
}
else {
this.setCurrentActivity(DATA_SPACE_VIEWER_ACTIVITY_MODE.DESCRIPTION);
this.layoutState.setCurrentNavigationZone('');
}
}
}
}
//# sourceMappingURL=DataSpaceViewerState.js.map