Skip to content

Commit b1d033e

Browse files
olaurendeauAntoLC
authored andcommitted
🩹(frontend) handle properly emojis in interlinking
Emoji in interlinking were not replacing the default icon when present.
1 parent 192fa76 commit b1d033e

File tree

4 files changed

+105
-57
lines changed

4 files changed

+105
-57
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import {
1313
} from './utils-common';
1414
import { getEditor, openSuggestionMenu, writeInEditor } from './utils-editor';
1515
import { connectOtherUserToDoc, updateShareLink } from './utils-share';
16-
import { createRootSubPage, navigateToPageFromTree } from './utils-sub-pages';
16+
import {
17+
createRootSubPage,
18+
getTreeRow,
19+
navigateToPageFromTree,
20+
} from './utils-sub-pages';
1721

1822
test.beforeEach(async ({ page }) => {
1923
await page.goto('/');
@@ -728,7 +732,13 @@ test.describe('Doc Editor', () => {
728732

729733
await verifyDocName(page, docChild2);
730734

731-
await page.locator('.bn-block-outer').last().fill('/');
735+
const treeRow = await getTreeRow(page, docChild2);
736+
await treeRow.locator('.--docs--doc-icon').click();
737+
await page.getByRole('button', { name: '😀' }).first().click();
738+
739+
await navigateToPageFromTree({ page, title: docChild1 });
740+
741+
await openSuggestionMenu({ page });
732742
await page.getByText('Link a doc').first().click();
733743

734744
const input = page.locator(
@@ -742,6 +752,16 @@ test.describe('Doc Editor', () => {
742752
await expect(searchContainer.getByText(docChild1)).toBeVisible();
743753
await expect(searchContainer.getByText(docChild2)).toBeVisible();
744754

755+
const searchContainerRow = searchContainer
756+
.getByRole('option')
757+
.filter({
758+
hasText: docChild2,
759+
})
760+
.first();
761+
762+
await expect(searchContainerRow).toContainText('😀');
763+
await expect(searchContainerRow.locator('svg').first()).toBeHidden();
764+
745765
await input.pressSequentially('-child');
746766

747767
await expect(searchContainer.getByText(docChild1)).toBeVisible();
@@ -756,32 +776,30 @@ test.describe('Doc Editor', () => {
756776
await expect(searchContainer).toBeHidden();
757777

758778
// Wait for the interlink to be created and rendered
759-
const editor = page.locator('.ProseMirror.bn-editor');
779+
const editor = await getEditor({ page });
760780

761-
const interlink = editor.getByRole('button', {
781+
const interlinkChild2 = editor.getByRole('button', {
762782
name: docChild2,
763783
});
764784

765-
await expect(interlink).toBeVisible({ timeout: 10000 });
766-
await interlink.click();
785+
await expect(interlinkChild2).toBeVisible({ timeout: 10000 });
786+
await expect(interlinkChild2).toContainText('😀');
787+
await expect(interlinkChild2.locator('svg').first()).toBeHidden();
788+
await interlinkChild2.click();
767789

768790
await verifyDocName(page, docChild2);
769-
});
770-
771-
test('it checks interlink shortcut @', async ({ page, browserName }) => {
772-
const [randomDoc] = await createDoc(page, 'doc-interlink', browserName, 1);
773-
774-
await verifyDocName(page, randomDoc);
775791

776-
const editor = page.locator('.bn-block-outer').last();
777792
await editor.click();
793+
778794
await page.keyboard.press('@');
795+
await input.fill(docChild1);
796+
await searchContainer.getByText(docChild1).click();
779797

780-
await expect(
781-
page.locator(
782-
"span[data-inline-content-type='interlinkingSearchInline'] input",
783-
),
784-
).toBeVisible();
798+
const interlinkChild1 = editor.getByRole('button', {
799+
name: docChild1,
800+
});
801+
await expect(interlinkChild1).toBeVisible({ timeout: 10000 });
802+
await expect(interlinkChild1.locator('svg').first()).toBeVisible();
785803
});
786804

787805
test('it checks multiple big doc scroll to the top', async ({

src/frontend/apps/impress/src/features/docs/doc-editor/assets/doc-found.svg

Lines changed: 1 addition & 7 deletions
Loading

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-inline-content/Interlinking/InterlinkingLinkInlineContent.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { css } from 'styled-components';
77
import { BoxButton, Text } from '@/components';
88
import { useCunninghamTheme } from '@/cunningham';
99
import SelectedPageIcon from '@/docs/doc-editor/assets/doc-selected.svg';
10-
import { useDoc } from '@/docs/doc-management';
10+
import { getEmojiAndTitle, useDoc } from '@/docs/doc-management';
1111

1212
export const InterlinkingLinkInlineContent = createReactInlineContentSpec(
1313
{
@@ -52,6 +52,8 @@ interface LinkSelectedProps {
5252
}
5353
const LinkSelected = ({ url, title }: LinkSelectedProps) => {
5454
const { colorsTokens } = useCunninghamTheme();
55+
56+
const { emoji, titleWithoutEmoji } = getEmojiAndTitle(title);
5557
const router = useRouter();
5658

5759
const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
@@ -78,9 +80,21 @@ const LinkSelected = ({ url, title }: LinkSelectedProps) => {
7880
transition: background-color 0.2s ease-in-out;
7981
`}
8082
>
81-
<SelectedPageIcon width={11.5} color={colorsTokens['primary-400']} />
82-
<Text $weight="500" spellCheck="false" $size="16px" $display="inline">
83-
{title}
83+
{emoji ? (
84+
<Text $size="16px">{emoji}</Text>
85+
) : (
86+
<SelectedPageIcon width={11.5} color={colorsTokens['primary-400']} />
87+
)}
88+
<Text
89+
$weight="500"
90+
spellCheck="false"
91+
$size="16px"
92+
$display="inline"
93+
$css={css`
94+
margin-left: 2px;
95+
`}
96+
>
97+
{titleWithoutEmoji}
8498
</Text>
8599
</BoxButton>
86100
);

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-inline-content/Interlinking/SearchPage.tsx

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import FoundPageIcon from '@/docs/doc-editor/assets/doc-found.svg';
2626
import AddPageIcon from '@/docs/doc-editor/assets/doc-plus.svg';
2727
import {
28+
getEmojiAndTitle,
2829
useCreateChildDocTree,
2930
useDocStore,
3031
useTrans,
@@ -236,35 +237,56 @@ export const SearchPage = ({
236237

237238
editor.focus();
238239
}}
239-
renderElement={(doc) => (
240-
<QuickSearchItemContent
241-
left={
242-
<Box
243-
$direction="row"
244-
$gap="0.6rem"
245-
$align="center"
246-
$padding={{ vertical: '0.5rem', horizontal: '0.2rem' }}
247-
$width="100%"
248-
>
249-
<FoundPageIcon style={{ flexShrink: 0 }} />
250-
<Text
251-
$size="14px"
252-
$color="var(--c--theme--colors--greyscale-1000)"
253-
spellCheck="false"
240+
renderElement={(doc) => {
241+
const { emoji, titleWithoutEmoji } = getEmojiAndTitle(
242+
doc.title || untitledDocument,
243+
);
244+
245+
return (
246+
<QuickSearchItemContent
247+
left={
248+
<Box
249+
$direction="row"
250+
$gap="0.2rem"
251+
$align="center"
252+
$padding={{ vertical: '0.5rem', horizontal: '0.2rem' }}
253+
$width="100%"
254254
>
255-
{doc.title}
256-
</Text>
257-
</Box>
258-
}
259-
right={
260-
<Icon
261-
iconName="keyboard_return"
262-
$variation="600"
263-
spellCheck="false"
264-
/>
265-
}
266-
/>
267-
)}
255+
<Box
256+
$css={css`
257+
width: 24px;
258+
flex-shrink: 0;
259+
`}
260+
>
261+
{emoji ? (
262+
<Text $size="18px">{emoji}</Text>
263+
) : (
264+
<FoundPageIcon
265+
width="100%"
266+
style={{ maxHeight: '24px' }}
267+
/>
268+
)}
269+
</Box>
270+
271+
<Text
272+
$size="14px"
273+
$color="var(--c--theme--colors--greyscale-1000)"
274+
spellCheck="false"
275+
>
276+
{titleWithoutEmoji}
277+
</Text>
278+
</Box>
279+
}
280+
right={
281+
<Icon
282+
iconName="keyboard_return"
283+
$variation="600"
284+
spellCheck="false"
285+
/>
286+
}
287+
/>
288+
);
289+
}}
268290
/>
269291
<QuickSearchGroup
270292
group={{

0 commit comments

Comments
 (0)