🏷️(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.
This commit is contained in:
Anthony LC
2025-09-18 13:16:37 +02:00
parent 1ed01fd64b
commit 75da342058
4 changed files with 38 additions and 27 deletions

View File

@@ -434,7 +434,9 @@ test.describe('Doc Header', () => {
test('it pins a document', async ({ page, browserName }) => { test('it pins a document', async ({ page, browserName }) => {
const [docTitle] = await createDoc(page, `Pin doc`, browserName); const [docTitle] = await createDoc(page, `Pin doc`, browserName);
await page.getByLabel('Open the document options').click(); await page
.getByRole('button', { name: 'Open the document options' })
.click();
// Pin // Pin
await page.getByText('push_pin').click(); await page.getByText('push_pin').click();
@@ -453,11 +455,15 @@ test.describe('Doc Header', () => {
await expect(leftPanelFavorites.getByText(docTitle)).toBeVisible(); await expect(leftPanelFavorites.getByText(docTitle)).toBeVisible();
await row.getByText(docTitle).click(); await row.getByText(docTitle).click();
await page.getByLabel('Open the document options').click(); await page
.getByRole('button', { name: 'Open the document options' })
.click();
// Unpin // Unpin
await page.getByText('Unpin').click(); await page.getByText('Unpin').click();
await page.getByLabel('Open the document options').click(); await page
.getByRole('button', { name: 'Open the document options' })
.click();
await expect(page.getByText('push_pin')).toBeVisible(); await expect(page.getByText('push_pin')).toBeVisible();
await page.goto('/'); await page.goto('/');

View File

@@ -60,7 +60,7 @@ export interface Doc {
path: string; path: string;
is_favorite: boolean; is_favorite: boolean;
link_reach: LinkReach; link_reach: LinkReach;
link_role: LinkRole; link_role?: LinkRole;
nb_accesses_direct: number; nb_accesses_direct: number;
nb_accesses_ancestors: number; nb_accesses_ancestors: number;
computed_link_reach: LinkReach; computed_link_reach: LinkReach;

View File

@@ -1,7 +1,7 @@
import emojiRegex from 'emoji-regex'; import emojiRegex from 'emoji-regex';
import * as Y from 'yjs'; import * as Y from 'yjs';
import { Doc, LinkReach, LinkRole } from './types'; import { Doc, LinkReach } from './types';
export const base64ToYDoc = (base64: string) => { export const base64ToYDoc = (base64: string) => {
const uint8Array = Buffer.from(base64, 'base64'); const uint8Array = Buffer.from(base64, 'base64');
@@ -18,7 +18,7 @@ export const getDocLinkReach = (doc: Doc): LinkReach => {
return doc.computed_link_reach ?? doc.link_reach; return doc.computed_link_reach ?? doc.link_reach;
}; };
export const getDocLinkRole = (doc: Doc): LinkRole => { export const getDocLinkRole = (doc: Doc): Doc['link_role'] => {
return doc.computed_link_role ?? doc.link_role; return doc.computed_link_role ?? doc.link_role;
}; };

View File

@@ -54,6 +54,10 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
const linkReachOptions: DropdownMenuOption[] = useMemo(() => { const linkReachOptions: DropdownMenuOption[] = useMemo(() => {
return Object.values(LinkReach).map((key) => { return Object.values(LinkReach).map((key) => {
const isDisabled = doc.abilities.link_select_options[key] === undefined; const isDisabled = doc.abilities.link_select_options[key] === undefined;
let linkRole = undefined;
if (key !== LinkReach.RESTRICTED) {
linkRole = docLinkRole;
}
return { return {
label: linkReachTranslations[key], label: linkReachTranslations[key],
@@ -61,6 +65,7 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
updateDocLink({ updateDocLink({
id: doc.id, id: doc.id,
link_reach: key, link_reach: key,
link_role: linkRole,
}), }),
isSelected: docLinkReach === key, isSelected: docLinkReach === key,
disabled: isDisabled, disabled: isDisabled,
@@ -70,6 +75,7 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
doc.abilities.link_select_options, doc.abilities.link_select_options,
doc.id, doc.id,
docLinkReach, docLinkReach,
docLinkRole,
linkReachTranslations, linkReachTranslations,
updateDocLink, updateDocLink,
]); ]);
@@ -78,7 +84,8 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
(option) => option.disabled, (option) => option.disabled,
); );
const showLinkRoleOptions = doc.computed_link_reach !== LinkReach.RESTRICTED; const showLinkRoleOptions =
docLinkReach !== LinkReach.RESTRICTED && docLinkRole;
const linkRoleOptions: DropdownMenuOption[] = useMemo(() => { const linkRoleOptions: DropdownMenuOption[] = useMemo(() => {
const options = doc.abilities.link_select_options[docLinkReach] ?? []; const options = doc.abilities.link_select_options[docLinkReach] ?? [];
@@ -175,26 +182,24 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
</Box> </Box>
{showLinkRoleOptions && ( {showLinkRoleOptions && (
<Box $direction="row" $align="center" $gap={spacingsTokens['3xs']}> <Box $direction="row" $align="center" $gap={spacingsTokens['3xs']}>
{docLinkReach !== LinkReach.RESTRICTED && ( <DropdownMenu
<DropdownMenu testId="doc-access-mode"
testId="doc-access-mode" disabled={!canManage}
disabled={!canManage} showArrow={true}
showArrow={true} options={linkRoleOptions}
options={linkRoleOptions} topMessage={
topMessage={ haveDisabledLinkRoleOptions
haveDisabledLinkRoleOptions ? t(
? t( 'You cannot restrict access to a subpage relative to its parent page.',
'You cannot restrict access to a subpage relative to its parent page.', )
) : undefined
: undefined }
} label={t('Document access mode')}
label={t('Document access mode')} >
> <Text $weight="initial" $variation="600">
<Text $weight="initial" $variation="600"> {linkModeTranslations[docLinkRole]}
{linkModeTranslations[docLinkRole]} </Text>
</Text> </DropdownMenu>
</DropdownMenu>
)}
</Box> </Box>
)} )}
</Box> </Box>