@finos/legend-query-builder 4.17.81 → 4.17.84

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.
@@ -0,0 +1,235 @@
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
+ type GraphManagerState,
19
+ type Class,
20
+ DataProduct,
21
+ type V1_DataProductArtifact,
22
+ ModelAccessPointGroup,
23
+ type NativeModelExecutionContext,
24
+ CORE_PURE_PATH,
25
+ type NativeModelAccess,
26
+ resolveUsableDataProductClasses,
27
+ } from '@finos/legend-graph';
28
+ import { QueryBuilderState } from '../../QueryBuilderState.js';
29
+ import { type GenericLegendApplicationStore } from '@finos/legend-application';
30
+ import type {
31
+ QueryBuilderActionConfig,
32
+ QueryBuilderWorkflowState,
33
+ } from '../../query-workflow/QueryBuilderWorkFlowState.js';
34
+ import type { QueryBuilderConfig } from '../../../graph-manager/QueryBuilderConfig.js';
35
+ import { renderDataProductQueryBuilderSetupPanelContent } from '../../../components/workflows/DataProductQueryBuilder.js';
36
+ import {
37
+ ActionState,
38
+ filterByType,
39
+ type GeneratorFn,
40
+ } from '@finos/legend-shared';
41
+ import { action, computed, flow, makeObservable, observable } from 'mobx';
42
+ import {
43
+ DepotEntityWithOrigin,
44
+ type QueryableSourceInfo,
45
+ } from '@finos/legend-storage';
46
+ import { compareLabelFn } from '@finos/legend-art';
47
+
48
+ export type DataProductOption = {
49
+ label: string;
50
+ value: DepotEntityWithOrigin;
51
+ };
52
+
53
+ export const buildDataProductOption = (
54
+ value: DepotEntityWithOrigin,
55
+ ): DataProductOption => ({
56
+ label: value.name,
57
+ value,
58
+ });
59
+
60
+ export const buildExecOptions = (
61
+ val: NativeModelExecutionContext,
62
+ ): {
63
+ label: string;
64
+ value: NativeModelExecutionContext;
65
+ } => {
66
+ return {
67
+ label: val.key,
68
+ value: val,
69
+ };
70
+ };
71
+
72
+ export class DataProductQueryBuilderState extends QueryBuilderState {
73
+ readonly onClassChange?: ((val: Class) => void) | undefined;
74
+ readonly onDataProductChange?: (val: DepotEntityWithOrigin) => Promise<void>;
75
+ readonly onExecutionContextChange?:
76
+ | ((val: NativeModelExecutionContext) => void)
77
+ | undefined;
78
+
79
+ loadDataProductModelState = ActionState.create();
80
+ nativeModelAccess: NativeModelAccess;
81
+ dataProduct: DataProduct;
82
+ dataProductArtifact: V1_DataProductArtifact | undefined;
83
+ selectedExecContext: NativeModelExecutionContext;
84
+ entities: DepotEntityWithOrigin[] | undefined;
85
+
86
+ prioritizeEntityFunc?: ((val: DepotEntityWithOrigin) => boolean) | undefined;
87
+
88
+ override TEMPORARY__setupPanelContentRenderer = (): React.ReactNode =>
89
+ renderDataProductQueryBuilderSetupPanelContent(this);
90
+
91
+ constructor(
92
+ applicationStore: GenericLegendApplicationStore,
93
+ graphManagerState: GraphManagerState,
94
+ workflow: QueryBuilderWorkflowState,
95
+ dataProduct: DataProduct,
96
+ artifact: V1_DataProductArtifact | undefined,
97
+ actionConfig: QueryBuilderActionConfig,
98
+ nativeNativeModelAccess: NativeModelAccess,
99
+ nativeModelExecContext: NativeModelExecutionContext,
100
+ prioritizeEntityFunc: ((val: DepotEntityWithOrigin) => boolean) | undefined,
101
+ onDataProductChange: (val: DepotEntityWithOrigin) => Promise<void>,
102
+ onExecutionContextChange?:
103
+ | ((val: NativeModelExecutionContext) => void)
104
+ | undefined,
105
+ onClassChange?: ((val: Class) => void) | undefined,
106
+ config?: QueryBuilderConfig | undefined,
107
+ sourceInfo?: QueryableSourceInfo | undefined,
108
+ ) {
109
+ super(applicationStore, graphManagerState, workflow, config, sourceInfo);
110
+ makeObservable(this, {
111
+ selectedExecContext: observable,
112
+ dataProduct: observable,
113
+ setExecOptions: action,
114
+ selectedDataProductOption: computed,
115
+ isProductLinkable: computed,
116
+ loadEntities: flow,
117
+ entities: observable,
118
+ });
119
+ this.workflowState.updateActionConfig(actionConfig);
120
+ this.dataProduct = dataProduct;
121
+ this.dataProductArtifact = artifact;
122
+ this.nativeModelAccess = nativeNativeModelAccess;
123
+ this.selectedExecContext = nativeModelExecContext;
124
+ this.prioritizeEntityFunc = prioritizeEntityFunc;
125
+ this.onDataProductChange = onDataProductChange;
126
+ this.onExecutionContextChange = onExecutionContextChange;
127
+ this.onClassChange = onClassChange;
128
+ }
129
+
130
+ get isProductLinkable(): boolean {
131
+ return false;
132
+ }
133
+
134
+ copyDataProductLinkToClipBoard(): void {
135
+ if (!this.isProductLinkable) {
136
+ this.applicationStore.notificationService.notifyError(
137
+ 'Data Product link is not available.',
138
+ );
139
+ }
140
+ }
141
+
142
+ protected getElementType(): typeof DataProduct {
143
+ return DataProduct;
144
+ }
145
+
146
+ setExecOptions(exec: NativeModelExecutionContext): void {
147
+ this.selectedExecContext = exec;
148
+ }
149
+
150
+ *loadEntities(): GeneratorFn<void> {
151
+ this.loadDataProductModelState.inProgress();
152
+ this.entities = this.graphManagerState.graph.allOwnElements
153
+ .filter(filterByType(this.getElementType()))
154
+ .map((element) => this.transformElement(element));
155
+ this.loadDataProductModelState.complete();
156
+ }
157
+
158
+ protected transformElement(element: DataProduct): DepotEntityWithOrigin {
159
+ return new DepotEntityWithOrigin(
160
+ undefined,
161
+ element.name,
162
+ element.path,
163
+ CORE_PURE_PATH.DATA_PRODUCT,
164
+ );
165
+ }
166
+
167
+ get dataProductOptions(): DataProductOption[] {
168
+ const sortedAllOptions = (this.entities ?? [])
169
+ .map(buildDataProductOption)
170
+ .sort(compareLabelFn);
171
+
172
+ return this.prioritizeEntityFunc
173
+ ? [
174
+ ...sortedAllOptions.filter((val) =>
175
+ this.prioritizeEntityFunc?.(val.value),
176
+ ),
177
+ ...sortedAllOptions.filter(
178
+ (val) => !this.prioritizeEntityFunc?.(val.value),
179
+ ),
180
+ ]
181
+ : sortedAllOptions;
182
+ }
183
+
184
+ get selectedDataProductOption(): DataProductOption {
185
+ return {
186
+ label: this.dataProduct.title ?? this.dataProduct.name,
187
+ value: new DepotEntityWithOrigin(
188
+ undefined,
189
+ this.dataProduct.name,
190
+ this.dataProduct.path,
191
+ CORE_PURE_PATH.DATA_PRODUCT,
192
+ ),
193
+ };
194
+ }
195
+
196
+ get isSupported(): boolean {
197
+ return (
198
+ this.dataProduct.nativeModelAccess !== undefined ||
199
+ // contains model access point group
200
+ this.dataProduct.accessPointGroups.filter(
201
+ filterByType(ModelAccessPointGroup),
202
+ ).length > 0
203
+ );
204
+ }
205
+
206
+ // includes model access point group if more than one group
207
+ get execOptions(): { label: string; value: NativeModelExecutionContext }[] {
208
+ return (
209
+ this.dataProduct.nativeModelAccess?.nativeModelExecutionContexts.map(
210
+ buildExecOptions,
211
+ ) ?? []
212
+ ).sort(compareLabelFn);
213
+ }
214
+
215
+ override async propagateExecutionContextChange(
216
+ requireReBuildingGraph?: boolean | undefined,
217
+ ): Promise<void> {
218
+ const currentMapping = this.executionContextState.mapping;
219
+ const execMapping = this.selectedExecContext.mapping.value;
220
+ if (execMapping !== currentMapping) {
221
+ this.changeMapping(execMapping, {
222
+ keepQueryContent: true,
223
+ });
224
+ const classes = resolveUsableDataProductClasses(
225
+ this.nativeModelAccess.featuredElements,
226
+ this.selectedExecContext.mapping.value,
227
+ this.graphManagerState,
228
+ undefined,
229
+ );
230
+ if (this.class && !classes.includes(this.class)) {
231
+ this.setClass(classes[0]);
232
+ }
233
+ }
234
+ }
235
+ }
package/tsconfig.json CHANGED
@@ -219,6 +219,7 @@
219
219
  "./src/stores/workflows/FunctionQueryBuilderState.ts",
220
220
  "./src/stores/workflows/MappingQueryBuilderState.ts",
221
221
  "./src/stores/workflows/ServiceQueryBuilderState.ts",
222
+ "./src/stores/workflows/dataProduct/DataProductQueryBuilderState.ts",
222
223
  "./src/components/QueryBuilder.tsx",
223
224
  "./src/components/QueryBuilderConstantExpressionPanel.tsx",
224
225
  "./src/components/QueryBuilderDiffPanel.tsx",
@@ -282,6 +283,7 @@
282
283
  "./src/components/shared/QueryBuilderVariableSelector.tsx",
283
284
  "./src/components/shared/V1_BasicValueSpecificationEditor.tsx",
284
285
  "./src/components/workflows/ClassQueryBuilder.tsx",
286
+ "./src/components/workflows/DataProductQueryBuilder.tsx",
285
287
  "./src/components/workflows/MappingQueryBuilder.tsx",
286
288
  "./src/components/workflows/ServiceQueryBuilder.tsx"
287
289
  ],