Skip to content

Auto delete through tabs lifecycle hook#1572

Merged
yujonglee merged 7 commits intomainfrom
tab-lifecycle-close
Oct 15, 2025
Merged

Auto delete through tabs lifecycle hook#1572
yujonglee merged 7 commits intomainfrom
tab-lifecycle-close

Conversation

@yujonglee
Copy link
Contributor

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Refactors the monolithic tabs store into modular Zustand slices (schema, utils, basic, navigation, lifecycle, state), replaces the old store with a composed useTabs hook, adds tests and test utilities, updates app layout to register an on-close handler, refactors Devtool drawer, and tweaks timeline sidebar UI.

Changes

Cohort / File(s) Summary of changes
Sidebar Timeline UI
apps/desktop2/src/components/main/sidebar/timeline/index.tsx
Adjusts Button markup/classes, wraps icon+label in an inner div, and adds an absolute-positioned underline element whose position/color toggles with isScrolledPastToday and hover.
Devtool Drawer Refactor
apps/desktop2/src/devtool/index.tsx
Removes local seed state and inline seed rendering; introduces DevtoolSection, SeedList, SeedButton, NavigationList; replaces direct seed handling with a unified onSeed prop and adds router Link usage.
App Layout Close Hook
apps/desktop2/src/routes/app/main/_layout.tsx
Registers registerOnClose handler from useTabs; on closing a sessions tab fetches persisted row and deletes it if it exists and lacks metadata; effect registers/unregisters handler.
Old Tabs Store Removed
apps/desktop2/src/store/zustand/tabs.ts
Deletes the previous monolithic Zustand tab store and its types/helpers.
Tabs Store: Composition Entry
apps/desktop2/src/store/zustand/tabs/index.ts
Adds composed useTabs store by merging slices; re-exports Tab type and schema helpers (isSameTab, rowIdfromTab, tabSchema, uniqueIdfromTab).
Tabs Store: Schema
apps/desktop2/src/store/zustand/tabs/schema.ts
Adds zod tabSchema (discriminated union for tab variants), Tab and TabHistory types, and helpers: rowIdfromTab, uniqueIdfromTab, isSameTab.
Tabs Store: Utilities
apps/desktop2/src/store/zustand/tabs/utils.ts
Adds history utilities and helpers: ACTIVE_TAB_SLOT_ID, getSlotId, notifyTabClose, notifyTabsClose, computeHistoryFlags, pushHistory, updateHistoryCurrent.
Tabs Store: Basic Slice
apps/desktop2/src/store/zustand/tabs/basic.ts
Implements core tab actions: setTabs, openCurrent, openNew, select, close, reorder; integrates history handling and close notifications.
Tabs Store: Navigation Slice
apps/desktop2/src/store/zustand/tabs/navigation.ts
Adds navigation state/actions: history: Map, canGoBack, canGoNext, and goBack/goNext implementations using per-slot history.
Tabs Store: Lifecycle Slice
apps/desktop2/src/store/zustand/tabs/lifecycle.ts
Adds lifecycle state and registerOnClose API that returns an unsubscribe function; manages onCloseHandlers immutably.
Tabs Store: State Updater Slice
apps/desktop2/src/store/zustand/tabs/state.ts
Adds updateSessionTabState and updateContactsTabState to update tab-specific state and synchronize currentTab and history.
Tests & Test Utils
apps/desktop2/src/store/zustand/tabs/*.test.ts, .../test-utils.ts
Adds basic.test.ts, lifecycle.test.ts, state.test.ts and test-utils.ts factories/reset helpers; updates navigation test import path to new index.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as App Layout
  participant Store as useTabs (lifecycle/basic)
  participant DB as persistedStore

  Note over UI,Store: Layout registers on-close handler at mount
  UI->>Store: registerOnClose(handler)
  Store-->>UI: unsubscribe()

  User->>Store: close(tab: sessions)
  Store->>Store: invoke onClose handlers
  Store->>UI: handler(tab)
  UI->>DB: fetch row by tab.id
  alt row exists && no metadata
    UI->>DB: delete row
  else
    Note right of UI: no deletion
  end
Loading
sequenceDiagram
  autonumber
  actor User
  participant Store as useTabs (basic/navigation)
  participant Utils as History Utils

  User->>Store: openCurrent(tabA)
  Store->>Utils: pushHistory(tabA)
  Store-->>User: state updated (currentTab=tabA)

  User->>Store: openNew(tabB)
  Store->>Utils: pushHistory(tabB)
  Store-->>User: state updated (currentTab=tabB)

  User->>Store: goBack()
  Store->>Utils: computeHistoryFlags & select previous
  Store-->>User: state updated (currentTab=tabA, flags)

  User->>Store: goNext()
  Store->>Utils: computeHistoryFlags & select next
  Store-->>User: state updated (currentTab=tabB, flags)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60–90 minutes

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is completely missing, providing no context or summary of the changes implemented in the changeset. Please add a descriptive summary that outlines the key changes and objectives of this pull request to help reviewers understand its scope and purpose.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title highlights the introduction of an auto-delete mechanism via a tabs lifecycle hook, which is indeed part of the changeset, even though the pull request also contains a broader refactor of the tab store into multiple slices. Because it refers to a real change in the code, it is partially related and meets the criteria for a passing title.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6cd7dfe and 4a23879.

📒 Files selected for processing (5)
  • apps/desktop2/src/store/zustand/tabs/basic.test.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/basic.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/lifecycle.test.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/state.test.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/test-utils.ts (1 hunks)

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
apps/desktop2/src/components/main/sidebar/timeline/index.tsx (1)

76-85: Consider using cn instead of clsx for consistency.

According to the coding guidelines for this path pattern, the cn utility should be used when composing Tailwind classNames with conditional logic. This button has conditional positioning logic, so switching from clsx to cn would align with the project's standards.

Apply this diff:

         <Button
           size="sm"
           variant="outline"
           onClick={scrollToToday}
-          className={clsx([
+          className={cn([
             "group",
             "relative",
             "absolute left-1/2 transform -translate-x-1/2",

Based on coding guidelines.

apps/desktop2/src/devtool/index.tsx (1)

151-196: LGTM! Clean refactoring with improved modularity.

The extraction of DevtoolSection, SeedList, SeedButton, and NavigationList components improves code organization and reusability. The implementation follows the coding guidelines correctly:

  • cn utility is used with arrays throughout
  • Tailwind classes are logically grouped
  • No unused code or unnecessary comments

Optional: Consider adding aria-labels for better accessibility.

To improve screen reader support, you could add descriptive aria-label attributes:

 function SeedButton({ seed, onClick }: { seed: SeedDefinition; onClick: () => void }) {
   return (
     <button
       type="button"
       onClick={onClick}
+      aria-label={`Apply ${seed.label} seed`}
       className={cn([

Similarly, the navigation links could benefit from more descriptive labels if needed, though the current text content is already clear.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12f9665 and 6cd7dfe.

📒 Files selected for processing (13)
  • apps/desktop2/src/components/main/sidebar/timeline/index.tsx (2 hunks)
  • apps/desktop2/src/devtool/index.tsx (4 hunks)
  • apps/desktop2/src/routes/app/main/_layout.tsx (1 hunks)
  • apps/desktop2/src/store/zustand/tabs.ts (0 hunks)
  • apps/desktop2/src/store/zustand/tabs/basic.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/index.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/lifecycle.test.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/lifecycle.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/navigation.test.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/navigation.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/schema.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/state.ts (1 hunks)
  • apps/desktop2/src/store/zustand/tabs/utils.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/desktop2/src/store/zustand/tabs.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,ts,tsx,rs}

⚙️ CodeRabbit configuration file

**/*.{js,ts,tsx,rs}: 1. Do not add any error handling. Keep the existing one.
2. No unused imports, variables, or functions.
3. For comments, keep it minimal. It should be about "Why", not "What".

