Skip to content

Commit

Permalink
Merge pull request #1662 from solita-sabinaf/TIS-736/locate_stop_point
Browse files Browse the repository at this point in the history
Add button to locate a stop point from the editor form on the map
  • Loading branch information
testower authored Nov 21, 2024
2 parents 14ce061 + 9b05836 commit 62c5833
Show file tree
Hide file tree
Showing 25 changed files with 648 additions and 291 deletions.
29 changes: 24 additions & 5 deletions src/components/StopPointsEditor/Generic/GenericStopPointEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DeleteButton from 'components/DeleteButton/DeleteButton';
import { getErrorFeedback } from 'helpers/errorHandling';
import { validateStopPoint } from 'helpers/validation';
import usePristine from 'hooks/usePristine';
import { useState } from 'react';
import React, { useCallback, useState } from 'react';
import { useIntl } from 'react-intl';
import {
BoardingTypeSelect,
Expand All @@ -20,6 +20,7 @@ import {
} from '../common/FrontTextTextField';
import { QuayRefField, useOnQuayRefChange } from '../common/QuayRefField';
import { StopPointEditorProps } from '../common/StopPointEditorProps';
import SandboxFeature from '../../../ext/SandboxFeature';

export const GenericStopPointEditor = ({
order,
Expand All @@ -31,6 +32,7 @@ export const GenericStopPointEditor = ({
onDelete,
canDelete,
flexibleLineType,
onFocusedQuayIdUpdate,
}: StopPointEditorProps) => {
const { formatMessage } = useIntl();
const {
Expand All @@ -48,6 +50,10 @@ export const GenericStopPointEditor = ({

const [isDeleteDialogOpen, setDeleteDialogOpen] = useState(false);

const onDeleteDialogOpen = useCallback((isOpen: boolean) => {
setDeleteDialogOpen(isOpen);
}, []);

return (
<div className="stop-point">
<div className="stop-point-element">
Expand Down Expand Up @@ -80,10 +86,23 @@ export const GenericStopPointEditor = ({
/>
</div>

<DeleteButton
disabled={!canDelete}
onClick={() => setDeleteDialogOpen(true)}
title={formatMessage({ id: 'editorDeleteButtonText' })}
<SandboxFeature
feature={'JourneyPatternStopPointMap/StopPointButtonGroup'}
renderFallback={() => (
<DeleteButton
thin={true}
disabled={!canDelete}
onClick={() => {
onDeleteDialogOpen(true);
}}
title={formatMessage({ id: 'editorDeleteButtonText' })}
/>
)}
stopPoint={stopPoint}
onDeleteDialogOpen={onDeleteDialogOpen}
flexibleLineType={flexibleLineType}
onFocusedQuayIdUpdate={onFocusedQuayIdUpdate}
canDelete={canDelete}
/>

<ConfirmDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SandboxFeature from '../../../ext/SandboxFeature';
import { useConfig } from '../../../config/ConfigContext';
import { SmallAlertBox } from '@entur/alert';
import '../styles.scss';
import { useEffect } from 'react';
import { useCallback, useEffect, useState } from 'react';

export const GenericStopPointsEditor = ({
pointsInSequence,
Expand All @@ -24,6 +24,9 @@ export const GenericStopPointsEditor = ({
const { formatMessage } = useIntl();
const { sandboxFeatures } = useConfig();
const isMapEnabled = sandboxFeatures?.JourneyPatternStopPointMap;
const [focusedQuayId, setFocusedQuayId] = useState<string | undefined | null>(
undefined,
);

useEffect(() => {
// if map isn't enabled, let's produce two empty stop points
Expand All @@ -32,6 +35,13 @@ export const GenericStopPointsEditor = ({
}
}, []);

const onFocusedQuayIdUpdate = useCallback(
(quayId: string | undefined | null) => {
setFocusedQuayId(quayId);
},
[],
);

return (
<section style={{ marginTop: '2em' }}>
<Heading3>{formatMessage({ id: 'editorStopPoints' })}</Heading3>
Expand Down Expand Up @@ -64,6 +74,7 @@ export const GenericStopPointsEditor = ({
onDelete={() => deleteStopPoint(pointIndex)}
canDelete={pointsInSequence.length > 2}
flexibleLineType={flexibleLineType}
onFocusedQuayIdUpdate={onFocusedQuayIdUpdate}
/>
))}
</div>
Expand All @@ -73,6 +84,8 @@ export const GenericStopPointsEditor = ({
addStopPoint={addStopPoint}
deleteStopPoint={deleteStopPoint}
transportMode={transportMode}
focusedQuayId={focusedQuayId}
onFocusedQuayIdUpdate={onFocusedQuayIdUpdate}
/>
</div>
<AddButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export type StopPointEditorProps = {
canDelete?: boolean;
flexibleStopPlaces?: FlexibleStopPlace[];
flexibleLineType?: FlexibleLineType;
onFocusedQuayIdUpdate?: (quayId: string | undefined | null) => void;
};
19 changes: 19 additions & 0 deletions src/components/StopPointsEditor/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,30 @@
> :last-child {
margin-right: 0;
}

.buttons-group {
display: flex;
flex-direction: column;
min-width: fit-content;
margin-left: 0.25rem;
}
}
}

> :last-child {
border-bottom: none;
}
}

#locate-button {
margin: 0;
padding: 0 0.5rem;
min-width: fit-content;
width: fit-content;
margin-top: 1.5rem;

svg {
margin-right: 0;
}
}
}
4 changes: 4 additions & 0 deletions src/ext/Fintraffic/CustomStyle/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ section .notices {
margin-left: 1rem;
}

.stop-point #locate-button {
margin-left: 1rem;
}

.modal-content .eds-form-control-wrapper {
margin-top: 1.5rem;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ext/JourneyPatternStopPointMap/ClusterMarker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Marker, useMap } from 'react-leaflet';
import { getClusterIcon } from './markers';
import { getClusterIcon } from './markerIcons';

interface ClusterMarkerProps {
longitude: number;
Expand Down
Loading

0 comments on commit 62c5833

Please sign in to comment.