From b07ccfb8608d3242455fa06115e769a8c3c3acab Mon Sep 17 00:00:00 2001 From: Benoit Simard Date: Thu, 23 Nov 2023 18:06:21 +0100 Subject: [PATCH] front: editor - Adding help on catenary tool Close #5371 Refacto the code of range tool, to avoid namings that are not generic to all tool only one range tool. --- front/public/locales/en/translation.json | 6 + front/public/locales/fr/translation.json | 6 + .../catenary/CatenaryEditionLayers.tsx | 36 ++- .../editor/tools/rangeEdition/components.tsx | 259 +++++++++--------- .../SpeedSectionEditionLayers.tsx | 10 +- .../tools/rangeEdition/tool-factory.tsx | 29 +- .../editor/tools/rangeEdition/types.ts | 22 +- .../editor/tools/rangeEdition/utils.ts | 30 +- 8 files changed, 210 insertions(+), 188 deletions(-) diff --git a/front/public/locales/en/translation.json b/front/public/locales/en/translation.json index 61bbb211c80..1468c608ef5 100644 --- a/front/public/locales/en/translation.json +++ b/front/public/locales/en/translation.json @@ -220,6 +220,11 @@ "reset-catenary": "Cancel the current modifications", "delete-catenary": "Delete the catenary" }, + "help": { + "init": "Click on a track section to link it to the catenary", + "add-track": "Link the track section '{{track.id}}' to the catenary {{voltage}}", + "remove-range": "Remove the track section from the catenary {{voltage}}" + }, "add-new-catenary": "Add new catenary", "catenaries": "Electrification", "catenary-default": "Default catenary", @@ -253,6 +258,7 @@ "edit-track-range-start": "Edit departure point", "edit-track-range-end": "Edit arrival point", "linked-track-sections": "Associated track sections", + "empty-linked-track-section": "Click on a track section to link it to the catenary", "only-show-n": "Only show the first {{count}} track sections", "show-more-ranges_one": "See an additional track section", "show-more-ranges_other": "See {{count}} additional track sections" diff --git a/front/public/locales/fr/translation.json b/front/public/locales/fr/translation.json index 7f48b9cf159..f7149da1b82 100644 --- a/front/public/locales/fr/translation.json +++ b/front/public/locales/fr/translation.json @@ -220,6 +220,11 @@ "reset-catenary": "Annuler les modifications en cours", "delete-catenary": "Supprimer l'électrification" }, + "help": { + "init":"Cliquez sur un tronçon d'itinéraire pour l'associer à l'électrification", + "add-track": "Ajouter le tronçon '{{track.id}}' à l'électrification {{voltage}}", + "remove-range": "Supprimer le tronçon de l'électrification {{voltage}}" + }, "add-new-catenary": "Ajouter une nouvelle électrification", "catenaries": "Électrification", "catenary-default": "Électrification par défaut", @@ -253,6 +258,7 @@ "edit-track-range-start": "Modifier le point de départ", "edit-track-range-end": "Modifier le point d'arrivée", "linked-track-sections": "Tronçons d'itinéraire de voie associés", + "empty-linked-track-section": "Cliquez sur un tronçon d'itinéraire pour l'associer", "only-show-n": "Ne montrer que les {{count}} premières sections de lignes", "show-more-ranges_one": "Voir une section de ligne de plus", "show-more-ranges_other": "Voir {{count}} sections de lignes de plus" diff --git a/front/src/applications/editor/tools/rangeEdition/catenary/CatenaryEditionLayers.tsx b/front/src/applications/editor/tools/rangeEdition/catenary/CatenaryEditionLayers.tsx index 13f1df1e356..de69e7cce99 100644 --- a/front/src/applications/editor/tools/rangeEdition/catenary/CatenaryEditionLayers.tsx +++ b/front/src/applications/editor/tools/rangeEdition/catenary/CatenaryEditionLayers.tsx @@ -36,7 +36,7 @@ export const CatenaryEditionLayers: FC = () => { return [(entity.properties.track_ranges || [])[interactionState.rangeIndex].track]; // Custom hovered element: - if (hoveredItem?.speedSectionItemType) return [hoveredItem.track.properties.id]; + if (hoveredItem?.itemType) return [hoveredItem.track.properties.id]; // EditorEntity hovered element: if ( @@ -137,7 +137,7 @@ export const CatenaryEditionLayers: FC = () => { const popUps = !isOnModeMove(interactionState.type) ? ( <> - {hoveredItem?.speedSectionItemType === 'TrackRangeExtremity' && ( + {hoveredItem?.itemType === 'TrackRangeExtremity' && ( { )} - {hoveredItem?.speedSectionItemType === 'TrackRange' && ( + {hoveredItem?.itemType === 'TrackRange' && ( { ); }; -export const CatenaryMessages: FC = () => null; - -// export const CatenaryMessages: FC = () => { -// const { t } = useTranslation(); -// const { -// state: { -// /* TODO */ -// }, -// } = useContext(EditorContext) as ExtendedEditorContextType; -// return null; -// }; +export const CatenaryMessages: FC = () => { + const { t } = useTranslation(); + const { state } = useContext(EditorContext) as ExtendedEditorContextType< + RangeEditionState + >; + if (state.hoveredItem && state.hoveredItem.type === 'TrackSection') + return t('Editor.tools.catenary-edition.help.add-track', { + track: state.hoveredItem, + voltage: state.initialEntity.properties.voltage, + }); + + if (state.hoveredItem && state.hoveredItem.itemType === 'TrackRange') + return t('Editor.tools.catenary-edition.help.remove-range', { + range: state.hoveredItem, + voltage: state.initialEntity.properties.voltage, + }); + + return t('Editor.tools.catenary-edition.help.init'); +}; diff --git a/front/src/applications/editor/tools/rangeEdition/components.tsx b/front/src/applications/editor/tools/rangeEdition/components.tsx index eca714510cf..c6277e85215 100644 --- a/front/src/applications/editor/tools/rangeEdition/components.tsx +++ b/front/src/applications/editor/tools/rangeEdition/components.tsx @@ -54,138 +54,145 @@ export const TrackRangesList: FC = () => {

{t('Editor.tools.range-edition.linked-track-sections')}

-
    - {(showAll ? ranges : ranges.slice(0, DEFAULT_DISPLAYED_RANGES_COUNT)).map((range, i) => { - const trackState = trackSectionsCache[range.track]; + {ranges.length === 0 ? ( +

    + {t('Editor.tools.range-edition.empty-linked-track-section')} +

    + ) : ( +
      + {(showAll ? ranges : ranges.slice(0, DEFAULT_DISPLAYED_RANGES_COUNT)).map((range, i) => { + const trackState = trackSectionsCache[range.track]; - return ( -
    • - {(!trackState || trackState.type === 'loading') && ( -
      - -
      - )} - {trackState?.type === 'success' && ( - <> -
      - - - - - - - - - + return ( +
    • + {(!trackState || trackState.type === 'loading') && ( +
      +
      -
      - - {entity.objType !== 'Catenary' && ( -
      - -
      - )} -
      - - )} -
    • - ); - })} -
    + + + + +
    + + {entity.objType !== 'Catenary' && ( +
    + +
    + )} +
    + + )} + + ); + })} +
+ )} {ranges.length > DEFAULT_DISPLAYED_RANGES_COUNT && (