Repository navigation
fix(datagrid): keep the column and operator a highlight rule was given - #3027
Merged
Merged
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Signed-off-by: Ngô Quốc Đạt <[email protected]>
Signed-off-by: Ngô Quốc Đạt <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:MainEditorContentViewholds@ObservedObject HighlightRuleStorage.sharedand rebuilds the whole status bar on every rule write, handsHighlightRulesPopovera 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 Rulelooked fine the whole time, and that is the tell: it also writesfocusedRuleID, a@Stateof the popover, and a@Statewrite 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.addRuleandMainContentCoordinator.presentHighlightRulesuse.equal;HighlightMenuBuilder.quickRuleuses.equal, or.isNull/.isEmptyon 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.
HighlightRulesPopoverholds the rules in@State, seeded ininitthe wayFilterSettingsPopoverseeds its settings, and every edit writes that@Stateand then callsonChangeto carry it out. A@Statewrite is what invalidates the view, so an edit both shows and composes with the next one.Adding
@ObservedObjectto the popover also works and was measured working, but it only covers the one store it names, and these rules live inHighlightRuleStoragefor a table and onQueryTabfor 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), sobinding.field = xis a whole-value get-modify-set through the parent binding's owngetandset. 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 aswiftcprobe against the real chain:Binding.transactiondoes 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.selectingOperatorkeeps the existing no-op guard, so reselecting the operator already in force leaves a hand-set Match Case alone.AppearanceSettingsView.slotThemeBindingis 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:Added(5 chars)customer_shipping_postal_code(29)FilterRowView.swift:189-194already 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.regularExpressionswallows the compile error,matchesRegexthen answers false for every row, and nothing looked at the nil, so a half-typed^(Livehighlighted 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, andactiveRuleCountstops counting it.isValidis deliberately unchanged, becausediscardIncompleteHighlightRuleswould then silently delete a half-typed pattern when the popover closes.Verified
Built and run in an isolated worktree off
main.buildtest(6 suites, incl. the new one)uitest HighlightRulesUITestslint(every changed file)docsHighlightRuleEditingTestsis 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.HighlightRulesUITestsgains 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 untouchedmain.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
HighlightRulesUITestscases, which assert the exact values the recording shows snapping back.