@finos/legend-application-studio 28.19.49 → 28.19.51

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 (28) hide show
  1. package/lib/components/editor/editor-group/data-editor/EmbeddedDataEditor.d.ts.map +1 -1
  2. package/lib/components/editor/editor-group/data-editor/EmbeddedDataEditor.js +5 -1
  3. package/lib/components/editor/editor-group/data-editor/EmbeddedDataEditor.js.map +1 -1
  4. package/lib/components/editor/editor-group/data-editor/RelationElementsDataEditor.d.ts +23 -0
  5. package/lib/components/editor/editor-group/data-editor/RelationElementsDataEditor.d.ts.map +1 -0
  6. package/lib/components/editor/editor-group/data-editor/RelationElementsDataEditor.js +197 -0
  7. package/lib/components/editor/editor-group/data-editor/RelationElementsDataEditor.js.map +1 -0
  8. package/lib/index.css +2 -2
  9. package/lib/index.css.map +1 -1
  10. package/lib/package.json +1 -1
  11. package/lib/stores/editor/editor-state/ExternalFormatState.d.ts +2 -1
  12. package/lib/stores/editor/editor-state/ExternalFormatState.d.ts.map +1 -1
  13. package/lib/stores/editor/editor-state/ExternalFormatState.js +1 -0
  14. package/lib/stores/editor/editor-state/ExternalFormatState.js.map +1 -1
  15. package/lib/stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.d.ts +30 -1
  16. package/lib/stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.d.ts.map +1 -1
  17. package/lib/stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.js +195 -1
  18. package/lib/stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.js.map +1 -1
  19. package/lib/stores/editor/editor-state/element-editor-state/function-activator/testable/FunctionTestableState.d.ts.map +1 -1
  20. package/lib/stores/editor/editor-state/element-editor-state/function-activator/testable/FunctionTestableState.js +13 -5
  21. package/lib/stores/editor/editor-state/element-editor-state/function-activator/testable/FunctionTestableState.js.map +1 -1
  22. package/package.json +10 -10
  23. package/src/components/editor/editor-group/data-editor/EmbeddedDataEditor.tsx +9 -0
  24. package/src/components/editor/editor-group/data-editor/RelationElementsDataEditor.tsx +567 -0
  25. package/src/stores/editor/editor-state/ExternalFormatState.ts +1 -0
  26. package/src/stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.ts +233 -0
  27. package/src/stores/editor/editor-state/element-editor-state/function-activator/testable/FunctionTestableState.ts +24 -5
  28. package/tsconfig.json +1 -0
