Skip to content

feat(filters): choose case sensitivity for postgres text matches - #1173

Closed
umairnaeem0309 wants to merge 1 commit into
TabularisDB:mainfrom
umairnaeem0309:feat/postgres-filter-match-case
Closed

umairnaeem0309 wants to merge 1 commit into
TabularisDB:mainfrom
umairnaeem0309:feat/postgres-filter-match-case

Conversation

@umairnaeem0309

@umairnaeem0309 umairnaeem0309 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1164.

What changed

Literal text filters (contains, starts with, ends with) always generated LIKE, so a PostgreSQL connection had no way to ask for a case-insensitive match. A filter row now carries an optional matchCase flag:

Row state PostgreSQL Everything else
absent / true (default) LIKE LIKE
false ILIKE LIKE (flag ignored)

The default is true for every row, including rows saved before this change, so nothing existing starts matching differently.

  • src/utils/filterBar.ts — matchCase?: boolean on StructuredFilter, isMatchCaseEnabled() helper, buildLiteralLikeClause() picks the keyword. Dialect comes from isPostgresDialect, so it is capability-driven, not id-driven.
  • src/components/ui/FilterRow.tsx — an Aa toggle next to the value field, rendered only for the three literal text operators. It exposes state with aria-pressed, has a translated aria-label, a hint on title, and the standard focus-visible:outline-focus ring.
  • src/components/ui/TableToolbar.tsx — computes supportsMatchCase={isPostgresDialect(quotingDriver)} from activeCapabilities ?? activeDriver.

Escaping is untouched: the pattern is escaped once (! → !!, % → !%, _ → !_, quotes doubled) and only the keyword changes, with ESCAPE '!' kept in both modes. The new tests assert the case-insensitive literal is the case-sensitive one with LIKE swapped for ILIKE, so escaping cannot drift between modes.

Dialect and plugin behaviour

  • Built-in postgres — toggle shown, ILIKE available.
  • Plugin declaring sql_dialect: "postgres" — toggle shown, ILIKE available. Verified with a full PluginManifest fixture (also covers a plugin id that is not postgres), consistent with .rules/plugins.md.
  • Plugin that omits sql_dialect — treated as postgres, matching the manifest schema default that isPostgresDialect uses.
  • mysql, mariadb, sqlite, mssql, oracle, generic — toggle hidden, and the builder is asserted to return byte-identical SQL with the flag on and off, so no existing filter changes.

MySQL/MariaDB backslash doubling is unaffected and still covered by the existing tests in both modes.

Testing

New coverage:

  • tests/utils/filterBar.test.ts — default stays LIKE; a filter round-tripped from JSON without the field stays LIKE; ILIKE for the builtin driver and for a plugin capabilities object + full manifest; escaping identical in both modes; per-dialect no-op assertion for the six non-postgres dialects; the setting applies per row inside a combined clause; other operators untouched.
  • tests/components/ui/FilterRow.test.tsx — toggle offered only on postgres, reflects the stored value, flips onChange without touching the value, and is absent when supportsMatchCase is false or the operator is not a text match.
  • tests/i18n/filterMatchCase.test.ts — all 11 locales cover both strings, and the hint keeps naming ILIKE.

Mutation-checked, so the tests are not vacuous:

  • force LIKE always → 4 failures
  • drop the dialect guard (emit ILIKE everywhere) → 6 failures
  • render the toggle unconditionally → 2 failures

Review follow-up (thanks @kilo-code-bot[bot]): the escaping fixture used a \s literal, which JavaScript reads as plain s, so it never actually held a backslash. It now carries a real one, and expect(value).toContain("\\") asserts the fixture itself, so the test name and the data cannot drift apart again.

Commands run (exit status captured directly, not through a pipe):

npx vitest run tests/utils/filterBar.test.ts tests/components/ui/FilterRow.test.tsx \
  tests/components/ui/TableToolbar.test.tsx tests/i18n    # exit 0, 380 tests
pnpm lint                                                 # exit 0, theme token check OK
pnpm exec tsc -b                                          # exit 0

tests/i18n/filterMatchCase.test.ts lives under tests/i18n/ next to the existing per-feature locale tests rather than mirroring src/, following that directory's established pattern.

