From 17d711c3b77f8f3f8d5e70ae00e97f9970dd4bbd Mon Sep 17 00:00:00 2001 From: Maxime Perrault Date: Wed, 27 Nov 2024 12:06:02 +0100 Subject: [PATCH 1/2] feat: fix comments debounce, add loading feedback on briefing, hide reporting legend if no reportings selected --- .../DashboardForm/Comments/index.tsx | 23 +++++--- .../components/Pdf/Comments/index.tsx | 8 ++- .../components/Pdf/GeneratePdfButton.tsx | 4 +- .../components/Pdf/Reportings/index.tsx | 52 ++++++++++--------- 4 files changed, 51 insertions(+), 36 deletions(-) diff --git a/frontend/src/features/Dashboard/components/DashboardForm/Comments/index.tsx b/frontend/src/features/Dashboard/components/DashboardForm/Comments/index.tsx index 71020f7a5..73b8f7aa0 100644 --- a/frontend/src/features/Dashboard/components/DashboardForm/Comments/index.tsx +++ b/frontend/src/features/Dashboard/components/DashboardForm/Comments/index.tsx @@ -2,7 +2,7 @@ import { dashboardActions } from '@features/Dashboard/slice' import { useAppDispatch } from '@hooks/useAppDispatch' import { Textarea } from '@mtes-mct/monitor-ui' import { debounce } from 'lodash' -import { forwardRef, useState } from 'react' +import { forwardRef, useCallback, useMemo, useState } from 'react' import styled from 'styled-components' import { Accordion } from '../Accordion' @@ -19,14 +19,21 @@ export const Comments = forwardRef( const dispatch = useAppDispatch() const [commentsValue, setCommentsValue] = useState(comments) - const onQuery = debounce((value: string | undefined) => { - dispatch(dashboardActions.setComments({ comments: value, key: dashboardKey })) - }, 500) + const onQuery = useMemo( + () => + debounce((value: string | undefined) => { + dispatch(dashboardActions.setComments({ comments: value, key: dashboardKey })) + }, 500), + [dashboardKey, dispatch] + ) - const updateComments = (value: string | undefined) => { - setCommentsValue(value) - onQuery(value) - } + const updateComments = useCallback( + (value: string | undefined) => { + setCommentsValue(value) + onQuery(value) + }, + [onQuery] + ) return ( Commentaires - {!!comments && getPrettyComments(comments).map(comment => {comment})} + {!!comments && + getPrettyComments(comments).map((comment, index) => ( + // eslint-disable-next-line react/no-array-index-key + + {comment} + + ))} ) diff --git a/frontend/src/features/Dashboard/components/Pdf/GeneratePdfButton.tsx b/frontend/src/features/Dashboard/components/Pdf/GeneratePdfButton.tsx index abf2774e5..06ba8b052 100644 --- a/frontend/src/features/Dashboard/components/Pdf/GeneratePdfButton.tsx +++ b/frontend/src/features/Dashboard/components/Pdf/GeneratePdfButton.tsx @@ -87,8 +87,8 @@ export function GeneratePdfButton({ dashboard }: GeneratePdfButtonProps) { } return ( - - Générer un brief + + {pdf.loading ? 'Chargement du brief' : 'Générer un brief'} ) } diff --git a/frontend/src/features/Dashboard/components/Pdf/Reportings/index.tsx b/frontend/src/features/Dashboard/components/Pdf/Reportings/index.tsx index 4e4e6072f..63e783e87 100644 --- a/frontend/src/features/Dashboard/components/Pdf/Reportings/index.tsx +++ b/frontend/src/features/Dashboard/components/Pdf/Reportings/index.tsx @@ -173,35 +173,37 @@ export function Reportings({ {reportings.length} sélectionnée(s) - - - - Signalements en cours - - - Observation + {reportings.length > 0 && ( + + + + Signalements en cours + + + Observation + + + Suspicion d'infraction + + + Rattaché à une mission + - - Suspicion d'infraction - - - Rattaché à une mission - - - - Signalements archivés - - Observation - - - Suspicion d'infraction - - - Rattaché à une mission + + Signalements archivés + + Observation + + + Suspicion d'infraction + + + Rattaché à une mission + - + )} {reportings.map(reporting => ( {reportingStatusFlag(reporting)} From 9adbc4514285570cb1e1f06f52843d093583741d Mon Sep 17 00:00:00 2001 From: Maxime Perrault Date: Mon, 2 Dec 2024 17:05:57 +0100 Subject: [PATCH 2/2] feat: Add spinner to download button --- .../components/Pdf/GeneratePdfButton.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/frontend/src/features/Dashboard/components/Pdf/GeneratePdfButton.tsx b/frontend/src/features/Dashboard/components/Pdf/GeneratePdfButton.tsx index 06ba8b052..53eebf07d 100644 --- a/frontend/src/features/Dashboard/components/Pdf/GeneratePdfButton.tsx +++ b/frontend/src/features/Dashboard/components/Pdf/GeneratePdfButton.tsx @@ -87,10 +87,22 @@ export function GeneratePdfButton({ dashboard }: GeneratePdfButtonProps) { } return ( - + {pdf.loading ? 'Chargement du brief' : 'Générer un brief'} ) } -const StyledLinkButton = styled(Button)`` +const StyledLinkButton = styled(Button)` + ${p => + p.disabled && + `@keyframes spin { + to { + transform: rotate(360deg); + } + } + > .Element-IconBox > svg { + animation: spin 2s linear infinite; + transform-origin: center; + }`} +`