@@ -0,0 +1,567 @@
1
+ /**
2
+ * Copyright (c) 2025-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 { observer } from 'mobx-react-lite';
18
+ import React, { useState, useRef } from 'react';
19
+ import {
20
+ BlankPanelPlaceholder,
21
+ PanelContent,
22
+ PanelHeader,
23
+ PlusIcon,
24
+ TimesIcon,
25
+ LockIcon,
26
+ TrashIcon,
27
+ UploadIcon,
28
+ FileImportIcon,
29
+ Dialog,
30
+ clsx,
31
+ CustomSelectorInput,
32
+ } from '@finos/legend-art';
33
+ import { RelationElement } from '@finos/legend-graph';
34
+ import { guaranteeNonNullable } from '@finos/legend-shared';
35
+ import type {
36
+ RelationElementsDataState,
37
+ RelationElementState,
38
+ } from '../../../../stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.js';
39
+ import {
40
+ ActionAlertActionType,
41
+ ActionAlertType,
42
+ useApplicationNavigationContext,
43
+ } from '@finos/legend-application';
44
+ import { LEGEND_STUDIO_APPLICATION_NAVIGATION_CONTEXT_KEY } from '../../../../__lib__/LegendStudioApplicationNavigationContext.js';
45
+ import { useEditorStore } from '../../EditorStoreProvider.js';
46
+
47
+ const NewRelationElementModal = observer(
48
+ (props: { dataState: RelationElementsDataState; isReadOnly: boolean }) => {
49
+ const { isReadOnly, dataState } = props;
50
+ const applicationStore = dataState.editorStore.applicationStore;
51
+
52
+ enum PathType {
53
+ SCHEMA_TABLE = 'Schema and Table',
54
+ }
55
+ interface PathTypeOption {
56
+ value: PathType;
57
+ label: string;
58
+ }
59
+ const pathTypeOptions = Object.values(PathType).map((type) => ({
60
+ label: type,
61
+ value: type,
62
+ }));
63
+ const [pathType, setPathType] = useState<PathTypeOption | undefined>(
64
+ pathTypeOptions[0],
65
+ );
66
+ const onPathTypeChange = (val: PathTypeOption): void => {
67
+ setPathType(val);
68
+ };
69
+
70
+ const [schemaName, setSchemaName] = useState<string | undefined>();
71
+ const [tableName, setTableName] = useState<string | undefined>();
72
+ const changeSchemaValue: React.ChangeEventHandler<HTMLInputElement> = (
73
+ event,
74
+ ) => {
75
+ setSchemaName(event.target.value);
76
+ };
77
+ const changeTableValue: React.ChangeEventHandler<HTMLInputElement> = (
78
+ event,
79
+ ) => {
80
+ setTableName(event.target.value);
81
+ };
82
+
83
+ const closeModal = (): void =>
84
+ dataState.setShowNewRelationElementModal(false);
85
+ const handleSubmit = (): void => {
86
+ const path: string[] = [];
87
+ if (pathType && schemaName && tableName) {
88
+ path.push(schemaName);
89
+ path.push(tableName);
90
+ }
91
+ const relationalElement = new RelationElement();
92
+ relationalElement.columns = [];
93
+ relationalElement.rows = [];
94
+ relationalElement.paths = path;
95
+
96
+ dataState.addRelationElement(relationalElement);
97
+ closeModal();
98
+ };
99
+
100
+ return (
101
+ <Dialog
102
+ open={dataState.showNewRelationElementModal}
103
+ onClose={closeModal}
104
+ classes={{ container: 'search-modal__container' }}
105
+ PaperProps={{ classes: { root: 'search-modal__inner-container' } }}
106
+ >
107
+ <form
108
+ onSubmit={(event) => {
109
+ event.preventDefault();
110
+ handleSubmit();
111
+ closeModal();
112
+ }}
113
+ className="modal modal--dark search-modal"
114
+ >
115
+ <div className="modal__title">Add Relational Element</div>
116
+ <div className="relational-data-editor__identifier">
117
+ <div className="relational-data-editor__identifier__values">
118
+ <CustomSelectorInput
119
+ className="explorer__new-element-modal__driver__dropdown"
120
+ options={pathTypeOptions}
121
+ onChange={onPathTypeChange}
122
+ value={pathType}
123
+ isClearable={false}
124
+ darkMode={
125
+ !applicationStore.layoutService
126
+ .TEMPORARY__isLightColorThemeEnabled
127
+ }
128
+ />
129
+ </div>
130
+ <>
131
+ <div className="relational-data-editor__identifier__values">
132
+ <input
133
+ className="panel__content__form__section__input"
134
+ disabled={isReadOnly}
135
+ placeholder="schemaName"
136
+ value={schemaName}
137
+ onChange={changeSchemaValue}
138
+ />
139
+ </div>
140
+ <div className="relational-data-editor__identifier__values">
141
+ <input
142
+ className="relational-data-editor__identifier__values panel__content__form__section__input"
143
+ disabled={isReadOnly}
144
+ placeholder="tableName"
145
+ value={tableName}
146
+ onChange={changeTableValue}
147
+ />
148
+ </div>
149
+ </>
150
+ </div>
151
+ <div className="search-modal__actions">
152
+ <button className="btn btn--dark" disabled={isReadOnly}>
153
+ Add
154
+ </button>
155
+ </div>
156
+ </form>
157
+ </Dialog>
158
+ );
159
+ },
160
+ );
161
+
162
+ const RelationElementEditor = observer(
163
+ (props: {
164
+ relationElementState: RelationElementState;
165
+ isReadOnly: boolean;
166
+ }) => {
167
+ const { relationElementState, isReadOnly } = props;
168
+ const editorStore = useEditorStore();
169
+ const embeddedData = relationElementState.relationElement;
170
+ const [exportFormat, setExportFormat] = useState<'json' | 'csv' | 'sql'>(
171
+ 'json',
172
+ );
173
+ const fileInputRef = useRef<HTMLInputElement>(null);
174
+
175
+ const addColumn = (): void => {
176
+ if (!isReadOnly) {
177
+ const columnName = `column_${embeddedData.columns.length + 1}`;
178
+ relationElementState.addColumn(columnName);
179
+ }
180
+ };
181
+
182
+ const removeColumn = (index: number): void => {
183
+ if (!isReadOnly) {
184
+ relationElementState.removeColumn(index);
185
+ }
186
+ };
187
+
188
+ const updateColumn = (index: number, value: string): void => {
189
+ if (!isReadOnly) {
190
+ const column = embeddedData.columns[index];
191
+ if (column) {
192
+ relationElementState.updateColumn(index, value);
193
+ }
194
+ }
195
+ };
196
+
197
+ const addRow = (): void => {
198
+ if (!isReadOnly) {
199
+ relationElementState.addRow();
200
+ }
201
+ };
202
+
203
+ const removeRow = (index: number): void => {
204
+ if (!isReadOnly) {
205
+ relationElementState.removeRow(index);
206
+ }
207
+ };
208
+
209
+ const updateCellValue = (
210
+ rowIndex: number,
211
+ columnIndex: number,
212
+ value: string,
213
+ ): void => {
214
+ if (!isReadOnly) {
215
+ relationElementState.updateRow(rowIndex, columnIndex, value);
216
+ }
217
+ };
218
+
219
+ const handleFileUpload = (
220
+ event: React.ChangeEvent<HTMLInputElement>,
221
+ ): void => {
222
+ const file = event.target.files?.[0];
223
+ if (file && file.type === 'text/csv') {
224
+ const reader = new FileReader();
225
+ reader.onload = (e) => {
226
+ const csvContent = e.target?.result as string;
227
+ if (csvContent) {
228
+ relationElementState.importCSV(csvContent);
229
+ }
230
+ };
231
+ reader.readAsText(file);
232
+ }
233
+ if (fileInputRef.current) {
234
+ fileInputRef.current.value = '';
235
+ }
236
+ };
237
+
238
+ const exportData = (): void => {
239
+ let content = '';
240
+ let filename = '';
241
+ let mimeType = '';
242
+
243
+ switch (exportFormat) {
244
+ case 'json':
245
+ content = relationElementState.exportJSON();
246
+ filename = 'test_data.json';
247
+ mimeType = 'application/json';
248
+ break;
249
+ case 'csv':
250
+ content = relationElementState.exportCSV();
251
+ filename = 'test_data.csv';
252
+ mimeType = 'text/csv';
253
+ break;
254
+ case 'sql':
255
+ content = relationElementState.exportSQL();
256
+ filename = 'test_data.sql';
257
+ mimeType = 'text/sql';
258
+ break;
259
+ default:
260
+ content = relationElementState.exportJSON();
261
+ filename = 'test_data.json';
262
+ mimeType = 'application/json';
263
+ break;
264
+ }
265
+
266
+ const blob = new Blob([content], { type: mimeType });
267
+ const url = URL.createObjectURL(blob);
268
+ const a = document.createElement('a');
269
+ a.href = url;
270
+ a.download = filename;
271
+ document.body.appendChild(a);
272
+ a.click();
273
+ document.body.removeChild(a);
274
+ URL.revokeObjectURL(url);
275
+ };
276
+
277
+ const handleClearData = (): void => {
278
+ editorStore.applicationStore.alertService.setActionAlertInfo({
279
+ message: 'Are you sure you want to clear all test data?',
280
+ type: ActionAlertType.CAUTION,
281
+ actions: [
282
+ {
283
+ label: 'Confirm',
284
+ type: ActionAlertActionType.PROCEED_WITH_CAUTION,
285
+ handler: (): void => {
286
+ relationElementState.clearAllData();
287
+ },
288
+ },
289
+ {
290
+ label: 'Cancel',
291
+ type: ActionAlertActionType.PROCEED,
292
+ default: true,
293
+ },
294
+ ],
295
+ });
296
+ };
297
+
298
+ return (
299
+ <div className="relation-test-data-editor__content">
300
+ <div className="relation-test-data-editor__columns">
301
+ <div className="relation-test-data-editor__section-header">
302
+ <div className="relation-test-data-editor__section-title">
303
+ Column Definitions
304
+ </div>
305
+ <button
306
+ className="btn--icon btn--dark btn--sm"
307
+ onClick={addColumn}
308
+ disabled={isReadOnly}
309
+ title="Add Column"
310
+ >
311
+ <PlusIcon />
312
+ </button>
313
+ </div>
314
+ <div className="relation-test-data-editor__columns-grid">
315
+ {embeddedData.columns.map((column, index) => (
316
+ <div
317
+ key={`column-${guaranteeNonNullable(index)}`}
318
+ className="relation-test-data-editor__column-row"
319
+ >
320
+ <input
321
+ className="relation-test-data-editor__column-input"
322
+ type="text"
323
+ value={column}
324
+ onChange={(e) => updateColumn(index, e.target.value)}
325
+ placeholder="Column Name"
326
+ disabled={isReadOnly}
327
+ />
328
+ <button
329
+ className="btn--icon btn--caution btn--dark btn--sm"
330
+ onClick={() => removeColumn(index)}
331
+ disabled={isReadOnly}
332
+ title="Remove Column"
333
+ >
334
+ <TimesIcon />
335
+ </button>
336
+ </div>
337
+ ))}
338
+ </div>
339
+ </div>
340
+
341
+ <div className="relation-test-data-editor__data">
342
+ <div className="relation-test-data-editor__section-header">
343
+ <div className="relation-test-data-editor__section-title">
344
+ Test Data ({embeddedData.rows.length} rows)
345
+ </div>
346
+ </div>
347
+ {embeddedData.rows.length === 0 ? (
348
+ <div className="relation-test-data-editor__empty-data">
349
+ <div className="relation-test-data-editor__empty-text">
350
+ No test data rows. Click &quot;+&quot; below to start entering
351
+ data.
352
+ </div>
353
+ </div>
354
+ ) : (
355
+ <div className="relation-test-data-editor__data-grid">
356
+ <div className="relation-test-data-editor__data-header">
357
+ {embeddedData.columns.map((column) => (
358
+ <div
359
+ key={column}
360
+ className="relation-test-data-editor__data-header-cell"
361
+ >
362
+ {column}
363
+ {/* <span className="relation-test-data-editor__data-type">
364
+ ({column.type})
365
+ </span> */}
366
+ </div>
367
+ ))}
368
+ <div className="relation-test-data-editor__data-header-cell relation-test-data-editor__data-actions">
369
+ Actions
370
+ </div>
371
+ </div>
372
+ {embeddedData.rows.map((row, rowIndex) => (
373
+ <div
374
+ key={`row-${guaranteeNonNullable(rowIndex)}`}
375
+ className="relation-test-data-editor__data-row"
376
+ >
377
+ {embeddedData.columns.map((column, columnIndex) => (
378
+ <div
379
+ key={column}
380
+ className="relation-test-data-editor__data-cell"
381
+ >
382
+ <input
383
+ type="text"
384
+ value={row.values[columnIndex] ?? ''}
385
+ onChange={(e) =>
386
+ updateCellValue(rowIndex, columnIndex, e.target.value)
387
+ }
388
+ disabled={isReadOnly}
389
+ className="relation-test-data-editor__data-input"
390
+ />
391
+ </div>
392
+ ))}
393
+ <div className="relation-test-data-editor__data-cell relation-test-data-editor__data-actions">
394
+ <button
395
+ className="btn--icon btn--caution btn--dark btn--sm"
396
+ onClick={() => removeRow(rowIndex)}
397
+ disabled={isReadOnly}
398
+ title="Remove Row"
399
+ >
400
+ <TimesIcon />
401
+ </button>
402
+ </div>
403
+ </div>
404
+ ))}
405
+ </div>
406
+ )}
407
+
408
+ <div className="relation-test-data-editor__export-controls">
409
+ <div className="relation-test-data-editor__export-controls__btn-group">
410
+ <button
411
+ className="btn--icon btn--dark btn--sm"
412
+ onClick={addRow}
413
+ disabled={isReadOnly || embeddedData.columns.length === 0}
414
+ title="Add Row"
415
+ >
416
+ <PlusIcon />
417
+ </button>
418
+
419
+ <button
420
+ className="btn--icon btn--caution btn--dark btn--sm"
421
+ onClick={handleClearData}
422
+ disabled={isReadOnly || embeddedData.rows.length === 0}
423
+ title="Clear All Data"
424
+ >
425
+ <TrashIcon />
426
+ </button>
427
+ </div>
428
+ <div className="relation-test-data-editor__export-format">
429
+ <label htmlFor="exportFormat">Export as:</label>
430
+ <select
431
+ id="exportFormat"
432
+ value={exportFormat}
433
+ onChange={(e) =>
434
+ setExportFormat(e.target.value as 'json' | 'csv' | 'sql')
435
+ }
436
+ disabled={isReadOnly}
437
+ className="relation-test-data-editor__export-select"
438
+ >
439
+ <option value="json">JSON</option>
440
+ <option value="csv">CSV</option>
441
+ <option value="sql">SQL INSERT</option>
442
+ </select>
443
+ <button
444
+ className="btn--icon btn--dark btn--sm"
445
+ onClick={exportData}
446
+ disabled={isReadOnly}
447
+ title={`Export as ${exportFormat.toUpperCase()}`}
448
+ >
449
+ <FileImportIcon />
450
+ </button>
451
+ </div>
452
+
453
+ <div className="relation-test-data-editor__import-controls">
454
+ <input
455
+ ref={fileInputRef}
456
+ type="file"
457
+ accept=".csv"
458
+ onChange={handleFileUpload}
459
+ style={{ display: 'none' }}
460
+ disabled={isReadOnly}
461
+ />
462
+ <button
463
+ className="btn--icon btn--dark btn--sm"
464
+ onClick={() => fileInputRef.current?.click()}
465
+ disabled={isReadOnly}
466
+ title="Upload a file of CSV"
467
+ >
468
+ <UploadIcon />
469
+ </button>
470
+ </div>
471
+ </div>
472
+ </div>
473
+ </div>
474
+ );
475
+ },
476
+ );
477
+
478
+ export const RelationElementsDataEditor = observer(
479
+ (props: { dataState: RelationElementsDataState; isReadOnly: boolean }) => {
480
+ const { dataState, isReadOnly } = props;
481
+
482
+ useApplicationNavigationContext(
483
+ LEGEND_STUDIO_APPLICATION_NAVIGATION_CONTEXT_KEY.EMBEDDED_DATA_RELATIONAL_EDITOR,
484
+ );
485
+
486
+ const addRelationElement = (): void => {
487
+ dataState.setShowNewRelationElementModal(true);
488
+ };
489
+
490
+ const changeRelationElement = (
491
+ newRelationElement: RelationElementState,
492
+ ): void => {
493
+ dataState.setActiveRelationElement(newRelationElement);
494
+ };
495
+
496
+ return (
497
+ <div className="panel relation-test-data-editor">
498
+ <PanelHeader>
499
+ <div className="panel__header__title">
500
+ {isReadOnly && (
501
+ <div className="panel__header__lock">
502
+ <LockIcon />
503
+ </div>
504
+ )}
505
+ <div className="panel__header__title__label">
506
+ {dataState.label()}
507
+ </div>
508
+ </div>
509
+ </PanelHeader>
510
+ <PanelContent>
511
+ <div className="panel__header service-editor__header--with-tabs">
512
+ <div className="uml-element-editor__tabs">
513
+ {dataState.relationElementStates.map((relationElementState) => (
514
+ <div
515
+ key={relationElementState.relationElement.paths.join('.')}
516
+ onClick={(): void =>
517
+ changeRelationElement(relationElementState)
518
+ }
519
+ className={clsx('service-editor__tab', {
520
+ 'service-editor__tab--active':
521
+ relationElementState === dataState.activeRelationElement,
522
+ })}
523
+ >
524
+ {relationElementState.relationElement.paths.length > 1 ? (
525
+ <span>
526
+ {relationElementState.relationElement.paths.join('.')}
527
+ </span>
528
+ ) : (
529
+ <span>{relationElementState.relationElement.paths[0]}</span>
530
+ )}
531
+ </div>
532
+ ))}
533
+ </div>
534
+ <button
535
+ onClick={addRelationElement}
536
+ disabled={isReadOnly}
537
+ title="Add Relation Element"
538
+ >
539
+ <PlusIcon />
540
+ </button>
541
+ </div>
542
+ {dataState.relationElementStates.length === 0 ||
543
+ dataState.activeRelationElement === undefined ? (
544
+ <BlankPanelPlaceholder
545
+ text="Add a relation element to define your test data structure"
546
+ onClick={addRelationElement}
547
+ clickActionType="add"
548
+ tooltipText="Add Relation Element"
549
+ disabled={isReadOnly}
550
+ />
551
+ ) : (
552
+ <RelationElementEditor
553
+ relationElementState={dataState.activeRelationElement}
554
+ isReadOnly={isReadOnly}
555
+ />
556
+ )}
557
+ </PanelContent>
558
+ {dataState.showNewRelationElementModal && (
559
+ <NewRelationElementModal
560
+ dataState={dataState}
561
+ isReadOnly={isReadOnly}
562
+ />
563
+ )}
564
+ </div>
565
+ );
566
+ },
567
+ );
@@ -36,6 +36,7 @@ export enum EmbeddedDataType {
36
36
  MODEL_STORE_DATA = 'MODEL_STORE',
37
37
  RELATIONAL_CSV = 'RELATIONAL',
38
38
  DATA_ELEMENT = 'DATA_ELEMENT',
39
+ RELATION_ELEMENTS_DATA = 'RELATION_ELEMENTS_DATA',
39
40
  }
40
41
 
41
42
  export class ExternalFormatState {