@@ -7,16 +7,20 @@ import {
7
7
} from ' @/components/visualizations/TableVisualization/tableVizToolbar'
8
8
import { Ast } from ' @/util/ast'
9
9
import { Pattern } from ' @/util/ast/match'
10
+ import { Icon } from ' @/util/iconMetadata/iconName'
10
11
import { useVisualizationConfig } from ' @/util/visualizationBuiltins'
11
12
import type {
12
13
CellClassParams ,
13
14
CellDoubleClickedEvent ,
14
15
ColDef ,
15
16
ColumnVisibleEvent ,
17
+ GetContextMenuItems ,
18
+ GetContextMenuItemsParams ,
16
19
ICellRendererParams ,
17
20
IServerSideDatasource ,
18
21
IServerSideGetRowsRequest ,
19
22
ITooltipParams ,
23
+ MenuItemDef ,
20
24
SetFilterValuesFuncParams ,
21
25
SortChangedEvent ,
22
26
} from ' ag-grid-enterprise'
@@ -159,19 +163,92 @@ const defaultColDef: Ref<ColDef> = ref({
159
163
cellRenderer: cellRenderer ,
160
164
cellClass: cellClass ,
161
165
cellStyle: { ' padding-left' : 0 , ' border-right' : ' 1px solid #C0C0C0' },
162
- contextMenuItems: [
163
- commonContextMenuActions .copy ,
164
- commonContextMenuActions .copyWithHeaders ,
165
- ' separator' ,
166
- ' export' ,
167
- ],
168
166
} satisfies ColDef )
169
167
const rowData = ref <Record <string , any >[]>([])
170
168
const columnDefs: Ref <ColDef []> = ref ([])
171
169
const nodeType = ref <string | undefined >(undefined )
172
170
const grid = ref <
173
171
ComponentInstance < typeof AgGridTableView > & ComponentExposed < typeof AgGridTableView >
174
172
> ()
173
+
174
+ const getSvgTemplate = (icon : Icon ) =>
175
+ ` <svg viewBox="0 0 16 16" width="16" height="16"> <use xlink:href="${icons }#${icon }"/> </svg> `
176
+
177
+ const getContextMenuItems = (
178
+ params : GetContextMenuItemsParams ,
179
+ ): (MenuItemDef | string )[] | GetContextMenuItems => {
180
+ const colId = params .column ? params .column .getColId () : null
181
+ const { rowIndex } = params .node ?? {}
182
+
183
+ const actions = [
184
+ { name: ' Get Column' , action: ' at' , colId , icon: ' select_column' },
185
+ { name: ' Get Row' , action: ' get_row' , rowIndex , icon: ' select_row' },
186
+ { name: ' Get Value' , action: ' get_value' , colId , rowIndex , icon: ' local_scope4' },
187
+ ]
188
+
189
+ const createMenuItem = ({ name , action , colId , rowIndex , icon }: (typeof actions )[number ]) => ({
190
+ name ,
191
+ action : () => createValueNode (colId , rowIndex , action ),
192
+ icon: getSvgTemplate (icon as Icon ),
193
+ })
194
+
195
+ return [
196
+ commonContextMenuActions .copy ,
197
+ commonContextMenuActions .copyWithHeaders ,
198
+ ' separator' ,
199
+ ' export' ,
200
+ ... actions .map (createMenuItem ),
201
+ ]
202
+ }
203
+
204
+ function getAstValuePattern(value ? : string | number , action ? : string ) {
205
+ if (action && value != null ) {
206
+ return Pattern .new <Ast .Expression >((ast ) =>
207
+ Ast .App .positional (
208
+ Ast .PropertyAccess .new (ast .module , ast , Ast .identifier (action )! ),
209
+ typeof value === ' number' ?
210
+ Ast .tryNumberToEnso (value , ast .module )!
211
+ : Ast .TextLiteral .new (value , ast .module ),
212
+ ),
213
+ )
214
+ }
215
+ }
216
+
217
+ function getAstGetValuePattern(columnId ? : string , rowIndex ? : number , action ? : string ) {
218
+ if (action && columnId && rowIndex != undefined ) {
219
+ const pattern = Pattern .parseExpression (' __ __' )
220
+ return Pattern .new <Ast .Expression >((ast ) =>
221
+ Ast .App .positional (
222
+ Ast .PropertyAccess .new (ast .module , ast , Ast .identifier (' get_value' )! ),
223
+ pattern .instantiateCopied ([
224
+ Ast .TextLiteral .new (columnId as string , ast .module ),
225
+ Ast .tryNumberToEnso (rowIndex as number , ast .module )! ,
226
+ ]),
227
+ ),
228
+ )
229
+ }
230
+ }
231
+
232
+ function createValueNode(columnId ? : string | null , rowIndex ? : number | null , action ? : string ) {
233
+ let pattern
234
+ if (action === ' at' && columnId != null ) {
235
+ pattern = getAstValuePattern (columnId , action )
236
+ }
237
+ if (action === ' get_row' && rowIndex != null ) {
238
+ pattern = getAstValuePattern (rowIndex , action )
239
+ }
240
+ if (action === ' get_value' && columnId != null && rowIndex != null ) {
241
+ pattern = getAstGetValuePattern (columnId , rowIndex , action )
242
+ }
243
+
244
+ if (pattern ) {
245
+ config .createNodes ({
246
+ content: pattern ,
247
+ commit: true ,
248
+ })
249
+ }
250
+ }
251
+
175
252
const allRowCount = computed (() =>
176
253
typeof props .data === ' object' && ' all_rows_count' in props .data ? props .data .all_rows_count : 0 ,
177
254
)
@@ -277,13 +354,13 @@ const isCreateNewNodeEnabled = computed(
277
354
278
355
const numberFormatGroupped = new Intl .NumberFormat (undefined , {
279
356
style: ' decimal' ,
280
- maximumFractionDigits: 12 ,
357
+ maximumSignificantDigits: 16 ,
281
358
useGrouping: true ,
282
359
})
283
360
284
361
const numberFormat = new Intl .NumberFormat (undefined , {
285
362
style: ' decimal' ,
286
- maximumFractionDigits: 12 ,
363
+ maximumSignificantDigits: 16 ,
287
364
useGrouping: false ,
288
365
})
289
366
@@ -579,8 +656,6 @@ function toField(
579
656
const showDataQuality =
580
657
dataQualityMetrics .filter ((obj ) => (Object .values (obj )[0 ] as number ) > 0 ).length > 0
581
658
582
- const getSvgTemplate = (icon : string ) =>
583
- ` <svg viewBox="0 0 16 16" width="16" height="16"> <use xlink:href="${icons }#${icon }"/> </svg> `
584
659
const svgTemplateWarning = showDataQuality ? getSvgTemplate (' warning' ) : ' '
585
660
const menu = ` <span data-ref="eMenu" class="ag-header-icon ag-header-cell-menu-button"> </span> `
586
661
const filterButton = ` <span data-ref="eFilterButton" class="ag-header-icon ag-header-cell-filter-button" aria-hidden="true"></span> `
@@ -1087,6 +1162,7 @@ config.setToolbar(
1087
1162
:isServerSideModel =" isSSRM"
1088
1163
:statusBar =" statusBar"
1089
1164
:gridIdHash =" tableVersionHash"
1165
+ :getContextMenuItems =" getContextMenuItems"
1090
1166
@sortOrFilterUpdated =" checkSortAndFilter"
1091
1167
@columnStateChanged =" onColumnStateChange"
1092
1168
/>
0 commit comments