@finos/legend-application-studio 13.1.2 → 15.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/lib/components/EditorComponentTestUtils.d.ts +3 -13
  2. package/lib/components/EditorComponentTestUtils.d.ts.map +1 -1
  3. package/lib/components/EditorComponentTestUtils.js +3 -22
  4. package/lib/components/EditorComponentTestUtils.js.map +1 -1
  5. package/lib/components/editor/edit-panel/EditPanel.js +4 -4
  6. package/lib/components/editor/edit-panel/EditPanel.js.map +1 -1
  7. package/lib/components/editor/edit-panel/{ModelLoader.d.ts → ModelImporter.d.ts} +2 -2
  8. package/lib/components/editor/edit-panel/ModelImporter.d.ts.map +1 -0
  9. package/lib/components/editor/edit-panel/ModelImporter.js +127 -0
  10. package/lib/components/editor/edit-panel/ModelImporter.js.map +1 -0
  11. package/lib/components/editor/edit-panel/external-format-editor/SchemaSetElementEditor.d.ts +7 -0
  12. package/lib/components/editor/edit-panel/external-format-editor/SchemaSetElementEditor.d.ts.map +1 -1
  13. package/lib/components/editor/edit-panel/external-format-editor/SchemaSetElementEditor.js +18 -42
  14. package/lib/components/editor/edit-panel/external-format-editor/SchemaSetElementEditor.js.map +1 -1
  15. package/lib/components/editor/edit-panel/external-format-editor/SchemaSetModelGenerationEditor.d.ts +24 -0
  16. package/lib/components/editor/edit-panel/external-format-editor/SchemaSetModelGenerationEditor.d.ts.map +1 -0
  17. package/lib/components/editor/edit-panel/external-format-editor/SchemaSetModelGenerationEditor.js +75 -0
  18. package/lib/components/editor/edit-panel/external-format-editor/SchemaSetModelGenerationEditor.js.map +1 -0
  19. package/lib/components/editor/edit-panel/mapping-editor/NewMappingElementModal.d.ts.map +1 -1
  20. package/lib/components/editor/edit-panel/mapping-editor/NewMappingElementModal.js +1 -2
  21. package/lib/components/editor/edit-panel/mapping-editor/NewMappingElementModal.js.map +1 -1
  22. package/lib/components/editor/side-bar/Explorer.js +4 -4
  23. package/lib/components/editor/side-bar/Explorer.js.map +1 -1
  24. package/lib/index.css +1 -1
  25. package/lib/index.d.ts +1 -0
  26. package/lib/index.d.ts.map +1 -1
  27. package/lib/index.js +1 -0
  28. package/lib/index.js.map +1 -1
  29. package/lib/package.json +7 -7
  30. package/lib/stores/EditorGraphState.d.ts +1 -1
  31. package/lib/stores/EditorGraphState.d.ts.map +1 -1
  32. package/lib/stores/EditorGraphState.js +10 -10
  33. package/lib/stores/EditorGraphState.js.map +1 -1
  34. package/lib/stores/EditorStore.d.ts +3 -3
  35. package/lib/stores/EditorStore.d.ts.map +1 -1
  36. package/lib/stores/EditorStore.js +6 -8
  37. package/lib/stores/EditorStore.js.map +1 -1
  38. package/lib/stores/LegendStudioApplicationPlugin.d.ts +7 -5
  39. package/lib/stores/LegendStudioApplicationPlugin.d.ts.map +1 -1
  40. package/lib/stores/LegendStudioApplicationPlugin.js.map +1 -1
  41. package/lib/stores/editor-state/ExternalFormatState.d.ts +3 -2
  42. package/lib/stores/editor-state/ExternalFormatState.d.ts.map +1 -1
  43. package/lib/stores/editor-state/ExternalFormatState.js +11 -8
  44. package/lib/stores/editor-state/ExternalFormatState.js.map +1 -1
  45. package/lib/stores/editor-state/ModelImporterState.d.ts +100 -0
  46. package/lib/stores/editor-state/ModelImporterState.d.ts.map +1 -0
  47. package/lib/stores/editor-state/ModelImporterState.js +358 -0
  48. package/lib/stores/editor-state/ModelImporterState.js.map +1 -0
  49. package/lib/stores/editor-state/element-editor-state/external-format/SchemaSetEditorState.d.ts +35 -12
  50. package/lib/stores/editor-state/element-editor-state/external-format/SchemaSetEditorState.d.ts.map +1 -1
  51. package/lib/stores/editor-state/element-editor-state/external-format/SchemaSetEditorState.js +141 -34
  52. package/lib/stores/editor-state/element-editor-state/external-format/SchemaSetEditorState.js.map +1 -1
  53. package/lib/stores/editor-state/entity-diff-editor-state/EntityChangeConflictEditorState.js +1 -1
  54. package/lib/stores/editor-state/entity-diff-editor-state/EntityChangeConflictEditorState.js.map +1 -1
  55. package/lib/stores/graphModifier/DSLExternalFormat_GraphModifierHelper.d.ts +1 -0
  56. package/lib/stores/graphModifier/DSLExternalFormat_GraphModifierHelper.d.ts.map +1 -1
  57. package/lib/stores/graphModifier/DSLExternalFormat_GraphModifierHelper.js +3 -0
  58. package/lib/stores/graphModifier/DSLExternalFormat_GraphModifierHelper.js.map +1 -1
  59. package/package.json +15 -15
  60. package/src/components/EditorComponentTestUtils.tsx +2 -29
  61. package/src/components/editor/edit-panel/EditPanel.tsx +4 -4
  62. package/src/components/editor/edit-panel/ModelImporter.tsx +372 -0
  63. package/src/components/editor/edit-panel/external-format-editor/SchemaSetElementEditor.tsx +47 -163
  64. package/src/components/editor/edit-panel/external-format-editor/SchemaSetModelGenerationEditor.tsx +226 -0
  65. package/src/components/editor/edit-panel/mapping-editor/NewMappingElementModal.tsx +1 -2
  66. package/src/components/editor/side-bar/Explorer.tsx +8 -8
  67. package/src/index.ts +1 -0
  68. package/src/stores/EditorGraphState.ts +13 -12
  69. package/src/stores/EditorStore.ts +7 -9
  70. package/src/stores/LegendStudioApplicationPlugin.ts +16 -7
  71. package/src/stores/editor-state/ExternalFormatState.ts +15 -12
  72. package/src/stores/editor-state/ModelImporterState.ts +514 -0
  73. package/src/stores/editor-state/element-editor-state/external-format/SchemaSetEditorState.ts +203 -46
  74. package/src/stores/editor-state/entity-diff-editor-state/EntityChangeConflictEditorState.ts +1 -1
  75. package/src/stores/graphModifier/DSLExternalFormat_GraphModifierHelper.ts +5 -0
  76. package/tsconfig.json +3 -2
  77. package/lib/components/editor/edit-panel/ModelLoader.d.ts.map +0 -1
  78. package/lib/components/editor/edit-panel/ModelLoader.js +0 -95
  79. package/lib/components/editor/edit-panel/ModelLoader.js.map +0 -1
  80. package/lib/stores/editor-state/ModelLoaderState.d.ts +0 -52
  81. package/lib/stores/editor-state/ModelLoaderState.d.ts.map +0 -1
  82. package/lib/stores/editor-state/ModelLoaderState.js +0 -199
  83. package/lib/stores/editor-state/ModelLoaderState.js.map +0 -1
  84. package/src/components/editor/edit-panel/ModelLoader.tsx +0 -259
  85. package/src/stores/editor-state/ModelLoaderState.ts +0 -280