Notes

  • Impact analysis: the repository asks for a GitNexus impact() pass; the MCP tools were not available in my environment, so call sites were enumerated directly instead. buildSingleFilterClause has one caller (TableToolbar.tsx). buildLiteralLikeClause has two: buildSingleFilterClause here, and buildCellValueFilterClause (src/utils/cellValueFilter.ts:47, the filter-by-cell-value path), which passes four arguments and therefore keeps emitting LIKE — that path has no case option in its UI and is deliberately unchanged in this PR. buildStructuredFilterClause is called from TableToolbar.tsx and from buildValuePickerWhere in the same module. The new StructuredFilter field and the new buildLiteralLikeClause parameter are optional, so no signature breaks.
  • Not verified in the running app: I could not launch the Tauri desktop build here, so the toggle's placement is verified through the component tests, not by eye. Happy to adjust the position or label if you want it elsewhere in the row.
  • cargo test was not run; no Rust code changed.

Copilot AI balanced review requested due to automatic review settings October 17, 2026 13:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Comment thread tests/utils/filterBar.test.ts Outdated
});

it("escapes wildcards, quotes and the escape character identically in both modes", () => {
const value = "100%_off!\sale O'Brien";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: \s in these string literals is not a backslash

In a JS string literal "\s" is just "s" (an unnecessary escape), so this value is actually 100%_off!sale O'Brien and no backslash is exercised. The expectation on line 728 only passes because !!\s collapses to !!s the same way. The test title promises to cover the escape character and quotes, so an accidental \s reads as if a backslash case were covered when it is not. Either drop the stray backslash or use \\ if a literal backslash is intended (note that postgres does not double it, unlike MySQL).

Suggested change
const value = "100%_off!\sale O'Brien";
const value = "100%_off!sale O'Brien";

(Line 728 would need the matching change: "name LIKE '%100!%!_off!!sale O''Brien%' ESCAPE '!'".)


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Notes

  • The earlier test-data suggestion is resolved: the escape-character test now uses a real backslash (\\) with an explicit toContain("\\") assertion and a matching expectation.
  • matchCase defaults to on, so rows saved before this change keep emitting LIKE. Non-postgres dialects always get LIKE, and the toggle is hidden for them.
  • All 11 locales add matchCase and matchCaseHint, with a new i18n test covering them.
  • I did not run the test suite (read-only review).
Files Reviewed (17 files)
  • src/components/ui/FilterRow.tsx
  • src/components/ui/TableToolbar.tsx
  • src/utils/filterBar.ts
  • src/i18n/locales/*.json (11 files)
  • tests/components/ui/FilterRow.test.tsx
  • tests/i18n/filterMatchCase.test.ts
  • tests/utils/filterBar.test.ts
Previous Review Summaries (2 snapshots, latest commit 17ead8a)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 17ead8a)

Status: 1 Issue Found | Recommendation: Merge (optional test-data cleanup)

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
tests/utils/filterBar.test.ts 725 "\s" in the JS string literal is just s, so the "escape character" test does not actually exercise a backslash; drop it or use \\ deliberately (and update line 728 to match).

Notes

  • The head commit is unchanged since the previous review, and the earlier finding is still present in the current code.
  • matchCase defaults to on, so rows saved before this change keep emitting LIKE. Non-postgres dialects always get LIKE, and the toggle is hidden for them.
  • All 11 locales add matchCase and matchCaseHint, with a new i18n test covering them.
  • I did not run the test suite (read-only review).

Fix these issues in Kilo Cloud

Files Reviewed (17 files)
  • src/components/ui/FilterRow.tsx
  • src/components/ui/TableToolbar.tsx
  • src/utils/filterBar.ts
  • src/i18n/locales/*.json (11 files)
  • tests/components/ui/FilterRow.test.tsx
  • tests/i18n/filterMatchCase.test.ts
  • tests/utils/filterBar.test.ts - 1 issue

Previous review (commit 1c59a39)

Status: 1 Issue Found | Recommendation: Merge (optional test-data cleanup)

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
tests/utils/filterBar.test.ts 725 "\s" in the JS string literal is just s, so the "escape character" test does not actually exercise a backslash; drop it or use \\ deliberately (and update line 728 to match).

Notes

  • matchCase defaults to on (!== false), so rows saved before this change keep emitting LIKE. buildLiteralLikeClause takes matchCase = true as a default parameter, so the other caller (cellValueFilter.ts) is unchanged.
  • ILIKE is gated on isPostgresDialect(driver), which is capability-driven (sql_dialect). Non-postgres dialects always get LIKE, and the toggle is hidden for them through supportsMatchCase.
  • Escaping is computed once, and only the keyword changes. The toggle goes through onChange, so the applied-state reset behaves like the other row edits.
  • All 11 locales add matchCase and matchCaseHint, and the new i18n test checks them.
  • The toggle button has aria-pressed, aria-label and a focus-visible style, and uses theme tokens.
  • I did not run the test suite (read-only review).

Fix these issues in Kilo Cloud

Files Reviewed (16 files)
  • src/components/ui/FilterRow.tsx
  • src/components/ui/TableToolbar.tsx
  • src/utils/filterBar.ts
  • src/i18n/locales/*.json (11 files)
  • tests/i18n/filterMatchCase.test.ts
  • tests/utils/filterBar.test.ts - 1 issue

Reviewed by claude-sonnet-5.5 · Input: 258 · Output: 1.8K · Cached: 296.3K

Review guidance: REVIEW.md from base branch main

@umairnaeem0309
umairnaeem0309 force-pushed the feat/postgres-filter-match-case branch from 1c59a39 to 17ead8a Compare October 17, 2026 13:29
Literal text filters always built LIKE, so a PostgreSQL connection had no
way to ask for a case-insensitive match. A filter row now carries an
optional matchCase flag: true (the default, including for rows saved before
this change) keeps LIKE, false emits ILIKE.

Only the postgres dialect acts on it. Every other dialect ignores the flag
and produces byte-identical SQL, which is asserted per dialect, and the
toggle is hidden where ILIKE cannot run. Plugin drivers are covered through
sql_dialect, matching isPostgresDialect's existing capability reading.

The pattern is escaped once and only the keyword changes, so wildcards,
quotes and the ESCAPE '!' clause behave the same in both modes.
@umairnaeem0309
umairnaeem0309 force-pushed the feat/postgres-filter-match-case branch from 17ead8a to 5128828 Compare October 17, 2026 13:36
@umairnaeem0309

umairnaeem0309 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @kilo-code-bot[bot] — the \s catch was correct: JavaScript reads that as plain s, so the fixture never held a backslash and the test was proving less than its name claimed. Fixed in 5128828: the value now carries a real backslash and expect(value).toContain("\\") asserts the fixture itself, so the data and the test name can't drift apart again.

I also took the cellValueFilter.ts note seriously: my impact analysis listed buildLiteralLikeClause as having one caller, which was wrong — buildCellValueFilterClause calls it too. That call passes four arguments, so it keeps emitting LIKE and its behaviour is unchanged; the PR description now says so explicitly rather than understating the blast radius.

Re-ran on the pushed commit: 380 tests exit 0, pnpm lint exit 0, pnpm exec tsc -b exit 0.

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, and welcome! I really liked the escaping test that checks the case-insensitive SQL is exactly the case-sensitive SQL with LIKE swapped for ILIKE, so the two modes can't drift apart. It's also great to see the plugin side handled properly: the toggle is gated on isPostgresDialect(activeCapabilities ?? activeDriver), and there are tests with a capabilities object and a plugin manifest under a different id, which is exactly what .rules/plugins.md asks for.

Since this is your first PR here: if you'd like to hang out with us, we'd be happy to see you on Discord: https://discord.com/invite/K2hmhfHRSt

The tests pass on the branch (259 across filterBar, FilterRow, TableToolbar, cellValueFilter and the i18n test), and lint and typecheck are clean. There's one bug I'd like fixed before merging, though:

Flipping Aa on an applied filter doesn't reset the "Applied" state. The toggle calls onChange({ ...filter, matchCase: !matchCase }), but handleFilterChange in TableToolbar.tsx decides whether to call onResetApplied by comparing only column, operator, value and value2. Since matchCase isn't in that comparison, the change is treated like a simple enable/disable toggle. Steps to see it: apply name contains ada, then click Aa without re-applying. The row button stays green "Applied" while the grid still shows the old LIKE/ILIKE result. Adding isMatchCaseEnabled(prev) === isMatchCaseEnabled(updated) to that check, plus a test, should be enough.

A small nit while you're there: FilterRow.tsx hardcodes the three text-match operators, while filterBar.ts already has the LikeMatchMode type for them. A small helper next to it would keep the list in one place.

@debba

debba commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks a lot for the work on this, and sorry for how it turned out. #1164 got picked up again in #1252, which also covers the Applied state issue from my review here, and it has now been merged, so I'm closing this one as superseded. I really appreciate the time you put into it, and I hope to see more PRs from you!

@debba debba closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat]: Choose case sensitivity for PostgreSQL text filters

3 participants