From 8319516d1a0c7c83c6284b7696a7c42c8d1c0cd0 Mon Sep 17 00:00:00 2001 From: Colin Holzman Date: Wed, 6 Aug 2025 09:06:15 -0400 Subject: [PATCH] fix: boolean filters (#4966) --- plugin/filter/common_converter.go | 18 +----------------- plugin/filter/dialect.go | 15 --------------- store/db/postgres/memo_filter_test.go | 12 ++++++------ web/src/pages/Home.tsx | 1 - 4 files changed, 7 insertions(+), 39 deletions(-) diff --git a/plugin/filter/common_converter.go b/plugin/filter/common_converter.go index 47ae4314a..44270e5b5 100644 --- a/plugin/filter/common_converter.go +++ b/plugin/filter/common_converter.go @@ -550,23 +550,7 @@ func (c *CommonSQLConverter) handleBooleanComparison(ctx *ConvertContext, field, // Handle PostgreSQL differently - it uses the raw operator if _, ok := c.dialect.(*PostgreSQLDialect); ok { - var jsonExtract string - // Special handling for has_link, has_code, has_incomplete_tasks - if field == "has_link" || field == "has_code" || field == "has_incomplete_tasks" { - // Use memo-> format for these fields - parts := strings.Split(strings.TrimPrefix(jsonPath, "$."), ".") - jsonExtract = "memo->'payload'" - for i, part := range parts { - if i == len(parts)-1 { - jsonExtract += fmt.Sprintf("->>'%s'", part) - } else { - jsonExtract += fmt.Sprintf("->'%s'", part) - } - } - } else { - // Use standard format for has_task_list - jsonExtract = c.dialect.GetJSONExtract(jsonPath) - } + var jsonExtract = c.dialect.GetJSONExtract(jsonPath) sqlExpr := fmt.Sprintf("(%s)::boolean %s %s", jsonExtract, diff --git a/plugin/filter/dialect.go b/plugin/filter/dialect.go index 41adc2ffe..da2de82f2 100644 --- a/plugin/filter/dialect.go +++ b/plugin/filter/dialect.go @@ -203,21 +203,6 @@ func (d *PostgreSQLDialect) GetBooleanComparison(path string, _ bool) string { } func (d *PostgreSQLDialect) GetBooleanCheck(path string) string { - // Special handling for standalone boolean identifiers - if strings.Contains(path, "hasLink") || strings.Contains(path, "hasCode") || strings.Contains(path, "hasIncompleteTasks") { - // Use memo-> instead of memo.payload-> for these fields - parts := strings.Split(strings.TrimPrefix(path, "$."), ".") - result := fmt.Sprintf("%s->'payload'", d.GetTablePrefix()) - for i, part := range parts { - if i == len(parts)-1 { - result += fmt.Sprintf("->>'%s'", part) - } else { - result += fmt.Sprintf("->'%s'", part) - } - } - return fmt.Sprintf("(%s)::boolean = true", result) - } - // Use default format for other fields return fmt.Sprintf("(%s)::boolean IS TRUE", d.GetJSONExtract(path)) } diff --git a/store/db/postgres/memo_filter_test.go b/store/db/postgres/memo_filter_test.go index 2ee804e15..fe32ef7e7 100644 --- a/store/db/postgres/memo_filter_test.go +++ b/store/db/postgres/memo_filter_test.go @@ -117,32 +117,32 @@ func TestConvertExprToSQL(t *testing.T) { }, { filter: `has_link == true`, - want: "(memo->'payload'->'property'->>'hasLink')::boolean = $1", + want: "(memo.payload->'property'->>'hasLink')::boolean = $1", args: []any{true}, }, { filter: `has_code == false`, - want: "(memo->'payload'->'property'->>'hasCode')::boolean = $1", + want: "(memo.payload->'property'->>'hasCode')::boolean = $1", args: []any{false}, }, { filter: `has_incomplete_tasks != false`, - want: "(memo->'payload'->'property'->>'hasIncompleteTasks')::boolean != $1", + want: "(memo.payload->'property'->>'hasIncompleteTasks')::boolean != $1", args: []any{false}, }, { filter: `has_link`, - want: "(memo->'payload'->'property'->>'hasLink')::boolean = true", + want: "(memo.payload->'property'->>'hasLink')::boolean IS TRUE", args: []any{}, }, { filter: `has_code`, - want: "(memo->'payload'->'property'->>'hasCode')::boolean = true", + want: "(memo.payload->'property'->>'hasCode')::boolean IS TRUE", args: []any{}, }, { filter: `has_incomplete_tasks`, - want: "(memo->'payload'->'property'->>'hasIncompleteTasks')::boolean = true", + want: "(memo.payload->'property'->>'hasIncompleteTasks')::boolean IS TRUE", args: []any{}, }, } diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsx index 398255ae9..49d0b792f 100644 --- a/web/src/pages/Home.tsx +++ b/web/src/pages/Home.tsx @@ -50,7 +50,6 @@ const Home = observer(() => { conditions.push(`${factor} >= ${timestampAfter} && ${factor} < ${timestampAfter + 60 * 60 * 24}`); } } - console.log("conditions", conditions); return conditions.length > 0 ? conditions.join(" && ") : undefined; }, [memoFilterStore.filters, selectedShortcut?.filter]);