Skip to content

Commit f3d1c3f

Browse files
authored
Merge pull request #5763 from HSLdevcom/more-pier-platform-track-changes
AB#488 - Allow the use of correct terms for ferries related to platform numbers
2 parents 9970062 + ae4dcf5 commit f3d1c3f

20 files changed

Lines changed: 259 additions & 143 deletions

app/component/AddressRow.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { FormattedMessage } from 'react-intl';
3+
import { useIntl } from 'react-intl';
44
import StopCode from './StopCode';
5+
import { getTerminalOrStationText } from '../util/modeUtils';
56

6-
const getTerminalTypeId = vehicleMode => {
7-
if (vehicleMode === 'FERRY') {
8-
return 'terminal';
9-
}
10-
return 'station';
7+
const AddressRow = props => {
8+
const intl = useIntl();
9+
return (
10+
<div className="route-address-row-container">
11+
<span className="route-stop-address-row">{props.desc}</span>
12+
{props.code && <StopCode code={props.code} />}
13+
{props.isTerminal && (
14+
<StopCode code={getTerminalOrStationText(intl, props.vehicleMode)} />
15+
)}
16+
</div>
17+
);
1118
};
1219

13-
const AddressRow = props => (
14-
<div className="route-address-row-container">
15-
<span className="route-stop-address-row">{props.desc}</span>
16-
{props.code && <StopCode code={props.code} />}
17-
{props.isTerminal && (
18-
<StopCode
19-
code={<FormattedMessage id={getTerminalTypeId(props.vehicleMode)} />}
20-
/>
21-
)}
22-
</div>
23-
);
24-
2520
AddressRow.propTypes = {
2621
desc: PropTypes.string,
2722
code: PropTypes.string,

app/component/DepartureRow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export default function DepartureRow(
240240
<PlatformNumber
241241
number={departure.stop?.platformCode}
242242
short
243-
isRailOrSubway={mode === 'RAIL' || mode === 'SUBWAY'}
243+
mode={mode}
244244
withText={false}
245245
updated={platformUpdated}
246246
/>

app/component/PlatformNumber.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3-
import { FormattedMessage } from 'react-intl';
3+
import { useIntl } from 'react-intl';
44
import cx from 'classnames';
55
import Icon from './Icon';
6+
import {
7+
getTrackOrPierOrPlatformText,
8+
getTrackOrPierOrPlatformTextShort,
9+
} from '../util/modeUtils';
610

7-
function PlatformNumber({ number, short, isRailOrSubway, updated, withText }) {
11+
function PlatformNumber({ number, short, mode, updated, withText, plain }) {
12+
const intl = useIntl();
813
if (!number) {
914
return false;
1015
}
@@ -16,12 +21,9 @@ function PlatformNumber({ number, short, isRailOrSubway, updated, withText }) {
1621
if (short) {
1722
return (
1823
<span className="platform-short">
19-
{withText && (
20-
<FormattedMessage
21-
id={isRailOrSubway ? 'track' : 'platform-short-no-num'}
22-
defaultMessage={isRailOrSubway ? 'Track ' : 'Plat. '}
23-
/>
24-
)}
24+
{withText &&
25+
mode &&
26+
getTrackOrPierOrPlatformTextShort(intl, mode.toUpperCase())}
2527
<span
2628
className={cx('platform-number-wrapper', {
2729
'platform-updated': updated,
@@ -35,13 +37,10 @@ function PlatformNumber({ number, short, isRailOrSubway, updated, withText }) {
3537
}
3638

3739
return (
38-
<span className="platform-number">
39-
{withText && (
40-
<FormattedMessage
41-
id={isRailOrSubway ? 'track' : 'platform'}
42-
defaultMessage={isRailOrSubway ? 'Track ' : 'Platform '}
43-
/>
44-
)}
40+
<span className={plain ? 'platform-number-plain' : 'platform-number'}>
41+
{withText &&
42+
mode &&
43+
getTrackOrPierOrPlatformText(intl, mode.toUpperCase())}
4544
<span
4645
className={cx('platform-number-wrapper', {
4746
'platform-updated': updated,
@@ -57,17 +56,18 @@ function PlatformNumber({ number, short, isRailOrSubway, updated, withText }) {
5756
PlatformNumber.propTypes = {
5857
number: PropTypes.string,
5958
short: PropTypes.bool,
60-
isRailOrSubway: PropTypes.bool,
59+
mode: PropTypes.string.isRequired,
6160
updated: PropTypes.bool,
6261
withText: PropTypes.bool,
62+
plain: PropTypes.bool,
6363
};
6464

6565
PlatformNumber.defaultProps = {
6666
number: undefined,
6767
short: true,
68-
isRailOrSubway: false,
6968
updated: false,
7069
withText: true,
70+
plain: false,
7171
};
7272

7373
PlatformNumber.displayName = 'PlatformNumber';

app/component/itinerary/BicycleLeg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export default function BicycleLeg(
318318
<PlatformNumber
319319
number={bicycleWalkLeg.from.stop.platformCode}
320320
short
321-
isRailOrSubway
321+
mode={bicycleWalkLeg.from.stop.vehicleMode}
322322
/>
323323
</>
324324
)}
Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React from 'react';
2-
import { FormattedMessage } from 'react-intl';
32
import cx from 'classnames';
43
import PlatformNumber from '../PlatformNumber';
5-
import { modeUsesTrack } from '../../util/modeUtils';
4+
import {
5+
getTrackOrPierOrPlatformChangeText,
6+
getTrackOrPierOrPlatformWithNumText,
7+
} from '../../util/modeUtils';
68
import { isPlatformChanged } from '../../util/legUtils';
79
import { legShape } from '../../util/shapes';
810

@@ -25,24 +27,14 @@ function BoardingInformation({ leg }) {
2527
})}
2628
>
2729
{comma}
28-
{platformChanged ? (
29-
<>
30-
<FormattedMessage
31-
id={modeUsesTrack(leg.mode) ? 'track' : 'platform'}
32-
/>
33-
<PlatformNumber
34-
number={platformCode}
35-
updated={platformChanged}
36-
isRailOrSubway={modeUsesTrack(leg.mode)}
37-
withText={false}
38-
/>
39-
</>
40-
) : (
41-
<FormattedMessage
42-
id={modeUsesTrack(leg.mode) ? 'track-num' : 'platform-num'}
43-
values={{ platformCode }}
44-
/>
45-
)}
30+
<PlatformNumber
31+
number={platformCode}
32+
short={false}
33+
updated={platformChanged}
34+
mode={leg.mode}
35+
withText
36+
plain
37+
/>
4638
</span>
4739
);
4840
}
@@ -53,19 +45,6 @@ BoardingInformation.propTypes = {
5345
leg: legShape.isRequired,
5446
};
5547

56-
/**
57-
* Returns a message indicating a platform or track change.
58-
* @param {boolean} isTrack - True if the mode uses track, false for platform.
59-
* @param {Object} intl - The intl object for formatting messages.
60-
* @return {string} The platform change label.
61-
*/
62-
function getPlatformChangeLabel(isTrack, intl) {
63-
return intl.formatMessage({
64-
id: isTrack ? 'navigation-track-change' : 'navigation-platform-change',
65-
defaultMessage: isTrack ? 'Track change' : 'Platform change',
66-
});
67-
}
68-
6948
/**
7049
* Returns a string with platform/track information for a transit leg, for screen reader use.
7150
* @param {Object} leg - The transit leg object.
@@ -78,21 +57,20 @@ function getBoardingInformationText(leg, intl, showPlatformChangeLabel = true) {
7857
}
7958
const platformCode = leg?.from?.stop?.platformCode;
8059
if (platformCode) {
81-
const isTrack = modeUsesTrack(leg.mode);
8260
const platformChangeLabelText =
8361
showPlatformChangeLabel && isPlatformChanged(leg)
84-
? `${getPlatformChangeLabel(isTrack, intl)}:`
62+
? `${getTrackOrPierOrPlatformChangeText(intl, leg.mode)}:`
8563
: '';
86-
const platformLabel = intl.formatMessage(
87-
{
88-
id: isTrack ? 'track-num' : 'platform-num',
89-
},
90-
{ platformCode },
64+
const platformLabel = getTrackOrPierOrPlatformWithNumText(
65+
intl,
66+
leg.mode,
67+
platformCode,
9168
);
69+
9270
return `${platformChangeLabelText} ${platformLabel}`;
9371
}
9472
return '';
9573
}
9674

97-
export { getBoardingInformationText, getPlatformChangeLabel };
75+
export { getBoardingInformationText };
9876
export default BoardingInformation;

app/component/itinerary/TransitLeg.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ import InterlineInfo from './InterlineInfo';
4848
import AlternativeLegsInfo from './AlternativeLegsInfo';
4949
import LegInfo from './LegInfo';
5050
import ExternalLink from '../ExternalLink';
51-
import {
52-
getBoardingInformationText,
53-
getPlatformChangeLabel,
54-
} from './BoardingInformation';
55-
import { modeUsesTrack } from '../../util/modeUtils';
51+
import { getBoardingInformationText } from './BoardingInformation';
52+
import { getTrackOrPierOrPlatformChangeText } from '../../util/modeUtils';
5653

5754
const stopCode = code => code && <StopCode code={code} />;
5855

@@ -276,7 +273,7 @@ class TransitLeg extends React.Component {
276273
trackInfo: getBoardingInformationText(leg, intl, false),
277274
}}
278275
/>
279-
{platformChanged && getPlatformChangeLabel(modeUsesTrack(mode), intl)}
276+
{platformChanged && getTrackOrPierOrPlatformChangeText(intl, mode)}
280277
</>
281278
);
282279

@@ -504,9 +501,7 @@ class TransitLeg extends React.Component {
504501
<PlatformNumber
505502
number={leg.from.stop.platformCode}
506503
short
507-
isRailOrSubway={
508-
modeClassName === 'rail' || modeClassName === 'subway'
509-
}
504+
mode={mode}
510505
updated={platformChanged}
511506
/>
512507
</div>

app/component/itinerary/WalkLeg.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,7 @@ function WalkLeg({
282282
<PlatformNumber
283283
number={leg[toOrFrom].stop.platformCode}
284284
short
285-
isRailOrSubway={
286-
fromMode === 'RAIL' || fromMode === 'SUBWAY'
287-
}
285+
mode={fromMode}
288286
/>
289287
)}
290288
</div>

app/component/itinerary/navigator/NaviCardExtension.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import ZoneIcon from '../../ZoneIcon';
1515
import { legShape, configShape } from '../../../util/shapes';
1616
import { getDestinationProperties, LEGTYPE, withRealTime } from './NaviUtils';
17-
import { getTripOrRouteMode, modeUsesTrack } from '../../../util/modeUtils';
17+
import { getTripOrRouteMode } from '../../../util/modeUtils';
1818
import RouteNumberContainer from '../../RouteNumberContainer';
1919
import BoardingInfo from './BoardingInfo';
2020
import { getModeIconColor } from '../../../util/colorUtils';
@@ -127,7 +127,7 @@ const NaviCardExtension = (
127127
<PlatformNumber
128128
number={platformCode}
129129
short
130-
isRailOrSubway={modeUsesTrack(vehicleMode)}
130+
mode={vehicleMode}
131131
updated={platformUpdated}
132132
/>
133133
)}

app/component/itinerary/navigator/NaviUtils.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
getTripOrRouteMode,
1010
getStopMode,
1111
transitIconName,
12-
modeUsesTrack,
12+
getTrackOrPierOrPlatformRestoredText,
13+
getTrackOrPierOrPlatformChangeText,
14+
getTrackOrPierOrPlatformChangeDetailsText,
1315
} from '../../../util/modeUtils';
1416
import { locationToUri } from '../../../util/otpStrings';
1517
import { getItineraryPagePath } from '../../../util/path';
@@ -711,20 +713,17 @@ export const getItineraryAlerts = (
711713
) {
712714
const id = `platform-${nextLeg.legId}`;
713715
if (!messages.get(id)?.closed) {
714-
const boardingType = modeUsesTrack(nextLeg.mode) ? 'track' : 'platform';
715-
const translationKey =
716+
const title =
716717
platformStatus === PLATFORM_STATUS.RESTORED
717-
? `navigation-${boardingType}-restored`
718-
: `navigation-${boardingType}-change`;
719-
const title = intl.formatMessage({ id: translationKey });
718+
? getTrackOrPierOrPlatformRestoredText(intl, nextLeg.mode)
719+
: getTrackOrPierOrPlatformChangeText(intl, nextLeg.mode);
720720
const lMode = getLocalizedMode(nextLeg.mode, intl, config);
721721
const routeName = `${lMode} ${nextLeg.route?.shortName}`;
722-
const body = intl.formatMessage(
723-
{ id: `navigation-${boardingType}-change-details` },
724-
{
725-
number: nextLeg.from.stop.platformCode || '',
726-
name: routeName || '',
727-
},
722+
const body = getTrackOrPierOrPlatformChangeDetailsText(
723+
intl,
724+
nextLeg.mode,
725+
nextLeg.from.stop.platformCode,
726+
routeName,
728727
);
729728
alerts.push({
730729
severity: 'WARNING',

app/component/itinerary/navigator/navigator.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@
468468
.platform-short {
469469
width: unset;
470470
font-size: $font-size-small;
471-
letter-spacing: $letter-spacing;
472471
display: inline-flex;
473472
align-items: center;
474473

0 commit comments

Comments
 (0)