Skip to content

Commit

Permalink
fix filter node drilldown for number columns (#11572)
Browse files Browse the repository at this point in the history
  • Loading branch information
marthasharkey authored Nov 21, 2024
1 parent 2fd29a5 commit 76ad347
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,29 @@ watchEffect(() => {
defaultColDef.value.sortable = !isTruncated.value
})
const colTypeMap = computed(() => {
const colMap: Map<string, string> = new Map()
if (typeof props.data === 'object' && !('error' in props.data)) {
const valueTypes = 'value_type' in props.data ? props.data.value_type : []
const headers = 'header' in props.data ? props.data.header : []
headers?.forEach((header, index) => {
if (valueTypes[index]) {
colMap.set(header, valueTypes[index].constructor)
}
})
}
return colMap
})
const getColumnValueToEnso = (columnName: string) => {
const columnType = colTypeMap.value.get(columnName) ?? ''
const isNumber = ['Integer', 'Float', 'Decimal', 'Byte']
if (isNumber.indexOf(columnType) != -1) {
return (item: string, module: Ast.MutableModule) => Ast.tryNumberToEnso(Number(item), module)!
}
return (item: string) => Ast.TextLiteral.new(item)
}
function checkSortAndFilter(e: SortChangedEvent) {
const gridApi = e.api
const columnApi = e.columnApi
Expand Down Expand Up @@ -657,6 +680,7 @@ config.setToolbar(
isDisabled: () => !isCreateNodeEnabled.value,
isFilterSortNodeEnabled,
createNodes: config.createNodes,
getColumnValueToEnso,
}),
)
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export interface SortFilterNodesButtonOptions {
isDisabled: ToValue<boolean>
isFilterSortNodeEnabled: ToValue<boolean>
createNodes: (...options: NodeCreationOptions[]) => void
getColumnValueToEnso: (
columnName: string,
) => (columnValue: string, module: Ast.MutableModule) => Ast.Owned<Ast.MutableAst>
}

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

Expand Down Expand Up @@ -73,7 +77,8 @@ function useSortFilterNodesButton({
boolToInclude,
])
}
const itemList = items.map((i) => Ast.TextLiteral.new(i))
const valueFormatter = getColumnValueToEnso(columnName)
const itemList = items.map((i) => valueFormatter(i, module))
return filterPattern.value.instantiateCopied([
Ast.TextLiteral.new(columnName),
Ast.parseExpression('..Is_In')!,
Expand Down Expand Up @@ -122,7 +127,7 @@ function useSortFilterNodesButton({
const sortModelValue = toValue(sortModel)
if (Object.keys(filterModelValue).length) {
for (const [columnName, columnFilter] of Object.entries(filterModelValue)) {
const items = columnFilter.values.map((item) => `${item}`)
const items = columnFilter.values
const filterPatterns =
sortModelValue.length ?
getAstPatternFilterAndSort(columnName, items)
Expand Down

0 comments on commit 76ad347

Please sign in to comment.