-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Add mentions feature to objects in notes #16373
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
Merged
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
1ae428a
feat: add mention inline content spec for notes mentions
acee3 6581b92
feat: add mention menu dropdown UI
acee3 b314708
feat: add mention menu data hook
acee3 5a39f3f
feat: integrate mention menu into block editor with click-outside beh…
acee3 ad66b21
fix: Made in-line styling of tags more consistent to not cut-off any …
acee3 b7646fc
fix: Changed wrong limit statement to first statement in graphql query
acee3 086267a
fix: Undid fix to change limit to first
acee3 9895165
fix: Make limit on retrieved items actually work by following similar…
acee3 fc01449
fix: Add error handling to rendering of mentions
acee3 f68dd72
fix: Updated to remove race condition with async function
acee3 b7aa32f
refactor: remove duplicated code
acee3 22979fb
fix: Fixed the padding issue of the scrollable dropdown by moving the…
acee3 70a2728
chore: set width of menu to 240px
acee3 df513d9
feat: Added name of object as subtitle
acee3 89070fb
fix: Added image icon to the chip component and centered it
acee3 80f59f8
Merge branch 'main' into acee3/add-mentions
acee3 a0204fc
Merge branch 'main' into acee3/add-mentions
acee3 bc83f4a
fix: Added permissions check
acee3 1855124
core: remove redundant code
acee3 f91b558
Merge branch 'main' into acee3/add-mentions
FelixMalfait b743445
Merge branch 'main' into acee3/add-mentions
FelixMalfait 512774b
Improvements
FelixMalfait ca247d3
Fix mention fallback ordering and use isDefined/isNonEmptyString util…
FelixMalfait 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
63 changes: 63 additions & 0 deletions
63
packages/twenty-front/src/modules/activities/blocks/components/MentionInlineContent.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,63 @@ | ||
| import { RecordChip } from '@/object-record/components/RecordChip'; | ||
| import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord'; | ||
| import { createReactInlineContentSpec } from '@blocknote/react'; | ||
| import styled from '@emotion/styled'; | ||
|
|
||
| const StyledRecordChip = styled(RecordChip)` | ||
| height: auto; | ||
| margin: 0; | ||
| padding: ${({ theme }) => `0 ${theme.spacing(1)}`}; | ||
| `; | ||
|
|
||
| const MentionInlineContentRenderer = ({ | ||
| recordId, | ||
| objectNameSingular, | ||
| }: { | ||
| recordId: string; | ||
| objectNameSingular: string; | ||
| }) => { | ||
| const { record } = useFindOneRecord({ | ||
| objectNameSingular, | ||
| objectRecordId: recordId, | ||
| skip: !objectNameSingular || !recordId, | ||
| }); | ||
|
|
||
| if (!record || !objectNameSingular) { | ||
| return <span>@mention</span>; | ||
| } | ||
|
|
||
| return ( | ||
| <StyledRecordChip | ||
| objectNameSingular={objectNameSingular} | ||
| record={record} | ||
| forceDisableClick={false} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export const MentionInlineContent = createReactInlineContentSpec( | ||
| { | ||
| type: 'mention' as const, | ||
| propSchema: { | ||
| recordId: { | ||
| default: '' as const, | ||
| }, | ||
| objectNameSingular: { | ||
| default: '' as const, | ||
| }, | ||
| }, | ||
| content: 'none', | ||
| }, | ||
| { | ||
| render: (props) => { | ||
| const { recordId, objectNameSingular } = props.inlineContent.props; | ||
|
|
||
| return ( | ||
| <MentionInlineContentRenderer | ||
| recordId={recordId} | ||
| objectNameSingular={objectNameSingular} | ||
| /> | ||
| ); | ||
| }, | ||
| }, | ||
| ); |
11 changes: 10 additions & 1 deletion
11
packages/twenty-front/src/modules/activities/blocks/constants/Schema.ts
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 |
|---|---|---|
| @@ -1,10 +1,19 @@ | ||
| import { BlockNoteSchema, defaultBlockSpecs } from '@blocknote/core'; | ||
| import { | ||
| BlockNoteSchema, | ||
| defaultBlockSpecs, | ||
| defaultInlineContentSpecs, | ||
| } from '@blocknote/core'; | ||
|
|
||
| import { FileBlock } from '@/activities/blocks/components/FileBlock'; | ||
| import { MentionInlineContent } from '../components/MentionInlineContent'; | ||
|
|
||
| export const BLOCK_SCHEMA = BlockNoteSchema.create({ | ||
| blockSpecs: { | ||
| ...defaultBlockSpecs, | ||
| file: FileBlock, | ||
| }, | ||
| inlineContentSpecs: { | ||
| ...defaultInlineContentSpecs, | ||
| mention: MentionInlineContent, | ||
| }, | ||
| }); |
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
2 changes: 2 additions & 0 deletions
2
packages/twenty-front/src/modules/ui/input/constants/MentionMenuDropdownClickOutsideId.ts
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,2 @@ | ||
| export const MENTION_MENU_DROPDOWN_CLICK_OUTSIDE_ID = | ||
| 'mention-menu-dropdown-click-outside-id'; |
1 change: 1 addition & 0 deletions
1
packages/twenty-front/src/modules/ui/input/constants/MentionMenuListId.ts
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 @@ | ||
| export const MENTION_MENU_LIST_ID = 'mention-menu-list-id'; |
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
105 changes: 105 additions & 0 deletions
105
packages/twenty-front/src/modules/ui/input/editor/components/CustomMentionMenu.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,105 @@ | ||
| import styled from '@emotion/styled'; | ||
| import { autoUpdate, useFloating } from '@floating-ui/react'; | ||
| import { motion } from 'framer-motion'; | ||
| import { useEffect, type MouseEvent as ReactMouseEvent } from 'react'; | ||
| import { createPortal } from 'react-dom'; | ||
|
|
||
| import { MENTION_MENU_DROPDOWN_CLICK_OUTSIDE_ID } from '@/ui/input/constants/MentionMenuDropdownClickOutsideId'; | ||
| import { MENTION_MENU_LIST_ID } from '@/ui/input/constants/MentionMenuListId'; | ||
| import { CustomMentionMenuListItem } from '@/ui/input/editor/components/CustomMentionMenuListItem'; | ||
| import { | ||
| type CustomMentionMenuProps, | ||
| type MentionItem, | ||
| } from '@/ui/input/editor/components/types'; | ||
| import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent'; | ||
| import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer'; | ||
| import { OverlayContainer } from '@/ui/layout/overlay/components/OverlayContainer'; | ||
| import { SelectableList } from '@/ui/layout/selectable-list/components/SelectableList'; | ||
| import { useSelectableList } from '@/ui/layout/selectable-list/hooks/useSelectableList'; | ||
| import { isDefined } from 'twenty-shared/utils'; | ||
|
|
||
| export type { MentionItem }; | ||
|
|
||
| const MenuPixelWidth = 240; | ||
|
|
||
| const StyledContainer = styled.div` | ||
| height: 1px; | ||
| width: 1px; | ||
| `; | ||
|
|
||
| export const CustomMentionMenu = ({ | ||
| items, | ||
| selectedIndex, | ||
| }: CustomMentionMenuProps) => { | ||
| const { refs, floatingStyles } = useFloating({ | ||
| placement: 'bottom-start', | ||
| whileElementsMounted: autoUpdate, | ||
| }); | ||
|
|
||
| const { setSelectedItemId } = useSelectableList(MENTION_MENU_LIST_ID); | ||
|
|
||
| useEffect(() => { | ||
| if (!isDefined(selectedIndex) || !isDefined(items)) return; | ||
|
|
||
| const selectedItem = items[selectedIndex]; | ||
|
|
||
| if (isDefined(selectedItem) && isDefined(selectedItem.recordId)) { | ||
| setSelectedItemId(selectedItem.recordId); | ||
| } | ||
| }, [items, selectedIndex, setSelectedItemId]); | ||
|
|
||
| const handleContainerClick = (e: ReactMouseEvent) => { | ||
| e.stopPropagation(); | ||
| }; | ||
|
|
||
| if (!isDefined(items) || items.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const filteredItems = items.filter( | ||
| (item) => isDefined(item.recordId) && isDefined(item.objectNameSingular), | ||
| ); | ||
|
|
||
| return ( | ||
| <StyledContainer ref={refs.setReference}> | ||
| <> | ||
| {createPortal( | ||
| <motion.div | ||
| initial={{ opacity: 0 }} | ||
| animate={{ opacity: 1 }} | ||
| transition={{ duration: 0.1 }} | ||
| onClick={handleContainerClick} | ||
| > | ||
| <OverlayContainer | ||
| ref={refs.setFloating} | ||
| style={floatingStyles} | ||
| data-click-outside-id={MENTION_MENU_DROPDOWN_CLICK_OUTSIDE_ID} | ||
| > | ||
| <DropdownContent widthInPixels={MenuPixelWidth}> | ||
| <DropdownMenuItemsContainer hasMaxHeight> | ||
| <SelectableList | ||
| focusId={MENTION_MENU_DROPDOWN_CLICK_OUTSIDE_ID} | ||
| selectableListInstanceId={MENTION_MENU_LIST_ID} | ||
| selectableItemIdArray={filteredItems.map( | ||
| (item) => item.recordId!, | ||
| )} | ||
| > | ||
| {filteredItems.map((item) => ( | ||
| <CustomMentionMenuListItem | ||
| key={item.recordId!} | ||
| recordId={item.recordId!} | ||
| onClick={() => item.onItemClick()} | ||
| objectNameSingular={item.objectNameSingular!} | ||
| /> | ||
| ))} | ||
| </SelectableList> | ||
| </DropdownMenuItemsContainer> | ||
| </DropdownContent> | ||
| </OverlayContainer> | ||
| </motion.div>, | ||
| document.body, | ||
| )} | ||
| </> | ||
| </StyledContainer> | ||
| ); | ||
| }; | ||
70 changes: 70 additions & 0 deletions
70
packages/twenty-front/src/modules/ui/input/editor/components/CustomMentionMenuListItem.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,70 @@ | ||
| import { type MouseEvent } from 'react'; | ||
|
|
||
| import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; | ||
| import { getAvatarType } from '@/object-metadata/utils/getAvatarType'; | ||
| import { searchRecordStoreFamilyState } from '@/object-record/record-picker/multiple-record-picker/states/searchRecordStoreComponentFamilyState'; | ||
| import { MENTION_MENU_LIST_ID } from '@/ui/input/constants/MentionMenuListId'; | ||
| import { SelectableListItem } from '@/ui/layout/selectable-list/components/SelectableListItem'; | ||
| import { useSelectableList } from '@/ui/layout/selectable-list/hooks/useSelectableList'; | ||
| import { isSelectedItemIdComponentFamilySelector } from '@/ui/layout/selectable-list/states/selectors/isSelectedItemIdComponentFamilySelector'; | ||
| import { useRecoilComponentFamilyValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyValue'; | ||
| import { useRecoilValue } from 'recoil'; | ||
| import { isDefined } from 'twenty-shared/utils'; | ||
| import { Avatar } from 'twenty-ui/display'; | ||
| import { MenuItemSuggestion } from 'twenty-ui/navigation'; | ||
|
|
||
| type CustomMentionMenuListItemProps = { | ||
| recordId: string; | ||
| onClick: () => void; | ||
| objectNameSingular: string; | ||
| }; | ||
|
|
||
| export const CustomMentionMenuListItem = ({ | ||
| recordId, | ||
| onClick, | ||
| objectNameSingular, | ||
| }: CustomMentionMenuListItemProps) => { | ||
| const { resetSelectedItem } = useSelectableList(MENTION_MENU_LIST_ID); | ||
|
|
||
| const isSelectedItem = useRecoilComponentFamilyValue( | ||
| isSelectedItemIdComponentFamilySelector, | ||
| recordId, | ||
| ); | ||
|
|
||
| // Get the search record from the store (same pattern as SingleRecordPickerMenuItem) | ||
| const searchRecord = useRecoilValue(searchRecordStoreFamilyState(recordId)); | ||
|
|
||
| const { objectMetadataItem } = useObjectMetadataItem({ objectNameSingular }); | ||
|
|
||
| const handleClick = (event?: MouseEvent) => { | ||
| event?.preventDefault(); | ||
| event?.stopPropagation(); | ||
| resetSelectedItem(); | ||
| onClick(); | ||
| }; | ||
|
|
||
| if (!isDefined(searchRecord)) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <SelectableListItem itemId={recordId} onEnter={handleClick}> | ||
| <MenuItemSuggestion | ||
| selected={isSelectedItem} | ||
| onClick={handleClick} | ||
| text={`${searchRecord.label}`} | ||
| contextualText={objectMetadataItem.labelSingular} | ||
| contextualTextPosition="left" | ||
| LeftIcon={() => ( | ||
| <Avatar | ||
| placeholder={searchRecord.label} | ||
| placeholderColorSeed={recordId} | ||
| avatarUrl={searchRecord.imageUrl} | ||
| type={getAvatarType(objectNameSingular) ?? 'rounded'} | ||
| size="sm" | ||
| /> | ||
| )} | ||
| /> | ||
| </SelectableListItem> | ||
| ); | ||
| }; |
16 changes: 12 additions & 4 deletions
16
packages/twenty-front/src/modules/ui/input/editor/components/types.ts
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 |
|---|---|---|
| @@ -1,11 +1,19 @@ | ||
| import type { SuggestionMenuProps } from '@blocknote/react'; | ||
| import type { | ||
| DefaultReactSuggestionItem, | ||
| SuggestionMenuProps, | ||
| } from '@blocknote/react'; | ||
| import { type IconComponent } from 'twenty-ui/display'; | ||
|
|
||
| export type SuggestionItem = { | ||
| title: string; | ||
| onItemClick: () => void; | ||
| export type SuggestionItem = DefaultReactSuggestionItem & { | ||
| aliases?: string[]; | ||
| Icon?: IconComponent; | ||
| }; | ||
|
|
||
| export type CustomSlashMenuProps = SuggestionMenuProps<SuggestionItem>; | ||
|
|
||
| export type MentionItem = DefaultReactSuggestionItem & { | ||
| recordId?: string; | ||
| objectNameSingular?: string; | ||
acee3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| export type CustomMentionMenuProps = SuggestionMenuProps<MentionItem>; | ||
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.