026ed949fb
Related to #5
7.9 KiB
7.9 KiB
Plan: Implement Independent Tags for Quick Commands
This plan outlines the steps to add a tagging and grouping feature for Quick Commands, ensuring the tag system is completely separate from the existing tag system used for SSH Connections.
1. Database Migration (packages/backend/src/database/migrations.ts)
- Goal: Add two new tables to the database schema to manage quick command specific tags and their associations.
- Steps:
- Analyze
migrations.tsto understand the current migration process (Done - uses versioned migrations). - Add a new migration (e.g.,
id: 2,name: 'Create quick_command_tags table'):- SQL:
CREATE TABLE IF NOT EXISTS quick_command_tags (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')), updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))); - Include a
checkfunction usingtableExists(db, 'quick_command_tags').
- SQL:
- Add another new migration (e.g.,
id: 3,name: 'Create quick_command_tag_associations table'):- SQL:
CREATE TABLE IF NOT EXISTS quick_command_tag_associations (quick_command_id INTEGER NOT NULL, tag_id INTEGER NOT NULL, PRIMARY KEY (quick_command_id, tag_id), FOREIGN KEY (quick_command_id) REFERENCES quick_commands(id) ON DELETE CASCADE, FOREIGN KEY (tag_id) REFERENCES quick_command_tags(id) ON DELETE CASCADE); - Include a
checkfunction usingtableExists(db, 'quick_command_tag_associations').
- SQL:
- Analyze
2. Database Schema (packages/backend/src/database/schema.ts)
- Goal: Keep schema definitions consistent.
- Steps:
- Add
createQuickCommandTagsTableSQLconstant with the SQL from Migration 2. - Add
createQuickCommandTagAssociationsTableSQLconstant with the SQL from Migration 3.
- Add
3. Backend (packages/backend)
-
Goal: Create dedicated modules for managing quick command tags and integrate them with the existing quick command logic.
-
New Module: Quick Command Tags
repositories/quick-command-tag.repository.ts:- Define
QuickCommandTaginterface (id,name,created_at,updated_at). - Implement CRUD functions for
quick_command_tagstable (findAll,findById,create,update,delete). - Implement functions to manage
quick_command_tag_associations:setCommandTagAssociations(commandId: number, tagIds: number[]): Promise<boolean>(Transactional: delete old, insert new).findTagsByCommandId(commandId: number): Promise<QuickCommandTag[]>(JOINquick_command_tag_associationsandquick_command_tags).- (Optional)
addTagAssociation,removeTagAssociation.
- Define
services/quick-command-tag.service.ts:- Inject
QuickCommandTagRepository. - Implement business logic for managing quick command tags (validation, orchestration).
- Inject
quick-command-tags/quick-command-tag.controller.ts&quick-command-tags/quick-command-tag.routes.ts:- Create new API endpoints (e.g.,
POST /quick-command-tags,GET /quick-command-tags,PUT /quick-command-tags/:id,DELETE /quick-command-tags/:id). - Inject
QuickCommandTagService. - Handle HTTP requests/responses.
- Create new API endpoints (e.g.,
-
Modify Module: Quick Commands
repositories/quick-commands.repository.ts:- Update
QuickCommandinterface (or createQuickCommandWithTags) to includetagIds: number[](referencingquick_command_tags.id). - Modify
getAllQuickCommandsandfindQuickCommandById: UseLEFT JOIN quick_command_tag_associationsandGROUP_CONCATto fetchtag_ids_str, parse intotagIdsarray.
- Update
services/quick-commands.service.ts:- Inject new
QuickCommandTagRepositoryorQuickCommandTagService. - Modify
addQuickCommandsignature: accepttagIds?: number[]. Implementation: call repoaddQuickCommand, then call new repo/servicesetCommandTagAssociations. - Modify
updateQuickCommandsignature: accepttagIds?: number[]. Implementation: call repoupdateQuickCommand, then call new repo/servicesetCommandTagAssociations. - Modify
getAllQuickCommandsreturn type to includetagIds.
- Inject new
quick-commands/quick-commands.controller.ts:- Modify
addQuickCommandandupdateQuickCommandrequest validation to accept optionaltagIds: number[]. - Pass
tagIdsto the service layer. - Ensure
getAllQuickCommandsresponse includestagIds.
- Modify
4. Frontend (packages/frontend)
-
Goal: Create a dedicated state management for quick command tags and update the UI to display grouped commands and allow tag selection.
-
Types (
types/quick-commands.types.tsor similar):- Update
QuickCommandinterface to includetagIds: number[].
- Update
-
New Store (
stores/quickCommandTags.store.ts):- Define
QuickCommandTaginterface (matching backend). - State:
tags: ref<QuickCommandTag[]>,isLoading,error. - Actions:
fetchTags(from/quick-command-tags),addTag,updateTag,deleteTag. Include caching logic if desired.
- Define
-
Modify Store (
stores/quickCommands.store.ts):- Inject new
useQuickCommandTagsStore. - State: Add
expandedGroups: ref<Record<string, boolean>>({}). - Actions:
- Add
toggleGroup(groupName: string)action (manageexpandedGroups, potentially save to localStorage). - Modify
fetchQuickCommands: Fetch data includingtagIdsfrom/quick-commands. RemovesortByAPI parameter. - Modify
addQuickCommand,updateQuickCommand: SendtagIdsin the request body. - Modify
incrementUsage: Adjust logic if sorting is now purely frontend within groups.
- Add
- Getters:
- Rewrite
filteredAndSortedCommands(or createfilteredAndGroupedCommands):- Filter
quickCommandsListbysearchTerm. - Use
quickCommandTagsStore.tagsto group filtered commands bytagIds(create "Untagged" group). - Sort commands within each group based on
sortBystate. - Sort groups (e.g., alphabetically).
- Return nested structure:
Array<{ groupName: string; tagId: number | null; commands: QuickCommandFE[] }>.
- Filter
- Add
flatVisibleCommands: Compute a flat list of commands only from currently expanded groups.
- Rewrite
- Keyboard Navigation Actions (
selectNextCommand,selectPreviousCommand): Modify to operate onflatVisibleCommandsandselectedIndex. - Caching: Re-evaluate or simplify caching strategy.
- Inject new
-
Modify View (
views/QuickCommandsView.vue):<template>:- Use nested
v-forto iterate through grouped data from the store. - Render clickable group headers with expand/collapse icons, bound to
expandedGroupsstate andtoggleGroupaction. - Render command items (
<li>) within each group.
- Use nested
<script>:- Inject new
useQuickCommandTagsStore. - Bind template to new/modified store getters (
filteredAndGroupedCommands,expandedGroups). - Adjust keyboard navigation highlighting based on
flatVisibleCommandsandselectedIndex. - Modify
scrollToSelectedto find the correct DOM element based on the selected command inflatVisibleCommands.
- Inject new
-
Modify Component (
components/AddEditQuickCommandForm.vue):- Inject new
useQuickCommandTagsStore. - Add a tag selection UI component (e.g., multi-select dropdown, chip input using
TagInput.vueif adaptable, or a new component).- Populate options using
quickCommandTagsStore.tags. - Allow creating new tags (calling
quickCommandTagsStore.addTag). - Bind selected
tagIdsto form state.
- Populate options using
- Modify form submission logic to include
tagIdswhen callingquickCommandsStore.add/updateQuickCommand.
- Inject new