Repository navigation
feat(categories): support field-scoped regex rules - #840
Conversation
Greptile SummaryThis PR adds optional
Confidence Score: 5/5Safe to merge; all changed production paths correctly honour field-scoped rules and the modal normalises select_keys on both load and save. The field-scoping logic is correctly implemented in both No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as CategoryEditModal
participant CL as classes.ts
participant TL as Timeline.vue
participant CO as color.ts
Note over UI: User saves category with select_keys
UI->>CL: cleanCategory(cat) strips invalid/empty select_keys
UI->>CL: saveClasses([...])
Note over TL: Category filter applied
TL->>CO: getCategorizationStringFromEvent(bucket, e)
CO-->>TL: str (e.g. "Firefox\nSession notes")
TL->>CL: matchString(str, allCats, e)
CL->>CL: getRuleSelectKeys(rule) returns ['app'] or CLASSIFY_KEYS
CL->>CL: re.test(e.data[key]) for each selected key
CL-->>TL: matched Category or null
Note over CO: Event colour lookup
CO->>CO: getCategorizationStringFromEvent(bucket, e)
CO->>CL: matchString(str, allCats, e)
CL->>CL: field-scoped test via select_keys
CL-->>CO: matched Category or null
CO->>CO: getColorFromCategory(c, allCats) or fallbackColor(str)
Reviews (4): Last reviewed commit: "test(categories): add direct matchString..." | Re-trigger Greptile |
| const rule = _.cloneDeep(cat.rule); | ||
| if (rule.type === 'regex') { | ||
| rule.select_keys = rule.select_keys ? [...rule.select_keys] : []; | ||
| } |
There was a problem hiding this comment.
When
resetModal is called for a category whose rule type is not regex (e.g., none), select_keys is never set on the cloned rule object. If the user then changes the type dropdown to regex, editing.rule.select_keys is undefined rather than [], and the b-form-checkbox-group v-model starts in an undefined state. While Vue 3's proxy may recover on the first selection, the initial render could produce a warning and the "Leave blank to match all fields" path would silently produce no-op checkbox state instead of a clean empty array.
| const rule = _.cloneDeep(cat.rule); | |
| if (rule.type === 'regex') { | |
| rule.select_keys = rule.select_keys ? [...rule.select_keys] : []; | |
| } | |
| const rule = _.cloneDeep(cat.rule); | |
| rule.select_keys = rule.type === 'regex' && rule.select_keys ? [...rule.select_keys] : []; |
There was a problem hiding this comment.
Fixed in 30b6dee — resetModal now initializes select_keys to [] regardless of the existing rule type (not just when type is already regex), so switching a none-rule to regex always starts the checkbox group with a valid empty array.
Also added a direct matchString unit test for the event-based field-scoping path in b1bedfd (the second Greptile finding from the re-review).
…r paths matchString now accepts an optional IEvent; when provided and the category has select_keys set, it tests only those specific fields instead of the pre-concatenated string. Without the event the existing behavior is preserved (backward-compatible). Callers updated: - Timeline.vue: passes e to matchString so category filter honors select_keys - color.ts: getCategoryColorFromEvent calls matchString directly with the event instead of routing through getCategoryColorFromString Also ensures select_keys is always initialized to [] in resetModal regardless of the existing rule type, so switching a none-rule to regex gives the checkbox group a valid empty array instead of undefined. Addresses Greptile review findings on PR ActivityWatch#840.
|
Fixed both findings in 30b6dee: P1 (matchString ignores select_keys): Updated P2 (select_keys undefined on rule-type switch): |
|
Greptile's re-review (on 30b6dee) correctly notes that The three views that do have raw events — Timeline filtering, Happy to track that as a follow-up if it matters. |
…lect_keys scoping Greptile noted the new event path in matchString lacked a direct unit test. Added matchString-with-event test covering: - event + select_keys matches only the specified field (app hit, title-only miss) - fallback to string matching when no event is provided
|
@greptileai review |
|
All Greptile findings from the review cycles have been addressed — the latest re-review came back at 5/5 confidence, safe to merge. Quick recap of what changed since the initial draft:
Happy to rebase or make any tweaks @ErikBjare — otherwise this should be ready to merge. |
Summary
select_keyssupport to the web UI regex rule shapeVerification
./node_modules/.bin/jest --runInBand test/unit/classes.test.node.ts test/unit/store/categories.test.node.ts./node_modules/.bin/eslint src/util/classes.ts src/components/CategoryEditModal.vueCloses #823