Skip to content

fix(datagrid): keep the column and operator a highlight rule was given - #3027

Merged
datlechin merged 3 commits into
mainfrom
fix/highlight-rule-selection-reverts
Sep 20, 2026
Merged

datlechin merged 3 commits into
mainfrom
fix/highlight-rule-selection-reverts

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #3015.

What was wrong

Picking a different column, or a different operator, in the Highlight Rules popover did nothing: the pull-down closed and went straight back to what it said before. The reporter's screen recording shows it twice, once on the column pull-down and once on the operator menu.

Root cause

SwiftUI does not re-evaluate a .popover's content when the view presenting it re-renders. Measured on this popover: MainEditorContentView holds @ObservedObject HighlightRuleStorage.shared and rebuilds the whole status bar on every rule write, hands HighlightRulesPopover a fresh [HighlightRule] each time, and the popover kept drawing the array it was first constructed with. So a pull-down wrote its new value to the store and then redrew from the stale copy, which is the snap-back.

Add Rule looked fine the whole time, and that is the tell: it also writes focusedRuleID, a @State of the popover, and a @State write is what actually invalidates that view. Picking a column or an operator writes no @State, so nothing redrew.

That made this much wider than two pull-downs. The only other places a rule is created hard-code their operator (HighlightRulesPopover.addRule and MainContentCoordinator.presentHighlightRules use .equal; HighlightMenuBuilder.quickRule uses .equal, or .isNull / .isEmpty on a null or empty cell). With the operator menu inert, every operator except those three has been unreachable for as long as the feature has shipped, and a rule's column could never be repointed after it was created.

The fix

The popover owns its editing model. HighlightRulesPopover holds the rules in @State, seeded in init the way FilterSettingsPopover seeds its settings, and every edit writes that @State and then calls onChange to carry it out. A @State write is what invalidates the view, so an edit both shows and composes with the next one.

Adding @ObservedObject to the popover also works and was measured working, but it only covers the one store it names, and these rules live in HighlightRuleStorage for a table and on QueryTab for a query result.

A coupled edit is one write. There is a second, independent defect in the same code, worth fixing on its own terms. Binding.subscript(dynamicMember:) is get-only (macOS 27 SDK, SwiftUICore.swiftinterface), so binding.field = x is a whole-value get-modify-set through the parent binding's own get and set. Both setters wrote two properties in a row, so the second resolved against the same starting value as the first and only the last survived. Measured with a swiftc probe against the real chain:

after write 1 (columnName = Artist):      columnName: "Artist"   <- lands
after write 2 (columnOccurrence = 0):     columnName: "Added"    <- clobbered
after write 1 (filterOperator = between): filterOperator: "between"
after write 2 (isCaseSensitive = false):  filterOperator: "equals"
single write only:                        columnName: "Artist"   <- survives

Binding.transaction does not coalesce and no SwiftUI API batches field writes, so each coupled edit is now one write of one whole value, expressed as a nonmutating transition on the model (HighlightRule.selectingColumn(named:occurrence:), selectingOperator(_:)) where a test can reach it. selectingOperator keeps the existing no-op guard, so reselecting the operator already in force leaves a hand-set Match Case alone. AppearanceSettingsView.slotThemeBinding is the same shape.

Two defects the fix makes reachable, so they ship with it

The column pull-down had no width cap. It was bare .fixedSize() inside a popover pinned to 540pt, and selecting between adds a second value field. Measured against the 523pt a row actually gets inside that list:

column name row with between
Added (5 chars) 444pt fits
customer_shipping_postal_code (29) 582pt clipped
62 characters 791pt clipped
either, capped at 140 511pt fits

FilterRowView.swift:189-194 already caps the identical control, with its own measured comment; this row was the copy that never got it. Its 160 does not fit here, because that row lives in a wider host.

An uncompilable regular expression was counted as an active rule. HighlightCondition.regularExpression swallows the compile error, matchesRegex then answers false for every row, and nothing looked at the nil, so a half-typed ^(Live highlighted nothing while the status bar still reported it among "N rules". The row now carries an Invalid pattern warning beside the existing Not in this result one, and activeRuleCount stops counting it. isValid is deliberately unchanged, because discardIncompleteHighlightRules would then silently delete a half-typed pattern when the popover closes.

Verified

Built and run in an isolated worktree off main.

step result
build PASS
test (6 suites, incl. the new one) PASS, 110 of 110
uitest HighlightRulesUITests PASS, 8 of 8
lint (every changed file) 0 violations
docs PASS

HighlightRuleEditingTests is new: it pins both transitions, the write count per edit, the single-property controls that were never broken, the warning precedence, and the active count. HighlightRulesUITests gains two cases that drive the real popover and assert the pull-downs hold their selection; both fail against the code before this change.

Worth stating plainly: an earlier revision of this fix, which only made the binding read live and the writes atomic, passed every unit test and still reverted in the app. The UI cases are what caught it, and they are also what caught a regression that revision introduced in the pre-existing testAddingARuleFromTheStatusBarKeepsItForTheTable, which was confirmed against a passing baseline run on untouched main.

Before / after

Not captured. The popover's controls are not reachable through the accessibility tree from a terminal-driven build, so the two states could not be scripted into stills; the data grid behind them cannot be driven by synthetic input at all since #2381. The reporter's recording on #3015 is the before. The after is covered by the two new HighlightRulesUITests cases, which assert the exact values the recording shows snapping back.

@mintlify

mintlify Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
TablePro 🟢 Ready View Preview Sep 20, 2026, 5:16 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@datlechin
datlechin merged commit afadf2f into main Sep 20, 2026
2 of 3 checks passed
@datlechin
datlechin deleted the fix/highlight-rule-selection-reverts branch September 20, 2026 17:17
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.

Select fields not working when trying to add highlighting rule

1 participant