Skip to content

Commit 75da342

Browse files
committed
🏷️(frontend) adapt types to link-configuration endpoint
The link-configuration endpoint has now a strict validation schema about the combination of link_reach and link_role. We need to adapt our types frontend side to reflect that.
1 parent 1ed01fd commit 75da342

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,9 @@ test.describe('Doc Header', () => {
434434
test('it pins a document', async ({ page, browserName }) => {
435435
const [docTitle] = await createDoc(page, `Pin doc`, browserName);
436436

437-
await page.getByLabel('Open the document options').click();
437+
await page
438+
.getByRole('button', { name: 'Open the document options' })
439+
.click();
438440

439441
// Pin
440442
await page.getByText('push_pin').click();
@@ -453,11 +455,15 @@ test.describe('Doc Header', () => {
453455
await expect(leftPanelFavorites.getByText(docTitle)).toBeVisible();
454456

455457
await row.getByText(docTitle).click();
456-
await page.getByLabel('Open the document options').click();
458+
await page
459+
.getByRole('button', { name: 'Open the document options' })
460+
.click();
457461

458462
// Unpin
459463
await page.getByText('Unpin').click();
460-
await page.getByLabel('Open the document options').click();
464+
await page
465+
.getByRole('button', { name: 'Open the document options' })
466+
.click();
461467
await expect(page.getByText('push_pin')).toBeVisible();
462468

463469
await page.goto('/');

src/frontend/apps/impress/src/features/docs/doc-management/types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface Doc {
6060
path: string;
6161
is_favorite: boolean;
6262
link_reach: LinkReach;
63-
link_role: LinkRole;
63+
link_role?: LinkRole;
6464
nb_accesses_direct: number;
6565
nb_accesses_ancestors: number;
6666
computed_link_reach: LinkReach;

src/frontend/apps/impress/src/features/docs/doc-management/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import emojiRegex from 'emoji-regex';
22
import * as Y from 'yjs';
33

4-
import { Doc, LinkReach, LinkRole } from './types';
4+
import { Doc, LinkReach } from './types';
55

66
export const base64ToYDoc = (base64: string) => {
77
const uint8Array = Buffer.from(base64, 'base64');
@@ -18,7 +18,7 @@ export const getDocLinkReach = (doc: Doc): LinkReach => {
1818
return doc.computed_link_reach ?? doc.link_reach;
1919
};
2020

21-
export const getDocLinkRole = (doc: Doc): LinkRole => {
21+
export const getDocLinkRole = (doc: Doc): Doc['link_role'] => {
2222
return doc.computed_link_role ?? doc.link_role;
2323
};
2424

src/frontend/apps/impress/src/features/docs/doc-share/components/DocVisibility.tsx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,18 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
5454
const linkReachOptions: DropdownMenuOption[] = useMemo(() => {
5555
return Object.values(LinkReach).map((key) => {
5656
const isDisabled = doc.abilities.link_select_options[key] === undefined;
57+
let linkRole = undefined;
58+
if (key !== LinkReach.RESTRICTED) {
59+
linkRole = docLinkRole;
60+
}
5761

5862
return {
5963
label: linkReachTranslations[key],
6064
callback: () =>
6165
updateDocLink({
6266
id: doc.id,
6367
link_reach: key,
68+
link_role: linkRole,
6469
}),
6570
isSelected: docLinkReach === key,
6671
disabled: isDisabled,
@@ -70,6 +75,7 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
7075
doc.abilities.link_select_options,
7176
doc.id,
7277
docLinkReach,
78+
docLinkRole,
7379
linkReachTranslations,
7480
updateDocLink,
7581
]);
@@ -78,7 +84,8 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
7884
(option) => option.disabled,
7985
);
8086

81-
const showLinkRoleOptions = doc.computed_link_reach !== LinkReach.RESTRICTED;
87+
const showLinkRoleOptions =
88+
docLinkReach !== LinkReach.RESTRICTED && docLinkRole;
8289

8390
const linkRoleOptions: DropdownMenuOption[] = useMemo(() => {
8491
const options = doc.abilities.link_select_options[docLinkReach] ?? [];
@@ -175,26 +182,24 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
175182
</Box>
176183
{showLinkRoleOptions && (
177184
<Box $direction="row" $align="center" $gap={spacingsTokens['3xs']}>
178-
{docLinkReach !== LinkReach.RESTRICTED && (
179-
<DropdownMenu
180-
testId="doc-access-mode"
181-
disabled={!canManage}
182-
showArrow={true}
183-
options={linkRoleOptions}
184-
topMessage={
185-
haveDisabledLinkRoleOptions
186-
? t(
187-
'You cannot restrict access to a subpage relative to its parent page.',
188-
)
189-
: undefined
190-
}
191-
label={t('Document access mode')}
192-
>
193-
<Text $weight="initial" $variation="600">
194-
{linkModeTranslations[docLinkRole]}
195-
</Text>
196-
</DropdownMenu>
197-
)}
185+
<DropdownMenu
186+
testId="doc-access-mode"
187+
disabled={!canManage}
188+
showArrow={true}
189+
options={linkRoleOptions}
190+
topMessage={
191+
haveDisabledLinkRoleOptions
192+
? t(
193+
'You cannot restrict access to a subpage relative to its parent page.',
194+
)
195+
: undefined
196+
}
197+
label={t('Document access mode')}
198+
>
199+
<Text $weight="initial" $variation="600">
200+
{linkModeTranslations[docLinkRole]}
201+
</Text>
202+
</DropdownMenu>
198203
</Box>
199204
)}
200205
</Box>

0 commit comments

Comments
 (0)