@@ -0,0 +1,514 @@
1
+ /**
2
+ * Copyright (c) 2020-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import {
18
+ observable,
19
+ action,
20
+ flow,
21
+ makeObservable,
22
+ computed,
23
+ flowResult,
24
+ } from 'mobx';
25
+ import { EditorState } from './EditorState.js';
26
+ import {
27
+ type GeneratorFn,
28
+ assertErrorThrown,
29
+ LogEvent,
30
+ UnsupportedOperationError,
31
+ isNonNullable,
32
+ ActionState,
33
+ assertTrue,
34
+ } from '@finos/legend-shared';
35
+ import { LEGEND_STUDIO_APP_EVENT } from '../LegendStudioAppEvent.js';
36
+ import type { EditorStore } from '../EditorStore.js';
37
+ import type { Entity } from '@finos/legend-storage';
38
+ import { TAB_SIZE } from '@finos/legend-application';
39
+ import type {
40
+ ModelImporterExtensionConfiguration,
41
+ LegendStudioApplicationPlugin,
42
+ } from '../LegendStudioApplicationPlugin.js';
43
+ import {
44
+ type ExternalFormatDescription,
45
+ type PureModel,
46
+ SchemaSet,
47
+ observe_SchemaSet,
48
+ } from '@finos/legend-graph';
49
+ import {
50
+ externalFormat_schemaSet_setFormat,
51
+ externalFormat_schemaSet_setSchemas,
52
+ } from '../graphModifier/DSLExternalFormat_GraphModifierHelper.js';
53
+ import { InnerSchemaSetEditorState } from './element-editor-state/external-format/SchemaSetEditorState.js';
54
+
55
+ export enum MODEL_IMPORT_NATIVE_INPUT_TYPE {
56
+ ENTITIES = 'ENTITIES',
57
+ PURE_PROTOCOL = 'PURE_PROTOCOL',
58
+ PURE_GRAMMAR = 'PURE_GRAMMAR',
59
+ }
60
+
61
+ export enum MODEL_IMPORT_TYPE {
62
+ NATIVE = 'NATIVE',
63
+ EXTERNAL_FORMAT = 'EXTERNAL_FORMAT',
64
+ EXTENSIONS = 'EXTENSIONS',
65
+ }
66
+
67
+ export abstract class ModelImporterEditorState {
68
+ readonly editorStore: EditorStore;
69
+ readonly modelImporterState: ModelImporterState;
70
+ loadModelActionState = ActionState.create();
71
+
72
+ constructor(modelImporterState: ModelImporterState) {
73
+ this.editorStore = modelImporterState.editorStore;
74
+ this.modelImporterState = modelImporterState;
75
+ }
76
+
77
+ abstract get label(): string;
78
+
79
+ abstract get allowHardReplace(): boolean;
80
+
81
+ abstract get isLoadingDisabled(): boolean;
82
+
83
+ abstract loadModel(): GeneratorFn<void>;
84
+ }
85
+
86
+ export class NativeModelImporterEditorState extends ModelImporterEditorState {
87
+ nativeType = MODEL_IMPORT_NATIVE_INPUT_TYPE.ENTITIES;
88
+ modelText: string;
89
+ loadCurrentProjectActionState = ActionState.create();
90
+
91
+ constructor(modelImporterState: ModelImporterState) {
92
+ super(modelImporterState);
93
+ this.modelText = this.getExampleEntitiesInputText();
94
+ makeObservable(this, {
95
+ nativeType: observable,
96
+ modelText: observable,
97
+ loadModelActionState: observable,
98
+ setModelText: action,
99
+ setNativeImportType: action,
100
+ isLoadingDisabled: computed,
101
+ loadModel: flow,
102
+ loadCurrentProjectEntities: flow,
103
+ });
104
+ }
105
+
106
+ get label(): string {
107
+ return this.nativeType;
108
+ }
109
+
110
+ get allowHardReplace(): boolean {
111
+ return true;
112
+ }
113
+
114
+ get isLoadingDisabled(): boolean {
115
+ return this.loadCurrentProjectActionState.isInProgress;
116
+ }
117
+
118
+ setModelText(val: string): void {
119
+ this.modelText = val;
120
+ }
121
+
122
+ setNativeImportType(nativeImportType: MODEL_IMPORT_NATIVE_INPUT_TYPE): void {
123
+ if (this.nativeType !== nativeImportType) {
124
+ this.nativeType = nativeImportType;
125
+ this.modelText = this.getNativeImportExampleText(nativeImportType);
126
+ }
127
+ }
128
+
129
+ getNativeImportExampleText(
130
+ inputType: MODEL_IMPORT_NATIVE_INPUT_TYPE,
131
+ ): string {
132
+ switch (inputType) {
133
+ case MODEL_IMPORT_NATIVE_INPUT_TYPE.PURE_PROTOCOL:
134
+ return this.getExamplePureProtocolInputText();
135
+ case MODEL_IMPORT_NATIVE_INPUT_TYPE.ENTITIES:
136
+ return this.getExampleEntitiesInputText();
137
+ case MODEL_IMPORT_NATIVE_INPUT_TYPE.PURE_GRAMMAR:
138
+ return this.getExamplePureGrammarText();
139
+ default:
140
+ return '';
141
+ }
142
+ }
143
+
144
+ async loadEntites(): Promise<Entity[]> {
145
+ switch (this.nativeType) {
146
+ case MODEL_IMPORT_NATIVE_INPUT_TYPE.PURE_PROTOCOL: {
147
+ return this.editorStore.graphManagerState.graphManager.pureProtocolTextToEntities(
148
+ this.modelText,
149
+ );
150
+ }
151
+ case MODEL_IMPORT_NATIVE_INPUT_TYPE.ENTITIES: {
152
+ return JSON.parse(this.modelText) as Entity[];
153
+ }
154
+ case MODEL_IMPORT_NATIVE_INPUT_TYPE.PURE_GRAMMAR: {
155
+ return await this.editorStore.graphManagerState.graphManager.pureCodeToEntities(
156
+ this.modelText,
157
+ );
158
+ }
159
+ default:
160
+ throw new UnsupportedOperationError(
161
+ `Can't load model for input of type '${this.nativeType}'`,
162
+ );
163
+ }
164
+ }
165
+
166
+ *loadCurrentProjectEntities(): GeneratorFn<void> {
167
+ this.loadCurrentProjectActionState.inProgress();
168
+ switch (this.nativeType) {
169
+ case MODEL_IMPORT_NATIVE_INPUT_TYPE.PURE_PROTOCOL: {
170
+ const graphEntities = this.editorStore.graphManagerState.graphBuildState
171
+ .hasSucceeded
172
+ ? this.editorStore.graphManagerState.graph.allOwnElements.map(
173
+ (element) =>
174
+ this.editorStore.graphManagerState.graphManager.elementToEntity(
175
+ element,
176
+ ),
177
+ )
178
+ : this.editorStore.changeDetectionState
179
+ .workspaceLocalLatestRevisionState.entities;
180
+ this.modelText =
181
+ (yield this.editorStore.graphManagerState.graphManager.entitiesToPureProtocolText(
182
+ graphEntities,
183
+ )) as string;
184
+ break;
185
+ }
186
+ case MODEL_IMPORT_NATIVE_INPUT_TYPE.ENTITIES: {
187
+ const graphEntities = this.editorStore.graphManagerState.graphBuildState
188
+ .hasSucceeded
189
+ ? this.editorStore.graphManagerState.graph.allOwnElements.map(
190
+ (element) =>
191
+ this.editorStore.graphManagerState.graphManager.elementToEntity(
192
+ element,
193
+ ),
194
+ )
195
+ : this.editorStore.changeDetectionState
196
+ .workspaceLocalLatestRevisionState.entities;
197
+ this.modelText = JSON.stringify(graphEntities, undefined, TAB_SIZE);
198
+ break;
199
+ }
200
+ case MODEL_IMPORT_NATIVE_INPUT_TYPE.PURE_GRAMMAR: {
201
+ this.modelText =
202
+ (yield this.editorStore.graphManagerState.graphManager.graphToPureCode(
203
+ this.editorStore.graphManagerState.graph,
204
+ )) as string;
205
+ break;
206
+ }
207
+ default:
208
+ this.loadCurrentProjectActionState.fail();
209
+ throw new UnsupportedOperationError(
210
+ `Can't load current project entities for input type of type '${this.nativeType}'`,
211
+ );
212
+ }
213
+ this.loadCurrentProjectActionState.complete();
214
+ }
215
+
216
+ private getExampleEntitiesInputText(): string {
217
+ return `${JSON.stringify(
218
+ [
219
+ {
220
+ classifierPath: 'string',
221
+ content: {},
222
+ path: 'string',
223
+ } as Entity,
224
+ ],
225
+ undefined,
226
+ TAB_SIZE,
227
+ )}`;
228
+ }
229
+
230
+ private getExamplePureProtocolInputText(): string {
231
+ return `${this.editorStore.graphManagerState.graphManager.getExamplePureProtocolText()}`;
232
+ }
233
+
234
+ private getExamplePureGrammarText(): string {
235
+ return `###Pure\n Class model::A\n {\n\n}`;
236
+ }
237
+
238
+ *loadModel(): GeneratorFn<void> {
239
+ try {
240
+ this.loadModelActionState.inProgress();
241
+ this.editorStore.setBlockingAlert({
242
+ message: 'Loading model...',
243
+ prompt: 'Please do not close the application',
244
+ showLoading: true,
245
+ });
246
+ const entities = (yield this.loadEntites()) as Entity[];
247
+ const message = `loading entities from ${
248
+ this.editorStore.applicationStore.config.appName
249
+ } [${this.modelImporterState.replace ? `potentially affected ` : ''} ${
250
+ entities.length
251
+ } entities]`;
252
+ yield this.editorStore.sdlcServerClient.updateEntities(
253
+ this.editorStore.sdlcState.activeProject.projectId,
254
+ this.editorStore.sdlcState.activeWorkspace,
255
+ { replace: this.modelImporterState.replace, entities, message },
256
+ );
257
+ this.editorStore.applicationStore.navigator.reload();
258
+ } catch (error) {
259
+ assertErrorThrown(error);
260
+ this.editorStore.applicationStore.log.error(
261
+ LogEvent.create(LEGEND_STUDIO_APP_EVENT.MODEL_LOADER_FAILURE),
262
+ error,
263
+ );
264
+ this.editorStore.applicationStore.notifyError(error);
265
+ } finally {
266
+ this.loadModelActionState.complete();
267
+ this.editorStore.setBlockingAlert(undefined);
268
+ }
269
+ }
270
+ }
271
+
272
+ export abstract class ExtensionModelImportRendererState {
273
+ importerState: ModelImporterState;
274
+
275
+ constructor(importerState: ModelImporterState) {
276
+ this.importerState = importerState;
277
+ }
278
+ }
279
+ export class ExtensionModelImporterEditorState extends ModelImporterEditorState {
280
+ config: ModelImporterExtensionConfiguration;
281
+ rendererState: ExtensionModelImportRendererState;
282
+
283
+ constructor(
284
+ config: ModelImporterExtensionConfiguration,
285
+ rendererState: ExtensionModelImportRendererState,
286
+ modelImporterState: ModelImporterState,
287
+ ) {
288
+ super(modelImporterState);
289
+ this.config = config;
290
+ this.rendererState = rendererState;
291
+ makeObservable(this, {
292
+ config: observable,
293
+ modelImporterState: observable,
294
+ loadModelActionState: observable,
295
+ rendererState: observable,
296
+ isLoadingDisabled: computed,
297
+ setExtension: action,
298
+ loadModel: flow,
299
+ });
300
+ }
301
+
302
+ get label(): string {
303
+ return this.config.label ?? this.config.key;
304
+ }
305
+
306
+ get allowHardReplace(): boolean {
307
+ return Boolean(this.config.allowHardReplace);
308
+ }
309
+
310
+ get isLoadingDisabled(): boolean {
311
+ return false;
312
+ }
313
+
314
+ setExtension(
315
+ extensionConfiguration: ModelImporterExtensionConfiguration,
316
+ ): void {
317
+ this.config = extensionConfiguration;
318
+ }
319
+
320
+ *loadModel(): GeneratorFn<void> {
321
+ flowResult(this.config.loadModel(this.rendererState));
322
+ }
323
+ }
324
+
325
+ const DEFAULT_SCHEMA_PACKAGE = '__internal__';
326
+ const DEFAULT_SCHEMA_NAME = 'MyShemaSet';
327
+
328
+ export class ExternalFormatModelImporterState extends ModelImporterEditorState {
329
+ schemaSet: SchemaSet;
330
+ schemaSetEditorState: InnerSchemaSetEditorState;
331
+ description: ExternalFormatDescription;
332
+ isolatedSchemaGraph: PureModel;
333
+
334
+ constructor(
335
+ description: ExternalFormatDescription,
336
+ modelImporterState: ModelImporterState,
337
+ ) {
338
+ super(modelImporterState);
339
+ this.description = description;
340
+ this.schemaSet = new SchemaSet(DEFAULT_SCHEMA_NAME);
341
+ this.schemaSet.format = description.name;
342
+
343
+ observe_SchemaSet(this.schemaSet);
344
+ const emptyGraph = this.editorStore.graphManagerState.createEmptyGraph();
345
+ emptyGraph.addElement(this.schemaSet, DEFAULT_SCHEMA_PACKAGE);
346
+ this.isolatedSchemaGraph = emptyGraph;
347
+ this.schemaSetEditorState = new InnerSchemaSetEditorState(
348
+ false,
349
+ this.schemaSet,
350
+ this.editorStore,
351
+ this.isolatedSchemaGraph,
352
+ );
353
+ makeObservable(this, {
354
+ schemaSet: observable,
355
+ schemaSetEditorState: observable,
356
+ loadModelActionState: observable,
357
+ description: observable,
358
+ isolatedSchemaGraph: observable,
359
+ setExternalFormat: action,
360
+ setDescription: action,
361
+ isLoadingDisabled: computed,
362
+ loadModel: flow,
363
+ });
364
+ }
365
+
366
+ get allowHardReplace(): boolean {
367
+ return true;
368
+ }
369
+ get label(): string {
370
+ return this.schemaSet.format;
371
+ }
372
+
373
+ get isLoadingDisabled(): boolean {
374
+ return (
375
+ !this.schemaSetEditorState.schemaSetModelGenerationState.canGenerate ||
376
+ this.schemaSetEditorState.schemaSetModelGenerationState
377
+ .generatingModelsState.isInProgress ||
378
+ this.schemaSetEditorState.schemaSetModelGenerationState
379
+ .importGeneratedElementsState.isInProgress
380
+ );
381
+ }
382
+
383
+ setDescription(val: ExternalFormatDescription): void {
384
+ this.description = val;
385
+ }
386
+
387
+ setExternalFormat(description: ExternalFormatDescription): void {
388
+ if (description !== this.description) {
389
+ this.setDescription(description);
390
+ externalFormat_schemaSet_setFormat(this.schemaSet, this.description.name);
391
+ externalFormat_schemaSet_setSchemas(this.schemaSet, []);
392
+ this.schemaSetEditorState.reset();
393
+ }
394
+ }
395
+
396
+ *loadModel(): GeneratorFn<void> {
397
+ this.loadModelActionState.inProgress();
398
+ try {
399
+ this.loadModelActionState.inProgress();
400
+ this.editorStore.setBlockingAlert({
401
+ message: 'Loading model...',
402
+ prompt: 'Please do not close the application',
403
+ showLoading: true,
404
+ });
405
+ const modelgenerationstate =
406
+ this.schemaSetEditorState.schemaSetModelGenerationState;
407
+ const entities = (yield flowResult(
408
+ modelgenerationstate.getImportEntities(),
409
+ )) as Entity[];
410
+ if (modelgenerationstate.targetBinding) {
411
+ const schemaEntity = (yield flowResult(
412
+ this.editorStore.graphManagerState.graphManager.elementToEntity(
413
+ this.schemaSet,
414
+ ),
415
+ )) as Entity;
416
+ entities.push(schemaEntity);
417
+ }
418
+ assertTrue(Boolean(entities.length), 'No entities to load');
419
+ const message = `loading entities from ${
420
+ this.editorStore.applicationStore.config.appName
421
+ } [${this.modelImporterState.replace ? `potentially affected ` : ''} ${
422
+ entities.length
423
+ } entities]`;
424
+ yield this.editorStore.sdlcServerClient.updateEntities(
425
+ this.editorStore.sdlcState.activeProject.projectId,
426
+ this.editorStore.sdlcState.activeWorkspace,
427
+ { replace: this.modelImporterState.replace, entities, message },
428
+ );
429
+ this.editorStore.applicationStore.navigator.reload();
430
+ } catch (error) {
431
+ assertErrorThrown(error);
432
+ this.editorStore.applicationStore.notifyError(error);
433
+ } finally {
434
+ this.loadModelActionState.complete();
435
+ this.editorStore.setBlockingAlert(undefined);
436
+ }
437
+ }
438
+ }
439
+
440
+ export class ModelImporterState extends EditorState {
441
+ replace = true;
442
+ modelImportEditorState: ModelImporterEditorState;
443
+ extensionConfigs: ModelImporterExtensionConfiguration[] = [];
444
+
445
+ constructor(editorStore: EditorStore) {
446
+ super(editorStore);
447
+
448
+ makeObservable(this, {
449
+ replace: observable,
450
+ modelImportEditorState: observable,
451
+ extensionConfigs: observable,
452
+ setReplaceFlag: action,
453
+ setModelImporterExtension: action,
454
+ setNativeImportType: action,
455
+ setExternalFormatImportFormat: action,
456
+ setImportEditorState: action,
457
+ });
458
+ this.modelImportEditorState = new NativeModelImporterEditorState(this);
459
+ this.extensionConfigs = this.editorStore.pluginManager
460
+ .getApplicationPlugins()
461
+ .flatMap(
462
+ (plugin: LegendStudioApplicationPlugin) =>
463
+ plugin.getExtraModelImporterExtensionConfigurations?.() ?? [],
464
+ )
465
+ .filter(isNonNullable);
466
+ }
467
+
468
+ get headerName(): string {
469
+ return 'Model Importer';
470
+ }
471
+ setReplaceFlag(val: boolean): void {
472
+ this.replace = val;
473
+ }
474
+ setImportEditorState(val: ModelImporterEditorState): void {
475
+ this.modelImportEditorState = val;
476
+ }
477
+ setNativeImportType(
478
+ nativeImportType: MODEL_IMPORT_NATIVE_INPUT_TYPE,
479
+ ): NativeModelImporterEditorState {
480
+ const nativeEditorState =
481
+ this.modelImportEditorState instanceof NativeModelImporterEditorState
482
+ ? this.modelImportEditorState
483
+ : new NativeModelImporterEditorState(this);
484
+ nativeEditorState.setNativeImportType(nativeImportType);
485
+ this.setImportEditorState(nativeEditorState);
486
+ return nativeEditorState;
487
+ }
488
+ setExternalFormatImportFormat(
489
+ externalFormat: ExternalFormatDescription,
490
+ ): ExternalFormatModelImporterState {
491
+ const extensionEditorState =
492
+ this.modelImportEditorState instanceof ExternalFormatModelImporterState
493
+ ? this.modelImportEditorState
494
+ : new ExternalFormatModelImporterState(externalFormat, this);
495
+ extensionEditorState.setExternalFormat(externalFormat);
496
+ this.setImportEditorState(extensionEditorState);
497
+ return extensionEditorState;
498
+ }
499
+ setModelImporterExtension(
500
+ extension: ModelImporterExtensionConfiguration,
501
+ ): ExtensionModelImporterEditorState {
502
+ const externalEditorState =
503
+ this.modelImportEditorState instanceof ExtensionModelImporterEditorState
504
+ ? this.modelImportEditorState
505
+ : new ExtensionModelImporterEditorState(
506
+ extension,
507
+ extension.getExtensionModelImportRendererStateCreator(this),
508
+ this,
509
+ );
510
+ externalEditorState.setExtension(extension);
511
+ this.setImportEditorState(externalEditorState);
512
+ return externalEditorState;
513
+ }
514
+ }