-
Notifications
You must be signed in to change notification settings - Fork 455
✨(frontend) improve mobile UX by showing subdocs count #1540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,98 @@ | ||||||||||||||||||||||||||||||||||
| import { useTreeContext } from '@gouvfr-lasuite/ui-kit'; | ||||||||||||||||||||||||||||||||||
| import { t } from 'i18next'; | ||||||||||||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import { Text } from '@/components'; | ||||||||||||||||||||||||||||||||||
| import { useConfig } from '@/core'; | ||||||||||||||||||||||||||||||||||
| import { useDate } from '@/hook'; | ||||||||||||||||||||||||||||||||||
| import { useResponsiveStore } from '@/stores'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| Doc, | ||||||||||||||||||||||||||||||||||
| Role, | ||||||||||||||||||||||||||||||||||
| useIsCollaborativeEditable, | ||||||||||||||||||||||||||||||||||
| useTrans, | ||||||||||||||||||||||||||||||||||
| } from '../../doc-management'; | ||||||||||||||||||||||||||||||||||
| import { useDocChildren, useDocTree } from '../../doc-tree'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| interface DocHeaderInfoProps { | ||||||||||||||||||||||||||||||||||
| doc: Doc; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export const DocHeaderInfo = ({ doc }: DocHeaderInfoProps) => { | ||||||||||||||||||||||||||||||||||
| const { data: tree } = useDocTree({ docId: doc.id }); | ||||||||||||||||||||||||||||||||||
| const { isDesktop } = useResponsiveStore(); | ||||||||||||||||||||||||||||||||||
| const treeContext = useTreeContext<Doc | null>(); | ||||||||||||||||||||||||||||||||||
| const { transRole } = useTrans(); | ||||||||||||||||||||||||||||||||||
| const { isEditable } = useIsCollaborativeEditable(doc); | ||||||||||||||||||||||||||||||||||
| const { relativeDate, calculateDaysLeft } = useDate(); | ||||||||||||||||||||||||||||||||||
| const { data: config } = useConfig(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const { data: childrenPage } = useDocChildren( | ||||||||||||||||||||||||||||||||||
| { docId: doc.id, page_size: 1 }, | ||||||||||||||||||||||||||||||||||
| { enabled: true }, | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| const countFromTreeContext = | ||||||||||||||||||||||||||||||||||
| treeContext?.root?.id === doc.id | ||||||||||||||||||||||||||||||||||
| ? treeContext?.treeData?.nodes?.length | ||||||||||||||||||||||||||||||||||
| : undefined; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const childrenCount = | ||||||||||||||||||||||||||||||||||
| countFromTreeContext ?? | ||||||||||||||||||||||||||||||||||
| childrenPage?.count ?? | ||||||||||||||||||||||||||||||||||
| doc.numchild ?? | ||||||||||||||||||||||||||||||||||
| tree?.children?.length ?? | ||||||||||||||||||||||||||||||||||
| 0; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| let dateToDisplay = t('Last update: {{update}}', { | ||||||||||||||||||||||||||||||||||
| update: relativeDate(doc.updated_at), | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| const relativeOnly = relativeDate(doc.updated_at); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
+51
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
| if (config?.TRASHBIN_CUTOFF_DAYS && doc.deleted_at) { | ||||||||||||||||||||||||||||||||||
| const daysLeft = calculateDaysLeft( | ||||||||||||||||||||||||||||||||||
| doc.deleted_at, | ||||||||||||||||||||||||||||||||||
| config.TRASHBIN_CUTOFF_DAYS, | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| dateToDisplay = `${t('Days remaining:')} ${daysLeft} ${t('days', { count: daysLeft })}`; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const hasChildren = childrenCount > 0; | ||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||
| {isDesktop ? ( | ||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||
| <Text | ||||||||||||||||||||||||||||||||||
| $variation="600" | ||||||||||||||||||||||||||||||||||
| $size="s" | ||||||||||||||||||||||||||||||||||
| $weight="bold" | ||||||||||||||||||||||||||||||||||
| $theme={isEditable ? 'greyscale' : 'warning'} | ||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||
| {transRole( | ||||||||||||||||||||||||||||||||||
| isEditable ? doc.user_role || doc.link_role : Role.READER, | ||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||
| · | ||||||||||||||||||||||||||||||||||
| </Text> | ||||||||||||||||||||||||||||||||||
| <Text $variation="600" $size="s"> | ||||||||||||||||||||||||||||||||||
| {dateToDisplay} | ||||||||||||||||||||||||||||||||||
| </Text> | ||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||
| <Text $variation="400" $size="s"> | ||||||||||||||||||||||||||||||||||
| {hasChildren ? relativeOnly : dateToDisplay} | ||||||||||||||||||||||||||||||||||
| </Text> | ||||||||||||||||||||||||||||||||||
| {hasChildren ? ( | ||||||||||||||||||||||||||||||||||
| <Text $variation="400" $size="s"> | ||||||||||||||||||||||||||||||||||
| • | ||||||||||||||||||||||||||||||||||
| {t('Contains {{count}} sub-documents', { | ||||||||||||||||||||||||||||||||||
| count: childrenCount, | ||||||||||||||||||||||||||||||||||
| })} | ||||||||||||||||||||||||||||||||||
| </Text> | ||||||||||||||||||||||||||||||||||
| ) : null} | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+86
to
+93
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+64
to
+94
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AntoLC I was hesitating to create DocHeaderInfoDesktop and DocHeaderInfoMobile components to make this component clearer and more readable. We would just have a bit of props drilling, what do you think?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is ok, but to improve a bit readability you can maybe do: if(isDesktop){
return ...
}
return ... |
||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need all that ? Why is
doc.numchildnot enough ?