-
Notifications
You must be signed in to change notification settings - Fork 13.8k
fix: GIF/rich attachment collapse state resetting on message list scroll #41783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nazabucciarelli
wants to merge
9
commits into
develop
Choose a base branch
from
fix/giphy-collapse-state-scroll
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0b671a
fix: GIF/rich attachment collapse state resetting on message list scroll
nazabucciarelli b7d00c7
add recursive logic to keep mounted nested attachments
nazabucciarelli 52e28d2
change of approach, use a context to store collapsed state of message…
nazabucciarelli 24e42da
delete previous changeset
nazabucciarelli 72dfa1b
make each message attachment able to be toggled independently
nazabucciarelli ff31382
add cache bound
nazabucciarelli c0c0781
renaming from "messages" to "attachments"
nazabucciarelli 6a0082e
remove unneeded comments
nazabucciarelli 9d8f02d
reset store between tests
nazabucciarelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Fixes an issue where message attachments lose their collapsed state when scrolled out of view. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
apps/meteor/client/components/message/content/attachments/DefaultAttachment.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
|
|
||
| import DefaultAttachment from './DefaultAttachment'; | ||
| import { collapseToggleStore } from '../../../../views/room/MessageList/contexts/CollapsedAttachmentsContext'; | ||
|
|
||
| beforeEach(() => { | ||
| collapseToggleStore.toggledAttachments.clear(); | ||
| }); | ||
|
|
||
| const giphyAttachment = (collapseKey: string | undefined) => ({ | ||
| collapseKey, | ||
| title: 'GIPHY', | ||
| image_url: 'https://media.giphy.com/foo.gif', | ||
| image_alt: 'a fun gif', | ||
| }); | ||
|
|
||
| it('should render expanded by default and collapse on toggle click', async () => { | ||
| render(<DefaultAttachment {...giphyAttachment('message-1-0')} />, { wrapper: mockAppRoot().build() }); | ||
| expect(screen.getByRole('img')).toBeInTheDocument(); | ||
|
|
||
| await userEvent.click(screen.getByTitle('Collapse')); | ||
| expect(screen.queryByRole('img')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should keep a manually collapsed attachment collapsed after the row unmounts and remounts (simulating virtua recycling it on scroll)', async () => { | ||
| const attachment = giphyAttachment('message-2-0'); | ||
| const { unmount } = render(<DefaultAttachment {...attachment} />, { wrapper: mockAppRoot().build() }); | ||
|
|
||
| await userEvent.click(screen.getByTitle('Collapse')); | ||
| expect(screen.queryByRole('img')).not.toBeInTheDocument(); | ||
|
|
||
| unmount(); | ||
|
|
||
| render(<DefaultAttachment {...attachment} />, { wrapper: mockAppRoot().build() }); | ||
| expect(screen.queryByRole('img')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should keep a manually expanded attachment expanded after unmount/remount when collapsed by default', async () => { | ||
| const attachment = { ...giphyAttachment('message-3-0'), collapsed: true }; | ||
|
|
||
| const { unmount } = render(<DefaultAttachment {...attachment} />, { wrapper: mockAppRoot().build() }); | ||
| expect(screen.queryByRole('img')).not.toBeInTheDocument(); | ||
|
|
||
| await userEvent.click(screen.getByTitle('Uncollapse')); | ||
| expect(screen.getByRole('img')).toBeInTheDocument(); | ||
|
|
||
| unmount(); | ||
|
|
||
| render(<DefaultAttachment {...attachment} />, { wrapper: mockAppRoot().build() }); | ||
| expect(screen.getByRole('img')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should not affect other messages when one is toggled', async () => { | ||
| const { unmount } = render(<DefaultAttachment {...giphyAttachment('message-4a-0')} />, { wrapper: mockAppRoot().build() }); | ||
| await userEvent.click(screen.getByTitle('Collapse')); | ||
|
|
||
| unmount(); | ||
|
|
||
| render(<DefaultAttachment {...giphyAttachment('message-4b-0')} />, { wrapper: mockAppRoot().build() }); | ||
| expect(screen.getByRole('img')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should toggle attachments within the same message independently', async () => { | ||
| const { unmount } = render(<DefaultAttachment {...giphyAttachment('message-5-0')} />, { | ||
| wrapper: mockAppRoot().build(), | ||
| }); | ||
| await userEvent.click(screen.getByTitle('Collapse')); | ||
|
|
||
| unmount(); | ||
|
|
||
| render(<DefaultAttachment {...giphyAttachment('message-5-1')} />, { wrapper: mockAppRoot().build() }); | ||
| expect(screen.getByRole('img')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should still toggle via local state when there is no collapseKey (e.g. the composer quote preview)', async () => { | ||
| render(<DefaultAttachment {...giphyAttachment(undefined)} />, { wrapper: mockAppRoot().build() }); | ||
| expect(screen.getByRole('img')).toBeInTheDocument(); | ||
|
|
||
| await userEvent.click(screen.getByTitle('Collapse')); | ||
| expect(screen.queryByRole('img')).not.toBeInTheDocument(); | ||
|
|
||
| await userEvent.click(screen.getByTitle('Uncollapse')); | ||
| expect(screen.getByRole('img')).toBeInTheDocument(); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.