From 008a7fb85e5ab1134609e53a9da8a2bb9286ced4 Mon Sep 17 00:00:00 2001 From: marthasharkey Date: Wed, 27 Nov 2024 12:30:59 +0000 Subject: [PATCH] Add date support for filter drilldown (#11626) ![filter-drilldown-date](https://github.com/user-attachments/assets/9574a172-95af-41c6-aef1-a586ee6cda98) ![filter-drilldown-time](https://github.com/user-attachments/assets/9fd5c3f0-0594-4d9c-8c00-c9616ae997be) Date Time using Date_Time.parse ![date-drilldown-date-time-1](https://github.com/user-attachments/assets/9960cdba-8f13-4f72-9c11-b681ae63e988) ![date-drilldown-date-time-2](https://github.com/user-attachments/assets/caaeb53d-8d2e-4332-aaa4-3d3e210a0893) --- .../visualizations/TableVisualization.vue | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/gui/src/project-view/components/visualizations/TableVisualization.vue b/app/gui/src/project-view/components/visualizations/TableVisualization.vue index 3af3b8c393e..9c558a28480 100644 --- a/app/gui/src/project-view/components/visualizations/TableVisualization.vue +++ b/app/gui/src/project-view/components/visualizations/TableVisualization.vue @@ -616,6 +616,26 @@ const getColumnValueToEnso = (columnName: string) => { if (isNumber.indexOf(columnType) != -1) { return (item: string, module: Ast.MutableModule) => Ast.tryNumberToEnso(Number(item), module)! } + const createDateTimePattern = (pattern: string, numberOfParts: number) => { + const dateOrTimePattern = Pattern.parseExpression(pattern) + return (item: string, module: Ast.MutableModule) => { + const dateTimeParts = item.match(/\d+/g)!.map(Number) + const dateTimePartsNumeric = [] + for (let i = 0; i < numberOfParts; i++) { + dateTimePartsNumeric.push(Ast.tryNumberToEnso(Number(dateTimeParts[i] ?? 0), module)!) + } + return dateOrTimePattern.instantiateCopied(dateTimePartsNumeric) + } + } + if (columnType === 'Date') { + return createDateTimePattern('(Date.new __ __ __)', 3) + } + if (columnType === 'Time') { + return createDateTimePattern('(Time_Of_Day.new __ __ __ __ __ __)', 6) + } + if (columnType === 'Date_Time') { + return (item: string) => Ast.parseExpression(`(Date_Time.parse '${item}')`)! + } return (item: string) => Ast.TextLiteral.new(item) }