@finos/legend-query-builder 4.14.21 → 4.14.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. package/lib/__lib__/QueryBuilderTesting.d.ts +1 -0
  2. package/lib/__lib__/QueryBuilderTesting.d.ts.map +1 -1
  3. package/lib/__lib__/QueryBuilderTesting.js +1 -0
  4. package/lib/__lib__/QueryBuilderTesting.js.map +1 -1
  5. package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.d.ts.map +1 -1
  6. package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.js +2 -1
  7. package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.js.map +1 -1
  8. package/lib/components/fetch-structure/QueryBuilderTDSPanel.d.ts.map +1 -1
  9. package/lib/components/fetch-structure/QueryBuilderTDSPanel.js +1 -1
  10. package/lib/components/fetch-structure/QueryBuilderTDSPanel.js.map +1 -1
  11. package/lib/components/fetch-structure/QueryBuilderTDSWindowPanel.d.ts.map +1 -1
  12. package/lib/components/fetch-structure/QueryBuilderTDSWindowPanel.js +132 -67
  13. package/lib/components/fetch-structure/QueryBuilderTDSWindowPanel.js.map +1 -1
  14. package/lib/components/result/QueryBuilderResultPanel.d.ts.map +1 -1
  15. package/lib/components/result/QueryBuilderResultPanel.js +1 -0
  16. package/lib/components/result/QueryBuilderResultPanel.js.map +1 -1
  17. package/lib/components/result/tds/QueryBuilderTDSGridResult.d.ts.map +1 -1
  18. package/lib/components/result/tds/QueryBuilderTDSGridResult.js +1 -0
  19. package/lib/components/result/tds/QueryBuilderTDSGridResult.js.map +1 -1
  20. package/lib/index.css +16 -0
  21. package/lib/package.json +1 -1
  22. package/lib/stores/QueryBuilderResultState.d.ts +2 -0
  23. package/lib/stores/QueryBuilderResultState.d.ts.map +1 -1
  24. package/lib/stores/QueryBuilderResultState.js +11 -4
  25. package/lib/stores/QueryBuilderResultState.js.map +1 -1
  26. package/lib/stores/QueryBuilderStateHashUtils.d.ts +1 -1
  27. package/lib/stores/QueryBuilderStateHashUtils.d.ts.map +1 -1
  28. package/lib/stores/QueryBuilderStateHashUtils.js +1 -1
  29. package/lib/stores/QueryBuilderStateHashUtils.js.map +1 -1
  30. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.d.ts.map +1 -1
  31. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js +6 -3
  32. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js.map +1 -1
  33. package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.d.ts +7 -2
  34. package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.d.ts.map +1 -1
  35. package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.js +46 -29
  36. package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.js.map +1 -1
  37. package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowValueSpecificationBuilder.js +1 -1
  38. package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowValueSpecificationBuilder.js.map +1 -1
  39. package/package.json +6 -6
  40. package/src/__lib__/QueryBuilderTesting.ts +1 -0
  41. package/src/components/fetch-structure/QueryBuilderFetchStructurePanel.tsx +2 -1
  42. package/src/components/fetch-structure/QueryBuilderTDSPanel.tsx +1 -0
  43. package/src/components/fetch-structure/QueryBuilderTDSWindowPanel.tsx +232 -140
  44. package/src/components/result/QueryBuilderResultPanel.tsx +1 -0
  45. package/src/components/result/tds/QueryBuilderTDSGridResult.tsx +1 -0
  46. package/src/stores/QueryBuilderResultState.ts +13 -4
  47. package/src/stores/QueryBuilderStateHashUtils.ts +1 -1
  48. package/src/stores/fetch-structure/tds/QueryBuilderTDSState.ts +16 -3
  49. package/src/stores/fetch-structure/tds/window/QueryBuilderWindowState.ts +70 -38
  50. package/src/stores/fetch-structure/tds/window/QueryBuilderWindowValueSpecificationBuilder.ts +1 -1
