-
Notifications
You must be signed in to change notification settings - Fork 7
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
Tet 1501/etapes fa #3477
Merged
Merged
Tet 1501/etapes fa #3477
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a80a5b0
Change query en mutation pour des routes trpc des étapes d'une fiche …
cparthur 9dfca8b
Composant Etape d'une fiche action et hooks CRUD associés
cparthur bf304cb
Onglet Etapes d'une fiche action
cparthur 504eb00
Ajoute une fonction onChange par défaut à Checkbox du DS pour ne réso…
cparthur 04b4ee1
Corrige le useEffect de AutoResizedTextarea pour ré-initialiser la va…
cparthur 93300f1
Remplace les chemins d'import par les nouveaux alias
cparthur ea500f3
Renforce temporairement un type dans les etapes FA
cparthur 5f3f58a
Ajoute des utilitaires dnd-kit
cparthur 0017970
Ajoute le drag and drop sur les étapes de la fiche action
cparthur c1706b2
Augmente le contraste des étapes en mode visite
cparthur 4b67a2d
Corrige des erreurs ts sur un SVG
cparthur 678b146
Désactive le champs de création d'une étape le temps de la mutation
cparthur 0191903
Corrige un problème de hauteur sur l'élément dragué dans les étapes FA
cparthur b90e4c0
Améliore les curseurs dans les étapes de la FA
cparthur da843ca
Change un commentaire
cparthur 9bdcf4e
Update l'ordre des étapes restantes après une suppression dans l'état…
cparthur ed93855
Ajoute les étapes à l'export PDF de la fiche action
cparthur 34d94fd
Enlève du code inutilisé
cparthur 32ebde4
Répare l'erreur console de la Checkbox du DS plus proprement
cparthur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...nsitions.react/src/app/pages/collectivite/PlansActions/FicheAction/etapes/etape/etape.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { useState } from 'react'; | ||
import classNames from 'classnames'; | ||
import { useSortable } from '@dnd-kit/sortable'; | ||
import { CSS } from '@dnd-kit/utilities'; | ||
|
||
import { RouterOutput } from '@/api/utils/trpc/client'; | ||
|
||
import { Button, Checkbox } from '@/ui'; | ||
|
||
import { useEtapesDispatch } from '../etapes-context'; | ||
import ModalDeleteEtape from './modal-delete-etape'; | ||
import { Textarea } from './textarea'; | ||
import { useUpsertEtape } from './use-upsert-etape'; | ||
|
||
type Props = { | ||
etape: RouterOutput['plans']['fiches']['etapes']['list'][0]; | ||
isReadonly: boolean; | ||
}; | ||
|
||
export const Etape = ({ etape, isReadonly }: Props) => { | ||
const { | ||
attributes, | ||
listeners, | ||
setNodeRef, | ||
transform, | ||
transition, | ||
isDragging, | ||
} = useSortable({ | ||
id: etape.id, | ||
disabled: isReadonly, | ||
}); | ||
|
||
// permet de corriger un bug de hauteur avec le scale de l'élêment qui est drag | ||
const custromTransform = transform | ||
? isDragging | ||
? { ...transform, scaleY: 1 } // renforce le scale | ||
: transform | ||
: null; | ||
|
||
const style = { | ||
transform: CSS.Transform.toString(custromTransform), | ||
transition, | ||
opacity: isDragging ? 0.5 : 1, | ||
}; | ||
|
||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); | ||
|
||
const dispatchEtapes = useEtapesDispatch(); | ||
const { mutate: updateEtape } = useUpsertEtape(); | ||
|
||
return ( | ||
<div | ||
ref={setNodeRef} | ||
style={style} | ||
{...attributes} | ||
{...listeners} | ||
className={classNames( | ||
'group relative flex items-start w-full p-4 rounded-lg', | ||
|
||
{ | ||
'bg-error-2 bg-opacity-50': isDeleteModalOpen, | ||
'hover:bg-grey-2': !isReadonly, | ||
'cursor-default': isReadonly, | ||
'z-10 hover:cursor-grabbing': isDragging, | ||
} | ||
)} | ||
> | ||
<Checkbox | ||
checked={etape.realise} | ||
disabled={isReadonly} | ||
className={classNames({ '!cursor-default': isReadonly })} | ||
onChange={() => { | ||
dispatchEtapes({ | ||
type: 'toggleRealise', | ||
payload: { | ||
etapeId: etape.id, | ||
}, | ||
}); | ||
updateEtape({ | ||
...etape, | ||
realise: !etape.realise, | ||
}); | ||
}} | ||
/> | ||
<Textarea | ||
nom={etape.nom} | ||
realise={etape.realise} | ||
placeholder="Renseigner l'étape." | ||
disabled={isReadonly} | ||
className={classNames({ | ||
'cursor-grabbing': isDragging, | ||
'!cursor-default': isReadonly, | ||
})} | ||
onBlur={(newTitle) => { | ||
if (newTitle.length) { | ||
dispatchEtapes({ | ||
type: 'updateNom', | ||
payload: { | ||
etapeId: etape.id, | ||
nom: newTitle, | ||
}, | ||
}); | ||
updateEtape({ | ||
...etape, | ||
nom: newTitle, | ||
}); | ||
} else { | ||
setIsDeleteModalOpen(true); | ||
} | ||
}} | ||
/> | ||
{/** Actions visibles au hover */} | ||
{!isReadonly && !isDragging && ( | ||
<div className="invisible group-hover:visible absolute top-3 right-3"> | ||
<Button | ||
className="hover:!bg-grey-3" | ||
icon="delete-bin-6-line" | ||
size="xs" | ||
variant="grey" | ||
onClick={() => setIsDeleteModalOpen(true)} | ||
/> | ||
{isDeleteModalOpen && ( | ||
<ModalDeleteEtape | ||
etapeId={etape.id} | ||
openState={{ | ||
isOpen: isDeleteModalOpen, | ||
setIsOpen: setIsDeleteModalOpen, | ||
}} | ||
/> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
3 changes: 3 additions & 0 deletions
3
...ansitions.react/src/app/pages/collectivite/PlansActions/FicheAction/etapes/etape/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { Etape } from './etape'; | ||
export { Textarea } from './textarea'; | ||
export { useUpsertEtape } from './use-upsert-etape'; |
45 changes: 45 additions & 0 deletions
45
...t/src/app/pages/collectivite/PlansActions/FicheAction/etapes/etape/modal-delete-etape.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
|
||
import { Modal, ModalFooterOKCancel } from '@/ui'; | ||
import { OpenState } from '@/ui/utils/types'; | ||
|
||
import { useDeleteEtape } from './use-delete-etape'; | ||
import { useEtapesDispatch } from '../etapes-context'; | ||
|
||
type Props = { | ||
openState: OpenState; | ||
etapeId: number; | ||
}; | ||
|
||
const ModalDeleteEtape = ({ openState, etapeId }: Props) => { | ||
const dispatchEtapes = useEtapesDispatch(); | ||
const { mutate: deleteEtape } = useDeleteEtape(); | ||
|
||
return ( | ||
<Modal | ||
openState={openState} | ||
title="Supprimer l’étape" | ||
description="Cette étape sera supprimée définitivement de la fiche action. Souhaitez-vous vraiment supprimer cette étape ?" | ||
renderFooter={({ close }) => ( | ||
<ModalFooterOKCancel | ||
btnOKProps={{ | ||
children: 'Confirmer', | ||
onClick: () => { | ||
deleteEtape({ etapeId }); | ||
dispatchEtapes({ | ||
type: 'delete', | ||
payload: { etapeId }, | ||
}); | ||
close(); | ||
}, | ||
}} | ||
btnCancelProps={{ | ||
onClick: () => close(), | ||
}} | ||
/> | ||
)} | ||
/> | ||
); | ||
}; | ||
|
||
export default ModalDeleteEtape; |
68 changes: 68 additions & 0 deletions
68
...tions.react/src/app/pages/collectivite/PlansActions/FicheAction/etapes/etape/textarea.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { forwardRef, Ref, useState } from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import { AutoResizedTextarea, TextareaProps } from '@/ui'; | ||
import { RouterInput } from '@/api/utils/trpc/client'; | ||
|
||
type EtapeUpsert = RouterInput['plans']['fiches']['etapes']['upsert']; | ||
|
||
type Props = Pick<EtapeUpsert, 'nom' | 'realise'> & | ||
Pick<TextareaProps, 'className' | 'placeholder' | 'disabled'> & { | ||
/** | ||
* Méthode utilisée pour exécuter l'update du titre de l'étape. | ||
* Reçoit le nouveau titre en paramètre (`trim` appliqué). | ||
*/ | ||
onBlur: (newTitle: string) => void; | ||
}; | ||
|
||
/** | ||
* Wrapper de `AutoResizedTextarea` du design-system. | ||
* Utilisé pour l'affichage, la modification et la création du titre d'une étape. | ||
*/ | ||
export const Textarea = forwardRef( | ||
( | ||
{ nom, realise, onBlur, className, placeholder, disabled }: Props, | ||
ref?: Ref<HTMLTextAreaElement> | ||
) => { | ||
const initialNom = nom ?? ''; | ||
|
||
const [value, setValue] = useState(initialNom); | ||
|
||
return ( | ||
<AutoResizedTextarea | ||
ref={ref} | ||
containerClassname="w-full border-none bg-transparent resize-none" | ||
className={classNames( | ||
'ml-1 !p-0 font-medium !text-base text-grey-8 placeholder:!font-normal placeholder:!text-base placeholder:!italic', | ||
{ | ||
'!text-grey-8': disabled && !realise, | ||
'line-through !text-grey-6': realise, | ||
}, | ||
className | ||
)} | ||
value={value} | ||
onChange={(evt) => setValue(evt.currentTarget.value)} | ||
onKeyDown={(evt) => { | ||
if (['Enter', 'Escape', 'Tab'].includes(evt.key)) { | ||
evt.preventDefault(); | ||
evt.currentTarget.blur(); | ||
} | ||
}} | ||
onBlur={() => { | ||
const trimedValue = value.trim(); | ||
onBlur(trimedValue); | ||
// Cas pour la création d'une étape. | ||
// On veut réinitialiser le champ après l'ajout de l'étape | ||
if (initialNom.length === 0) return setValue(''); | ||
// Cas d'une étape existante avec un titre. | ||
// si le nouveau titre est vide, on remet l'ancien titre | ||
if (trimedValue.length === 0) return setValue(initialNom); | ||
}} | ||
placeholder={placeholder} | ||
disabled={disabled} | ||
/> | ||
); | ||
} | ||
); | ||
|
||
Textarea.displayName = 'Textarea'; |
14 changes: 14 additions & 0 deletions
14
...eact/src/app/pages/collectivite/PlansActions/FicheAction/etapes/etape/use-delete-etape.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { trpc } from '@/api/utils/trpc/client'; | ||
|
||
/** | ||
* Charge les étapes d'une fiche action | ||
*/ | ||
export const useDeleteEtape = () => { | ||
const utils = trpc.useUtils(); | ||
|
||
return trpc.plans.fiches.etapes.delete.useMutation({ | ||
onSuccess: () => { | ||
utils.plans.fiches.etapes.list.invalidate(); | ||
}, | ||
}); | ||
}; |
14 changes: 14 additions & 0 deletions
14
...eact/src/app/pages/collectivite/PlansActions/FicheAction/etapes/etape/use-upsert-etape.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { trpc } from '@/api/utils/trpc/client'; | ||
|
||
/** | ||
* Charge les étapes d'une fiche action | ||
*/ | ||
export const useUpsertEtape = () => { | ||
const utils = trpc.useUtils(); | ||
|
||
return trpc.plans.fiches.etapes.upsert.useMutation({ | ||
onSuccess: () => { | ||
utils.plans.fiches.etapes.list.invalidate(); | ||
}, | ||
}); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Je pense que niveau découvrabilité du drag and drop, il vaudrait mieux toujours avoir ce curseur activé sur la carte, ou alors utiliser les drag handle de la librairie
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.
Oui je suis d'accord avec le handle sur le côté mais pas sur les design et je n'ai pas le temps de faire un truc bien direct en code, je préfère ship ça déjà. Ça reviendra surement dans les améliorations.
Pour le curseur je ne suis pas pour, car dans l'étape il faut avoir celui du texte pour modifier l'étape et celui de la checkbox