Files:

  • apps/desktop2/src/store/zustand/tabs/navigation.ts
  • apps/desktop2/src/store/zustand/tabs/schema.ts
  • apps/desktop2/src/store/zustand/tabs/state.ts
  • apps/desktop2/src/routes/app/main/_layout.tsx
  • apps/desktop2/src/store/zustand/tabs/lifecycle.test.ts
  • apps/desktop2/src/store/zustand/tabs/basic.ts
  • apps/desktop2/src/components/main/sidebar/timeline/index.tsx
  • apps/desktop2/src/store/zustand/tabs/utils.ts
  • apps/desktop2/src/store/zustand/tabs/navigation.test.ts
  • apps/desktop2/src/store/zustand/tabs/lifecycle.ts
  • apps/desktop2/src/store/zustand/tabs/index.ts
  • apps/desktop2/src/devtool/index.tsx
apps/desktop2/**/*.{tsx,jsx}

📄 CodeRabbit inference engine (apps/desktop2/.cursor/rules/style.mdc)

apps/desktop2/**/*.{tsx,jsx}: When there are many Tailwind classNames with conditional logic, use the cn utility imported as import { cn } from "@hypr/ui/lib/utils"
Always pass an array to cn when composing Tailwind classNames
Split cn array entries by logical grouping when composing Tailwind classNames

Files:

  • apps/desktop2/src/routes/app/main/_layout.tsx
  • apps/desktop2/src/components/main/sidebar/timeline/index.tsx
  • apps/desktop2/src/devtool/index.tsx
🔇 Additional comments (1)
apps/desktop2/src/components/main/sidebar/timeline/index.tsx (1)

87-97: LGTM! Nice directional indicator UX.

The wrapper div cleanly separates the button content from the decorative underline, and the conditional positioning of the underline (opposite the button's own position) provides a clear visual cue pointing toward "Today."

@yujonglee yujonglee merged commit c9fa657 into main Oct 15, 2025
3 checks passed
@yujonglee yujonglee deleted the tab-lifecycle-close branch October 15, 2025 04:18
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

Comments