Skip to content

Commit f5e28a1

Browse files
authored
fix(organizations): show all sidebar chats (#7697)
1 parent a89b158 commit f5e28a1

2 files changed

Lines changed: 30 additions & 88 deletions

File tree

apps/sim/app/o/[organizationId]/components/organization-sidebar/components/chats-section/chats-section.test.tsx

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -98,60 +98,22 @@ async function render(props: Partial<Parameters<typeof ChatsSection>[0]> = {}) {
9898
}
9999

100100
describe('ChatsSection', () => {
101-
it('shows five chats with the workspace-style See more and See less controls', async () => {
101+
it('shows all chats without pagination controls', async () => {
102102
await render()
103-
expect(container.querySelectorAll('a[href^="/o/org-1/chat/"]')).toHaveLength(5)
104-
const more = Array.from(container.querySelectorAll('button')).find(
105-
(button) => button.textContent === 'See more'
106-
)!
107-
await act(async () => more.click())
108103
expect(container.querySelectorAll('a[href^="/o/org-1/chat/"]')).toHaveLength(8)
109-
const less = Array.from(container.querySelectorAll('button')).find(
110-
(button) => button.textContent === 'See less'
111-
)!
112-
await act(async () => less.click())
113-
expect(container.querySelectorAll('a[href^="/o/org-1/chat/"]')).toHaveLength(5)
104+
expect(container.textContent).not.toContain('See more')
105+
expect(container.textContent).not.toContain('See less')
114106
})
115107

116108
it('marks the chat on the current route active', async () => {
117-
await render({ pathname: '/o/org-1/chat/chat-3' })
109+
await render({ pathname: '/o/org-1/chat/chat-8' })
118110

119-
const current = container.querySelector('a[href="/o/org-1/chat/chat-3"]')
111+
const current = container.querySelector('a[href="/o/org-1/chat/chat-8"]')
120112
const other = container.querySelector('a[href="/o/org-1/chat/chat-4"]')
121113
expect(current?.className).toContain('surface-active')
122114
expect(other?.className).not.toContain('surface-active')
123115
})
124116

125-
it('keeps a bookmarked chat visible when collapsing expanded history', async () => {
126-
await render({ pathname: CHATS[5].href })
127-
expect(container.querySelectorAll('a[href^="/o/org-1/chat/"]')).toHaveLength(6)
128-
expect(container.querySelector(`a[href="${CHATS[5].href}"]`)?.className).toContain(
129-
'surface-active'
130-
)
131-
const more = Array.from(container.querySelectorAll('button')).find(
132-
(button) => button.textContent === 'See more'
133-
)!
134-
await act(async () => more.click())
135-
expect(container.querySelectorAll('a[href^="/o/org-1/chat/"]')).toHaveLength(8)
136-
const less = Array.from(container.querySelectorAll('button')).find(
137-
(button) => button.textContent === 'See less'
138-
)!
139-
await act(async () => less.click())
140-
expect(container.querySelectorAll('a[href^="/o/org-1/chat/"]')).toHaveLength(6)
141-
expect(container.querySelector(`a[href="${CHATS[5].href}"]`)).not.toBeNull()
142-
})
143-
144-
it('derives the visible range from the route without retaining automatic expansion', async () => {
145-
await render({ pathname: CHATS[7].href })
146-
expect(container.querySelectorAll('a[href^="/o/org-1/chat/"]')).toHaveLength(8)
147-
expect(container.textContent).not.toContain('See more')
148-
expect(container.textContent).not.toContain('See less')
149-
150-
await render({ pathname: null })
151-
expect(container.querySelectorAll('a[href^="/o/org-1/chat/"]')).toHaveLength(5)
152-
expect(container.textContent).toContain('See more')
153-
})
154-
155117
it.each([false, true])('renames via the options menu with collapsed=%s', async (isCollapsed) => {
156118
hoverState.isOpen = isCollapsed
157119
await render({ isCollapsed })

apps/sim/app/o/[organizationId]/components/organization-sidebar/components/chats-section/chats-section.tsx

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use client'
22

3-
import { useState } from 'react'
43
import {
5-
Chip,
64
ChipInput,
75
chipVariants,
86
cn,
@@ -117,8 +115,6 @@ interface ChatsSectionProps {
117115
pathname: string | null
118116
}
119117

120-
const PAGE_SIZE = 5
121-
122118
export function ChatsSection({
123119
organizationId,
124120
chats,
@@ -128,10 +124,6 @@ export function ChatsSection({
128124
}: ChatsSectionProps) {
129125
const actions = useOrganizationChatActions({ organizationId, chats })
130126
const { menu, hover, rename, selectedChat } = actions
131-
const [requestedCount, setRequestedCount] = useState(PAGE_SIZE)
132-
const minimumCount = Math.max(PAGE_SIZE, chats.findIndex((chat) => chat.href === pathname) + 1)
133-
const visibleCount = Math.min(chats.length, Math.max(requestedCount, minimumCount))
134-
const hasMore = chats.length > visibleCount
135127
const menuOpenChatId = menu.isOpen ? selectedChat?.id : null
136128
const saveRename = () => {
137129
void rename.saveRename()
@@ -192,43 +184,31 @@ export function ChatsSection({
192184
No chats yet
193185
</div>
194186
)}
195-
{chats
196-
.slice(0, visibleCount)
197-
.map((chat) =>
198-
rename.editingId === chat.id ? (
199-
<ChipInput
200-
key={chat.id}
201-
ref={rename.inputRef}
202-
aria-label={`Rename chat ${chat.name}`}
203-
value={rename.value}
204-
onChange={(event) => rename.setValue(event.target.value)}
205-
onKeyDown={rename.handleKeyDown}
206-
onBlur={saveRename}
207-
disabled={rename.isSaving}
208-
maxLength={100}
209-
autoComplete='off'
210-
/>
211-
) : (
212-
<ChatRow
213-
key={chat.id}
214-
chat={chat}
215-
isCurrentRoute={pathname === chat.href}
216-
isMenuOpen={menuOpenChatId === chat.id}
217-
onContextMenu={actions.onContextMenu}
218-
onMorePointerDown={actions.onMorePointerDown}
219-
onMoreClick={actions.onMoreClick}
220-
/>
221-
)
222-
)}
223-
{(hasMore || visibleCount > minimumCount) && (
224-
<Chip
225-
fullWidth
226-
onClick={() =>
227-
setRequestedCount(hasMore ? visibleCount + PAGE_SIZE : PAGE_SIZE)
228-
}
229-
>
230-
{hasMore ? 'See more' : 'See less'}
231-
</Chip>
187+
{chats.map((chat) =>
188+
rename.editingId === chat.id ? (
189+
<ChipInput
190+
key={chat.id}
191+
ref={rename.inputRef}
192+
aria-label={`Rename chat ${chat.name}`}
193+
value={rename.value}
194+
onChange={(event) => rename.setValue(event.target.value)}
195+
onKeyDown={rename.handleKeyDown}
196+
onBlur={saveRename}
197+
disabled={rename.isSaving}
198+
maxLength={100}
199+
autoComplete='off'
200+
/>
201+
) : (
202+
<ChatRow
203+
key={chat.id}
204+
chat={chat}
205+
isCurrentRoute={pathname === chat.href}
206+
isMenuOpen={menuOpenChatId === chat.id}
207+
onContextMenu={actions.onContextMenu}
208+
onMorePointerDown={actions.onMorePointerDown}
209+
onMoreClick={actions.onMoreClick}
210+
/>
211+
)
232212
)}
233213
</>
234214
)}

0 commit comments

Comments
 (0)