@@ -288,6 +288,7 @@ export const QueryBuilderResultPanel = observer(
288
288
  } else {
289
289
  queryBuilderState.resultState.setPreviewLimit(previewLimitValue);
290
290
  }
291
+ queryBuilderState.resultState.updatePreviewLimitInConfig();
291
292
  };
292
293
 
293
294
  const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (event) => {
@@ -241,6 +241,7 @@ export const QueryBuilderTDSGridResult = observer(
241
241
  columns: columnAPi.getColumnState(),
242
242
  isPivotModeEnabled: columnAPi.isPivotMode(),
243
243
  isLocalModeEnabled: true,
244
+ previewLimit: resultState.previewLimit,
244
245
  });
245
246
  };
246
247
 
@@ -82,6 +82,7 @@ type QueryBuilderDataGridConfig = {
82
82
  columns: DataGridColumnState[];
83
83
  isPivotModeEnabled: boolean | undefined;
84
84
  isLocalModeEnabled: boolean | undefined;
85
+ previewLimit?: number | undefined;
85
86
  };
86
87
 
87
88
  export class QueryBuilderResultState {
@@ -131,6 +132,7 @@ export class QueryBuilderResultState {
131
132
  setQueryRunPromise: action,
132
133
  setIsQueryUsageViewerOpened: action,
133
134
  handlePreConfiguredGridConfig: action,
135
+ updatePreviewLimitInConfig: action,
134
136
  exportData: flow,
135
137
  runQuery: flow,
136
138
  cancelQuery: flow,
@@ -191,21 +193,28 @@ export class QueryBuilderResultState {
191
193
  this.isQueryUsageViewerOpened = val;
192
194
  }
193
195
 
196
+ updatePreviewLimitInConfig(): void {
197
+ if (this.gridConfig) {
198
+ this.gridConfig.previewLimit = this.previewLimit;
199
+ }
200
+ }
201
+
194
202
  handlePreConfiguredGridConfig(config: QueryGridConfig): void {
195
203
  const newConfig = {
204
+ ...config,
196
205
  columns: config.columns as DataGridColumnState[],
197
- isPivotModeEnabled: Boolean(config.isPivotModeEnabled),
198
- isLocalModeEnabled: Boolean(config.isLocalModeEnabled),
199
206
  };
207
+ if (config.previewLimit) {
208
+ this.setPreviewLimit(config.previewLimit);
209
+ }
200
210
  this.setGridConfig(newConfig);
201
211
  }
202
212
 
203
213
  getQueryGridConfig(): QueryGridConfig | undefined {
204
214
  if (this.gridConfig) {
205
215
  return {
216
+ ...this.gridConfig,
206
217
  columns: this.gridConfig.columns as object[],
207
- isPivotModeEnabled: Boolean(this.gridConfig.isPivotModeEnabled),
208
- isLocalModeEnabled: Boolean(this.gridConfig.isLocalModeEnabled),
209
218
  };
210
219
  }
211
220
  return undefined;
@@ -71,7 +71,7 @@ export enum QUERY_BUILDER_STATE_HASH_STRUCTURE {
71
71
  // OLAPGroup state
72
72
  TDS_WINDOW_GROUPBY_STATE = 'TDS_WINDOW_STATE',
73
73
  TDS_WINDOW_GROUPBY_OPERATION_STATE = 'TDS_WINDOW_OPERATION_STATE',
74
- TDS_WINDOW_GROUPBY_AGG_OPERATION_STATE = 'TDS_WINDOW_AGG_OPERATION_STATE',
74
+ TDS_WINDOW_GROUPBY_AGG_OPERATOR_STATE = 'TDS_WINDOW_AGG_OPERATOR_STATE',
75
75
  TDS_WINDOW_COLUMN_STATE = 'TDS_WINDOW_COLUMN_STATE',
76
76
  TDS_WINDOW_COLUMN_SORTBY_STATE = 'TDS_WINDOW_COLUMN_SORTBY_STATE',
77
77
  TDS_WINDOW_OPERATOR_RANK = 'TDS_WINDOW_OPERATOR_RANK',
@@ -278,6 +278,7 @@ export class QueryBuilderTDSState
278
278
 
279
279
  get fetchStructureValidationIssues(): string[] {
280
280
  const validationIssues: string[] = [];
281
+
281
282
  const hasInValidCalendarAggregateColumns =
282
283
  this.aggregationState.columns.some(
283
284
  (column) =>
@@ -289,6 +290,7 @@ export class QueryBuilderTDSState
289
290
  'Query has calendar function with no date column specified',
290
291
  );
291
292
  }
293
+
292
294
  const hasDuplicatedProjectionColumns = this.projectionColumns.some(
293
295
  (column) =>
294
296
  this.projectionColumns.filter((c) => c.columnName === column.columnName)
@@ -296,12 +298,23 @@ export class QueryBuilderTDSState
296
298
  );
297
299
  if (hasDuplicatedProjectionColumns) {
298
300
  validationIssues.push('Query has duplicated projection columns');
299
- return validationIssues;
300
301
  }
301
- const hasNoProjectionColumns = this.projectionColumns.length === 0;
302
+
303
+ const hasDuplicatedProjectionWindowColumns = this.projectionColumns.some(
304
+ (column) =>
305
+ this.windowState.windowColumns.filter(
306
+ (c) => c.columnName === column.columnName,
307
+ ).length > 0,
308
+ );
309
+ if (hasDuplicatedProjectionWindowColumns) {
310
+ validationIssues.push('Query has duplicated projection/window columns');
311
+ }
312
+
313
+ const hasNoProjectionColumns =
314
+ this.projectionColumns.length === 0 &&
315
+ this.queryBuilderState.changeHistoryState.canUndo;
302
316
  if (hasNoProjectionColumns) {
303
317
  validationIssues.push('Query has no projection columns');
304
- return validationIssues;
305
318
  }
306
319
  return validationIssues;
307
320
  }
@@ -147,7 +147,7 @@ export class QueryBuilderTDS_WindowAggreationOperatorState extends QueryBuilderT
147
147
 
148
148
  override get hashCode(): string {
149
149
  return hashArray([
150
- QUERY_BUILDER_STATE_HASH_STRUCTURE.TDS_WINDOW_GROUPBY_AGG_OPERATION_STATE,
150
+ QUERY_BUILDER_STATE_HASH_STRUCTURE.TDS_WINDOW_GROUPBY_AGG_OPERATOR_STATE,
151
151
  this.lambdaParameterName,
152
152
  this.operator,
153
153
  this.columnState.columnName,
@@ -162,21 +162,21 @@ export class QueryBuilderWindowColumnState
162
162
  readonly windowState: QueryBuilderWindowState;
163
163
  windowColumns: QueryBuilderTDSColumnState[] = [];
164
164
  sortByState: WindowGroupByColumnSortByState | undefined;
165
- operationState: QueryBuilderTDS_WindowOperatorState;
165
+ operatorState: QueryBuilderTDS_WindowOperatorState;
166
166
  columnName: string;
167
167
 
168
168
  constructor(
169
169
  windowState: QueryBuilderWindowState,
170
170
  windowColumns: QueryBuilderTDSColumnState[],
171
171
  sortType: WindowGroupByColumnSortByState | undefined,
172
- operationState: QueryBuilderTDS_WindowOperatorState,
172
+ operatorState: QueryBuilderTDS_WindowOperatorState,
173
173
  columnName: string,
174
174
  ) {
175
175
  super();
176
176
  makeObservable(this, {
177
177
  windowColumns: observable,
178
178
  sortByState: observable,
179
- operationState: observable,
179
+ operatorState: observable,
180
180
  columnName: observable,
181
181
  setOperatorState: observable,
182
182
  setColumnName: action,
@@ -184,13 +184,14 @@ export class QueryBuilderWindowColumnState
184
184
  changeWindow: action,
185
185
  deleteWindow: action,
186
186
  addWindow: action,
187
+ setWindows: action,
187
188
  changeOperator: action,
188
189
  changeSortBy: action,
189
190
  });
190
191
  this.windowState = windowState;
191
192
  this.windowColumns = windowColumns;
192
193
  this.sortByState = sortType;
193
- this.operationState = operationState;
194
+ this.operatorState = operatorState;
194
195
  this.columnName = columnName;
195
196
  }
196
197
 
@@ -211,9 +212,9 @@ export class QueryBuilderWindowColumnState
211
212
 
212
213
  get referencedTDSColumns(): QueryBuilderTDSColumnState[] {
213
214
  const operatorReference =
214
- this.operationState instanceof
215
+ this.operatorState instanceof
215
216
  QueryBuilderTDS_WindowAggreationOperatorState
216
- ? [this.operationState.columnState]
217
+ ? [this.operatorState.columnState]
217
218
  : [];
218
219
  const soryByReference = this.sortByState
219
220
  ? [this.sortByState.columnState]
@@ -222,7 +223,7 @@ export class QueryBuilderWindowColumnState
222
223
  }
223
224
 
224
225
  getColumnType(): Type | undefined {
225
- return this.operationState.operator.getOperatorReturnType(
226
+ return this.operatorState.operator.getOperatorReturnType(
226
227
  this.windowState.tdsState.queryBuilderState.graphManagerState.graph,
227
228
  );
228
229
  }
@@ -232,7 +233,7 @@ export class QueryBuilderWindowColumnState
232
233
  }
233
234
 
234
235
  setOperatorState(op: QueryBuilderTDS_WindowOperatorState): void {
235
- this.operationState = op;
236
+ this.operatorState = op;
236
237
  }
237
238
 
238
239
  setSortBy(val: WindowGroupByColumnSortByState | undefined): void {
@@ -247,6 +248,10 @@ export class QueryBuilderWindowColumnState
247
248
  addUniqueEntry(this.windowColumns, val);
248
249
  }
249
250
 
251
+ setWindows(val: QueryBuilderTDSColumnState[]): void {
252
+ this.windowColumns = val;
253
+ }
254
+
250
255
  deleteWindow(val: QueryBuilderTDSColumnState): void {
251
256
  deleteEntry(this.windowColumns, val);
252
257
  }
@@ -262,42 +267,58 @@ export class QueryBuilderWindowColumnState
262
267
  return [];
263
268
  }
264
269
 
265
- changeOperator(windowOp: QueryBuilderTDS_WindowOperator): void {
266
- const currentOperator = this.operationState.operator;
267
- const currentAggregateColumn =
268
- this.operationState instanceof
269
- QueryBuilderTDS_WindowAggreationOperatorState
270
- ? this.operationState.columnState
271
- : undefined;
272
- if (currentOperator !== windowOp) {
273
- if (windowOp.isColumnAggregator()) {
270
+ getChangeOperatorStateAndColumnName(
271
+ currentOperator: QueryBuilderTDS_WindowOperator,
272
+ currentColumn: QueryBuilderTDSColumnState | undefined,
273
+ newOperator: QueryBuilderTDS_WindowOperator,
274
+ ):
275
+ | { operatorState: QueryBuilderTDS_WindowOperatorState; columnName: string }
276
+ | undefined {
277
+ if (currentOperator !== newOperator) {
278
+ if (newOperator.isColumnAggregator()) {
274
279
  const compatibleAggCol =
275
- currentAggregateColumn &&
276
- windowOp.isCompatibleWithColumn(currentAggregateColumn)
277
- ? currentAggregateColumn
278
- : this.possibleAggregatedColumns(windowOp)[0];
280
+ currentColumn && newOperator.isCompatibleWithColumn(currentColumn)
281
+ ? currentColumn
282
+ : this.possibleAggregatedColumns(newOperator)[0];
279
283
  if (compatibleAggCol) {
280
- this.setOperatorState(
281
- new QueryBuilderTDS_WindowAggreationOperatorState(
284
+ return {
285
+ operatorState: new QueryBuilderTDS_WindowAggreationOperatorState(
282
286
  this.windowState,
283
- windowOp,
287
+ newOperator,
284
288
  compatibleAggCol,
285
289
  ),
286
- );
287
- this.setColumnName(
288
- `${windowOp.getLabel()} of ${compatibleAggCol.columnName}`,
289
- );
290
+ columnName: `${newOperator.getLabel()} of ${
291
+ compatibleAggCol.columnName
292
+ }`,
293
+ };
290
294
  }
291
295
  } else {
292
- this.setOperatorState(
293
- new QueryBuilderTDS_WindowRankOperatorState(
296
+ return {
297
+ operatorState: new QueryBuilderTDS_WindowRankOperatorState(
294
298
  this.windowState,
295
- windowOp,
299
+ newOperator,
296
300
  ),
297
- );
298
- this.setColumnName(`${windowOp.getLabel()}`);
301
+ columnName: `${newOperator.getLabel()}`,
302
+ };
299
303
  }
300
304
  }
305
+ return undefined;
306
+ }
307
+
308
+ changeOperator(windowOp: QueryBuilderTDS_WindowOperator): void {
309
+ const stateAndName = this.getChangeOperatorStateAndColumnName(
310
+ this.operatorState.operator,
311
+ this.operatorState instanceof
312
+ QueryBuilderTDS_WindowAggreationOperatorState
313
+ ? this.operatorState.columnState
314
+ : undefined,
315
+ windowOp,
316
+ );
317
+
318
+ if (stateAndName) {
319
+ this.setOperatorState(stateAndName.operatorState);
320
+ this.setColumnName(stateAndName.columnName);
321
+ }
301
322
  }
302
323
 
303
324
  changeSortBy(sortOp: COLUMN_SORT_TYPE | undefined): void {
@@ -323,7 +344,7 @@ export class QueryBuilderWindowColumnState
323
344
  QUERY_BUILDER_STATE_HASH_STRUCTURE.TDS_WINDOW_COLUMN_STATE,
324
345
  hashArray(this.windowColumns),
325
346
  this.sortByState ?? '',
326
- this.operationState,
347
+ this.operatorState,
327
348
  this.columnName,
328
349
  ]);
329
350
  }
@@ -362,14 +383,14 @@ export class QueryBuilderWindowState implements Hashable {
362
383
  const windowCols = this.windowColumns;
363
384
  windowCols.forEach((item, index) => {
364
385
  if (
365
- item.operationState instanceof
386
+ item.operatorState instanceof
366
387
  QueryBuilderTDS_WindowAggreationOperatorState
367
388
  ) {
368
389
  if (
369
- item.operationState.columnState instanceof
390
+ item.operatorState.columnState instanceof
370
391
  QueryBuilderWindowColumnState
371
392
  ) {
372
- const windowColumnName = item.operationState.columnState.columnName;
393
+ const windowColumnName = item.operatorState.columnState.columnName;
373
394
  const hasExistingColumn = item.windowState.isColumnOrderValid(
374
395
  windowColumnName,
375
396
  index,
@@ -403,6 +424,17 @@ export class QueryBuilderWindowState implements Hashable {
403
424
  if (hasDuplicatedWindowColumns) {
404
425
  issues.push(`Query has duplicated window columns`);
405
426
  }
427
+
428
+ const hasDuplicatedProjectionWindowColumns = this.windowColumns.some(
429
+ (column) =>
430
+ this.tdsState.projectionColumns.filter(
431
+ (c) => c.columnName === column.columnName,
432
+ ).length > 0,
433
+ );
434
+ if (hasDuplicatedProjectionWindowColumns) {
435
+ issues.push('Query has duplicated projection/window columns');
436
+ }
437
+
406
438
  return issues;
407
439
  }
408
440
 
@@ -77,7 +77,7 @@ const appendOLAPGroupByColumnState = (
77
77
  }
78
78
 
79
79
  // create olap operation expression
80
- const operationState = olapGroupByColumnState.operationState;
80
+ const operationState = olapGroupByColumnState.operatorState;
81
81
  const olapFunc = extractElementNameFromPath(operationState.operator.pureFunc);
82
82
  const olapFuncExpression = new SimpleFunctionExpression(olapFunc);
83
83
  olapFuncExpression.parametersValues = [