@finos/legend-application-studio 27.1.1 → 27.1.3

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 (145) hide show
  1. package/lib/__lib__/LegendStudioApplicationNavigationContext.d.ts +1 -1
  2. package/lib/__lib__/LegendStudioApplicationNavigationContext.d.ts.map +1 -1
  3. package/lib/__lib__/LegendStudioApplicationNavigationContext.js +1 -1
  4. package/lib/__lib__/LegendStudioApplicationNavigationContext.js.map +1 -1
  5. package/lib/__lib__/LegendStudioDocumentation.d.ts +3 -1
  6. package/lib/__lib__/LegendStudioDocumentation.d.ts.map +1 -1
  7. package/lib/__lib__/LegendStudioDocumentation.js +3 -0
  8. package/lib/__lib__/LegendStudioDocumentation.js.map +1 -1
  9. package/lib/__lib__/LegendStudioTesting.d.ts +1 -0
  10. package/lib/__lib__/LegendStudioTesting.d.ts.map +1 -1
  11. package/lib/__lib__/LegendStudioTesting.js +1 -0
  12. package/lib/__lib__/LegendStudioTesting.js.map +1 -1
  13. package/lib/application/LegendStudioApplicationConfig.d.ts.map +1 -1
  14. package/lib/application/LegendStudioApplicationConfig.js +1 -1
  15. package/lib/application/LegendStudioApplicationConfig.js.map +1 -1
  16. package/lib/components/editor/editor-group/FunctionEditor.d.ts.map +1 -1
  17. package/lib/components/editor/editor-group/FunctionEditor.js +29 -25
  18. package/lib/components/editor/editor-group/FunctionEditor.js.map +1 -1
  19. package/lib/components/editor/editor-group/connection-editor/{DatabaseBuilder.d.ts → DatabaseBuilderWizard.d.ts} +4 -11
  20. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.d.ts.map +1 -0
  21. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.js +48 -0
  22. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.js.map +1 -0
  23. package/lib/components/editor/editor-group/connection-editor/DatabaseSchemaExplorer.d.ts +32 -0
  24. package/lib/components/editor/editor-group/connection-editor/DatabaseSchemaExplorer.d.ts.map +1 -0
  25. package/lib/components/editor/editor-group/connection-editor/DatabaseSchemaExplorer.js +99 -0
  26. package/lib/components/editor/editor-group/connection-editor/DatabaseSchemaExplorer.js.map +1 -0
  27. package/lib/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.js +1 -1
  28. package/lib/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.js.map +1 -1
  29. package/lib/components/editor/editor-group/mapping-editor/MappingEditor.d.ts.map +1 -1
  30. package/lib/components/editor/editor-group/mapping-editor/MappingEditor.js +2 -2
  31. package/lib/components/editor/editor-group/mapping-editor/MappingEditor.js.map +1 -1
  32. package/lib/components/editor/editor-group/mapping-editor/MappingTestableEditor.d.ts.map +1 -1
  33. package/lib/components/editor/editor-group/mapping-editor/MappingTestableEditor.js +47 -12
  34. package/lib/components/editor/editor-group/mapping-editor/MappingTestableEditor.js.map +1 -1
  35. package/lib/components/editor/editor-group/project-configuration-editor/ProjectConfigurationEditor.d.ts.map +1 -1
  36. package/lib/components/editor/editor-group/project-configuration-editor/ProjectConfigurationEditor.js +61 -11
  37. package/lib/components/editor/editor-group/project-configuration-editor/ProjectConfigurationEditor.js.map +1 -1
  38. package/lib/components/editor/editor-group/project-configuration-editor/ProjectDependencyEditor.d.ts.map +1 -1
  39. package/lib/components/editor/editor-group/project-configuration-editor/ProjectDependencyEditor.js +1 -1
  40. package/lib/components/editor/editor-group/project-configuration-editor/ProjectDependencyEditor.js.map +1 -1
  41. package/lib/components/editor/editor-group/uml-editor/ClassEditor.d.ts.map +1 -1
  42. package/lib/components/editor/editor-group/uml-editor/ClassEditor.js +24 -25
  43. package/lib/components/editor/editor-group/uml-editor/ClassEditor.js.map +1 -1
  44. package/lib/components/editor/editor-group/uml-editor/EnumerationEditor.js +2 -2
  45. package/lib/components/editor/editor-group/uml-editor/EnumerationEditor.js.map +1 -1
  46. package/lib/components/editor/editor-group/uml-editor/ProfileEditor.js +3 -3
  47. package/lib/components/editor/editor-group/uml-editor/ProfileEditor.js.map +1 -1
  48. package/lib/components/editor/editor-group/uml-editor/StereotypeSelector.js +2 -2
  49. package/lib/components/editor/editor-group/uml-editor/StereotypeSelector.js.map +1 -1
  50. package/lib/components/editor/editor-group/uml-editor/TaggedValueEditor.js +2 -2
  51. package/lib/components/editor/editor-group/uml-editor/TaggedValueEditor.js.map +1 -1
  52. package/lib/components/editor/panel-group/SQLPlaygroundPanel.d.ts +0 -7
  53. package/lib/components/editor/panel-group/SQLPlaygroundPanel.d.ts.map +1 -1
  54. package/lib/components/editor/panel-group/SQLPlaygroundPanel.js +20 -77
  55. package/lib/components/editor/panel-group/SQLPlaygroundPanel.js.map +1 -1
  56. package/lib/components/editor/side-bar/Explorer.js +3 -3
  57. package/lib/components/editor/side-bar/Explorer.js.map +1 -1
  58. package/lib/components/editor/side-bar/ProjectOverview.d.ts.map +1 -1
  59. package/lib/components/editor/side-bar/ProjectOverview.js +7 -1
  60. package/lib/components/editor/side-bar/ProjectOverview.js.map +1 -1
  61. package/lib/components/editor/side-bar/WorkflowManager.d.ts.map +1 -1
  62. package/lib/components/editor/side-bar/WorkflowManager.js +6 -1
  63. package/lib/components/editor/side-bar/WorkflowManager.js.map +1 -1
  64. package/lib/index.css +2 -2
  65. package/lib/index.css.map +1 -1
  66. package/lib/package.json +3 -3
  67. package/lib/stores/editor/ExplorerTreeState.d.ts +4 -4
  68. package/lib/stores/editor/ExplorerTreeState.d.ts.map +1 -1
  69. package/lib/stores/editor/ExplorerTreeState.js +4 -4
  70. package/lib/stores/editor/ExplorerTreeState.js.map +1 -1
  71. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.d.ts +12 -12
  72. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.d.ts.map +1 -1
  73. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.js +46 -47
  74. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.js.map +1 -1
  75. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.d.ts +20 -29
  76. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.d.ts.map +1 -1
  77. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.js +60 -141
  78. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.js.map +1 -1
  79. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.d.ts +33 -0
  80. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.d.ts.map +1 -0
  81. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.js +71 -0
  82. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.js.map +1 -0
  83. package/lib/stores/editor/editor-state/element-editor-state/mapping/DEPRECATED__MappingTestState.js +1 -1
  84. package/lib/stores/editor/editor-state/element-editor-state/mapping/DEPRECATED__MappingTestState.js.map +1 -1
  85. package/lib/stores/editor/editor-state/element-editor-state/mapping/MappingEditorState.d.ts +1 -1
  86. package/lib/stores/editor/editor-state/element-editor-state/mapping/MappingEditorState.d.ts.map +1 -1
  87. package/lib/stores/editor/editor-state/element-editor-state/mapping/MappingEditorState.js +2 -2
  88. package/lib/stores/editor/editor-state/element-editor-state/mapping/MappingEditorState.js.map +1 -1
  89. package/lib/stores/editor/editor-state/element-editor-state/mapping/MappingExecutionState.js +1 -1
  90. package/lib/stores/editor/editor-state/element-editor-state/mapping/MappingExecutionState.js.map +1 -1
  91. package/lib/stores/editor/editor-state/element-editor-state/service/ServiceExecutionState.js +1 -1
  92. package/lib/stores/editor/editor-state/element-editor-state/service/ServiceExecutionState.js.map +1 -1
  93. package/lib/stores/editor/editor-state/project-configuration-editor-state/ProjectConfigurationEditorState.d.ts +6 -2
  94. package/lib/stores/editor/editor-state/project-configuration-editor-state/ProjectConfigurationEditorState.d.ts.map +1 -1
  95. package/lib/stores/editor/editor-state/project-configuration-editor-state/ProjectConfigurationEditorState.js +39 -3
  96. package/lib/stores/editor/editor-state/project-configuration-editor-state/ProjectConfigurationEditorState.js.map +1 -1
  97. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.d.ts +3 -48
  98. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.d.ts.map +1 -1
  99. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.js +12 -350
  100. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.js.map +1 -1
  101. package/lib/stores/editor/sidebar-state/WorkflowManagerState.d.ts +5 -0
  102. package/lib/stores/editor/sidebar-state/WorkflowManagerState.d.ts.map +1 -1
  103. package/lib/stores/editor/sidebar-state/WorkflowManagerState.js +26 -0
  104. package/lib/stores/editor/sidebar-state/WorkflowManagerState.js.map +1 -1
  105. package/lib/stores/editor/utils/TestableUtils.js +2 -2
  106. package/lib/stores/editor/utils/TestableUtils.js.map +1 -1
  107. package/package.json +10 -10
  108. package/src/__lib__/LegendStudioApplicationNavigationContext.ts +1 -1
  109. package/src/__lib__/LegendStudioDocumentation.ts +4 -0
  110. package/src/__lib__/LegendStudioTesting.ts +1 -0
  111. package/src/application/LegendStudioApplicationConfig.ts +1 -1
  112. package/src/components/editor/editor-group/FunctionEditor.tsx +137 -122
  113. package/src/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.tsx +191 -0
  114. package/src/components/editor/editor-group/connection-editor/DatabaseSchemaExplorer.tsx +227 -0
  115. package/src/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.tsx +1 -1
  116. package/src/components/editor/editor-group/mapping-editor/MappingEditor.tsx +5 -2
  117. package/src/components/editor/editor-group/mapping-editor/MappingTestableEditor.tsx +68 -17
  118. package/src/components/editor/editor-group/project-configuration-editor/ProjectConfigurationEditor.tsx +137 -12
  119. package/src/components/editor/editor-group/project-configuration-editor/ProjectDependencyEditor.tsx +0 -1
  120. package/src/components/editor/editor-group/uml-editor/ClassEditor.tsx +354 -362
  121. package/src/components/editor/editor-group/uml-editor/EnumerationEditor.tsx +4 -4
  122. package/src/components/editor/editor-group/uml-editor/ProfileEditor.tsx +7 -7
  123. package/src/components/editor/editor-group/uml-editor/StereotypeSelector.tsx +4 -4
  124. package/src/components/editor/editor-group/uml-editor/TaggedValueEditor.tsx +4 -4
  125. package/src/components/editor/panel-group/SQLPlaygroundPanel.tsx +47 -211
  126. package/src/components/editor/side-bar/Explorer.tsx +3 -3
  127. package/src/components/editor/side-bar/ProjectOverview.tsx +14 -3
  128. package/src/components/editor/side-bar/WorkflowManager.tsx +10 -0
  129. package/src/stores/editor/ExplorerTreeState.ts +6 -9
  130. package/src/stores/editor/editor-state/element-editor-state/FunctionEditorState.ts +45 -51
  131. package/src/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.ts +88 -212
  132. package/src/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.ts +102 -0
  133. package/src/stores/editor/editor-state/element-editor-state/mapping/DEPRECATED__MappingTestState.ts +1 -1
  134. package/src/stores/editor/editor-state/element-editor-state/mapping/MappingEditorState.ts +2 -2
  135. package/src/stores/editor/editor-state/element-editor-state/mapping/MappingExecutionState.ts +1 -1
  136. package/src/stores/editor/editor-state/element-editor-state/service/ServiceExecutionState.ts +1 -1
  137. package/src/stores/editor/editor-state/project-configuration-editor-state/ProjectConfigurationEditorState.ts +59 -2
  138. package/src/stores/editor/panel-group/SQLPlaygroundPanelState.ts +13 -533
  139. package/src/stores/editor/sidebar-state/WorkflowManagerState.ts +47 -0
  140. package/src/stores/editor/utils/TestableUtils.ts +2 -2
  141. package/tsconfig.json +3 -1
  142. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilder.d.ts.map +0 -1
  143. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilder.js +0 -133
  144. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilder.js.map +0 -1
  145. package/src/components/editor/editor-group/connection-editor/DatabaseBuilder.tsx +0 -397
