@finos/legend-query-builder 3.1.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. package/lib/__lib__/QueryBuilderColorTheme.d.ts +23 -0
  2. package/lib/__lib__/QueryBuilderColorTheme.d.ts.map +1 -0
  3. package/lib/__lib__/QueryBuilderColorTheme.js +24 -0
  4. package/lib/__lib__/QueryBuilderColorTheme.js.map +1 -0
  5. package/lib/__lib__/QueryBuilderTelemetryHelper.d.ts +20 -20
  6. package/lib/__lib__/QueryBuilderTelemetryHelper.d.ts.map +1 -1
  7. package/lib/__lib__/QueryBuilderTelemetryHelper.js +40 -40
  8. package/lib/__lib__/QueryBuilderTelemetryHelper.js.map +1 -1
  9. package/lib/components/QueryBuilder.d.ts.map +1 -1
  10. package/lib/components/QueryBuilder.js +17 -15
  11. package/lib/components/QueryBuilder.js.map +1 -1
  12. package/lib/components/QueryBuilder_LegendApplicationPlugin.d.ts.map +1 -1
  13. package/lib/components/QueryBuilder_LegendApplicationPlugin.js +3 -0
  14. package/lib/components/QueryBuilder_LegendApplicationPlugin.js.map +1 -1
  15. package/lib/components/QueryLoader.d.ts +30 -0
  16. package/lib/components/QueryLoader.d.ts.map +1 -0
  17. package/lib/components/QueryLoader.js +164 -0
  18. package/lib/components/QueryLoader.js.map +1 -0
  19. package/lib/components/data-access/DataAccessOverview.d.ts +23 -0
  20. package/lib/components/data-access/DataAccessOverview.d.ts.map +1 -0
  21. package/lib/components/data-access/DataAccessOverview.js +146 -0
  22. package/lib/components/data-access/DataAccessOverview.js.map +1 -0
  23. package/lib/components/execution-plan/ExecutionPlanViewer.d.ts.map +1 -1
  24. package/lib/components/execution-plan/ExecutionPlanViewer.js +3 -3
  25. package/lib/components/execution-plan/ExecutionPlanViewer.js.map +1 -1
  26. package/lib/components/execution-plan/SQLExecutionNodeViewer.js +1 -1
  27. package/lib/components/execution-plan/SQLExecutionNodeViewer.js.map +1 -1
  28. package/lib/components/explorer/QueryBuilderPropertySearchPanel.js +1 -1
  29. package/lib/components/explorer/QueryBuilderPropertySearchPanel.js.map +1 -1
  30. package/lib/components/fetch-structure/QueryBuilderTDSPanel.d.ts +0 -18
  31. package/lib/components/fetch-structure/QueryBuilderTDSPanel.d.ts.map +1 -1
  32. package/lib/components/fetch-structure/QueryBuilderTDSPanel.js +34 -36
  33. package/lib/components/fetch-structure/QueryBuilderTDSPanel.js.map +1 -1
  34. package/lib/components/shared/LambdaEditor.d.ts.map +1 -1
  35. package/lib/components/shared/LambdaEditor.js +7 -19
  36. package/lib/components/shared/LambdaEditor.js.map +1 -1
  37. package/lib/components/shared/QueryBuilderPanelIssueCountBadge.d.ts.map +1 -1
  38. package/lib/components/shared/QueryBuilderPanelIssueCountBadge.js +2 -1
  39. package/lib/components/shared/QueryBuilderPanelIssueCountBadge.js.map +1 -1
  40. package/lib/index.css +1 -17
  41. package/lib/index.css.map +1 -1
  42. package/lib/index.d.ts +5 -0
  43. package/lib/index.d.ts.map +1 -1
  44. package/lib/index.js +5 -0
  45. package/lib/index.js.map +1 -1
  46. package/lib/package.json +4 -2
  47. package/lib/stores/QueryBuilderState.d.ts +3 -3
  48. package/lib/stores/QueryBuilderState.d.ts.map +1 -1
  49. package/lib/stores/QueryBuilderState.js +34 -18
  50. package/lib/stores/QueryBuilderState.js.map +1 -1
  51. package/lib/stores/QueryBuilder_LegendApplicationPlugin_Extension.d.ts +39 -0
  52. package/lib/stores/QueryBuilder_LegendApplicationPlugin_Extension.d.ts.map +1 -0
  53. package/lib/stores/QueryBuilder_LegendApplicationPlugin_Extension.js +17 -0
  54. package/lib/stores/QueryBuilder_LegendApplicationPlugin_Extension.js.map +1 -0
  55. package/lib/stores/QueryLoaderState.d.ts +67 -0
  56. package/lib/stores/QueryLoaderState.d.ts.map +1 -0
  57. package/lib/stores/QueryLoaderState.js +205 -0
  58. package/lib/stores/QueryLoaderState.js.map +1 -0
  59. package/lib/stores/data-access/DataAccessState.d.ts +56 -0
  60. package/lib/stores/data-access/DataAccessState.d.ts.map +1 -0
  61. package/lib/stores/data-access/DataAccessState.js +212 -0
  62. package/lib/stores/data-access/DataAccessState.js.map +1 -0
  63. package/lib/stores/entitlements/QueryBuilderCheckEntitlementsState.d.ts +4 -2
  64. package/lib/stores/entitlements/QueryBuilderCheckEntitlementsState.d.ts.map +1 -1
  65. package/lib/stores/entitlements/QueryBuilderCheckEntitlementsState.js +20 -6
  66. package/lib/stores/entitlements/QueryBuilderCheckEntitlementsState.js.map +1 -1
  67. package/lib/stores/shared/ValueSpecificationEditorHelper.d.ts +3 -1
  68. package/lib/stores/shared/ValueSpecificationEditorHelper.d.ts.map +1 -1
  69. package/lib/stores/shared/ValueSpecificationEditorHelper.js +7 -1
  70. package/lib/stores/shared/ValueSpecificationEditorHelper.js.map +1 -1
  71. package/package.json +12 -10
  72. package/src/__lib__/QueryBuilderColorTheme.ts +23 -0
  73. package/src/__lib__/QueryBuilderTelemetryHelper.ts +40 -59
  74. package/src/components/QueryBuilder.tsx +63 -47
  75. package/src/components/QueryBuilder_LegendApplicationPlugin.ts +4 -0
  76. package/src/components/QueryLoader.tsx +504 -0
  77. package/src/components/data-access/DataAccessOverview.tsx +308 -0
  78. package/src/components/execution-plan/ExecutionPlanViewer.tsx +1 -3
  79. package/src/components/execution-plan/SQLExecutionNodeViewer.tsx +1 -1
  80. package/src/components/explorer/QueryBuilderPropertySearchPanel.tsx +1 -1
  81. package/src/components/fetch-structure/QueryBuilderTDSPanel.tsx +99 -102
  82. package/src/components/shared/LambdaEditor.tsx +4 -21
  83. package/src/components/shared/QueryBuilderPanelIssueCountBadge.tsx +2 -1
  84. package/src/index.ts +7 -0
  85. package/src/stores/QueryBuilderState.ts +65 -19
  86. package/src/stores/QueryBuilder_LegendApplicationPlugin_Extension.ts +46 -0
  87. package/src/stores/QueryLoaderState.ts +298 -0
  88. package/src/stores/data-access/DataAccessState.ts +322 -0
  89. package/src/stores/entitlements/QueryBuilderCheckEntitlementsState.ts +53 -6
  90. package/src/stores/shared/ValueSpecificationEditorHelper.ts +39 -2
  91. package/tsconfig.json +6 -0
