Skip to content

Commit 0ce36a5

Browse files
committed
💄(frontend) Use StyledLink for sub doc tree
Replace ButtonBox by StyledLink in DocSubPageItem so ctrl+click on the sub document title open a new browser tab Signed-off-by: Paul Vernin <paul.vernin@gmail.com>
1 parent cd882c8 commit 0ce36a5

2 files changed

Lines changed: 11 additions & 74 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to
1616
- ♿(frontend) use aria-haspopup menu on DropButton triggers #2126
1717
- ♿️(frontend) add contextual browser tab titles for docs routes #2120
1818
- ♿️(frontend) fix empty heading before section titles in HTML export #2125
19+
- 💄(frontend) Use StyledLink for sub doc tree #2100
1920

2021
### Fixed
2122

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocSubPageItem.tsx

Lines changed: 10 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import {
2-
Spinner,
32
TreeViewDataType,
43
TreeViewItem,
54
TreeViewNodeProps,
6-
TreeViewNodeTypeEnum,
75
useTreeContext,
86
} from '@gouvfr-lasuite/ui-kit';
97
import { useRouter } from 'next/navigation';
10-
import { useEffect, useRef, useState } from 'react';
8+
import { useRef, useState } from 'react';
119
import { useTranslation } from 'react-i18next';
1210
import { css } from 'styled-components';
1311

14-
import { Box, BoxButton, Icon, Text } from '@/components';
12+
import { Box, Icon, StyledLink, Text } from '@/components';
1513
import { useCunninghamTheme } from '@/cunningham';
1614
import {
1715
Doc,
@@ -22,12 +20,11 @@ import {
2220
import { useLeftPanelStore } from '@/features/left-panel';
2321
import { useResponsiveStore } from '@/stores';
2422

25-
import { isDocNode } from '../utils';
26-
2723
import SubPageIcon from './../assets/sub-page-logo.svg';
2824
import { DocTreeItemActions } from './DocTreeItemActions';
2925

3026
const ItemTextCss = css`
27+
font-weight: normal;
3128
overflow: hidden;
3229
text-overflow: ellipsis;
3330
white-space: initial;
@@ -38,65 +35,6 @@ const ItemTextCss = css`
3835
`;
3936

4037
export const DocSubPageItem = (props: TreeViewNodeProps<Doc>) => {
41-
if (props.node.data.value.nodeType === TreeViewNodeTypeEnum.VIEW_MORE) {
42-
return <DocSubPageLoadMore {...props} />;
43-
}
44-
45-
if (!isDocNode(props.node.data.value)) {
46-
return <TreeViewItem {...props} />;
47-
}
48-
49-
return <DocSubPageItemContent {...props} />;
50-
};
51-
52-
const DocSubPageLoadMore = (props: TreeViewNodeProps<Doc>) => {
53-
const treeContext = useTreeContext<Doc>();
54-
const loaderRef = useRef<HTMLDivElement>(null);
55-
const inFlightRef = useRef<boolean>(false);
56-
57-
/**
58-
* Use IntersectionObserver to trigger loading more children when the "Load More" item comes into view.
59-
* This allows for infinite scrolling of child nodes without needing a "Load More" button click.
60-
* The observer is disconnected when the component unmounts to prevent memory leaks.
61-
*/
62-
useEffect(() => {
63-
const el = loaderRef.current;
64-
const parentKey = props.node.data.parentKey;
65-
if (!el || !parentKey) {
66-
return;
67-
}
68-
69-
const observer = new IntersectionObserver(
70-
([entry]) => {
71-
if (!entry.isIntersecting || inFlightRef.current) {
72-
return;
73-
}
74-
inFlightRef.current = true;
75-
void treeContext?.treeData.handleLoadChildren(parentKey).finally(() => {
76-
inFlightRef.current = false;
77-
});
78-
},
79-
{ threshold: 0.1 },
80-
);
81-
82-
observer.observe(el);
83-
return () => observer.disconnect();
84-
// eslint-disable-next-line react-hooks/exhaustive-deps
85-
}, []);
86-
87-
return (
88-
<Box
89-
ref={loaderRef}
90-
$align="center"
91-
$justify="center"
92-
$padding={{ vertical: 'xs' }}
93-
>
94-
<Spinner size="sm" />
95-
</Box>
96-
);
97-
};
98-
99-
const DocSubPageItemContent = (props: TreeViewNodeProps<Doc>) => {
10038
const doc = props.node.data.value as Doc;
10139
const treeContext = useTreeContext<Doc>();
10240
const { untitledDocument } = useTrans();
@@ -279,27 +217,25 @@ const DocSubPageItemContent = (props: TreeViewNodeProps<Doc>) => {
279217
buttonOptionRef={buttonOptionRef}
280218
/>
281219
</Box>
282-
<BoxButton
220+
<StyledLink
221+
href={`/docs/${doc.id}`}
283222
onClick={(e) => {
284223
e.stopPropagation();
224+
e.preventDefault();
285225
handleActivate();
286226
}}
287227
tabIndex={-1}
288-
$width="100%"
289-
$direction="row"
290-
$gap={spacingsTokens['xs']}
291-
$align="center"
292-
$minHeight="24px"
293228
data-testid={`doc-sub-page-item-${doc.id}`}
294229
aria-label={`${t('Open document {{title}}', { title: docTitle })}`}
295230
$css={css`
296-
text-align: left;
297-
min-width: 0;
231+
width: 100%;
298232
`}
299233
>
300234
<Box
301235
$direction="row"
302236
$align="center"
237+
$gap={spacingsTokens['xs']}
238+
$minHeight="24px"
303239
$css={css`
304240
display: flex;
305241
flex-direction: row;
@@ -322,7 +258,7 @@ const DocSubPageItemContent = (props: TreeViewNodeProps<Doc>) => {
322258
/>
323259
)}
324260
</Box>
325-
</BoxButton>
261+
</StyledLink>
326262
</TreeViewItem>
327263
</Box>
328264
);

0 commit comments

Comments
 (0)