@finos/legend-query-builder 4.11.5 → 4.11.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,10 +14,187 @@ import { jsx as _jsx } from "react/jsx-runtime";
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { clsx } from '@finos/legend-art';
17
+ import { ContextMenu, clsx } from '@finos/legend-art';
18
18
  import { observer } from 'mobx-react-lite';
19
+ import { getTDSRowRankByColumnInAsc, TDSExecutionResult, } from '@finos/legend-graph';
19
20
  import { DataGrid, } from '@finos/legend-lego/data-grid';
20
- import { getRowDataFromExecutionResult, QueryResultCellRenderer, } from './QueryBuilderTDSResultShared.js';
21
+ import { getRowDataFromExecutionResult, QueryBuilderGridResultContextMenu, } from './QueryBuilderTDSResultShared.js';
22
+ import { QueryBuilderTDSState } from '../../../stores/fetch-structure/tds/QueryBuilderTDSState.js';
23
+ import { DEFAULT_LOCALE } from '../../../graph-manager/QueryBuilderConst.js';
24
+ import { isNumber, isString, isValidURL } from '@finos/legend-shared';
25
+ const QueryResultCellRenderer = observer((params) => {
26
+ const resultState = params.resultState;
27
+ const tdsExecutionResult = params.tdsExecutionResult;
28
+ const fetchStructureImplementation = resultState.queryBuilderState.fetchStructureState.implementation;
29
+ const applicationStore = resultState.queryBuilderState.applicationStore;
30
+ const cellValue = params.value;
31
+ const formattedCellValue = () => {
32
+ if (isNumber(cellValue)) {
33
+ return Intl.NumberFormat(DEFAULT_LOCALE, {
34
+ maximumFractionDigits: 4,
35
+ }).format(Number(cellValue));
36
+ }
37
+ return cellValue;
38
+ };
39
+ const cellValueUrlLink = isString(cellValue) && isValidURL(cellValue) ? cellValue : undefined;
40
+ const columnName = params.column?.getColId() ?? '';
41
+ const findCoordinatesFromResultValue = (colId, rowNumber) => {
42
+ const colIndex = tdsExecutionResult.result.columns.findIndex((col) => col === colId);
43
+ return { rowIndex: rowNumber, colIndex: colIndex };
44
+ };
45
+ const currentCellCoordinates = findCoordinatesFromResultValue(columnName, params.rowIndex);
46
+ const cellInFilteredResults = resultState.selectedCells.some((result) => result.coordinates.colIndex === currentCellCoordinates.colIndex &&
47
+ result.coordinates.rowIndex === currentCellCoordinates.rowIndex);
48
+ const findColumnFromCoordinates = (colIndex) => {
49
+ if (!resultState.executionResult ||
50
+ !(resultState.executionResult instanceof TDSExecutionResult)) {
51
+ return undefined;
52
+ }
53
+ return resultState.executionResult.result.columns[colIndex];
54
+ };
55
+ const findResultValueFromCoordinates = (resultCoordinate) => {
56
+ const rowIndex = resultCoordinate[0];
57
+ const colIndex = resultCoordinate[1];
58
+ if (!resultState.executionResult ||
59
+ !(resultState.executionResult instanceof TDSExecutionResult)) {
60
+ return undefined;
61
+ }
62
+ if (params.columnApi.getColumnState()[colIndex]?.sort === 'asc') {
63
+ resultState.executionResult.result.rows.sort((a, b) => getTDSRowRankByColumnInAsc(a, b, colIndex));
64
+ }
65
+ else if (params.columnApi.getColumnState()[colIndex]?.sort === 'desc') {
66
+ resultState.executionResult.result.rows.sort((a, b) => getTDSRowRankByColumnInAsc(b, a, colIndex));
67
+ }
68
+ return resultState.executionResult.result.rows[rowIndex]?.values[colIndex];
69
+ };
70
+ const isCoordinatesSelected = (resultCoordinate) => resultState.selectedCells.some((cell) => cell.coordinates.rowIndex === resultCoordinate.rowIndex &&
71
+ cell.coordinates.colIndex === resultCoordinate.colIndex);
72
+ const mouseDown = (event) => {
73
+ event.preventDefault();
74
+ if (event.shiftKey) {
75
+ const coordinates = findCoordinatesFromResultValue(columnName, params.rowIndex);
76
+ const actualValue = findResultValueFromCoordinates([
77
+ coordinates.rowIndex,
78
+ coordinates.colIndex,
79
+ ]);
80
+ resultState.addSelectedCell({
81
+ value: actualValue,
82
+ columnName: columnName,
83
+ coordinates: coordinates,
84
+ });
85
+ return;
86
+ }
87
+ if (event.button === 0) {
88
+ resultState.setIsSelectingCells(true);
89
+ resultState.setSelectedCells([]);
90
+ const coordinates = findCoordinatesFromResultValue(columnName, params.rowIndex);
91
+ const actualValue = findResultValueFromCoordinates([
92
+ coordinates.rowIndex,
93
+ coordinates.colIndex,
94
+ ]);
95
+ resultState.setSelectedCells([
96
+ {
97
+ value: actualValue,
98
+ columnName: columnName,
99
+ coordinates: coordinates,
100
+ },
101
+ ]);
102
+ resultState.setMouseOverCell(resultState.selectedCells[0] ?? null);
103
+ }
104
+ if (event.button === 2) {
105
+ const coordinates = findCoordinatesFromResultValue(columnName, params.rowIndex);
106
+ const isInSelected = isCoordinatesSelected(coordinates);
107
+ if (!isInSelected) {
108
+ const actualValue = findResultValueFromCoordinates([
109
+ coordinates.rowIndex,
110
+ coordinates.colIndex,
111
+ ]);
112
+ resultState.setSelectedCells([
113
+ {
114
+ value: actualValue,
115
+ columnName: columnName,
116
+ coordinates: coordinates,
117
+ },
118
+ ]);
119
+ resultState.setMouseOverCell(resultState.selectedCells[0] ?? null);
120
+ }
121
+ }
122
+ };
123
+ const mouseUp = (event) => {
124
+ resultState.setIsSelectingCells(false);
125
+ };
126
+ const mouseOver = (event) => {
127
+ if (resultState.isSelectingCells) {
128
+ if (resultState.selectedCells.length < 1) {
129
+ return;
130
+ }
131
+ const results = resultState.selectedCells[0];
132
+ if (!results) {
133
+ return;
134
+ }
135
+ const firstCorner = results.coordinates;
136
+ const secondCorner = findCoordinatesFromResultValue(columnName, params.rowIndex);
137
+ resultState.setSelectedCells([results]);
138
+ const minRow = Math.min(firstCorner.rowIndex, secondCorner.rowIndex);
139
+ const minCol = Math.min(firstCorner.colIndex, secondCorner.colIndex);
140
+ const maxRow = Math.max(firstCorner.rowIndex, secondCorner.rowIndex);
141
+ const maxCol = Math.max(firstCorner.colIndex, secondCorner.colIndex);
142
+ for (let x = minRow; x <= maxRow; x++) {
143
+ for (let y = minCol; y <= maxCol; y++) {
144
+ const actualValue = findResultValueFromCoordinates([x, y]);
145
+ const valueAndColumnId = {
146
+ value: actualValue,
147
+ columnName: findColumnFromCoordinates(y),
148
+ coordinates: {
149
+ rowIndex: x,
150
+ colIndex: y,
151
+ },
152
+ };
153
+ if (!resultState.selectedCells.find((result) => result.coordinates.colIndex === y &&
154
+ result.coordinates.rowIndex === x)) {
155
+ resultState.addSelectedCell(valueAndColumnId);
156
+ }
157
+ }
158
+ }
159
+ }
160
+ resultState.setMouseOverCell(resultState.selectedCells[0] ?? null);
161
+ };
162
+ const getContextMenuRenderer = () => {
163
+ if (fetchStructureImplementation instanceof QueryBuilderTDSState) {
164
+ const copyCellValue = applicationStore.guardUnhandledError(() => applicationStore.clipboardService.copyTextToClipboard(fetchStructureImplementation.queryBuilderState.resultState.selectedCells
165
+ .map((cellData) => cellData.value)
166
+ .join(',')));
167
+ const findRowFromRowIndex = (rowIndex) => {
168
+ if (!fetchStructureImplementation.queryBuilderState.resultState
169
+ .executionResult ||
170
+ !(fetchStructureImplementation.queryBuilderState.resultState
171
+ .executionResult instanceof TDSExecutionResult)) {
172
+ return '';
173
+ }
174
+ // try to get the entire row value separated by comma
175
+ // rowData is in format of {columnName: value, columnName1: value, ...., rowNumber:value}
176
+ const valueArr = [];
177
+ Object.entries(params.api.getRenderedNodes().find((n) => n.rowIndex === rowIndex)
178
+ ?.data).forEach((entry) => {
179
+ if (entry[0] !== 'rowNumber') {
180
+ valueArr.push(entry[1]);
181
+ }
182
+ });
183
+ return valueArr.join(',');
184
+ };
185
+ const copyRowValue = applicationStore.guardUnhandledError(() => applicationStore.clipboardService.copyTextToClipboard(findRowFromRowIndex(fetchStructureImplementation.queryBuilderState.resultState
186
+ .selectedCells[0]?.coordinates.rowIndex ?? 0)));
187
+ return (_jsx(QueryBuilderGridResultContextMenu, { data: resultState.mousedOverCell, tdsState: fetchStructureImplementation, copyCellValueFunc: copyCellValue, copyCellRowValueFunc: copyRowValue }));
188
+ }
189
+ return null;
190
+ };
191
+ return (_jsx(ContextMenu, { content: getContextMenuRenderer(), disabled: !(resultState.queryBuilderState.fetchStructureState
192
+ .implementation instanceof QueryBuilderTDSState) ||
193
+ !resultState.queryBuilderState.isQuerySupported ||
194
+ !resultState.mousedOverCell, menuProps: { elevation: 7 }, className: clsx('ag-theme-balham-dark query-builder__result__tds-grid'), children: _jsx("div", { className: clsx('query-builder__result__values__table__cell', {
195
+ 'query-builder__result__values__table__cell--active': cellInFilteredResults,
196
+ }), onMouseDown: (event) => mouseDown(event), onMouseUp: (event) => mouseUp(event), onMouseOver: (event) => mouseOver(event), children: cellValueUrlLink ? (_jsx("a", { href: cellValueUrlLink, target: "_blank", rel: "noreferrer", children: cellValueUrlLink })) : (_jsx("span", { children: formattedCellValue() })) }) }));
197
+ });
21
198
  export const QueryBuilderTDSSimpleGridResult = observer((props) => {
22
199
  const { executionResult, queryBuilderState } = props;
23
200
  const resultState = queryBuilderState.resultState;
@@ -1 +1 @@
1
- {"version":3,"file":"QueryBuilderTDSSimpleGridResult.js","sourceRoot":"","sources":["../../../../src/components/result/tds/QueryBuilderTDSSimpleGridResult.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EACL,QAAQ,GAET,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAE1C,MAAM,CAAC,MAAM,+BAA+B,GAAG,QAAQ,CACrD,CAAC,KAGA,EAAE,EAAE;IACH,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,GAAG,KAAK,CAAC;IACrD,MAAM,WAAW,GAAG,iBAAiB,CAAC,WAAW,CAAC;IAClD,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAChD,CAAC,OAAO,EAAE,EAAE,CACV,CAAC;QACC,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,CAAC;QACP,YAAY,EAAE,uBAAuB;QACrC,kBAAkB,EAAE;YAClB,WAAW,EAAE,WAAW;YACxB,kBAAkB,EAAE,eAAe;SACpC;KACF,CAA6B,CACjC,CAAC;IAEF,OAAO,CACL,cAAK,SAAS,EAAC,sCAAsC,YACnD,cACE,SAAS,EAAE,IAAI,CACb,sDAAsD,CACvD,YAED,KAAC,QAAQ,IACP,OAAO,EAAE,6BAA6B,CAAC,eAAe,CAAC,EACvD,WAAW,EAAE;oBACX,uBAAuB,EAAE,IAAI;oBAC7B,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS;oBACvC,YAAY,EAAE,UAAU;iBACzB;gBACD,oHAAoH;gBACpH,oIAAoI;gBACpI,gBAAgB,EAAE,CAAC,MAAM,EAAE,EAAE;oBAC3B,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC3C,CAAC,EACD,wBAAwB,EAAE,IAAI,EAC9B,mBAAmB,EAAE,KAAK,EAC1B,UAAU,EAAE,OAAO,GACnB,GACE,GACF,CACP,CAAC;AACJ,CAAC,CACF,CAAC"}
1
+ {"version":3,"file":"QueryBuilderTDSSimpleGridResult.js","sourceRoot":"","sources":["../../../../src/components/result/tds/QueryBuilderTDSSimpleGridResult.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,QAAQ,GAET,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,6BAA6B,EAC7B,iCAAiC,GAElC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAC;AACnG,OAAO,EAAE,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H;gBACpH,oIAAoI;gBACpI,gBAAgB,EAAE,CAAC,MAAM,EAAE,EAAE;oBAC3B,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC3C,CAAC,EACD,wBAAwB,EAAE,IAAI,EAC9B,mBAAmB,EAAE,KAAK,EAC1B,UAAU,EAAE,OAAO,GACnB,GACE,GACF,CACP,CAAC;AACJ,CAAC,CACF,CAAC"}
package/lib/index.css CHANGED
@@ -1,4 +1,4 @@
1
- /** @license @finos/legend-query-builder v4.11.5
1
+ /** @license @finos/legend-query-builder v4.11.6
2
2
  * Copyright (c) 2020-present, Goldman Sachs
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finos/legend-query-builder",
3
- "version": "4.11.5",
3
+ "version": "4.11.6",
4
4
  "description": "Legend query builder core",
5
5
  "keywords": [
6
6
  "legend",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finos/legend-query-builder",
3
- "version": "4.11.5",
3
+ "version": "4.11.6",
4
4
  "description": "Legend query builder core",
5
5
  "keywords": [
6
6
  "legend",
@@ -44,8 +44,8 @@
44
44
  "dependencies": {
45
45
  "@finos/legend-application": "15.0.51",
46
46
  "@finos/legend-art": "7.1.5",
47
- "@finos/legend-graph": "31.3.10",
48
- "@finos/legend-lego": "1.1.47",
47
+ "@finos/legend-graph": "31.3.11",
48
+ "@finos/legend-lego": "1.1.48",
49
49
  "@finos/legend-server-depot": "6.0.32",
50
50
  "@finos/legend-shared": "10.0.28",
51
51
  "@finos/legend-storage": "3.0.78",
@@ -57,7 +57,6 @@ import { prettyDuration } from '@finos/legend-shared';
57
57
  import { useRef, useState } from 'react';
58
58
  import { QueryBuilderTDSState } from '../../stores/fetch-structure/tds/QueryBuilderTDSState.js';
59
59
  import { PARAMETER_SUBMIT_ACTION } from '../../stores/shared/LambdaParameterState.js';
60
-
61
60
  import { QUERY_BUILDER_TEST_ID } from '../../__lib__/QueryBuilderTesting.js';
62
61
  import {
63
62
  CODE_EDITOR_LANGUAGE,
@@ -18,19 +18,22 @@ import { clsx } from '@finos/legend-art';
18
18
  import { observer } from 'mobx-react-lite';
19
19
  import type { QueryBuilderState } from '../../../stores/QueryBuilderState.js';
20
20
  import type { TDSExecutionResult } from '@finos/legend-graph';
21
- import { useState } from 'react';
21
+ import { useState, useCallback } from 'react';
22
22
  import {
23
23
  DataGrid,
24
24
  type DataGridApi,
25
25
  type DataGridCellRange,
26
26
  type DataGridColumnApi,
27
27
  type DataGridColumnDefinition,
28
+ type DataGridGetContextMenuItemsParams,
28
29
  type DataGridIRowNode,
30
+ type DataGridMenuItemDef,
29
31
  } from '@finos/legend-lego/data-grid';
30
32
  import {
31
33
  getAggregationTDSColumnCustomizations,
32
34
  getRowDataFromExecutionResult,
33
- QueryResultEnterpriseCellRenderer,
35
+ type IQueryRendererParamsWithGridType,
36
+ filterByOrOutValues,
34
37
  } from './QueryBuilderTDSResultShared.js';
35
38
  import type {
36
39
  QueryBuilderResultState,
@@ -38,13 +41,18 @@ import type {
38
41
  QueryBuilderTDSResultCellDataType,
39
42
  QueryBuilderTDSRowDataType,
40
43
  } from '../../../stores/QueryBuilderResultState.js';
44
+ import { QueryBuilderTDSState } from '../../../stores/fetch-structure/tds/QueryBuilderTDSState.js';
45
+ import { DEFAULT_LOCALE } from '../../../graph-manager/QueryBuilderConst.js';
46
+ import { isNumber, isString, isValidURL } from '@finos/legend-shared';
47
+ import { useApplicationStore } from '@finos/legend-application';
41
48
 
42
49
  const getAdvancedColDefs = (
43
50
  executionResult: TDSExecutionResult,
44
51
  resultState: QueryBuilderResultState,
45
- // TODO: fix col return type
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- ): DataGridColumnDefinition<any, any>[] =>
52
+ ): DataGridColumnDefinition<
53
+ QueryBuilderTDSRowDataType,
54
+ QueryBuilderTDSResultCellDataType
55
+ >[] =>
48
56
  executionResult.result.columns.map((colName) => {
49
57
  const col = {
50
58
  minWidth: 50,
@@ -74,7 +82,53 @@ const getAdvancedColDefs = (
74
82
  return col;
75
83
  });
76
84
 
77
- const getEnterpriseModeColDefs = (
85
+ const QueryResultCellRenderer = observer(
86
+ (params: IQueryRendererParamsWithGridType) => {
87
+ const resultState = params.resultState;
88
+ const cellValue = params.value as QueryBuilderTDSResultCellDataType;
89
+ const formattedCellValue = (): QueryBuilderTDSResultCellDataType => {
90
+ if (isNumber(cellValue)) {
91
+ return Intl.NumberFormat(DEFAULT_LOCALE, {
92
+ maximumFractionDigits: 4,
93
+ }).format(Number(cellValue));
94
+ }
95
+ return cellValue;
96
+ };
97
+ const cellValueUrlLink =
98
+ isString(cellValue) && isValidURL(cellValue) ? cellValue : undefined;
99
+
100
+ const mouseDown: React.MouseEventHandler = (event) => {
101
+ event.preventDefault();
102
+ if (event.button === 0 || event.button === 2) {
103
+ resultState.setMouseOverCell(resultState.selectedCells[0] ?? null);
104
+ }
105
+ };
106
+ const mouseUp: React.MouseEventHandler = (event) => {
107
+ resultState.setIsSelectingCells(false);
108
+ };
109
+ const mouseOver: React.MouseEventHandler = (event) => {
110
+ resultState.setMouseOverCell(resultState.selectedCells[0] ?? null);
111
+ };
112
+ return (
113
+ <div
114
+ className={clsx('query-builder__result__values__table__cell')}
115
+ onMouseDown={(event) => mouseDown(event)}
116
+ onMouseUp={(event) => mouseUp(event)}
117
+ onMouseOver={(event) => mouseOver(event)}
118
+ >
119
+ {cellValueUrlLink ? (
120
+ <a href={cellValueUrlLink} target="_blank" rel="noreferrer">
121
+ {cellValueUrlLink}
122
+ </a>
123
+ ) : (
124
+ <span>{formattedCellValue()}</span>
125
+ )}
126
+ </div>
127
+ );
128
+ },
129
+ );
130
+
131
+ const getColDefs = (
78
132
  executionResult: TDSExecutionResult,
79
133
  resultState: QueryBuilderResultState,
80
134
  ): DataGridColumnDefinition<
@@ -89,7 +143,7 @@ const getEnterpriseModeColDefs = (
89
143
  resizable: true,
90
144
  field: colName,
91
145
  flex: 1,
92
- cellRenderer: QueryResultEnterpriseCellRenderer,
146
+ cellRenderer: QueryResultCellRenderer,
93
147
  cellRendererParams: {
94
148
  resultState: resultState,
95
149
  tdsExecutionResult: executionResult,
@@ -103,7 +157,7 @@ export const QueryBuilderTDSGridResult = observer(
103
157
  queryBuilderState: QueryBuilderState;
104
158
  }) => {
105
159
  const { executionResult, queryBuilderState } = props;
106
-
160
+ const applicationStore = useApplicationStore();
107
161
  const [columnAPi, setColumnApi] = useState<DataGridColumnApi | undefined>(
108
162
  undefined,
109
163
  );
@@ -111,7 +165,7 @@ export const QueryBuilderTDSGridResult = observer(
111
165
  const isAdvancedModeEnabled = queryBuilderState.isAdvancedModeEnabled;
112
166
  const colDefs = isAdvancedModeEnabled
113
167
  ? getAdvancedColDefs(executionResult, resultState)
114
- : getEnterpriseModeColDefs(executionResult, resultState);
168
+ : getColDefs(executionResult, resultState);
115
169
 
116
170
  const onSaveGridColumnState = (): void => {
117
171
  if (!columnAPi) {
@@ -126,15 +180,15 @@ export const QueryBuilderTDSGridResult = observer(
126
180
  const getSelectedCells = (
127
181
  api: DataGridApi<QueryBuilderTDSRowDataType>,
128
182
  ): QueryBuilderTDSResultCellData[] => {
129
- const seletcedRanges: DataGridCellRange[] | null = api.getCellRanges();
183
+ const selectedRanges: DataGridCellRange[] | null = api.getCellRanges();
130
184
  const nodes = api.getRenderedNodes();
131
185
  const columns = api.getColumnDefs() as DataGridColumnDefinition[];
132
186
  const selectedCells = [];
133
- if (seletcedRanges) {
134
- for (const seletcedRange of seletcedRanges) {
135
- const startRow: number = seletcedRange.startRow?.rowIndex ?? 0;
136
- const endRow: number = seletcedRange.endRow?.rowIndex ?? 0;
137
- const selectedColumns: string[] = seletcedRange.columns.map((col) =>
187
+ if (selectedRanges) {
188
+ for (const selectedRange of selectedRanges) {
189
+ const startRow: number = selectedRange.startRow?.rowIndex ?? 0;
190
+ const endRow: number = selectedRange.endRow?.rowIndex ?? 0;
191
+ const selectedColumns: string[] = selectedRange.columns.map((col) =>
138
192
  col.getColId(),
139
193
  );
140
194
  for (let x: number = startRow; x <= endRow; x++) {
@@ -164,6 +218,56 @@ export const QueryBuilderTDSGridResult = observer(
164
218
  return selectedCells;
165
219
  };
166
220
 
221
+ const getContextMenuItems = useCallback(
222
+ (
223
+ params: DataGridGetContextMenuItemsParams<QueryBuilderTDSRowDataType>,
224
+ ): (string | DataGridMenuItemDef)[] => {
225
+ let result: (string | DataGridMenuItemDef)[] = [];
226
+ const fetchStructureImplementation =
227
+ resultState.queryBuilderState.fetchStructureState.implementation;
228
+ if (fetchStructureImplementation instanceof QueryBuilderTDSState) {
229
+ result = [
230
+ {
231
+ name: 'Filter by',
232
+ action: () => {
233
+ filterByOrOutValues(
234
+ applicationStore,
235
+ resultState.mousedOverCell,
236
+ true,
237
+ fetchStructureImplementation,
238
+ );
239
+ },
240
+ },
241
+ {
242
+ name: 'Filter out',
243
+ action: () => {
244
+ filterByOrOutValues(
245
+ applicationStore,
246
+ resultState.mousedOverCell,
247
+ false,
248
+ fetchStructureImplementation,
249
+ );
250
+ },
251
+ },
252
+ 'copy',
253
+ 'copyWithHeaders',
254
+ {
255
+ name: 'Copy row value',
256
+ action: () => {
257
+ params.api.copySelectedRowsToClipboard();
258
+ },
259
+ },
260
+ ];
261
+ }
262
+ return result;
263
+ },
264
+ [
265
+ applicationStore,
266
+ resultState.mousedOverCell,
267
+ resultState.queryBuilderState.fetchStructureState.implementation,
268
+ ],
269
+ );
270
+
167
271
  return (
168
272
  <div className="query-builder__result__values__table">
169
273
  <div
@@ -182,7 +286,7 @@ export const QueryBuilderTDSGridResult = observer(
182
286
  }}
183
287
  gridOptions={{
184
288
  suppressScrollOnNewData: true,
185
- getRowId: (data) => data.data.rowNumber,
289
+ getRowId: (data) => data.data.rowNumber as string,
186
290
  rowSelection: 'multiple',
187
291
  pivotPanelShow: 'always',
188
292
  rowGroupPanelShow: 'always',
@@ -210,7 +314,7 @@ export const QueryBuilderTDSGridResult = observer(
210
314
  rowData={getRowDataFromExecutionResult(executionResult)}
211
315
  gridOptions={{
212
316
  suppressScrollOnNewData: true,
213
- getRowId: (data) => data.data.rowNumber,
317
+ getRowId: (data) => data.data.rowNumber as string,
214
318
  rowSelection: 'multiple',
215
319
  enableRangeSelection: true,
216
320
  }}
@@ -228,8 +332,11 @@ export const QueryBuilderTDSGridResult = observer(
228
332
  }}
229
333
  suppressFieldDotNotation={true}
230
334
  suppressClipboardPaste={false}
231
- suppressContextMenu={!isAdvancedModeEnabled}
335
+ suppressContextMenu={false}
232
336
  columnDefs={colDefs}
337
+ getContextMenuItems={(params): (string | DataGridMenuItemDef)[] =>
338
+ getContextMenuItems(params)
339
+ }
233
340
  />
234
341
  )}
235
342
  </div>