Skip to content

Commit 76ad347

Browse files
fix filter node drilldown for number columns (#11572)
1 parent 2fd29a5 commit 76ad347

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

app/gui/src/project-view/components/visualizations/TableVisualization.vue

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,29 @@ watchEffect(() => {
605605
defaultColDef.value.sortable = !isTruncated.value
606606
})
607607
608+
const colTypeMap = computed(() => {
609+
const colMap: Map<string, string> = new Map()
610+
if (typeof props.data === 'object' && !('error' in props.data)) {
611+
const valueTypes = 'value_type' in props.data ? props.data.value_type : []
612+
const headers = 'header' in props.data ? props.data.header : []
613+
headers?.forEach((header, index) => {
614+
if (valueTypes[index]) {
615+
colMap.set(header, valueTypes[index].constructor)
616+
}
617+
})
618+
}
619+
return colMap
620+
})
621+
622+
const getColumnValueToEnso = (columnName: string) => {
623+
const columnType = colTypeMap.value.get(columnName) ?? ''
624+
const isNumber = ['Integer', 'Float', 'Decimal', 'Byte']
625+
if (isNumber.indexOf(columnType) != -1) {
626+
return (item: string, module: Ast.MutableModule) => Ast.tryNumberToEnso(Number(item), module)!
627+
}
628+
return (item: string) => Ast.TextLiteral.new(item)
629+
}
630+
608631
function checkSortAndFilter(e: SortChangedEvent) {
609632
const gridApi = e.api
610633
const columnApi = e.columnApi
@@ -657,6 +680,7 @@ config.setToolbar(
657680
isDisabled: () => !isCreateNodeEnabled.value,
658681
isFilterSortNodeEnabled,
659682
createNodes: config.createNodes,
683+
getColumnValueToEnso,
660684
}),
661685
)
662686
</script>

app/gui/src/project-view/components/visualizations/tableVizToolbar.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export interface SortFilterNodesButtonOptions {
2424
isDisabled: ToValue<boolean>
2525
isFilterSortNodeEnabled: ToValue<boolean>
2626
createNodes: (...options: NodeCreationOptions[]) => void
27+
getColumnValueToEnso: (
28+
columnName: string,
29+
) => (columnValue: string, module: Ast.MutableModule) => Ast.Owned<Ast.MutableAst>
2730
}
2831

2932
export interface FormatMenuOptions {
@@ -38,6 +41,7 @@ function useSortFilterNodesButton({
3841
isDisabled,
3942
isFilterSortNodeEnabled,
4043
createNodes,
44+
getColumnValueToEnso,
4145
}: SortFilterNodesButtonOptions): ComputedRef<ToolbarItem | undefined> {
4246
const sortPatternPattern = computed(() => Pattern.parseExpression('(..Name __ __ )')!)
4347

@@ -73,7 +77,8 @@ function useSortFilterNodesButton({
7377
boolToInclude,
7478
])
7579
}
76-
const itemList = items.map((i) => Ast.TextLiteral.new(i))
80+
const valueFormatter = getColumnValueToEnso(columnName)
81+
const itemList = items.map((i) => valueFormatter(i, module))
7782
return filterPattern.value.instantiateCopied([
7883
Ast.TextLiteral.new(columnName),
7984
Ast.parseExpression('..Is_In')!,
@@ -122,7 +127,7 @@ function useSortFilterNodesButton({
122127
const sortModelValue = toValue(sortModel)
123128
if (Object.keys(filterModelValue).length) {
124129
for (const [columnName, columnFilter] of Object.entries(filterModelValue)) {
125-
const items = columnFilter.values.map((item) => `${item}`)
130+
const items = columnFilter.values
126131
const filterPatterns =
127132
sortModelValue.length ?
128133
getAstPatternFilterAndSort(columnName, items)

0 commit comments

Comments
 (0)