@@ -22,22 +22,14 @@ import {
22
22
  assertErrorThrown,
23
23
  LogEvent,
24
24
  addUniqueEntry,
25
- assertNonEmptyString,
26
- assertTrue,
27
25
  guaranteeNonNullable,
28
26
  isNonNullable,
29
27
  filterByType,
30
28
  ActionState,
31
29
  getNonNullableEntry,
30
+ guaranteeType,
32
31
  } from '@finos/legend-shared';
33
- import {
34
- observable,
35
- action,
36
- makeObservable,
37
- flow,
38
- flowResult,
39
- computed,
40
- } from 'mobx';
32
+ import { observable, action, makeObservable, flow, flowResult } from 'mobx';
41
33
  import { LEGEND_STUDIO_APP_EVENT } from '../../../../../__lib__/LegendStudioEvent.js';
42
34
  import type { EditorStore } from '../../../EditorStore.js';
43
35
  import {
@@ -47,20 +39,18 @@ import {
47
39
  DatabaseBuilderInput,
48
40
  DatabasePattern,
49
41
  TargetDatabase,
50
- PackageableElementExplicitReference,
51
42
  Column,
52
43
  Database,
53
- isValidFullPath,
54
44
  resolvePackagePathAndElementName,
55
- isStubbed_PackageableElement,
56
45
  getSchema,
57
46
  getNullableSchema,
58
47
  getNullableTable,
59
48
  } from '@finos/legend-graph';
60
- import { connection_setStore } from '../../../../graph-modifier/DSL_Mapping_GraphModifierHelper.js';
61
49
  import { GraphEditFormModeState } from '../../../GraphEditFormModeState.js';
62
50
 
63
- export abstract class DatabaseBuilderTreeNodeData implements TreeNodeData {
51
+ export abstract class DatabaseSchemaExplorerTreeNodeData
52
+ implements TreeNodeData
53
+ {
64
54
  isOpen?: boolean | undefined;
65
55
  id: string;
66
56
  label: string;
@@ -84,7 +74,7 @@ export abstract class DatabaseBuilderTreeNodeData implements TreeNodeData {
84
74
  }
85
75
  }
86
76
 
87
- export class SchemaDatabaseBuilderTreeNodeData extends DatabaseBuilderTreeNodeData {
77
+ export class DatabaseSchemaExplorerTreeSchemaNodeData extends DatabaseSchemaExplorerTreeNodeData {
88
78
  schema: Schema;
89
79
 
90
80
  constructor(id: string, schema: Schema) {
@@ -93,7 +83,7 @@ export class SchemaDatabaseBuilderTreeNodeData extends DatabaseBuilderTreeNodeDa
93
83
  }
94
84
  }
95
85
 
96
- export class TableDatabaseBuilderTreeNodeData extends DatabaseBuilderTreeNodeData {
86
+ export class DatabaseSchemaExplorerTreeTableNodeData extends DatabaseSchemaExplorerTreeNodeData {
97
87
  override parentId: string;
98
88
  owner: Schema;
99
89
  table: Table;
@@ -106,7 +96,7 @@ export class TableDatabaseBuilderTreeNodeData extends DatabaseBuilderTreeNodeDat
106
96
  }
107
97
  }
108
98
 
109
- export class ColumnDatabaseBuilderTreeNodeData extends DatabaseBuilderTreeNodeData {
99
+ export class DatabaseSchemaExplorerTreeColumnNodeData extends DatabaseSchemaExplorerTreeNodeData {
110
100
  override parentId: string;
111
101
  owner: Table;
112
102
  column: Column;
@@ -119,93 +109,57 @@ export class ColumnDatabaseBuilderTreeNodeData extends DatabaseBuilderTreeNodeDa
119
109
  }
120
110
  }
121
111
 
122
- export interface DatabaseBuilderTreeData
123
- extends TreeData<DatabaseBuilderTreeNodeData> {
112
+ export interface DatabaseExplorerTreeData
113
+ extends TreeData<DatabaseSchemaExplorerTreeNodeData> {
124
114
  database: Database;
125
115
  }
126
116
 
127
- const DEFAULT_DATABASE_PATH = 'store::MyDatabase';
128
-
129
- export class DatabaseBuilderState {
117
+ export class DatabaseSchemaExplorerState {
130
118
  readonly editorStore: EditorStore;
131
119
  readonly connection: RelationalDatabaseConnection;
132
- readonly isReadOnly: boolean;
120
+ readonly database: Database;
133
121
 
134
- showModal = false;
135
- databaseGrammarCode = '';
136
- isBuildingDatabase = false;
137
- isSavingDatabase = false;
138
- targetDatabasePath: string;
139
- treeData?: DatabaseBuilderTreeData | undefined;
122
+ isGeneratingDatabase = false;
123
+ isUpdatingDatabase = false;
124
+ treeData?: DatabaseExplorerTreeData | undefined;
140
125
 
141
126
  constructor(
142
127
  editorStore: EditorStore,
143
128
  connection: RelationalDatabaseConnection,
144
- isReadOnly: boolean,
145
129
  ) {
146
- makeObservable<DatabaseBuilderState>(this, {
147
- showModal: observable,
148
- targetDatabasePath: observable,
149
- databaseGrammarCode: observable,
150
- isBuildingDatabase: observable,
151
- isSavingDatabase: observable,
152
- currentDatabase: computed,
153
- setTargetDatabasePath: action,
154
- setShowModal: action,
155
- setDatabaseGrammarCode: action,
156
- setTreeData: action,
130
+ makeObservable(this, {
131
+ isGeneratingDatabase: observable,
132
+ isUpdatingDatabase: observable,
157
133
  treeData: observable,
134
+ setTreeData: action,
158
135
  onNodeSelect: flow,
159
- generateDatabase: flow,
160
- previewDatabaseModel: flow,
161
- createOrUpdateDatabase: flow,
162
136
  fetchDatabaseMetadata: flow,
163
137
  fetchSchemaMetadata: flow,
164
138
  fetchTableMetadata: flow,
139
+ generateDatabase: flow,
140
+ updateDatabase: flow,
165
141
  });
166
142
 
167
143
  this.connection = connection;
144
+ this.database = guaranteeType(connection.store.value, Database);
168
145
  this.editorStore = editorStore;
169
- this.targetDatabasePath =
170
- this.currentDatabase?.path ?? DEFAULT_DATABASE_PATH;
171
- this.isReadOnly = isReadOnly;
172
146
  }
173
147
 
174
- get currentDatabase(): Database | undefined {
175
- const store = this.connection.store.value;
176
- if (store instanceof Database && !isStubbed_PackageableElement(store)) {
177
- return store;
178
- }
179
- return undefined;
180
- }
181
-
182
- setShowModal(val: boolean): void {
183
- this.showModal = val;
184
- }
185
-
186
- setTreeData(builderTreeData?: DatabaseBuilderTreeData): void {
148
+ setTreeData(builderTreeData?: DatabaseExplorerTreeData): void {
187
149
  this.treeData = builderTreeData;
188
150
  }
189
151
 
190
- setDatabaseGrammarCode(val: string): void {
191
- this.databaseGrammarCode = val;
192
- }
193
-
194
- setTargetDatabasePath(val: string): void {
195
- this.targetDatabasePath = val;
196
- }
197
-
198
152
  *onNodeSelect(
199
- node: DatabaseBuilderTreeNodeData,
200
- treeData: DatabaseBuilderTreeData,
153
+ node: DatabaseSchemaExplorerTreeNodeData,
154
+ treeData: DatabaseExplorerTreeData,
201
155
  ): GeneratorFn<void> {
202
156
  if (
203
- node instanceof SchemaDatabaseBuilderTreeNodeData &&
157
+ node instanceof DatabaseSchemaExplorerTreeSchemaNodeData &&
204
158
  !node.childrenIds
205
159
  ) {
206
160
  yield flowResult(this.fetchSchemaMetadata(node, treeData));
207
161
  } else if (
208
- node instanceof TableDatabaseBuilderTreeNodeData &&
162
+ node instanceof DatabaseSchemaExplorerTreeTableNodeData &&
209
163
  !node.childrenIds
210
164
  ) {
211
165
  yield flowResult(this.fetchTableMetadata(node, treeData));
@@ -215,24 +169,24 @@ export class DatabaseBuilderState {
215
169
  }
216
170
 
217
171
  getChildNodes(
218
- node: DatabaseBuilderTreeNodeData,
219
- treeData: DatabaseBuilderTreeData,
220
- ): DatabaseBuilderTreeNodeData[] | undefined {
172
+ node: DatabaseSchemaExplorerTreeNodeData,
173
+ treeData: DatabaseExplorerTreeData,
174
+ ): DatabaseSchemaExplorerTreeNodeData[] | undefined {
221
175
  return node.childrenIds
222
176
  ?.map((childNode) => treeData.nodes.get(childNode))
223
177
  .filter(isNonNullable);
224
178
  }
225
179
 
226
180
  toggleCheckedNode(
227
- node: DatabaseBuilderTreeNodeData,
228
- treeData: DatabaseBuilderTreeData,
181
+ node: DatabaseSchemaExplorerTreeNodeData,
182
+ treeData: DatabaseExplorerTreeData,
229
183
  ): void {
230
184
  node.setChecked(!node.isChecked);
231
- if (node instanceof SchemaDatabaseBuilderTreeNodeData) {
185
+ if (node instanceof DatabaseSchemaExplorerTreeSchemaNodeData) {
232
186
  this.getChildNodes(node, treeData)?.forEach((childNode) => {
233
187
  childNode.setChecked(node.isChecked);
234
188
  });
235
- } else if (node instanceof TableDatabaseBuilderTreeNodeData) {
189
+ } else if (node instanceof DatabaseSchemaExplorerTreeTableNodeData) {
236
190
  if (node.parentId) {
237
191
  const parent = treeData.nodes.get(node.parentId);
238
192
  if (
@@ -252,12 +206,11 @@ export class DatabaseBuilderState {
252
206
 
253
207
  *fetchDatabaseMetadata(): GeneratorFn<void> {
254
208
  try {
255
- this.isBuildingDatabase = true;
209
+ this.isGeneratingDatabase = true;
256
210
  const databaseBuilderInput = new DatabaseBuilderInput(this.connection);
257
- const [packagePath, databaseName] = this.getDatabasePackageAndName();
258
211
  databaseBuilderInput.targetDatabase = new TargetDatabase(
259
- packagePath,
260
- databaseName,
212
+ guaranteeNonNullable(this.database.package).path,
213
+ this.database.name,
261
214
  );
262
215
  databaseBuilderInput.config.maxTables = undefined;
263
216
  databaseBuilderInput.config.enrichTables = false;
@@ -269,14 +222,14 @@ export class DatabaseBuilderState {
269
222
  )) as Database;
270
223
 
271
224
  const rootIds: string[] = [];
272
- const nodes = new Map<string, DatabaseBuilderTreeNodeData>();
225
+ const nodes = new Map<string, DatabaseSchemaExplorerTreeNodeData>();
273
226
  database.schemas
274
227
  .slice()
275
228
  .sort((schemaA, schemaB) => schemaA.name.localeCompare(schemaB.name))
276
229
  .forEach((schema) => {
277
230
  const schemaId = schema.name;
278
231
  rootIds.push(schemaId);
279
- const schemaNode = new SchemaDatabaseBuilderTreeNodeData(
232
+ const schemaNode = new DatabaseSchemaExplorerTreeSchemaNodeData(
280
233
  schemaId,
281
234
  schema,
282
235
  );
@@ -284,7 +237,7 @@ export class DatabaseBuilderState {
284
237
 
285
238
  schemaNode.setChecked(
286
239
  Boolean(
287
- this.currentDatabase?.schemas.find(
240
+ this.database.schemas.find(
288
241
  (cSchema) => cSchema.name === schema.name,
289
242
  ),
290
243
  ),
@@ -300,23 +253,22 @@ export class DatabaseBuilderState {
300
253
  );
301
254
  this.editorStore.applicationStore.notificationService.notifyError(error);
302
255
  } finally {
303
- this.isBuildingDatabase = false;
256
+ this.isGeneratingDatabase = false;
304
257
  }
305
258
  }
306
259
 
307
260
  *fetchSchemaMetadata(
308
- schemaNode: SchemaDatabaseBuilderTreeNodeData,
309
- treeData: DatabaseBuilderTreeData,
261
+ schemaNode: DatabaseSchemaExplorerTreeSchemaNodeData,
262
+ treeData: DatabaseExplorerTreeData,
310
263
  ): GeneratorFn<void> {
311
264
  try {
312
- this.isBuildingDatabase = true;
265
+ this.isGeneratingDatabase = true;
313
266
 
314
267
  const schema = schemaNode.schema;
315
268
  const databaseBuilderInput = new DatabaseBuilderInput(this.connection);
316
- const [packagePath, databaseName] = this.getDatabasePackageAndName();
317
269
  databaseBuilderInput.targetDatabase = new TargetDatabase(
318
- packagePath,
319
- databaseName,
270
+ guaranteeNonNullable(this.database.package).path,
271
+ this.database.name,
320
272
  );
321
273
  databaseBuilderInput.config.maxTables = undefined;
322
274
  databaseBuilderInput.config.enrichTables = true;
@@ -336,7 +288,7 @@ export class DatabaseBuilderState {
336
288
  .forEach((table) => {
337
289
  table.schema = schema;
338
290
  const tableId = `${schema.name}.${table.name}`;
339
- const tableNode = new TableDatabaseBuilderTreeNodeData(
291
+ const tableNode = new DatabaseSchemaExplorerTreeTableNodeData(
340
292
  tableId,
341
293
  schemaNode.id,
342
294
  schema,
@@ -345,21 +297,14 @@ export class DatabaseBuilderState {
345
297
  treeData.nodes.set(tableId, tableNode);
346
298
  addUniqueEntry(childrenIds, tableId);
347
299
 
348
- if (this.currentDatabase) {
349
- const matchingSchema = getNullableSchema(
350
- this.currentDatabase,
351
- schema.name,
352
- );
353
- tableNode.setChecked(
354
- Boolean(
355
- matchingSchema
356
- ? getNullableTable(matchingSchema, table.name)
357
- : undefined,
358
- ),
359
- );
360
- } else {
361
- tableNode.setChecked(false);
362
- }
300
+ const matchingSchema = getNullableSchema(this.database, schema.name);
301
+ tableNode.setChecked(
302
+ Boolean(
303
+ matchingSchema
304
+ ? getNullableTable(matchingSchema, table.name)
305
+ : undefined,
306
+ ),
307
+ );
363
308
  });
364
309
  schemaNode.childrenIds = childrenIds;
365
310
  this.setTreeData({ ...treeData });
@@ -371,24 +316,24 @@ export class DatabaseBuilderState {
371
316
  );
372
317
  this.editorStore.applicationStore.notificationService.notifyError(error);
373
318
  } finally {
374
- this.isBuildingDatabase = false;
319
+ this.isGeneratingDatabase = false;
375
320
  }
376
321
  }
377
322
 
378
323
  *fetchTableMetadata(
379
- tableNode: TableDatabaseBuilderTreeNodeData,
380
- treeData: DatabaseBuilderTreeData,
324
+ tableNode: DatabaseSchemaExplorerTreeTableNodeData,
325
+ treeData: DatabaseExplorerTreeData,
381
326
  ): GeneratorFn<void> {
382
327
  try {
383
- this.isBuildingDatabase = true;
328
+ this.isGeneratingDatabase = true;
384
329
 
385
330
  const databaseBuilderInput = new DatabaseBuilderInput(this.connection);
386
- const [packagePath, databaseName] = resolvePackagePathAndElementName(
387
- this.targetDatabasePath,
331
+ const [packagePath, name] = resolvePackagePathAndElementName(
332
+ this.database.path,
388
333
  );
389
334
  databaseBuilderInput.targetDatabase = new TargetDatabase(
390
335
  packagePath,
391
- databaseName,
336
+ name,
392
337
  );
393
338
  const table = tableNode.table;
394
339
  const config = databaseBuilderInput.config;
@@ -419,7 +364,7 @@ export class DatabaseBuilderState {
419
364
  .sort((colA, colB) => colA.name.localeCompare(colB.name))
420
365
  .forEach((column) => {
421
366
  const columnId = `${tableId}.${column.name}`;
422
- const columnNode = new ColumnDatabaseBuilderTreeNodeData(
367
+ const columnNode = new DatabaseSchemaExplorerTreeColumnNodeData(
423
368
  columnId,
424
369
  tableId,
425
370
  table,
@@ -439,29 +384,11 @@ export class DatabaseBuilderState {
439
384
  );
440
385
  this.editorStore.applicationStore.notificationService.notifyError(error);
441
386
  } finally {
442
- this.isBuildingDatabase = false;
387
+ this.isGeneratingDatabase = false;
443
388
  }
444
389
  }
445
390
 
446
- private getDatabasePackageAndName(): [string, string] {
447
- if (this.currentDatabase) {
448
- return [
449
- guaranteeNonNullable(this.currentDatabase.package).path,
450
- this.currentDatabase.name,
451
- ];
452
- }
453
- assertNonEmptyString(this.targetDatabasePath, 'Must specify database path');
454
- assertTrue(
455
- isValidFullPath(this.targetDatabasePath),
456
- 'Invalid database path',
457
- );
458
- return resolvePackagePathAndElementName(
459
- this.targetDatabasePath,
460
- this.targetDatabasePath,
461
- );
462
- }
463
-
464
- async buildIntermediateDatabase(
391
+ private async buildIntermediateDatabase(
465
392
  databaseBuilderInput: DatabaseBuilderInput,
466
393
  ): Promise<Database> {
467
394
  const entities =
@@ -483,14 +410,13 @@ export class DatabaseBuilderState {
483
410
 
484
411
  *generateDatabase(): GeneratorFn<Entity> {
485
412
  try {
486
- this.isBuildingDatabase = true;
413
+ this.isGeneratingDatabase = true;
487
414
 
488
415
  const treeData = guaranteeNonNullable(this.treeData);
489
416
  const databaseBuilderInput = new DatabaseBuilderInput(this.connection);
490
- const [packagePath, databaseName] = this.getDatabasePackageAndName();
491
417
  databaseBuilderInput.targetDatabase = new TargetDatabase(
492
- packagePath,
493
- databaseName,
418
+ guaranteeNonNullable(this.database.package).path,
419
+ this.database.name,
494
420
  );
495
421
  const config = databaseBuilderInput.config;
496
422
  config.maxTables = undefined;
@@ -501,7 +427,7 @@ export class DatabaseBuilderState {
501
427
  .map((e) => treeData.nodes.get(e))
502
428
  .filter(isNonNullable)
503
429
  .forEach((schemaNode) => {
504
- if (schemaNode instanceof SchemaDatabaseBuilderTreeNodeData) {
430
+ if (schemaNode instanceof DatabaseSchemaExplorerTreeSchemaNodeData) {
505
431
  const tableNodes = this.getChildNodes(schemaNode, treeData);
506
432
  const allChecked = tableNodes?.every((t) => t.isChecked === true);
507
433
  if (
@@ -514,7 +440,7 @@ export class DatabaseBuilderState {
514
440
  } else {
515
441
  tableNodes?.forEach((t) => {
516
442
  if (
517
- t instanceof TableDatabaseBuilderTreeNodeData &&
443
+ t instanceof DatabaseSchemaExplorerTreeTableNodeData &&
518
444
  t.isChecked
519
445
  ) {
520
446
  config.patterns.push(
@@ -535,40 +461,17 @@ export class DatabaseBuilderState {
535
461
  'Expected a database to be generated',
536
462
  );
537
463
  } finally {
538
- this.isBuildingDatabase = false;
539
- }
540
- }
541
-
542
- *previewDatabaseModel(): GeneratorFn<void> {
543
- if (!this.treeData) {
544
- return;
545
- }
546
-
547
- try {
548
- this.setDatabaseGrammarCode(
549
- (yield this.editorStore.graphManagerState.graphManager.entitiesToPureCode(
550
- [(yield flowResult(this.generateDatabase())) as Entity],
551
- )) as string,
552
- );
553
- } catch (error) {
554
- assertErrorThrown(error);
555
- this.editorStore.applicationStore.logService.error(
556
- LogEvent.create(LEGEND_STUDIO_APP_EVENT.DATABASE_BUILDER_FAILURE),
557
- error,
558
- );
559
- this.editorStore.applicationStore.notificationService.notifyError(error);
560
- } finally {
561
- this.isBuildingDatabase = false;
464
+ this.isGeneratingDatabase = false;
562
465
  }
563
466
  }
564
467
 
565
- *createOrUpdateDatabase(): GeneratorFn<void> {
468
+ *updateDatabase(): GeneratorFn<void> {
566
469
  if (!this.treeData) {
567
470
  return;
568
471
  }
569
472
 
570
473
  try {
571
- this.isSavingDatabase = true;
474
+ this.isUpdatingDatabase = true;
572
475
 
573
476
  const graph = this.editorStore.graphManagerState.createNewGraph();
574
477
  (yield this.editorStore.graphManagerState.graphManager.buildGraph(
@@ -582,40 +485,16 @@ export class DatabaseBuilderState {
582
485
  'Expected one database to be generated from input',
583
486
  );
584
487
 
585
- let currentDatabase: Database;
586
- const isUpdating = Boolean(this.currentDatabase);
587
- if (!this.currentDatabase) {
588
- const newDatabase = new Database(database.name);
589
- connection_setStore(
590
- this.connection,
591
- PackageableElementExplicitReference.create(newDatabase),
592
- );
593
- const packagePath = guaranteeNonNullable(
594
- database.package?.name,
595
- 'Database package is missing',
596
- );
597
- yield flowResult(
598
- this.editorStore.graphEditorMode.addElement(
599
- newDatabase,
600
- packagePath,
601
- false,
602
- ),
603
- );
604
- currentDatabase = newDatabase;
605
- } else {
606
- currentDatabase = this.currentDatabase;
607
- }
608
-
609
488
  // remove undefined schemas
610
489
  const schemas = Array.from(this.treeData.nodes.values())
611
490
  .map((schemaNode) => {
612
- if (schemaNode instanceof SchemaDatabaseBuilderTreeNodeData) {
491
+ if (schemaNode instanceof DatabaseSchemaExplorerTreeSchemaNodeData) {
613
492
  return schemaNode.schema;
614
493
  }
615
494
  return undefined;
616
495
  })
617
496
  .filter(isNonNullable);
618
- currentDatabase.schemas = currentDatabase.schemas.filter((schema) => {
497
+ this.database.schemas = this.database.schemas.filter((schema) => {
619
498
  if (
620
499
  schemas.find((item) => item.name === schema.name) &&
621
500
  !database.schemas.find((s) => s.name === schema.name)
@@ -627,30 +506,27 @@ export class DatabaseBuilderState {
627
506
 
628
507
  // update existing schemas
629
508
  database.schemas.forEach((schema) => {
630
- (schema as Writable<Schema>)._OWNER = currentDatabase;
631
- const currentSchemaIndex = currentDatabase.schemas.findIndex(
509
+ (schema as Writable<Schema>)._OWNER = this.database;
510
+ const currentSchemaIndex = this.database.schemas.findIndex(
632
511
  (item) => item.name === schema.name,
633
512
  );
634
513
  if (currentSchemaIndex !== -1) {
635
- currentDatabase.schemas[currentSchemaIndex] = schema;
514
+ this.database.schemas[currentSchemaIndex] = schema;
636
515
  } else {
637
- currentDatabase.schemas.push(schema);
516
+ this.database.schemas.push(schema);
638
517
  }
639
518
  });
640
519
 
641
520
  this.editorStore.applicationStore.notificationService.notifySuccess(
642
- `Database successfully '${isUpdating ? 'updated' : 'created'}`,
521
+ `Database successfully updated`,
522
+ );
523
+ yield flowResult(
524
+ this.editorStore
525
+ .getGraphEditorMode(GraphEditFormModeState)
526
+ .globalCompile({
527
+ message: `Can't compile graph after editing database. Redirecting you to text mode`,
528
+ }),
643
529
  );
644
- if (isUpdating) {
645
- yield flowResult(
646
- this.editorStore
647
- .getGraphEditorMode(GraphEditFormModeState)
648
- .globalCompile({
649
- message: `Can't compile graph after editing database. Redirecting you to text mode`,
650
- }),
651
- );
652
- }
653
- this.setShowModal(false);
654
530
  } catch (error) {
655
531
  assertErrorThrown(error);
656
532
  this.editorStore.applicationStore.logService.error(
@@ -659,7 +535,7 @@ export class DatabaseBuilderState {
659
535
  );
660
536
  this.editorStore.applicationStore.notificationService.notifyError(error);
661
537
  } finally {
662
- this.isSavingDatabase = false;
538
+ this.isUpdatingDatabase = false;
663
539
  }
664
540
  }
665
541
  }
@@ -0,0 +1,102 @@
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 type { Entity } from '@finos/legend-storage';
18
+ import {
19
+ type GeneratorFn,
20
+ assertErrorThrown,
21
+ LogEvent,
22
+ } from '@finos/legend-shared';
23
+ import { observable, action, makeObservable, flow, flowResult } from 'mobx';
24
+ import { LEGEND_STUDIO_APP_EVENT } from '../../../../../__lib__/LegendStudioEvent.js';
25
+ import type { EditorStore } from '../../../EditorStore.js';
26
+ import { type RelationalDatabaseConnection } from '@finos/legend-graph';
27
+ import { DatabaseSchemaExplorerState } from './DatabaseBuilderState.js';
28
+
29
+ export class DatabaseBuilderWizardState {
30
+ readonly editorStore: EditorStore;
31
+ readonly connection: RelationalDatabaseConnection;
32
+ readonly schemaExplorerState: DatabaseSchemaExplorerState;
33
+ readonly isReadOnly: boolean;
34
+
35
+ showModal = false;
36
+ databaseGrammarCode = '';
37
+
38
+ constructor(
39
+ editorStore: EditorStore,
40
+ connection: RelationalDatabaseConnection,
41
+ isReadOnly: boolean,
42
+ ) {
43
+ makeObservable(this, {
44
+ showModal: observable,
45
+ databaseGrammarCode: observable,
46
+ setShowModal: action,
47
+ setDatabaseGrammarCode: action,
48
+ previewDatabaseModel: flow,
49
+ updateDatabase: flow,
50
+ });
51
+
52
+ this.editorStore = editorStore;
53
+ this.connection = connection;
54
+ this.schemaExplorerState = new DatabaseSchemaExplorerState(
55
+ editorStore,
56
+ connection,
57
+ );
58
+ this.isReadOnly = isReadOnly;
59
+ }
60
+
61
+ setShowModal(val: boolean): void {
62
+ this.showModal = val;
63
+ }
64
+
65
+ setDatabaseGrammarCode(val: string): void {
66
+ this.databaseGrammarCode = val;
67
+ }
68
+
69
+ *previewDatabaseModel(): GeneratorFn<void> {
70
+ if (!this.schemaExplorerState.treeData) {
71
+ return;
72
+ }
73
+
74
+ try {
75
+ this.setDatabaseGrammarCode(
76
+ (yield this.editorStore.graphManagerState.graphManager.entitiesToPureCode(
77
+ [
78
+ (yield flowResult(
79
+ this.schemaExplorerState.generateDatabase(),
80
+ )) as Entity,
81
+ ],
82
+ )) as string,
83
+ );
84
+ } catch (error) {
85
+ assertErrorThrown(error);
86
+ this.editorStore.applicationStore.logService.error(
87
+ LogEvent.create(LEGEND_STUDIO_APP_EVENT.DATABASE_BUILDER_FAILURE),
88
+ error,
89
+ );
90
+ this.editorStore.applicationStore.notificationService.notifyError(error);
91
+ }
92
+ }
93
+
94
+ *updateDatabase(): GeneratorFn<void> {
95
+ if (!this.schemaExplorerState.treeData) {
96
+ return;
97
+ }
98
+
99
+ yield flowResult(this.schemaExplorerState.updateDatabase());
100
+ this.setShowModal(false);
101
+ }
102
+ }
@@ -890,7 +890,7 @@ export class DEPRECATED__MappingTestState extends MappingEditorTabState {
890
890
  rawPlan,
891
891
  this.editorStore.graphManagerState.graph,
892
892
  );
893
- this.executionPlanState.setPlan(plan);
893
+ this.executionPlanState.initialize(plan);
894
894
  } catch {
895
895
  // do nothing
896
896
  }