Skip to content

feat(wip): started working on category sets#369

Draft
ErikBjare wants to merge 2 commits intomasterfrom
dev/category-sets
Draft

feat(wip): started working on category sets#369
ErikBjare wants to merge 2 commits intomasterfrom
dev/category-sets

Conversation

@ErikBjare
Copy link
Copy Markdown
Member

@ErikBjare ErikBjare commented Sep 9, 2022

TODO

  • Make Activity view actually pick up the current category set
  • Check that import & export works as expected (move buttons a bit)
    • What should happen on duplicate import? Add suffix to ID of imported set?

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 9, 2022

Codecov Report

Base: 25.58% // Head: 25.23% // Decreases project coverage by -0.35% ⚠️

Coverage data is based on head (03f310f) compared to base (1980a40).
Patch coverage: 34.17% of modified lines in pull request are covered.

❗ Current head 03f310f differs from pull request most recent head 8b9d085. Consider uploading reports for the commit 8b9d085 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #369      +/-   ##
==========================================
- Coverage   25.58%   25.23%   -0.36%     
==========================================
  Files          26       26              
  Lines        1442     1474      +32     
  Branches      226      233       +7     
==========================================
+ Hits          369      372       +3     
- Misses       1020     1048      +28     
- Partials       53       54       +1     
Impacted Files Coverage Δ
src/util/color.ts 31.66% <0.00%> (ø)
src/util/classes.ts 69.42% <16.12%> (-13.41%) ⬇️
src/stores/categories.ts 58.09% <46.80%> (-5.07%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@lgtm-com
Copy link
Copy Markdown
Contributor

lgtm-com Bot commented Sep 9, 2022

This pull request introduces 1 alert when merging 03f310f into 1980a40 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link
Copy Markdown
Contributor

lgtm-com Bot commented Sep 24, 2022

This pull request introduces 1 alert when merging 8b9d085 into 1980a40 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

TimeToBuildBob added a commit to TimeToBuildBob/aw-webui that referenced this pull request Apr 15, 2026
…lti-set combining

Implements category sets from ActivityWatch#369 (Erik's 2022 WIP) with an
extended data model supporting priority-ordered combining of multiple active sets.

## What's new

- **CategorySet type** (`src/util/classes.ts`): `{ id: string; categories: Category[] }`
- **mergeCategorySets()**: merges sets in priority order (first = highest); more specific
  rules still win within a set, set order breaks ties
- **Settings store**: new `category_sets: CategorySet[]` + `active_set_ids: string[]` fields
  persisted alongside the legacy `classes` field (backwards compatible)
- **Categories store**: full CRUD for sets (`createSet`, `deleteSet`, `switchToSet`,
  `setActiveSets`, `renameSet`); `classes` always reflects the merged effective categories
  from all active sets; migration path for existing users (wraps legacy `classes` in a
  "default" set on first load)
- **CategorizationSettings UI**: set switcher dropdown, New/Delete buttons, per-set export

## Design notes

- `active_set_ids: string[]` data model supports combining; UI v1 exposes single-set
  switching — multi-set combining UI can follow in a subsequent PR
- Legacy `classes` field kept in sync for backwards compat with external readers
- `save()` syncs edits back to the primary active set before persisting all sets
- Import handles both legacy `{ categories: [] }` and new `{ id, categories }` formats

Closes / supersedes ActivityWatch#369
ErikBjare pushed a commit that referenced this pull request Apr 24, 2026
…lti-set combining (#804)

* feat(categorization): add category sets — named rule profiles with multi-set combining

Implements category sets from #369 (Erik's 2022 WIP) with an
extended data model supporting priority-ordered combining of multiple active sets.

## What's new

- **CategorySet type** (`src/util/classes.ts`): `{ id: string; categories: Category[] }`
- **mergeCategorySets()**: merges sets in priority order (first = highest); more specific
  rules still win within a set, set order breaks ties
- **Settings store**: new `category_sets: CategorySet[]` + `active_set_ids: string[]` fields
  persisted alongside the legacy `classes` field (backwards compatible)
- **Categories store**: full CRUD for sets (`createSet`, `deleteSet`, `switchToSet`,
  `setActiveSets`, `renameSet`); `classes` always reflects the merged effective categories
  from all active sets; migration path for existing users (wraps legacy `classes` in a
  "default" set on first load)
- **CategorizationSettings UI**: set switcher dropdown, New/Delete buttons, per-set export

## Design notes

- `active_set_ids: string[]` data model supports combining; UI v1 exposes single-set
  switching — multi-set combining UI can follow in a subsequent PR
- Legacy `classes` field kept in sync for backwards compat with external readers
- `save()` syncs edits back to the primary active set before persisting all sets
- Import handles both legacy `{ categories: [] }` and new `{ id, categories }` formats

Closes / supersedes #369

* fix(categorization): remove unused loadClasses import

* fix(categorization): fix P1 bugs found in Greptile review

- syncToPrimarySet: skip when multiple sets are active
  When active_set_ids.length > 1, state.classes is the merged result
  of all active sets. Writing it back to only the primary set would
  absorb all secondary sets' categories into it (data corruption).
  Now a no-op in multi-set mode until proper de-merge logic is added.

- onSetChange discard bypass: call discardChanges() before switchToSet()
  Without this, confirming "discard" still called switchToSet() which
  called syncToPrimarySet() first, writing the unsaved edits back into
  the primary set's in-memory state. Now we explicitly reset in-memory
  classes from the stored sets before switching.

- Add discardChanges() action to categories store
  Resets state.classes from stored sets without syncing back. Separates
  the "reload from sets" operation from "switch to set", enabling clean
  discard semantics.

* fix(categorization): fix P2 bugs in import/export identified by Greptile

- exportClasses: use classes_clean instead of activeSet.categories so
  unsaved in-memory edits are included in the export (was silently
  omitting any edits made since last save/switch)

- importCategories (active-set case): call discardChanges() instead of
  switchToSet() when importing into the currently active set. switchToSet
  calls syncToPrimarySet first which overwrites the just-imported
  categories with stale in-memory classes, making the import a silent
  no-op. discardChanges recomputes classes from the updated set data
  without the destructive sync.
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.

1 participant