Skip to content

Commit 8f9315f

Browse files
committed
Use filter to show and hide tram stops and stop areas on map
- User story 72790 - Add vehiclemode to stop data when fetching stops - Filter trams and bus stops separately with own toggle buttons - Remove placeholder filtering toggle buttons
1 parent d022d0b commit 8f9315f

18 files changed

Lines changed: 231 additions & 159 deletions

File tree

cypress/e2e/stop-registry/stopDetails.cy.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,12 +3077,17 @@ describe('Stop details', { tags: [Tag.StopRegistry] }, () => {
30773077
});
30783078

30793079
describe('latest change history', () => {
3080-
it('should display 5 latest change history items and support show all navigation', () => {
3080+
it('should display 5 latest change history items', () => {
30813081
StopDetailsPage.visit('H2003');
30823082
StopDetailsPage.page().shouldBeVisible();
30833083

30843084
StopDetailsPage.latestChangeHistory.container().shouldBeVisible();
3085-
StopDetailsPage.latestChangeHistory.title().shouldBeVisible();
3085+
StopDetailsPage.latestChangeHistory
3086+
.title()
3087+
.shouldBeVisible()
3088+
.should('contain.text', 'Muutoshistoria');
3089+
3090+
StopDetailsPage.latestChangeHistory.getItems().should('have.length', 1);
30863091

30873092
cy.section('Make multiple changes to create history', () => {
30883093
// Change 1
@@ -3134,27 +3139,32 @@ describe('Stop details', { tags: [Tag.StopRegistry] }, () => {
31343139

31353140
StopDetailsPage.latestChangeHistory
31363141
.getNthItem(0)
3137-
.should('be.visible')
3142+
.should('contain.text', 'Perustiedot')
3143+
.and('contain.text', 'ELY-numero:')
31383144
.and('contain.text', '9999999');
31393145

31403146
StopDetailsPage.latestChangeHistory
31413147
.getNthItem(1)
3142-
.should('be.visible')
3148+
.should('contain.text', 'Sijainti')
3149+
.and('contain.text', 'Postinumero:')
31433150
.and('contain.text', '00200');
31443151

31453152
StopDetailsPage.latestChangeHistory
31463153
.getNthItem(2)
3147-
.should('be.visible')
3154+
.should('contain.text', 'Perustiedot')
3155+
.and('contain.text', 'Sijainti (suomi):')
31483156
.and('contain.text', 'Uusi sijainti');
31493157

31503158
StopDetailsPage.latestChangeHistory
31513159
.getNthItem(3)
3152-
.should('be.visible')
3160+
.should('contain.text', 'Pysäkkikilvet')
3161+
.and('contain.text', 'Pysäkkikilpien tyyppi:')
31533162
.and('contain.text', 'Katoskehikko');
31543163

31553164
StopDetailsPage.latestChangeHistory
31563165
.getNthItem(4)
3157-
.should('be.visible')
3166+
.should('contain.text', 'Sijainti')
3167+
.and('contain.text', 'Pysäkin osoite:')
31583168
.and('contain.text', 'Mannerheimintie 1');
31593169
});
31603170

cypress/pageObjects/map/MapFooter.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,8 @@ export class MapFooter {
2424
.and('be.enabled')
2525
.click();
2626

27-
if (vehicleMode === ReusableComponentsVehicleModeEnum.Tram) {
28-
return cy
29-
.getByTestId('AddStopDropdownOption::addTramStop')
30-
.should('be.visible')
31-
.click();
32-
}
33-
3427
return cy
35-
.getByTestId('AddStopDropdownOption::addBusStop')
28+
.get(`[data-vehicle-mode="${vehicleMode}"]`)
3629
.should('be.visible')
3730
.click();
3831
}

ui/src/components/forms/stop/utils/useFindStopAreas.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ export function useFindStopAreas(
7373
compact(
7474
(rawAreas ?? [])
7575
.filter((area) =>
76-
!vehicleMode ? true : parseVehicleMode(area.transportMode) === vehicleMode,
76+
!vehicleMode
77+
? true
78+
: parseVehicleMode(area.transportMode) === vehicleMode,
7779
)
7880
.map(parseStopFormStopAreaInfo),
7981
),

ui/src/components/map/FilterPanel.tsx

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type Toggle = {
2626

2727
type IconToggle = Toggle & {
2828
readonly iconClassName: string;
29+
readonly activeColorClassName?: string;
30+
readonly inactiveColorClassName?: string;
2931
readonly disabled?: boolean;
3032
readonly tooltip: (t: TFunction) => string;
3133
readonly colorClassNames: {
@@ -49,14 +51,17 @@ const ToggleRow: FC<ToggleRowProps> = ({ toggles }) => {
4951
active,
5052
onToggle,
5153
iconClassName,
54+
activeColorClassName,
55+
inactiveColorClassName,
5256
disabled,
5357
testId,
5458
tooltip,
55-
colorClassNames,
5659
},
5760
index: number,
5861
) => (
5962
<IconToggle
63+
activeColorClassName={activeColorClassName}
64+
inactiveColorClassName={inactiveColorClassName}
6065
// We don't have proper ids to use as keys here.
6166
// This shouldn't matter as this array isn't dynamic.
6267
key={index} // eslint-disable-line react/no-array-index-key
@@ -67,56 +72,13 @@ const ToggleRow: FC<ToggleRowProps> = ({ toggles }) => {
6772
disabled={disabled}
6873
testId={testId}
6974
tooltip={tooltip(t)}
70-
colorClassNames={colorClassNames}
7175
/>
7276
),
7377
)}
7478
</Row>
7579
);
7680
};
7781

78-
const noop = () => null;
79-
// placeholder toggles of unimplemented features that can be used
80-
// for visual purposes.
81-
export const placeholderToggles: ReadonlyArray<IconToggle> = [
82-
{
83-
iconClassName: 'icon-train',
84-
active: false,
85-
onToggle: noop,
86-
disabled: true,
87-
testId: 'placeholder',
88-
tooltip: (t) => t('vehicleModeEnum.train'),
89-
colorClassNames: {
90-
active: 'bg-tweaked-brand text-white',
91-
inactive: 'bg-white text-tweaked-brand',
92-
},
93-
},
94-
{
95-
iconClassName: 'icon-ferry',
96-
active: false,
97-
onToggle: noop,
98-
disabled: true,
99-
testId: 'placeholder',
100-
tooltip: (t) => t('vehicleModeEnum.ferry'),
101-
colorClassNames: {
102-
active: 'bg-tweaked-brand text-white',
103-
inactive: 'bg-white text-tweaked-brand',
104-
},
105-
},
106-
{
107-
iconClassName: 'icon-metro',
108-
active: false,
109-
onToggle: noop,
110-
disabled: true,
111-
testId: 'placeholder',
112-
tooltip: (t) => t('vehicleModeEnum.metro'),
113-
colorClassNames: {
114-
active: 'bg-tweaked-brand text-white',
115-
inactive: 'bg-white text-tweaked-brand',
116-
},
117-
},
118-
];
119-
12082
type FilterPanelProps = {
12183
readonly routes: ReadonlyArray<IconToggle>;
12284
readonly stops: ReadonlyArray<IconToggle>;

ui/src/components/map/MapFilterPanel.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Dispatch, FC, SetStateAction } from 'react';
22
import { useAppDispatch, useAppSelector } from '../../hooks';
33
import { FilterType, selectMapFilter, setStopFilterAction } from '../../redux';
4-
import { FilterPanel, placeholderToggles } from './FilterPanel';
4+
import { FilterPanel } from './FilterPanel';
55

66
type MapFilterPanelProps = {
77
readonly routeDisplayed: boolean;
@@ -35,8 +35,6 @@ export const MapFilterPanel: FC<MapFilterPanelProps> = ({
3535
inactive: 'bg-white text-tweaked-brand',
3636
},
3737
},
38-
// We want to show placeholder toggles of unimplemented features for visual purposes
39-
...placeholderToggles,
4038
]}
4139
stops={[
4240
{
@@ -58,6 +56,8 @@ export const MapFilterPanel: FC<MapFilterPanelProps> = ({
5856
},
5957
{
6058
iconClassName: 'icon-tram',
59+
activeColorClassName: 'bg-hsl-tram-dark-green text-white',
60+
inactiveColorClassName: 'bg-white text-hsl-tram-dark-green',
6161
active: stopFilters[FilterType.ShowAllTramStops],
6262
onToggle: (isActive: boolean) =>
6363
dispatch(
@@ -73,7 +73,6 @@ export const MapFilterPanel: FC<MapFilterPanelProps> = ({
7373
inactive: 'bg-white text-hsl-tram-dark-green',
7474
},
7575
},
76-
...placeholderToggles,
7776
]}
7877
/>
7978
);

ui/src/components/map/MapFooterAddStopDropdown.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const testIds: Readonly<Record<string, string>> = {
1010
};
1111

1212
type MapFooterAddStopDropdownProps = {
13-
onAddStops: (vehicleMode: ReusableComponentsVehicleModeEnum) => void;
14-
testId: string;
15-
disabled?: boolean;
16-
inverted?: boolean;
13+
readonly onAddStops: (vehicleMode: ReusableComponentsVehicleModeEnum) => void;
14+
readonly testId: string;
15+
readonly disabled?: boolean;
16+
readonly inverted?: boolean;
1717
};
1818

1919
export const MapFooterAddStopDropdown: FC<MapFooterAddStopDropdownProps> = ({
@@ -32,13 +32,15 @@ export const MapFooterAddStopDropdown: FC<MapFooterAddStopDropdownProps> = ({
3232
disabledTooltip={t('dataModelRefactor.disabled')}
3333
>
3434
<SimpleDropdownMenuItem
35-
testId="AddStopDropdownOption::addBusStop"
35+
testId={testIds.addBusStop}
36+
data-vehicle-mode={ReusableComponentsVehicleModeEnum.Bus}
3637
onClick={() => onAddStops(ReusableComponentsVehicleModeEnum.Bus)}
3738
>
3839
{t('map.addBusStop')}
3940
</SimpleDropdownMenuItem>
4041
<SimpleDropdownMenuItem
41-
testId="AddStopDropdownOption::addTramStop"
42+
testId={testIds.addTramStop}
43+
data-vehicle-mode={ReusableComponentsVehicleModeEnum.Tram}
4244
onClick={() => onAddStops(ReusableComponentsVehicleModeEnum.Tram)}
4345
>
4446
{t('map.addTramStop')}

ui/src/components/map/stops/Stop.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,23 @@ function determineBorderColor(
5656
function determineFillColor(
5757
asMemberStop: boolean,
5858
isSelected: boolean,
59-
stopVehicleMode: ReusableComponentsVehicleModeEnum | undefined,
6059
inSelection: boolean,
60+
shouldBeGray: boolean,
61+
stopVehicleMode: ReusableComponentsVehicleModeEnum | undefined,
6162
) {
6263
if (isSelected || asMemberStop || inSelection) {
6364
return 'white';
6465
}
65-
switch (stopVehicleMode) {
66-
case ReusableComponentsVehicleModeEnum.Bus:
67-
return colors.stops.bus;
68-
case ReusableComponentsVehicleModeEnum.Tram:
69-
return colors.stops.tram;
70-
default:
71-
return colors.lightGrey;
66+
67+
if (shouldBeGray) {
68+
return colors.lightGrey;
7269
}
70+
71+
if (stopVehicleMode) {
72+
return colors.stops[stopVehicleMode] ?? 'white';
73+
}
74+
75+
return 'white';
7376
}
7477

7578
type BaseStopProps = {
@@ -82,6 +85,7 @@ type BaseStopProps = {
8285
readonly selected?: boolean;
8386
readonly testId?: string;
8487
readonly vehicleMode?: ReusableComponentsVehicleModeEnum;
88+
readonly shouldBeGray?: boolean;
8589
};
8690

8791
type ExistingStopSpecialProps = {
@@ -110,6 +114,7 @@ export const Stop: FC<StopProps> = ({
110114
selected = false,
111115
testId,
112116
vehicleMode,
117+
shouldBeGray = false,
113118
onClick,
114119
onResolveTitle,
115120
stop,
@@ -130,8 +135,9 @@ export const Stop: FC<StopProps> = ({
130135
const iconFillColor = determineFillColor(
131136
asMemberStop,
132137
selected,
133-
vehicleMode,
134138
inSelection,
139+
shouldBeGray,
140+
vehicleMode,
135141
);
136142

137143
return (

ui/src/components/map/stops/Stops.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
useDefaultErrorHandler,
4040
useMapStops,
4141
} from './hooks';
42+
import { useFilterStopsByVehicleMode } from './hooks/useFilterStopsByVehicleMode';
4243
import { Stop } from './Stop';
4344

4445
const testIds = {
@@ -109,8 +110,10 @@ export const StopsImpl: ForwardRefRenderFunction<StopsRef, StopsProps> = (
109110

110111
const { setIsLoading: setIsLoadingSaveStop } = useLoader(Operation.SaveStop);
111112

112-
const { getStopVehicleMode, getStopHighlighted } =
113+
const { getStopVehicleMode, getStopHighlighted, getStopShouldBeGray } =
113114
useMapStops(displayedRouteIds);
115+
const filterStopsByVehicleMode =
116+
useFilterStopsByVehicleMode(getStopVehicleMode);
114117

115118
const { setLoadingState: setFetchStopsLoadingState } = useLoader(
116119
Operation.FetchStops,
@@ -215,10 +218,12 @@ export const StopsImpl: ForwardRefRenderFunction<StopsRef, StopsProps> = (
215218
(isInSearchResultMode && mapStopSelection.byResultSelection) ||
216219
selectedStops.includes(stop.netex_id);
217220

221+
const modeFilteredStops = filterStopsByVehicleMode(filteredStops);
222+
218223
return (
219224
<>
220225
{/* Display existing stops */}
221-
{filteredStops.map((item) => {
226+
{modeFilteredStops.map((item) => {
222227
const point = mapLngLatToPoint(item.location.coordinates);
223228

224229
return (
@@ -240,6 +245,7 @@ export const StopsImpl: ForwardRefRenderFunction<StopsRef, StopsProps> = (
240245
: testIds.stopMarker(item.label, item.priority)
241246
}
242247
vehicleMode={getStopVehicleMode(item)}
248+
shouldBeGray={getStopShouldBeGray(item)}
243249
/>
244250
);
245251
})}

0 commit comments

Comments
 (0)