Skip to content

Commit 941ad09

Browse files
committed
♻️(frontend) use more reliable properties in useTreeUtils
Using the treeContext was causing issues with the current parent detection, in many places the context is not available. "depth" property is more reliable than "nb_accesses_ancestors".
1 parent 040eddb commit 941ad09

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const DocTreeItemActions = ({
4242
const deleteModal = useModal();
4343

4444
const copyLink = useCopyDocLink(doc.id);
45-
const { isCurrentParent } = useTreeUtils(doc);
45+
const { isCurrentRoot } = useTreeUtils(doc);
4646
const { mutate: detachDoc } = useDetachDoc();
4747
const treeContext = useTreeContext<Doc>();
4848

@@ -71,7 +71,7 @@ export const DocTreeItemActions = ({
7171
icon: <Icon iconName="link" $size="24px" />,
7272
callback: copyLink,
7373
},
74-
...(!isCurrentParent
74+
...(!isCurrentRoot
7575
? [
7676
{
7777
label: t('Move to my docs'),

src/frontend/apps/impress/src/features/docs/doc-tree/hooks/useTreeUtils.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import { useTreeContext } from '@gouvfr-lasuite/ui-kit';
2-
31
import { Doc } from '@/docs/doc-management';
42

53
export const useTreeUtils = (doc: Doc) => {
6-
const treeContext = useTreeContext<Doc>();
7-
84
return {
9-
isParent: doc.nb_accesses_ancestors <= 1, // it is a parent
10-
isChild: doc.nb_accesses_ancestors > 1, // it is a child
11-
isCurrentParent: treeContext?.root?.id === doc.id || doc.depth === 1, // it can be a child but not for the current user
5+
isRoot: doc.depth === 1,
6+
isChild: doc.depth > 1,
7+
isCurrentRoot: typeof doc.children === 'undefined', // it can be a child but not for the current user
128
isDesyncronized: !!(
139
doc.ancestors_link_reach &&
1410
doc.ancestors_link_role &&

src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGridItem.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { TreeProvider } from '@gouvfr-lasuite/ui-kit';
21
import { Tooltip, useModal } from '@openfun/cunningham-react';
32
import { DateTime } from 'luxon';
43
import { useTranslation } from 'react-i18next';
@@ -144,9 +143,7 @@ export const DocsGridItem = ({ doc, dragMode = false }: DocsGridItemProps) => {
144143
</Box>
145144
</Box>
146145
{shareModal.isOpen && (
147-
<TreeProvider initialNodeId={doc.id}>
148-
<DocShareModal doc={doc} onClose={shareModal.close} />
149-
</TreeProvider>
146+
<DocShareModal doc={doc} onClose={shareModal.close} />
150147
)}
151148
</>
152149
);

0 commit comments

Comments
 (0)