fix filter node drilldown for number columns (#11572)

This commit is contained in:
marthasharkey 2024-11-21 00:02:36 +00:00 committed by GitHub
parent 2fd29a5825
commit 76ad3475c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View File

@ -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
@ -657,6 +680,7 @@ config.setToolbar(
isDisabled: () => !isCreateNodeEnabled.value,
isFilterSortNodeEnabled,
createNodes: config.createNodes,
getColumnValueToEnso,
}),
)
</script>

View File

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