Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,10 @@ export const RichCommentEditor = ({
HTMLAttributes: { class: 'mention' },
suggestion: {
char: '@',
items: ({ query, editor }: { query: string; editor: Editor }) => {
const mentionedIds = new Set(
extractMentions(editor, optionsRef.current).map(person => person.id)
);

items: ({ query }: { query: string }) => {
return optionsRef.current
.filter(
person =>
!mentionedIds.has(person.id) &&
person.name.toLowerCase().includes(query.toLowerCase())
.filter(person =>
person.name.toLowerCase().includes(query.toLowerCase())
)
.slice(0, MAX_SUGGESTIONS);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
color: #40a9ff;
}

.description-editor-shell .description-content .mentions {
font-weight: 500;
.description-editor-shell .description-content .mentions,
.description-editor-shell .ql-editor .mentions {
display: inline-block;
padding: 0 4px;
border-radius: 4px;
padding: 1px 4px;
margin: 0 1px;
background-color: #f0f2f5;
font-weight: 500;
background-color: rgba(24, 144, 255, 0.12);
color: #1890ff;
border: 1px solid #1890ff;
margin-inline: 1px;
border: none;
}

.description-editor-shell .description-editor-preview {
Expand Down Expand Up @@ -126,10 +128,9 @@
color: #74c0fc;
}

.description-editor-shell.is-dark .description-content .mentions {
background-color: #1f3344;
.description-editor-shell.is-dark .description-content .mentions,
.description-editor-shell.is-dark .ql-editor .mentions {
color: #69b1ff;
border-color: #69b1ff;
}

.description-editor-shell.is-dark .description-editor-preview {
Expand Down Expand Up @@ -303,22 +304,6 @@ ol.ql-nested-list {
margin-bottom: 0 !important;
}

.description-editor-shell .ql-editor .mentions {
font-weight: 500;
border-radius: 4px;
padding: 1px 4px;
margin: 0 1px;
background-color: #f0f2f5;
color: #1890ff;
border: 1px solid #1890ff;
}

.description-editor-shell.is-dark .ql-editor .mentions {
background-color: #1f3344;
color: #69b1ff;
border-color: #69b1ff;
}

.description-mention-suggestions {
position: fixed;
z-index: 1100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { projectCommentsApiService } from '@/api/projects/comments/project-comme

const quillMock = vi.hoisted(() => ({
formatText: vi.fn(),
format: vi.fn(),
register: vi.fn(),
}));

Expand Down Expand Up @@ -50,6 +51,7 @@ vi.mock('react-quill-new', async () => {
getSelection: () => { index: number; length: number };
getBounds: () => { left: number; top: number; bottom: number };
getFormat: () => Record<string, unknown>;
format: (...args: unknown[]) => void;
formatText: (...args: unknown[]) => void;
deleteText: (index: number, length: number) => void;
insertText: (index: number, text: string) => void;
Expand All @@ -61,11 +63,12 @@ vi.mock('react-quill-new', async () => {
value?: string;
defaultValue?: string;
onChange: (value: string) => void;
onChangeSelection?: () => void;
onKeyDown?: React.KeyboardEventHandler<HTMLTextAreaElement>;
}

const MockQuill = React.forwardRef<{ getEditor: () => MockEditor }, MockProps>(
({ value, defaultValue, onChange, onKeyDown }, ref) => {
({ value, defaultValue, onChange, onChangeSelection, onKeyDown }, ref) => {
const initialValue = value ?? defaultValue ?? '';
const [editorValue, setEditorValue] = React.useState(initialValue);
const valueRef = React.useRef(initialValue);
Expand All @@ -91,6 +94,7 @@ vi.mock('react-quill-new', async () => {
getSelection: () => ({ index: cursorRef.current, length: 0 }),
getBounds: () => ({ left: 0, top: 0, bottom: 20 }),
getFormat: () => ({}),
format: (...args) => quillMock.format(...args),
formatText: (...args) => quillMock.formatText(...args),
deleteText: (index, length) =>
commit(
Expand Down Expand Up @@ -121,6 +125,7 @@ vi.mock('react-quill-new', async () => {
const nextValue = event.target.value;
commit(nextValue, nextValue.length);
}}
onSelect={onChangeSelection}
onKeyDown={onKeyDown}
/>
</div>
Expand All @@ -144,6 +149,7 @@ describe('DescriptionEditor', () => {
beforeEach(() => {
vi.mocked(projectCommentsApiService.getMentionMembers).mockReset();
quillMock.formatText.mockClear();
quillMock.format.mockClear();
quillMock.register.mockClear();
});

Expand Down Expand Up @@ -235,6 +241,7 @@ describe('DescriptionEditor', () => {
fireEvent.mouseDown(suggestion);

expect(textarea).toHaveValue('@Alice Example ');
expect(quillMock.format).toHaveBeenCalledWith('mention', false, 'user');
await waitFor(() =>
expect(quillMock.formatText).toHaveBeenCalledWith(0, 14, 'mention', true, 'silent')
);
Expand Down Expand Up @@ -265,6 +272,54 @@ describe('DescriptionEditor', () => {
);
});

it('preserves mention marks while members load and clears stale marks after lookup succeeds', async () => {
let resolveMembers!: (
response: Awaited<ReturnType<typeof projectCommentsApiService.getMentionMembers>>
) => void;
vi.mocked(projectCommentsApiService.getMentionMembers).mockReturnValue(
new Promise(resolve => {
resolveMembers = resolve;
})
);

render(
<DescriptionEditor
description='<p><span class="mentions">@Former Member</span></p>'
taskId="task-123"
parentTaskId={null}
projectId="project-123"
/>
);

fireEvent.click(screen.getByText('@Former Member'));
const textarea = await screen.findByTestId('mock-quill-textarea');
await waitFor(() => expect(projectCommentsApiService.getMentionMembers).toHaveBeenCalled());

fireEvent.select(textarea);
expect(quillMock.formatText).not.toHaveBeenCalledWith(
expect.any(Number),
expect.any(Number),
'mention',
false,
'silent'
);

resolveMembers({
done: true,
body: [{ id: 'member-1', name: 'Alice Example', role: <span /> }],
});

await waitFor(() =>
expect(quillMock.formatText).toHaveBeenCalledWith(
expect.any(Number),
expect.any(Number),
'mention',
false,
'silent'
)
);
});

it('closes mention suggestions on Escape without discarding the draft', async () => {
vi.mocked(projectCommentsApiService.getMentionMembers).mockResolvedValue({
done: true,
Expand Down
Loading
Loading