@finos/legend-application-query 13.0.11 → 13.0.13
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.
- package/lib/components/QueryEditor.d.ts.map +1 -1
- package/lib/components/QueryEditor.js +81 -106
- package/lib/components/QueryEditor.js.map +1 -1
- package/lib/index.css +1 -1
- package/lib/package.json +2 -2
- package/lib/stores/QueryEditorStore.d.ts +29 -50
- package/lib/stores/QueryEditorStore.d.ts.map +1 -1
- package/lib/stores/QueryEditorStore.js +147 -267
- package/lib/stores/QueryEditorStore.js.map +1 -1
- package/package.json +11 -11
- package/src/components/QueryEditor.tsx +201 -239
- package/src/stores/QueryEditorStore.ts +210 -371
@@ -21,6 +21,7 @@ import {
|
|
21
21
|
flowResult,
|
22
22
|
makeObservable,
|
23
23
|
observable,
|
24
|
+
override,
|
24
25
|
} from 'mobx';
|
25
26
|
import {
|
26
27
|
type GeneratorFn,
|
@@ -34,12 +35,12 @@ import {
|
|
34
35
|
StopWatch,
|
35
36
|
guaranteeType,
|
36
37
|
quantifyList,
|
38
|
+
assertNonNullable,
|
37
39
|
} from '@finos/legend-shared';
|
38
40
|
import {
|
39
41
|
type LightQuery,
|
40
42
|
type RawLambda,
|
41
43
|
GraphManagerState,
|
42
|
-
toLightQuery,
|
43
44
|
Query,
|
44
45
|
PureExecution,
|
45
46
|
PackageableElementExplicitReference,
|
@@ -52,6 +53,7 @@ import {
|
|
52
53
|
createGraphBuilderReport,
|
53
54
|
LegendSDLC,
|
54
55
|
QuerySearchSpecification,
|
56
|
+
toLightQuery,
|
55
57
|
} from '@finos/legend-graph';
|
56
58
|
import {
|
57
59
|
EXTERNAL_APPLICATION_NAVIGATION__generateStudioProjectViewUrl,
|
@@ -149,349 +151,65 @@ export interface QueryPersistConfiguration {
|
|
149
151
|
decorator: ((query: Query) => void) | undefined;
|
150
152
|
}
|
151
153
|
|
152
|
-
export class
|
154
|
+
export class QueryCreatorState {
|
153
155
|
readonly editorStore: QueryEditorStore;
|
154
|
-
readonly queryBuilderState: QueryBuilderState;
|
155
156
|
readonly createQueryState = ActionState.create();
|
156
|
-
|
157
|
-
lambda: RawLambda;
|
158
157
|
queryName: string;
|
159
|
-
|
160
|
-
onQueryUpdate?: ((query: Query) => void) | undefined;
|
161
|
-
decorator?: ((query: Query) => void) | undefined;
|
158
|
+
showCreateModal = false;
|
162
159
|
|
163
|
-
constructor(
|
164
|
-
editorStore: QueryEditorStore,
|
165
|
-
queryBuilderState: QueryBuilderState,
|
166
|
-
lambda: RawLambda,
|
167
|
-
config: QueryPersistConfiguration,
|
168
|
-
) {
|
160
|
+
constructor(editorStore: QueryEditorStore, queryName: string | undefined) {
|
169
161
|
makeObservable(this, {
|
170
162
|
queryName: observable,
|
171
|
-
|
163
|
+
showCreateModal: observable,
|
164
|
+
createQueryState: observable,
|
172
165
|
setQueryName: action,
|
166
|
+
setShowCreateModal: action,
|
173
167
|
createQuery: flow,
|
174
168
|
});
|
175
|
-
|
176
169
|
this.editorStore = editorStore;
|
177
|
-
this.
|
178
|
-
this.lambda = lambda;
|
179
|
-
this.allowUpdate = config.allowUpdate ?? false;
|
180
|
-
this.queryName = config.defaultName ?? 'New Query';
|
181
|
-
this.decorator = config.decorator;
|
182
|
-
this.onQueryUpdate = config.onQueryUpdate;
|
170
|
+
this.queryName = queryName ?? 'New Query';
|
183
171
|
}
|
184
172
|
|
185
173
|
setQueryName(val: string): void {
|
186
174
|
this.queryName = val;
|
187
175
|
}
|
188
176
|
|
189
|
-
|
190
|
-
|
191
|
-
!this.createQueryState.isInProgress &&
|
192
|
-
Boolean(this.queryBuilderState.mapping) &&
|
193
|
-
this.queryBuilderState.runtimeValue instanceof RuntimePointer
|
194
|
-
);
|
177
|
+
setShowCreateModal(val: boolean): void {
|
178
|
+
this.showCreateModal = val;
|
195
179
|
}
|
196
180
|
|
197
|
-
*createQuery(
|
198
|
-
if (
|
199
|
-
this.editorStore.isSaveActionDisabled ||
|
200
|
-
!this.queryBuilderState.mapping ||
|
201
|
-
!(this.queryBuilderState.runtimeValue instanceof RuntimePointer)
|
202
|
-
) {
|
203
|
-
return;
|
204
|
-
}
|
205
|
-
this.createQueryState.inProgress();
|
206
|
-
const query = new Query();
|
207
|
-
query.name = this.queryName;
|
208
|
-
query.mapping = PackageableElementExplicitReference.create(
|
209
|
-
this.queryBuilderState.mapping,
|
210
|
-
);
|
211
|
-
query.runtime = this.queryBuilderState.runtimeValue.packageableRuntime;
|
212
|
-
this.decorator?.(query);
|
181
|
+
*createQuery(): GeneratorFn<void> {
|
213
182
|
try {
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
)) as string;
|
218
|
-
} catch (error) {
|
219
|
-
assertErrorThrown(error);
|
220
|
-
this.editorStore.applicationStore.logService.error(
|
221
|
-
LogEvent.create(LEGEND_QUERY_APP_EVENT.GENERIC_FAILURE),
|
222
|
-
error,
|
183
|
+
const queryBuilderState = guaranteeNonNullable(
|
184
|
+
this.editorStore.queryBuilderState,
|
185
|
+
'Query builder state required to build query to edit',
|
223
186
|
);
|
224
|
-
this.
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
this.editorStore.
|
238
|
-
`Successfully created query!`,
|
239
|
-
);
|
240
|
-
|
241
|
-
LegendQueryEventHelper.notify_QueryCreateSucceeded(
|
242
|
-
this.editorStore.applicationStore.eventService,
|
243
|
-
{ queryId: newQuery.id },
|
244
|
-
);
|
245
|
-
|
246
|
-
LegendQueryTelemetryHelper.logEvent_CreateQuerySucceeded(
|
247
|
-
this.editorStore.applicationStore.telemetryService,
|
248
|
-
{
|
249
|
-
query: {
|
250
|
-
id: query.id,
|
251
|
-
name: query.name,
|
252
|
-
groupId: query.groupId,
|
253
|
-
artifactId: query.artifactId,
|
254
|
-
versionId: query.versionId,
|
255
|
-
},
|
256
|
-
},
|
257
|
-
);
|
258
|
-
|
259
|
-
this.queryBuilderState.changeDetectionState.initialize(this.lambda);
|
260
|
-
// turn off change detection at this point
|
261
|
-
// TODO: to make performance better, refrain from refreshing like this
|
262
|
-
this.editorStore.applicationStore.navigationService.navigator.goToLocation(
|
263
|
-
generateExistingQueryEditorRoute(newQuery.id),
|
264
|
-
);
|
265
|
-
} else {
|
266
|
-
const updatedQuery =
|
267
|
-
(yield this.editorStore.graphManagerState.graphManager.updateQuery(
|
268
|
-
query,
|
269
|
-
this.editorStore.graphManagerState.graph,
|
270
|
-
)) as Query;
|
271
|
-
this.editorStore.applicationStore.notificationService.notifySuccess(
|
272
|
-
`Successfully updated query!`,
|
273
|
-
);
|
274
|
-
|
275
|
-
LegendQueryTelemetryHelper.logEvent_UpdateQuerySucceeded(
|
276
|
-
this.editorStore.applicationStore.telemetryService,
|
277
|
-
{
|
278
|
-
query: {
|
279
|
-
id: query.id,
|
280
|
-
name: query.name,
|
281
|
-
groupId: query.groupId,
|
282
|
-
artifactId: query.artifactId,
|
283
|
-
versionId: query.versionId,
|
284
|
-
},
|
285
|
-
},
|
286
|
-
);
|
287
|
-
|
288
|
-
this.onQueryUpdate?.(updatedQuery);
|
289
|
-
}
|
290
|
-
} catch (error) {
|
291
|
-
assertErrorThrown(error);
|
292
|
-
this.editorStore.applicationStore.logService.error(
|
293
|
-
LogEvent.create(LEGEND_QUERY_APP_EVENT.GENERIC_FAILURE),
|
294
|
-
error,
|
295
|
-
);
|
296
|
-
this.editorStore.applicationStore.notificationService.notifyError(error);
|
297
|
-
} finally {
|
298
|
-
this.createQueryState.reset();
|
299
|
-
this.editorStore.setSaveAsState(undefined);
|
300
|
-
}
|
301
|
-
}
|
302
|
-
}
|
303
|
-
|
304
|
-
export class QuerySaveState {
|
305
|
-
readonly editorStore: QueryEditorStore;
|
306
|
-
readonly saveQueryState = ActionState.create();
|
307
|
-
|
308
|
-
queryBuilderState: QueryBuilderState;
|
309
|
-
lambda: RawLambda;
|
310
|
-
queryName: string;
|
311
|
-
allowUpdate = false;
|
312
|
-
onQueryUpdate?: ((query: Query) => void) | undefined;
|
313
|
-
decorator?: ((query: Query) => void) | undefined;
|
314
|
-
|
315
|
-
constructor(
|
316
|
-
editorStore: QueryEditorStore,
|
317
|
-
queryBuilderState: QueryBuilderState,
|
318
|
-
lambda: RawLambda,
|
319
|
-
config: QueryPersistConfiguration,
|
320
|
-
) {
|
321
|
-
makeObservable(this, {
|
322
|
-
queryName: observable,
|
323
|
-
allowPersist: computed,
|
324
|
-
saveQuery: flow,
|
325
|
-
});
|
326
|
-
|
327
|
-
this.editorStore = editorStore;
|
328
|
-
this.queryBuilderState = queryBuilderState;
|
329
|
-
this.lambda = lambda;
|
330
|
-
this.allowUpdate = config.allowUpdate ?? false;
|
331
|
-
this.queryName = config.defaultName ?? 'New Query';
|
332
|
-
this.decorator = config.decorator;
|
333
|
-
this.onQueryUpdate = config.onQueryUpdate;
|
334
|
-
}
|
335
|
-
|
336
|
-
get allowPersist(): boolean {
|
337
|
-
return (
|
338
|
-
!this.saveQueryState.isInProgress &&
|
339
|
-
Boolean(this.queryBuilderState.mapping) &&
|
340
|
-
this.queryBuilderState.runtimeValue instanceof RuntimePointer
|
341
|
-
);
|
342
|
-
}
|
343
|
-
|
344
|
-
*saveQuery(): GeneratorFn<void> {
|
345
|
-
if (
|
346
|
-
this.editorStore.isSaveActionDisabled ||
|
347
|
-
!this.queryBuilderState.mapping ||
|
348
|
-
!(this.queryBuilderState.runtimeValue instanceof RuntimePointer)
|
349
|
-
) {
|
350
|
-
return;
|
351
|
-
}
|
352
|
-
this.saveQueryState.inProgress();
|
353
|
-
const query = new Query();
|
354
|
-
query.name = this.queryName;
|
355
|
-
query.mapping = PackageableElementExplicitReference.create(
|
356
|
-
this.queryBuilderState.mapping,
|
357
|
-
);
|
358
|
-
query.runtime = this.queryBuilderState.runtimeValue.packageableRuntime;
|
359
|
-
this.decorator?.(query);
|
360
|
-
try {
|
361
|
-
query.content =
|
362
|
-
(yield this.editorStore.graphManagerState.graphManager.lambdaToPureCode(
|
363
|
-
this.lambda,
|
364
|
-
)) as string;
|
365
|
-
} catch (error) {
|
366
|
-
assertErrorThrown(error);
|
367
|
-
this.editorStore.applicationStore.logService.error(
|
368
|
-
LogEvent.create(LEGEND_QUERY_APP_EVENT.GENERIC_FAILURE),
|
369
|
-
error,
|
370
|
-
);
|
371
|
-
this.editorStore.applicationStore.notificationService.notifyError(error);
|
372
|
-
this.saveQueryState.reset();
|
373
|
-
return;
|
374
|
-
}
|
375
|
-
|
376
|
-
try {
|
377
|
-
const updatedQuery =
|
378
|
-
(yield this.editorStore.graphManagerState.graphManager.updateQuery(
|
187
|
+
this.createQueryState.inProgress();
|
188
|
+
const rawLambda = queryBuilderState.buildQuery();
|
189
|
+
const config = this.editorStore.getPersistConfiguration(rawLambda, {
|
190
|
+
update: true,
|
191
|
+
});
|
192
|
+
const query = (yield this.editorStore.buildQueryForPersistence(
|
193
|
+
new Query(),
|
194
|
+
rawLambda,
|
195
|
+
config,
|
196
|
+
)) as Query;
|
197
|
+
query.name = this.queryName;
|
198
|
+
query.id = uuid();
|
199
|
+
const newQuery =
|
200
|
+
(yield this.editorStore.graphManagerState.graphManager.createQuery(
|
379
201
|
query,
|
380
202
|
this.editorStore.graphManagerState.graph,
|
381
203
|
)) as Query;
|
382
204
|
this.editorStore.applicationStore.notificationService.notifySuccess(
|
383
|
-
`Successfully
|
384
|
-
);
|
385
|
-
|
386
|
-
LegendQueryTelemetryHelper.logEvent_UpdateQuerySucceeded(
|
387
|
-
this.editorStore.applicationStore.telemetryService,
|
388
|
-
{
|
389
|
-
query: {
|
390
|
-
id: query.id,
|
391
|
-
name: query.name,
|
392
|
-
groupId: query.groupId,
|
393
|
-
artifactId: query.artifactId,
|
394
|
-
versionId: query.versionId,
|
395
|
-
},
|
396
|
-
},
|
205
|
+
`Successfully created query!`,
|
397
206
|
);
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
this.editorStore.applicationStore.logService.error(
|
402
|
-
LogEvent.create(LEGEND_QUERY_APP_EVENT.GENERIC_FAILURE),
|
403
|
-
error,
|
207
|
+
LegendQueryEventHelper.notify_QueryCreateSucceeded(
|
208
|
+
this.editorStore.applicationStore.eventService,
|
209
|
+
{ queryId: newQuery.id },
|
404
210
|
);
|
405
|
-
this.editorStore.applicationStore.notificationService.notifyError(error);
|
406
|
-
} finally {
|
407
|
-
this.saveQueryState.reset();
|
408
|
-
this.editorStore.setSaveState(undefined);
|
409
|
-
}
|
410
|
-
}
|
411
|
-
}
|
412
211
|
|
413
|
-
|
414
|
-
readonly editorStore: QueryEditorStore;
|
415
|
-
readonly queryBuilderState: QueryBuilderState;
|
416
|
-
|
417
|
-
readonly renameQueryState = ActionState.create();
|
418
|
-
|
419
|
-
lambda: RawLambda;
|
420
|
-
queryName: string;
|
421
|
-
allowUpdate = false;
|
422
|
-
onQueryUpdate?: ((query: Query) => void) | undefined;
|
423
|
-
decorator?: ((query: Query) => void) | undefined;
|
424
|
-
|
425
|
-
constructor(
|
426
|
-
editorStore: QueryEditorStore,
|
427
|
-
queryBuilderState: QueryBuilderState,
|
428
|
-
lambda: RawLambda,
|
429
|
-
config: QueryPersistConfiguration,
|
430
|
-
) {
|
431
|
-
makeObservable(this, {
|
432
|
-
queryName: observable,
|
433
|
-
setQueryName: action,
|
434
|
-
renameQuery: flow,
|
435
|
-
});
|
436
|
-
|
437
|
-
this.editorStore = editorStore;
|
438
|
-
this.queryBuilderState = queryBuilderState;
|
439
|
-
this.lambda = lambda;
|
440
|
-
this.allowUpdate = config.allowUpdate ?? false;
|
441
|
-
this.queryName = config.defaultName ?? 'New Query';
|
442
|
-
this.decorator = config.decorator;
|
443
|
-
this.onQueryUpdate = config.onQueryUpdate;
|
444
|
-
}
|
445
|
-
|
446
|
-
setQueryName(val: string): void {
|
447
|
-
this.queryName = val;
|
448
|
-
}
|
449
|
-
|
450
|
-
*renameQuery(): GeneratorFn<void> {
|
451
|
-
if (
|
452
|
-
this.editorStore.isSaveActionDisabled ||
|
453
|
-
!this.queryBuilderState.mapping ||
|
454
|
-
!(this.queryBuilderState.runtimeValue instanceof RuntimePointer) ||
|
455
|
-
this.queryName === this.editorStore.title
|
456
|
-
) {
|
457
|
-
this.renameQueryState.reset();
|
458
|
-
this.editorStore.setRenameState(undefined);
|
459
|
-
return;
|
460
|
-
}
|
461
|
-
this.renameQueryState.inProgress();
|
462
|
-
const query = new Query();
|
463
|
-
query.name = this.queryName;
|
464
|
-
query.mapping = PackageableElementExplicitReference.create(
|
465
|
-
this.queryBuilderState.mapping,
|
466
|
-
);
|
467
|
-
query.runtime = this.queryBuilderState.runtimeValue.packageableRuntime;
|
468
|
-
this.decorator?.(query);
|
469
|
-
try {
|
470
|
-
query.content =
|
471
|
-
(yield this.editorStore.graphManagerState.graphManager.lambdaToPureCode(
|
472
|
-
this.lambda,
|
473
|
-
)) as string;
|
474
|
-
} catch (error) {
|
475
|
-
assertErrorThrown(error);
|
476
|
-
this.editorStore.applicationStore.logService.error(
|
477
|
-
LogEvent.create(LEGEND_QUERY_APP_EVENT.GENERIC_FAILURE),
|
478
|
-
error,
|
479
|
-
);
|
480
|
-
this.editorStore.applicationStore.notificationService.notifyError(error);
|
481
|
-
this.renameQueryState.reset();
|
482
|
-
return;
|
483
|
-
}
|
484
|
-
|
485
|
-
try {
|
486
|
-
const updatedQuery =
|
487
|
-
(yield this.editorStore.graphManagerState.graphManager.updateQuery(
|
488
|
-
query,
|
489
|
-
this.editorStore.graphManagerState.graph,
|
490
|
-
)) as Query;
|
491
|
-
this.editorStore.applicationStore.notificationService.notifySuccess(
|
492
|
-
`Renamed query successfully`,
|
493
|
-
);
|
494
|
-
LegendQueryTelemetryHelper.logEvent_UpdateQuerySucceeded(
|
212
|
+
LegendQueryTelemetryHelper.logEvent_CreateQuerySucceeded(
|
495
213
|
this.editorStore.applicationStore.telemetryService,
|
496
214
|
{
|
497
215
|
query: {
|
@@ -503,7 +221,13 @@ export class QueryRenameState {
|
|
503
221
|
},
|
504
222
|
},
|
505
223
|
);
|
506
|
-
|
224
|
+
queryBuilderState.changeDetectionState.initialize(rawLambda);
|
225
|
+
// turn off change detection at this point
|
226
|
+
// TODO: to make performance better, refrain from refreshing like this
|
227
|
+
this.editorStore.applicationStore.navigationService.navigator.goToLocation(
|
228
|
+
generateExistingQueryEditorRoute(newQuery.id),
|
229
|
+
);
|
230
|
+
this.createQueryState.complete();
|
507
231
|
} catch (error) {
|
508
232
|
assertErrorThrown(error);
|
509
233
|
this.editorStore.applicationStore.logService.error(
|
@@ -512,8 +236,7 @@ export class QueryRenameState {
|
|
512
236
|
);
|
513
237
|
this.editorStore.applicationStore.notificationService.notifyError(error);
|
514
238
|
} finally {
|
515
|
-
this.
|
516
|
-
this.editorStore.setRenameState(undefined);
|
239
|
+
this.createQueryState.reset();
|
517
240
|
}
|
518
241
|
}
|
519
242
|
}
|
@@ -528,10 +251,7 @@ export abstract class QueryEditorStore {
|
|
528
251
|
readonly initState = ActionState.create();
|
529
252
|
|
530
253
|
queryBuilderState?: QueryBuilderState | undefined;
|
531
|
-
|
532
|
-
saveState?: QuerySaveState | undefined;
|
533
|
-
renameState?: QueryRenameState | undefined;
|
534
|
-
title: string | undefined;
|
254
|
+
queryCreatorState: QueryCreatorState;
|
535
255
|
existingQueryName: string | undefined;
|
536
256
|
|
537
257
|
constructor(
|
@@ -539,16 +259,12 @@ export abstract class QueryEditorStore {
|
|
539
259
|
depotServerClient: DepotServerClient,
|
540
260
|
) {
|
541
261
|
makeObservable(this, {
|
542
|
-
|
262
|
+
queryCreatorState: observable,
|
543
263
|
queryLoaderState: observable,
|
544
|
-
renameState: observable,
|
545
|
-
saveState: observable,
|
546
264
|
existingQueryName: observable,
|
547
|
-
|
548
|
-
|
265
|
+
queryBuilderState: observable,
|
266
|
+
isPerformingBlockingAction: computed,
|
549
267
|
setExistingQueryName: action,
|
550
|
-
setSaveAsState: action,
|
551
|
-
setSaveState: action,
|
552
268
|
initialize: flow,
|
553
269
|
buildGraph: flow,
|
554
270
|
searchExistingQueryName: flow,
|
@@ -611,32 +327,25 @@ export abstract class QueryEditorStore {
|
|
611
327
|
},
|
612
328
|
},
|
613
329
|
);
|
330
|
+
this.queryCreatorState = new QueryCreatorState(this, undefined);
|
614
331
|
}
|
615
332
|
|
616
|
-
get
|
617
|
-
return
|
333
|
+
get label(): string | undefined {
|
334
|
+
return undefined;
|
618
335
|
}
|
619
336
|
|
620
|
-
get
|
337
|
+
get isViewProjectActionDisabled(): boolean {
|
621
338
|
return false;
|
622
339
|
}
|
623
340
|
|
624
|
-
setSaveAsState(val: QuerySaveAsState | undefined): void {
|
625
|
-
this.saveAsState = val;
|
626
|
-
}
|
627
|
-
|
628
|
-
setSaveState(val: QuerySaveState | undefined): void {
|
629
|
-
this.saveState = val;
|
630
|
-
}
|
631
|
-
|
632
|
-
setRenameState(val: QueryRenameState | undefined): void {
|
633
|
-
this.renameState = val;
|
634
|
-
}
|
635
|
-
|
636
341
|
setExistingQueryName(val: string | undefined): void {
|
637
342
|
this.existingQueryName = val;
|
638
343
|
}
|
639
344
|
|
345
|
+
get isPerformingBlockingAction(): boolean {
|
346
|
+
return this.queryCreatorState.createQueryState.isInProgress;
|
347
|
+
}
|
348
|
+
|
640
349
|
abstract getProjectInfo(): ProjectGAVCoordinates;
|
641
350
|
/**
|
642
351
|
* Set up the editor state before building the graph
|
@@ -646,6 +355,44 @@ export abstract class QueryEditorStore {
|
|
646
355
|
// do nothing
|
647
356
|
}
|
648
357
|
|
358
|
+
async buildQueryForPersistence(
|
359
|
+
query: Query,
|
360
|
+
rawLambda: RawLambda,
|
361
|
+
config: QueryPersistConfiguration | undefined,
|
362
|
+
): Promise<Query> {
|
363
|
+
try {
|
364
|
+
assertNonNullable(
|
365
|
+
this.queryBuilderState,
|
366
|
+
'Query builder state required to build query to edit',
|
367
|
+
);
|
368
|
+
assertNonNullable(
|
369
|
+
this.queryBuilderState.mapping,
|
370
|
+
'Query required mapping to update',
|
371
|
+
);
|
372
|
+
const runtimeValue = guaranteeType(
|
373
|
+
this.queryBuilderState.runtimeValue,
|
374
|
+
RuntimePointer,
|
375
|
+
'Query runtime must be of type runtime pointer',
|
376
|
+
);
|
377
|
+
query.mapping = PackageableElementExplicitReference.create(
|
378
|
+
this.queryBuilderState.mapping,
|
379
|
+
);
|
380
|
+
query.runtime = runtimeValue.packageableRuntime;
|
381
|
+
query.content =
|
382
|
+
await this.graphManagerState.graphManager.lambdaToPureCode(rawLambda);
|
383
|
+
config?.decorator?.(query);
|
384
|
+
return query;
|
385
|
+
} catch (error) {
|
386
|
+
assertErrorThrown(error);
|
387
|
+
this.applicationStore.logService.error(
|
388
|
+
LogEvent.create(LEGEND_QUERY_APP_EVENT.GENERIC_FAILURE),
|
389
|
+
error,
|
390
|
+
);
|
391
|
+
this.applicationStore.notificationService.notifyError(error);
|
392
|
+
throw error;
|
393
|
+
}
|
394
|
+
}
|
395
|
+
|
649
396
|
/**
|
650
397
|
* Set up the query builder state after building the graph
|
651
398
|
*/
|
@@ -654,7 +401,7 @@ export abstract class QueryEditorStore {
|
|
654
401
|
abstract getPersistConfiguration(
|
655
402
|
lambda: RawLambda,
|
656
403
|
options?: { update?: boolean | undefined },
|
657
|
-
):
|
404
|
+
): QueryPersistConfiguration;
|
658
405
|
|
659
406
|
*initialize(): GeneratorFn<void> {
|
660
407
|
if (!this.initState.isInInitialState) {
|
@@ -895,7 +642,7 @@ export class MappingQueryCreatorStore extends QueryEditorStore {
|
|
895
642
|
return queryBuilderState;
|
896
643
|
}
|
897
644
|
|
898
|
-
|
645
|
+
getPersistConfiguration(): QueryPersistConfiguration {
|
899
646
|
return {
|
900
647
|
decorator: (query: Query): void => {
|
901
648
|
query.id = uuid();
|
@@ -983,10 +730,10 @@ export class ServiceQueryCreatorStore extends QueryEditorStore {
|
|
983
730
|
return queryBuilderState;
|
984
731
|
}
|
985
732
|
|
986
|
-
|
733
|
+
getPersistConfiguration(
|
987
734
|
lambda: RawLambda,
|
988
735
|
options?: { update?: boolean | undefined },
|
989
|
-
):
|
736
|
+
): QueryPersistConfiguration {
|
990
737
|
return {
|
991
738
|
defaultName: options?.update
|
992
739
|
? `${extractElementNameFromPath(this.servicePath)}`
|
@@ -1003,9 +750,80 @@ export class ServiceQueryCreatorStore extends QueryEditorStore {
|
|
1003
750
|
}
|
1004
751
|
}
|
1005
752
|
|
753
|
+
export class ExistingQueryUpdateState {
|
754
|
+
readonly editorStore: ExistingQueryEditorStore;
|
755
|
+
queryRenamer = false;
|
756
|
+
readonly updateQueryState = ActionState.create();
|
757
|
+
|
758
|
+
constructor(editorState: ExistingQueryEditorStore) {
|
759
|
+
this.editorStore = editorState;
|
760
|
+
|
761
|
+
makeObservable(this, {
|
762
|
+
queryRenamer: observable,
|
763
|
+
setQueryRenamer: action,
|
764
|
+
updateQuery: flow,
|
765
|
+
});
|
766
|
+
}
|
767
|
+
|
768
|
+
setQueryRenamer(val: boolean): void {
|
769
|
+
this.queryRenamer = val;
|
770
|
+
}
|
771
|
+
|
772
|
+
*updateQuery(queryName: string | undefined): GeneratorFn<void> {
|
773
|
+
try {
|
774
|
+
const queryBuilderState = guaranteeNonNullable(
|
775
|
+
this.editorStore.queryBuilderState,
|
776
|
+
'Query builder state required to build query to edit',
|
777
|
+
);
|
778
|
+
const rawLambda = queryBuilderState.buildQuery();
|
779
|
+
const config = this.editorStore.getPersistConfiguration(rawLambda, {
|
780
|
+
update: true,
|
781
|
+
});
|
782
|
+
const query = (yield this.editorStore.buildQueryForPersistence(
|
783
|
+
this.editorStore.query ?? new Query(),
|
784
|
+
rawLambda,
|
785
|
+
config,
|
786
|
+
)) as Query;
|
787
|
+
query.name = queryName ?? query.name;
|
788
|
+
const updatedQuery =
|
789
|
+
(yield this.editorStore.graphManagerState.graphManager.updateQuery(
|
790
|
+
query,
|
791
|
+
this.editorStore.graphManagerState.graph,
|
792
|
+
)) as Query;
|
793
|
+
this.editorStore.applicationStore.notificationService.notifySuccess(
|
794
|
+
`Successfully updated query!`,
|
795
|
+
);
|
796
|
+
LegendQueryTelemetryHelper.logEvent_UpdateQuerySucceeded(
|
797
|
+
this.editorStore.applicationStore.telemetryService,
|
798
|
+
{
|
799
|
+
query: {
|
800
|
+
id: query.id,
|
801
|
+
name: query.name,
|
802
|
+
groupId: query.groupId,
|
803
|
+
artifactId: query.artifactId,
|
804
|
+
versionId: query.versionId,
|
805
|
+
},
|
806
|
+
},
|
807
|
+
);
|
808
|
+
config.onQueryUpdate?.(updatedQuery);
|
809
|
+
} catch (error) {
|
810
|
+
assertErrorThrown(error);
|
811
|
+
this.editorStore.applicationStore.logService.error(
|
812
|
+
LogEvent.create(LEGEND_QUERY_APP_EVENT.GENERIC_FAILURE),
|
813
|
+
error,
|
814
|
+
);
|
815
|
+
this.editorStore.applicationStore.notificationService.notifyError(error);
|
816
|
+
} finally {
|
817
|
+
this.updateQueryState.reset();
|
818
|
+
}
|
819
|
+
}
|
820
|
+
}
|
821
|
+
|
1006
822
|
export class ExistingQueryEditorStore extends QueryEditorStore {
|
1007
823
|
private queryId: string;
|
1008
|
-
private
|
824
|
+
private _lightQuery?: LightQuery | undefined;
|
825
|
+
query: Query | undefined;
|
826
|
+
updateState: ExistingQueryUpdateState;
|
1009
827
|
|
1010
828
|
constructor(
|
1011
829
|
applicationStore: LegendQueryApplicationStore,
|
@@ -1016,32 +834,51 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
|
|
1016
834
|
|
1017
835
|
makeObservable<ExistingQueryEditorStore, '_query'>(this, {
|
1018
836
|
_query: observable,
|
1019
|
-
query:
|
837
|
+
query: observable,
|
838
|
+
updateState: observable,
|
839
|
+
lightQuery: computed,
|
840
|
+
setLightQuery: action,
|
1020
841
|
setQuery: action,
|
842
|
+
isPerformingBlockingAction: override,
|
1021
843
|
});
|
1022
844
|
|
1023
845
|
this.queryId = queryId;
|
846
|
+
this.updateState = new ExistingQueryUpdateState(this);
|
847
|
+
}
|
848
|
+
|
849
|
+
get lightQuery(): LightQuery {
|
850
|
+
return guaranteeNonNullable(this._lightQuery, `Query has not been loaded`);
|
851
|
+
}
|
852
|
+
|
853
|
+
override get label(): string | undefined {
|
854
|
+
return this.lightQuery.name;
|
855
|
+
}
|
856
|
+
|
857
|
+
override get isPerformingBlockingAction(): boolean {
|
858
|
+
return (
|
859
|
+
super.isPerformingBlockingAction ||
|
860
|
+
this.updateState.updateQueryState.isInProgress
|
861
|
+
);
|
1024
862
|
}
|
1025
863
|
|
1026
|
-
|
1027
|
-
|
864
|
+
setLightQuery(val: LightQuery): void {
|
865
|
+
this._lightQuery = val;
|
1028
866
|
}
|
1029
867
|
|
1030
|
-
setQuery(val:
|
1031
|
-
this.
|
1032
|
-
this.title = val.name;
|
868
|
+
setQuery(val: Query): void {
|
869
|
+
this.query = val;
|
1033
870
|
}
|
1034
871
|
|
1035
872
|
getProjectInfo(): ProjectGAVCoordinates {
|
1036
873
|
return {
|
1037
|
-
groupId: this.
|
1038
|
-
artifactId: this.
|
1039
|
-
versionId: this.
|
874
|
+
groupId: this.lightQuery.groupId,
|
875
|
+
artifactId: this.lightQuery.artifactId,
|
876
|
+
versionId: this.lightQuery.versionId,
|
1040
877
|
};
|
1041
878
|
}
|
1042
879
|
|
1043
880
|
override async setUpEditorState(): Promise<void> {
|
1044
|
-
this.
|
881
|
+
this.setLightQuery(
|
1045
882
|
await this.graphManagerState.graphManager.getLightQuery(this.queryId),
|
1046
883
|
);
|
1047
884
|
}
|
@@ -1051,6 +888,7 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
|
|
1051
888
|
this.queryId,
|
1052
889
|
this.graphManagerState.graph,
|
1053
890
|
);
|
891
|
+
this.setQuery(query);
|
1054
892
|
LegendQueryUserDataHelper.addRecentlyViewedQuery(
|
1055
893
|
this.applicationStore.userDataService,
|
1056
894
|
query.id,
|
@@ -1101,23 +939,24 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
|
|
1101
939
|
return queryBuilderState;
|
1102
940
|
}
|
1103
941
|
|
1104
|
-
|
942
|
+
getPersistConfiguration(
|
1105
943
|
lambda: RawLambda,
|
1106
944
|
options?: { update?: boolean | undefined },
|
1107
|
-
):
|
945
|
+
): QueryPersistConfiguration {
|
1108
946
|
return {
|
1109
947
|
defaultName: options?.update
|
1110
|
-
? `${this.
|
1111
|
-
: `Copy of ${this.
|
1112
|
-
allowUpdate: this.
|
948
|
+
? `${this.lightQuery.name}`
|
949
|
+
: `Copy of ${this.lightQuery.name}`,
|
950
|
+
allowUpdate: this.lightQuery.isCurrentUserQuery,
|
1113
951
|
decorator: (query: Query): void => {
|
1114
|
-
query.id = this.
|
1115
|
-
query.groupId = this.
|
1116
|
-
query.artifactId = this.
|
1117
|
-
query.versionId = this.
|
952
|
+
query.id = this.lightQuery.id;
|
953
|
+
query.groupId = this.lightQuery.groupId;
|
954
|
+
query.artifactId = this.lightQuery.artifactId;
|
955
|
+
query.versionId = this.lightQuery.versionId;
|
1118
956
|
},
|
1119
957
|
onQueryUpdate: (query: Query): void => {
|
1120
|
-
this.
|
958
|
+
this.setLightQuery(toLightQuery(query));
|
959
|
+
this.setQuery(query);
|
1121
960
|
},
|
1122
961
|
};
|
1123
962
|
}
|