-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add highlight words feature for messages and user preferences #6809
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
DSingh0304
wants to merge
8
commits into
RocketChat:develop
Choose a base branch
from
DSingh0304:feature/highlight-words
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.
+366
−16
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5ba5e44
feat: add highlight words feature for messages and user preferences
DSingh0304 b051e3c
fix: standardize highlights prop naming across components
DSingh0304 7080855
feat: enhance highlight words saving logic to prevent unnecessary upd…
DSingh0304 7910c34
fix: optimize highlights update logic and improve save conditions
DSingh0304 f753a37
fix: streamline highlights update dispatch and improve save logic
DSingh0304 786b786
feat: implement highlight words feature with tests and user preferenc…
DSingh0304 1589f1c
feat: enhance highlight words functionality with structured preferenc…
DSingh0304 2d741b7
Merge branch 'RocketChat:develop' into feature/highlight-words
DSingh0304 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,37 @@ | ||
|
|
||
| import React from 'react'; | ||
| import { View, StyleSheet } from 'react-native'; | ||
| import { NavigationContainer } from '@react-navigation/native'; | ||
|
|
||
| import Markdown from '.'; | ||
| import { themes } from '../../lib/constants/colors'; | ||
|
|
||
| const theme = 'light'; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| marginHorizontal: 15, | ||
| backgroundColor: themes[theme].surfaceRoom, | ||
| marginVertical: 50 | ||
| } | ||
| }); | ||
|
|
||
| export default { | ||
| title: 'Markdown/Highlights', | ||
| decorators: [ | ||
| (Story: any) => ( | ||
| <NavigationContainer> | ||
| <Story /> | ||
| </NavigationContainer> | ||
| ) | ||
| ] | ||
| }; | ||
|
|
||
| export const Highlights = () => ( | ||
| <View style={styles.container}> | ||
| <Markdown highlights={['rocket', 'Lorem', 'mixed']} msg={'This is Rocket.Chat — highlight the word rocket (case-insensitive).'} /> | ||
| <Markdown highlights={['rocket', 'Lorem', 'mixed']} msg={'Lorem ipsum dolor sit amet, this should highlight Lorem and mixed-case Mixed.'} /> | ||
| <Markdown highlights={['rocket', 'Lorem', 'mixed']} msg={'Edge cases: rockets, rocketing (only exact words defined will match).'} /> | ||
| </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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react-native'; | ||
|
|
||
| import { ThemeContext } from '../../../theme'; | ||
| import { colors as themeColors } from '../../../lib/constants/colors'; | ||
| import MarkdownContext from '../contexts/MarkdownContext'; | ||
| import Plain from './Plain'; | ||
|
|
||
| describe('Plain (highlights)', () => { | ||
| const colors = themeColors.light; | ||
|
|
||
| const getBackground = (node: any) => { | ||
| const { style } = node.props; | ||
| return Array.isArray(style) ? style.find((s: any) => s && s.backgroundColor)?.backgroundColor : style?.backgroundColor; | ||
| }; | ||
|
|
||
| it('renders highlighted words with theme highlight background', () => { | ||
| const tree = render( | ||
| <ThemeContext.Provider value={{ theme: 'light', colors }}> | ||
| <MarkdownContext.Provider value={{ highlights: ['rocket'] }}> | ||
| <Plain value={'hello rocket world'} /> | ||
| </MarkdownContext.Provider> | ||
| </ThemeContext.Provider> | ||
| ); | ||
|
|
||
| const highlighted = tree.getByText('rocket'); | ||
| expect(highlighted).toBeTruthy(); | ||
| expect(getBackground(highlighted)).toBe(colors.statusBackgroundDanger); | ||
| }); | ||
|
|
||
| it('is case-insensitive when matching highlight words', () => { | ||
| const tree = render( | ||
| <ThemeContext.Provider value={{ theme: 'light', colors }}> | ||
| <MarkdownContext.Provider value={{ highlights: ['Rocket'] }}> | ||
| <Plain value={'hello rocket world'} /> | ||
| </MarkdownContext.Provider> | ||
| </ThemeContext.Provider> | ||
| ); | ||
|
|
||
| const highlighted = tree.getByText('rocket'); | ||
| expect(highlighted).toBeTruthy(); | ||
| expect(getBackground(highlighted)).toBe(colors.statusBackgroundDanger); | ||
| }); | ||
|
|
||
| it('handles punctuation after words', () => { | ||
| const tree = render( | ||
| <ThemeContext.Provider value={{ theme: 'light', colors }}> | ||
| <MarkdownContext.Provider value={{ highlights: ['rocket'] }}> | ||
| <Plain value={'hello rocket, world!'} /> | ||
| </MarkdownContext.Provider> | ||
| </ThemeContext.Provider> | ||
| ); | ||
|
|
||
| const highlighted = tree.getByText('rocket'); | ||
| expect(highlighted).toBeTruthy(); | ||
| expect(getBackground(highlighted)).toBe(colors.statusBackgroundDanger); | ||
| }); | ||
|
|
||
| it('renders multiple highlights', () => { | ||
| const tree = render( | ||
| <ThemeContext.Provider value={{ theme: 'light', colors }}> | ||
| <MarkdownContext.Provider value={{ highlights: ['rocket', 'world'] }}> | ||
| <Plain value={'hello rocket world'} /> | ||
| </MarkdownContext.Provider> | ||
| </ThemeContext.Provider> | ||
| ); | ||
|
|
||
| const h1 = tree.getByText('rocket'); | ||
| const h2 = tree.getByText('world'); | ||
| expect(h1).toBeTruthy(); | ||
| expect(h2).toBeTruthy(); | ||
| expect(getBackground(h1)).toBe(colors.statusBackgroundDanger); | ||
| expect(getBackground(h2)).toBe(colors.statusBackgroundDanger); | ||
| }); | ||
|
|
||
| it('when no highlights configured returns full text and does not create separate highlighted nodes', () => { | ||
| const tree = render( | ||
| <ThemeContext.Provider value={{ theme: 'light', colors }}> | ||
| <MarkdownContext.Provider value={{ highlights: [] }}> | ||
| <Plain value={'hello rocket world'} /> | ||
| </MarkdownContext.Provider> | ||
| </ThemeContext.Provider> | ||
| ); | ||
|
|
||
| const full = tree.getByText('hello rocket world'); | ||
| expect(full).toBeTruthy(); | ||
| // there should be no separate node with text 'rocket' | ||
| const rocket = tree.queryByText('rocket'); | ||
| expect(rocket).toBeNull(); | ||
| }); | ||
| }); | ||
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
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
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.
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.