@@ -15,6 +15,7 @@
15
15
  */
16
16
 
17
17
  import { TimesCircleIcon } from '@finos/legend-art';
18
+ import { quantifyList } from '@finos/legend-shared';
18
19
 
19
20
  export const QueryBuilderPanelIssueCountBadge: React.FC<{
20
21
  issues: string[] | undefined;
@@ -23,7 +24,7 @@ export const QueryBuilderPanelIssueCountBadge: React.FC<{
23
24
  if (!issues) {
24
25
  return null;
25
26
  }
26
- const labelText = `${issues.length} issue${issues.length > 1 ? 's' : ''}`;
27
+ const labelText = quantifyList(issues, 'issue');
27
28
  return (
28
29
  <div
29
30
  className="query-builder-panel-issue-count-badge"
package/src/index.ts CHANGED
@@ -70,3 +70,10 @@ export * from './stores/shared/ValueSpecificationEditorHelper.js';
70
70
 
71
71
  export * from './components/execution-plan/ExecutionPlanViewer.js';
72
72
  export * from './stores/execution-plan/ExecutionPlanState.js';
73
+
74
+ export * from './components/QueryLoader.js';
75
+ export * from './stores/QueryLoaderState.js';
76
+ export * from './stores/QueryBuilder_LegendApplicationPlugin_Extension.js';
77
+
78
+ export * from './stores/data-access/DataAccessState.js';
79
+ export * from './components/data-access/DataAccessOverview.js';
@@ -31,6 +31,7 @@ import {
31
31
  filterByType,
32
32
  ActionState,
33
33
  hashArray,
34
+ assertTrue,
34
35
  } from '@finos/legend-shared';
35
36
  import { QueryBuilderFilterState } from './filter/QueryBuilderFilterState.js';
36
37
  import { QueryBuilderFetchStructureState } from './fetch-structure/QueryBuilderFetchStructureState.js';
@@ -62,6 +63,15 @@ import {
62
63
  buildLambdaVariableExpressions,
63
64
  buildRawLambdaFromLambdaFunction,
64
65
  type ValueSpecification,
66
+ PrimitiveType,
67
+ type Type,
68
+ SimpleFunctionExpression,
69
+ extractElementNameFromPath,
70
+ SUPPORTED_FUNCTIONS,
71
+ PackageableElementExplicitReference,
72
+ InstanceValue,
73
+ Multiplicity,
74
+ RuntimePointer,
65
75
  } from '@finos/legend-graph';
66
76
  import { buildLambdaFunction } from './QueryBuilderValueSpecificationBuilder.js';
67
77
  import type {
@@ -79,6 +89,8 @@ import { QUERY_BUILDER_COMMAND_KEY } from './QueryBuilderCommand.js';
79
89
  import { QueryBuilderWatermarkState } from './watermark/QueryBuilderWatermarkState.js';
80
90
  import { QueryBuilderConstantsState } from './QueryBuilderConstantsState.js';
81
91
  import { QueryBuilderCheckEntitlementsState } from './entitlements/QueryBuilderCheckEntitlementsState.js';
92
+ import { QueryBuilderTDSState } from './fetch-structure/tds/QueryBuilderTDSState.js';
93
+ import { QUERY_BUILDER_PURE_PATH } from '../graph/QueryBuilderMetaModelConst.js';
82
94
 
83
95
  export abstract class QueryBuilderState implements CommandRegistrar {
84
96
  readonly applicationStore: GenericLegendApplicationStore;
@@ -87,7 +99,6 @@ export abstract class QueryBuilderState implements CommandRegistrar {
87
99
  readonly changeDetectionState: QueryBuilderChangeDetectionState;
88
100
  readonly queryCompileState = ActionState.create();
89
101
  readonly observerContext: ObserverContext;
90
- readonly saveQueryProgressState = ActionState.create();
91
102
 
92
103
  explorerState: QueryBuilderExplorerState;
93
104
  functionsExplorerState: QueryFunctionsExplorerState;
@@ -162,7 +173,6 @@ export abstract class QueryBuilderState implements CommandRegistrar {
162
173
  changeMapping: action,
163
174
 
164
175
  rebuildWithQuery: action,
165
- saveQuery: action,
166
176
  compileQuery: flow,
167
177
  hashCode: computed,
168
178
  });
@@ -381,6 +391,59 @@ export abstract class QueryBuilderState implements CommandRegistrar {
381
391
  );
382
392
  }
383
393
 
394
+ buildFromQuery(): RawLambda {
395
+ assertTrue(
396
+ this.isQuerySupported,
397
+ 'Query must be supported to build from function',
398
+ );
399
+ const mapping = guaranteeNonNullable(
400
+ this.mapping,
401
+ 'Mapping required to build from() function',
402
+ );
403
+ const runtime = guaranteeNonNullable(
404
+ this.runtimeValue,
405
+ 'Runtime required to build from query',
406
+ );
407
+ const runtimePointer = guaranteeType(
408
+ runtime,
409
+ RuntimePointer,
410
+ ).packageableRuntime;
411
+ const lambdaFunc = buildLambdaFunction(this);
412
+ const currentExpression = guaranteeNonNullable(
413
+ lambdaFunc.expressionSequence[0],
414
+ );
415
+ const _func = new SimpleFunctionExpression(
416
+ extractElementNameFromPath(SUPPORTED_FUNCTIONS.FROM),
417
+ );
418
+
419
+ const mappingInstance = new InstanceValue(Multiplicity.ONE, undefined);
420
+ mappingInstance.values = [
421
+ PackageableElementExplicitReference.create(mapping),
422
+ ];
423
+ const runtimeInstance = new InstanceValue(Multiplicity.ONE, undefined);
424
+ runtimeInstance.values = [
425
+ PackageableElementExplicitReference.create(runtimePointer.value),
426
+ ];
427
+ _func.parametersValues = [
428
+ currentExpression,
429
+ mappingInstance,
430
+ runtimeInstance,
431
+ ];
432
+ lambdaFunc.expressionSequence = [_func];
433
+ return buildRawLambdaFromLambdaFunction(lambdaFunc, this.graphManagerState);
434
+ }
435
+
436
+ getQueryReturnType(): Type {
437
+ if (
438
+ this.fetchStructureState.implementation instanceof QueryBuilderTDSState
439
+ ) {
440
+ return this.graphManagerState.graph.getClass(
441
+ QUERY_BUILDER_PURE_PATH.TDS_TABULAR_DATASET,
442
+ );
443
+ }
444
+ return PrimitiveType.STRING;
445
+ }
446
+
384
447
  initializeWithQuery(query: RawLambda): void {
385
448
  this.rebuildWithQuery(query);
386
449
  this.resetQueryResult();
@@ -452,23 +515,6 @@ export abstract class QueryBuilderState implements CommandRegistrar {
452
515
  }
453
516
  }
454
517
 
455
- async saveQuery(
456
- onSaveQuery: (lambda: RawLambda) => Promise<void>,
457
- ): Promise<void> {
458
- this.saveQueryProgressState.inProgress();
459
- try {
460
- const query = this.buildQuery();
461
- await onSaveQuery(query);
462
- } catch (error) {
463
- assertErrorThrown(error);
464
- this.applicationStore.notificationService.notifyError(
465
- `Can't save query: ${error.message}`,
466
- );
467
- } finally {
468
- this.saveQueryProgressState.complete();
469
- }
470
- }
471
-
472
518
  *compileQuery(): GeneratorFn<void> {
473
519
  if (!this.textEditorState.mode) {
474
520
  this.queryCompileState.inProgress();
@@ -0,0 +1,46 @@
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 { LegendApplicationPlugin } from '@finos/legend-application';
18
+ import type { QueryBuilderState } from './QueryBuilderState.js';
19
+ import type { QuerySearchSpecification } from '@finos/legend-graph';
20
+ import type { DatasetAccessInfo } from './data-access/DataAccessState.js';
21
+
22
+ export type LoadQueryFilterOption = {
23
+ key: string;
24
+ label: (queryBuilderState: QueryBuilderState) => string | undefined;
25
+ filterFunction: (
26
+ searchSpecification: QuerySearchSpecification,
27
+ queryBuilderState: QueryBuilderState,
28
+ ) => QuerySearchSpecification;
29
+ };
30
+
31
+ export type DatasetEntitlementAccessReportActionConfiguration = {
32
+ renderer: (info: DatasetAccessInfo) => React.ReactNode;
33
+ };
34
+
35
+ export interface QueryBuilder_LegendApplicationPlugin_Extension
36
+ extends LegendApplicationPlugin {
37
+ /**
38
+ * Get the list of filter options for query loader.
39
+ */
40
+ getExtraLoadQueryFilterOptions?(): LoadQueryFilterOption[];
41
+
42
+ /**
43
+ * Get the list of dataset entitlement access report action configurations.
44
+ */
45
+ getExtraDatasetEntitlementAccessNotGrantedReportActionConfigurations?(): DatasetEntitlementAccessReportActionConfiguration[];
46
+ }
@@ -0,0 +1,298 @@
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
+ DEFAULT_TYPEAHEAD_SEARCH_MINIMUM_SEARCH_LENGTH,
19
+ type GenericLegendApplicationStore,
20
+ } from '@finos/legend-application';
21
+ import {
22
+ type LightQuery,
23
+ QuerySearchSpecification,
24
+ type QueryInfo,
25
+ type BasicGraphManagerState,
26
+ type Query,
27
+ } from '@finos/legend-graph';
28
+ import {
29
+ ActionState,
30
+ type GeneratorFn,
31
+ assertErrorThrown,
32
+ guaranteeNonNullable,
33
+ } from '@finos/legend-shared';
34
+ import { makeObservable, observable, action, flow } from 'mobx';
35
+ import type { QueryBuilderState } from './QueryBuilderState.js';
36
+ import type {
37
+ LoadQueryFilterOption,
38
+ QueryBuilder_LegendApplicationPlugin_Extension,
39
+ } from './QueryBuilder_LegendApplicationPlugin_Extension.js';
40
+
41
+ export const QUERY_LOADER_TYPEAHEAD_SEARCH_LIMIT = 20;
42
+
43
+ export class QueryLoaderState {
44
+ readonly applicationStore: GenericLegendApplicationStore;
45
+ readonly graphManagerState: BasicGraphManagerState;
46
+
47
+ readonly searchQueriesState = ActionState.create();
48
+ readonly renameQueryState = ActionState.create();
49
+ readonly deleteQueryState = ActionState.create();
50
+ readonly previewQueryState = ActionState.create();
51
+
52
+ readonly decorateSearchSpecification?:
53
+ | ((val: QuerySearchSpecification) => QuerySearchSpecification)
54
+ | undefined;
55
+
56
+ readonly loadQuery: (query: LightQuery) => void;
57
+ readonly fetchDefaultQueries?: (() => Promise<LightQuery[]>) | undefined;
58
+ readonly generateDefaultQueriesSummaryText?:
59
+ | ((queries: LightQuery[]) => string)
60
+ | undefined;
61
+
62
+ readonly isReadOnly?: boolean | undefined;
63
+ readonly onQueryRenamed?: ((query: LightQuery) => void) | undefined;
64
+ readonly onQueryDeleted?: ((query: LightQuery) => void) | undefined;
65
+
66
+ queryBuilderState?: QueryBuilderState | undefined;
67
+
68
+ searchText = '';
69
+ showCurrentUserQueriesOnly = false; // TODO: if we start having more native filters, we should make them part of `extraFilters`
70
+ extraFilters = new Map<string, boolean>();
71
+ extraFilterOptions: LoadQueryFilterOption[] = [];
72
+ queries: LightQuery[] = [];
73
+
74
+ isQueryLoaderDialogOpen = false;
75
+ showingDefaultQueries = true;
76
+ showPreviewViewer = false;
77
+ queryPreviewContent?: QueryInfo;
78
+
79
+ constructor(
80
+ applicationStore: GenericLegendApplicationStore,
81
+ graphManagerState: BasicGraphManagerState,
82
+ options: {
83
+ decorateSearchSpecification?:
84
+ | ((val: QuerySearchSpecification) => QuerySearchSpecification)
85
+ | undefined;
86
+
87
+ loadQuery: (query: LightQuery) => void;
88
+ fetchDefaultQueries?: (() => Promise<LightQuery[]>) | undefined;
89
+ generateDefaultQueriesSummaryText?:
90
+ | ((queries: LightQuery[]) => string)
91
+ | undefined;
92
+
93
+ isReadOnly?: boolean | undefined;
94
+ onQueryRenamed?: ((query: LightQuery) => void) | undefined;
95
+ onQueryDeleted?: ((query: LightQuery) => void) | undefined;
96
+ },
97
+ ) {
98
+ makeObservable(this, {
99
+ isQueryLoaderDialogOpen: observable,
100
+ queryPreviewContent: observable,
101
+ showingDefaultQueries: observable,
102
+ queries: observable,
103
+ showCurrentUserQueriesOnly: observable,
104
+ showPreviewViewer: observable,
105
+ searchText: observable,
106
+ setSearchText: action,
107
+ setQueryLoaderDialogOpen: action,
108
+ setQueries: action,
109
+ setShowCurrentUserQueriesOnly: action,
110
+ setShowPreviewViewer: action,
111
+ searchQueries: flow,
112
+ getPreviewQueryContent: flow,
113
+ deleteQuery: flow,
114
+ renameQuery: flow,
115
+ initialize: flow,
116
+ });
117
+
118
+ this.applicationStore = applicationStore;
119
+ this.graphManagerState = graphManagerState;
120
+
121
+ this.loadQuery = options.loadQuery;
122
+ this.fetchDefaultQueries = options.fetchDefaultQueries;
123
+ this.generateDefaultQueriesSummaryText =
124
+ options.generateDefaultQueriesSummaryText;
125
+ this.decorateSearchSpecification = options.decorateSearchSpecification;
126
+ this.isReadOnly = options.isReadOnly;
127
+ this.onQueryRenamed = options.onQueryRenamed;
128
+ this.onQueryDeleted = options.onQueryDeleted;
129
+ }
130
+
131
+ setSearchText(val: string): void {
132
+ this.searchText = val;
133
+ }
134
+
135
+ setQueryLoaderDialogOpen(val: boolean): void {
136
+ this.isQueryLoaderDialogOpen = val;
137
+ }
138
+
139
+ setQueries(val: LightQuery[]): void {
140
+ this.queries = val;
141
+ }
142
+
143
+ setShowPreviewViewer(val: boolean): void {
144
+ this.showPreviewViewer = val;
145
+ }
146
+
147
+ setShowCurrentUserQueriesOnly(val: boolean): void {
148
+ this.showCurrentUserQueriesOnly = val;
149
+ }
150
+
151
+ reset(): void {
152
+ this.setShowCurrentUserQueriesOnly(false);
153
+ }
154
+
155
+ *initialize(queryBuilderState: QueryBuilderState): GeneratorFn<void> {
156
+ this.queryBuilderState = queryBuilderState;
157
+ this.extraFilterOptions = this.applicationStore.pluginManager
158
+ .getApplicationPlugins()
159
+ .flatMap(
160
+ (plugin) =>
161
+ (
162
+ plugin as QueryBuilder_LegendApplicationPlugin_Extension
163
+ ).getExtraLoadQueryFilterOptions?.() ?? [],
164
+ );
165
+ const extraFilters = this.extraFilterOptions.map((filterOption) =>
166
+ filterOption.label(guaranteeNonNullable(this.queryBuilderState)),
167
+ );
168
+ extraFilters.forEach(
169
+ (filter) => filter && this.extraFilters.set(filter, false),
170
+ );
171
+ }
172
+
173
+ *searchQueries(searchText: string): GeneratorFn<void> {
174
+ if (
175
+ searchText.length < DEFAULT_TYPEAHEAD_SEARCH_MINIMUM_SEARCH_LENGTH &&
176
+ !this.showCurrentUserQueriesOnly &&
177
+ Array.from(this.extraFilters.values()).every((value) => value === false)
178
+ ) {
179
+ // if no search text is specified, use fetch the default queries
180
+ if (!searchText) {
181
+ this.showingDefaultQueries = true;
182
+ this.searchQueriesState.inProgress();
183
+ this.queries = [];
184
+ try {
185
+ if (!this.fetchDefaultQueries) {
186
+ return;
187
+ }
188
+ this.queries = (yield this.fetchDefaultQueries()) as LightQuery[];
189
+ this.searchQueriesState.pass();
190
+ } catch (error) {
191
+ this.searchQueriesState.fail();
192
+ assertErrorThrown(error);
193
+ this.applicationStore.notificationService.notifyError(error);
194
+ }
195
+ }
196
+
197
+ // skip otherwise
198
+ return;
199
+ }
200
+
201
+ // search using the search term
202
+ this.showingDefaultQueries = false;
203
+ this.searchQueriesState.inProgress();
204
+ try {
205
+ let searchSpecification = new QuerySearchSpecification();
206
+ searchSpecification.searchTerm = searchText;
207
+ searchSpecification.limit = QUERY_LOADER_TYPEAHEAD_SEARCH_LIMIT + 1;
208
+ searchSpecification.showCurrentUserQueriesOnly =
209
+ this.showCurrentUserQueriesOnly;
210
+ if (this.queryBuilderState) {
211
+ Array.from(this.extraFilters.entries()).forEach(([key, value]) => {
212
+ if (value) {
213
+ const filterOption = this.extraFilterOptions.find(
214
+ (option) =>
215
+ option.label(guaranteeNonNullable(this.queryBuilderState)) ===
216
+ key,
217
+ );
218
+ if (filterOption) {
219
+ searchSpecification = filterOption.filterFunction(
220
+ searchSpecification,
221
+ guaranteeNonNullable(this.queryBuilderState),
222
+ );
223
+ }
224
+ }
225
+ });
226
+ }
227
+ searchSpecification =
228
+ this.decorateSearchSpecification?.(searchSpecification) ??
229
+ searchSpecification;
230
+ this.queries = (yield this.graphManagerState.graphManager.searchQueries(
231
+ searchSpecification,
232
+ )) as LightQuery[];
233
+ this.searchQueriesState.pass();
234
+ } catch (error) {
235
+ assertErrorThrown(error);
236
+ this.applicationStore.notificationService.notifyError(error);
237
+ this.searchQueriesState.fail();
238
+ }
239
+ }
240
+
241
+ *renameQuery(queryId: string, name: string): GeneratorFn<void> {
242
+ this.renameQueryState.inProgress();
243
+ try {
244
+ const query = (yield this.graphManagerState.graphManager.renameQuery(
245
+ queryId,
246
+ name,
247
+ )) as Query;
248
+ this.onQueryRenamed?.(query);
249
+ this.applicationStore.notificationService.notify(
250
+ 'Renamed query successfully',
251
+ );
252
+ this.renameQueryState.pass();
253
+ this.searchQueries(this.searchText); // trigger a search to refresh the query list
254
+ } catch (error) {
255
+ assertErrorThrown(error);
256
+ this.applicationStore.notificationService.notifyError(error);
257
+ this.renameQueryState.fail();
258
+ }
259
+ }
260
+
261
+ *deleteQuery(queryId: string): GeneratorFn<void> {
262
+ this.deleteQueryState.inProgress();
263
+ try {
264
+ const query = (yield this.graphManagerState.graphManager.deleteQuery(
265
+ queryId,
266
+ )) as Query;
267
+ this.onQueryDeleted?.(query);
268
+ this.applicationStore.notificationService.notify(
269
+ 'Deleted query successfully',
270
+ );
271
+ this.deleteQueryState.pass();
272
+ this.searchQueries(this.searchText); // trigger a search to refresh the query list
273
+ } catch (error) {
274
+ assertErrorThrown(error);
275
+ this.applicationStore.notificationService.notifyError(error);
276
+ this.deleteQueryState.fail();
277
+ }
278
+ }
279
+
280
+ *getPreviewQueryContent(queryId: string): GeneratorFn<void> {
281
+ this.previewQueryState.inProgress();
282
+ try {
283
+ const queryInfo = (yield this.graphManagerState.graphManager.getQueryInfo(
284
+ queryId,
285
+ )) as QueryInfo;
286
+ this.queryPreviewContent = queryInfo;
287
+ this.queryPreviewContent.content =
288
+ (yield this.graphManagerState.graphManager.prettyLambdaContent(
289
+ queryInfo.content,
290
+ )) as string;
291
+ this.previewQueryState.pass();
292
+ } catch (error) {
293
+ assertErrorThrown(error);
294
+ this.applicationStore.notificationService.notifyError(error);
295
+ this.previewQueryState.fail();
296
+ }
297
+ }
298
+ }