Skip to content

Commit 08f2527

Browse files
authored
Merge pull request #5813 from HSLdevcom/trafficnow-v3
AB#425 Trafficnow canceled trips and other improvements
2 parents 0fcc5ac + c7ce96b commit 08f2527

54 files changed

Lines changed: 2293 additions & 699 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/component/Card.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
22
import React, { forwardRef } from 'react';
33
import cx from 'classnames';
44

5-
const Card = forwardRef(({ className, children, ...rest }, ref) => {
5+
const Card = forwardRef(({ className = undefined, children, ...rest }, ref) => {
66
return (
77
<div ref={ref} className={cx('card', className)} {...rest}>
88
{children}
@@ -17,6 +17,4 @@ Card.propTypes = {
1717
children: PropTypes.node.isRequired,
1818
};
1919

20-
Card.defaultProps = { className: undefined };
21-
2220
export default Card;

app/component/Icon.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ const Icon = ({
3131
viewBox={!omitViewBox ? viewBox : null}
3232
className={cx('icon', className)}
3333
aria-label={ariaLabel}
34+
transform={
35+
background?.props?.shape === 'stopsign'
36+
? 'translate(0, -3.33)'
37+
: undefined
38+
}
3439
>
3540
{background}
3641
<g

app/component/icon/IconBackground.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
const STOP_SIGN_POLE_WIDTH = 4;
4+
const STOP_SIGN_POLE_WIDTH = 3;
55
const STOP_SIGN_POLE_X = 20 - STOP_SIGN_POLE_WIDTH / 2;
66

77
const IconBackground = ({ shape, color }) => {
@@ -10,23 +10,23 @@ const IconBackground = ({ shape, color }) => {
1010
}
1111
return (
1212
<>
13-
<circle
14-
className="icon-circle"
15-
cx="20"
16-
cy="20"
17-
fill={color}
18-
r={shape === 'stopsign' ? '13.33' : '20'}
19-
/>
2013
{shape === 'stopsign' && (
2114
<rect
2215
x={STOP_SIGN_POLE_X}
23-
y="33.33"
16+
y="30"
2417
width={STOP_SIGN_POLE_WIDTH}
25-
height="6.67"
18+
height="10"
2619
fill="#333333"
2720
rx="2"
2821
/>
2922
)}
23+
<circle
24+
className="icon-circle"
25+
cx="20"
26+
cy="20"
27+
fill={color}
28+
r={shape === 'stopsign' ? '13.33' : '20'}
29+
/>
3030
{shape === 'square' && (
3131
<rect
3232
className="icon-square"

app/component/trafficnow/Alerts.js

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import React from 'react';
2+
import { useRouter } from 'found';
3+
import { DateTime } from 'luxon';
4+
import PropTypes from 'prop-types';
5+
import { useIntl } from 'react-intl';
6+
import { useConfigContext } from '../../configurations/ConfigContext';
7+
import { PREFIX_TIMETABLE, TRAFFICNOW, routePagePath } from '../../util/path';
8+
import Card from '../Card';
9+
import Icon from '../Icon';
10+
import CanceledDepartures from './components/CanceledDepartures';
11+
import RouteBadgeGroup from './components/RouteBadgeGroup';
12+
import DisruptionBadge from './DisruptionBadge';
13+
14+
const CanceledTripCard = ({ mode, totalCount, trips }) => {
15+
const { router } = useRouter();
16+
const { colors } = useConfigContext();
17+
const intl = useIntl();
18+
19+
const handleRouteBadgeClick = url => e => {
20+
e.preventDefault();
21+
e.stopPropagation();
22+
router.push(url);
23+
};
24+
25+
/* eslint-disable no-param-reassign */
26+
const groupedTrips = trips.reduce((container, { start, trip }) => {
27+
if (!trip?.route?.gtfsId || !start?.schedule?.time?.departure) {
28+
return container;
29+
}
30+
31+
const shortName = trip?.route?.shortName || 'unknown';
32+
if (container[shortName]) {
33+
container[shortName].trips.push({
34+
...trip,
35+
departureTime: DateTime.fromISO(
36+
start?.schedule.time.departure,
37+
).toFormat('HH:mm'),
38+
});
39+
} else {
40+
container[shortName] = {
41+
routeGtfsId: trip.route.gtfsId,
42+
trips: [
43+
{
44+
...trip,
45+
departureTime: DateTime.fromISO(
46+
start?.schedule.time.departure,
47+
).toFormat('HH:mm'),
48+
},
49+
],
50+
};
51+
}
52+
return container;
53+
}, {});
54+
55+
const isSingleRoute = Object.keys(groupedTrips).length === 1;
56+
57+
return (
58+
<Card
59+
className="disruption-card clickable"
60+
onClick={handleRouteBadgeClick(`/${TRAFFICNOW}/peruutukset/${mode}`)}
61+
>
62+
<header>
63+
<DisruptionBadge showIcon variant="WARNING" label="NO_SERVICE" />
64+
<button type="button">
65+
<Icon
66+
img="icon_arrow-collapse--right"
67+
color={colors.primary}
68+
className="disruption-card__icon"
69+
/>
70+
</button>
71+
</header>
72+
<div className="badges">
73+
<RouteBadgeGroup
74+
mode={mode}
75+
stopPropagation
76+
routes={Object.entries(groupedTrips).map(
77+
([shortName, { routeGtfsId, trips: groupedRouteTrips }]) => ({
78+
id: shortName,
79+
name: shortName,
80+
url: routePagePath(routeGtfsId, PREFIX_TIMETABLE),
81+
gtfsId: routeGtfsId,
82+
trips: groupedRouteTrips,
83+
}),
84+
)}
85+
renderRouteSuffix={({ trips: groupedRouteTrips }) =>
86+
isSingleRoute ? (
87+
<CanceledDepartures
88+
departures={groupedRouteTrips.map(
89+
({ tripId, departureTime }) => ({
90+
tripId,
91+
departureTime,
92+
}),
93+
)}
94+
/>
95+
) : null
96+
}
97+
renderSuffix={
98+
totalCount > trips.length ? (
99+
<span style={{ backgroundColor: '#F2F5F7' }}>
100+
<Icon img="icon_three-dots" width={1.3} height={1.3} />
101+
</span>
102+
) : null
103+
}
104+
/>
105+
</div>
106+
<div className="disruption-card__body-row-validity-icon text-xs">
107+
<Icon img="icon_clock" />
108+
{intl.formatMessage({ id: 'valid', defaultMessage: 'Active' })}
109+
</div>
110+
</Card>
111+
);
112+
};
113+
114+
CanceledTripCard.propTypes = {
115+
mode: PropTypes.string.isRequired,
116+
totalCount: PropTypes.number.isRequired,
117+
trips: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
118+
};
119+
120+
export default CanceledTripCard;

0 commit comments

Comments
 (0)