Skip to content

Commit

Permalink
Merge branch 'v3' into waltti
Browse files Browse the repository at this point in the history
  • Loading branch information
vesameskanen committed Dec 27, 2024
2 parents 11387af + e607e53 commit 412fcfe
Show file tree
Hide file tree
Showing 49 changed files with 1,326 additions and 441 deletions.
61 changes: 52 additions & 9 deletions app/component/RouteNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,43 @@ const LONG_ROUTE_NUMBER_LENGTH = 6;

function RouteNumber(props, context) {
const mode = props.mode.toLowerCase();
const { alertSeverityLevel, color, withBicycle, text } = props;
const { alertSeverityLevel, color, withBicycle, withCar } = props;
const isScooter = mode === TransportMode.Scooter.toLowerCase();
const textIsText = typeof text === 'string'; // can be also react node

// Perform text-related processing
let filteredText = props.text;
if (
props.shortenLongText &&
context.config.disabledLegTextModes?.includes(mode) &&
props.className.includes('line')
) {
filteredText = '';
}
const textFieldIsText = typeof filteredText === 'string'; // can be also react node
if (
props.shortenLongText &&
context.config.shortenLongTextThreshold &&
filteredText &&
textFieldIsText &&
filteredText.length > context.config.shortenLongTextThreshold
) {
filteredText = `${filteredText.substring(
0,
context.config.shortenLongTextThreshold - 3,
)}...`;
}
const longText =
text && textIsText && text.length >= LONG_ROUTE_NUMBER_LENGTH;
filteredText &&
textFieldIsText &&
filteredText.length >= LONG_ROUTE_NUMBER_LENGTH;
// Checks if route only has letters without identifying numbers and
// length doesn't fit in the tab view
const hasNoShortName =
text && textIsText && /^([^0-9]*)$/.test(text) && text.length > 3;
filteredText &&
textFieldIsText &&
/^([^0-9]*)$/.test(filteredText) &&
filteredText.length > 3;

const getColor = () => color || (props.isTransitLeg ? 'currentColor' : null);

const getIcon = (
Expand Down Expand Up @@ -57,6 +85,12 @@ function RouteNumber(props, context) {
className="itinerary-icon_with-bicycle"
/>
)}
{withCar && (
<Icon
img="icon-icon_car-withoutBox"
className="itinerary-icon_with-car"
/>
)}
</React.Fragment>
);
}
Expand All @@ -83,6 +117,12 @@ function RouteNumber(props, context) {
className="itinerary-icon_with-bicycle"
/>
)}
{withCar && (
<Icon
img="icon-icon_car-withoutBox"
className="itinerary-icon_with-car"
/>
)}
</React.Fragment>
);
};
Expand Down Expand Up @@ -128,7 +168,7 @@ function RouteNumber(props, context) {
)}
</div>
)}
{text && (
{filteredText && (
<div
className={cx(
'vehicle-number-container-v'.concat(props.card ? '-map' : ''),
Expand All @@ -146,10 +186,10 @@ function RouteNumber(props, context) {
)}
style={{ color: !props.withBar && getColor() }}
>
{props.text}
{filteredText}
</span>
{textIsText && (
<span className="sr-only">{text?.toLowerCase()}</span>
{textFieldIsText && (
<span className="sr-only">{filteredText?.toLowerCase()}</span>
)}
</div>
)}
Expand Down Expand Up @@ -206,9 +246,11 @@ RouteNumber.propTypes = {
duration: PropTypes.number,
isTransitLeg: PropTypes.bool,
withBicycle: PropTypes.bool,
withCar: PropTypes.bool,
card: PropTypes.bool,
appendClass: PropTypes.string,
occupancyStatus: PropTypes.string,
shortenLongText: PropTypes.bool,
};

RouteNumber.defaultProps = {
Expand All @@ -228,15 +270,16 @@ RouteNumber.defaultProps = {
isTransitLeg: false,
renderModeIcons: false,
withBicycle: false,
withCar: false,
color: undefined,
duration: undefined,
occupancyStatus: undefined,
shortenLongText: false,
};

RouteNumber.contextTypes = {
intl: intlShape.isRequired,
config: configShape.isRequired,
};

RouteNumber.displayName = 'RouteNumber';
export default RouteNumber;
36 changes: 3 additions & 33 deletions app/component/RouteNumberContainer.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,35 @@
import PropTypes from 'prop-types';
import React from 'react';
import { routeShape, configShape } from '../util/shapes';
import { getLegText } from '../util/legUtils';
import { getRouteText } from '../util/legUtils';
import RouteNumber from './RouteNumber';

const RouteNumberContainer = (
{
alertSeverityLevel,
interliningWithRoute,
className,
route,
isCallAgency,
withBicycle,
occupancyStatus,
mode,
...props
},
{ interliningWithRoute, route, mode, ...props },
{ config },
) =>
route && (
<RouteNumber
alertSeverityLevel={alertSeverityLevel}
className={className}
isCallAgency={isCallAgency}
color={route.color ? `#${route.color}` : null}
mode={mode !== undefined ? mode : route.mode}
text={getLegText(route, config, interliningWithRoute)}
withBicycle={withBicycle}
occupancyStatus={occupancyStatus}
text={getRouteText(route, config, interliningWithRoute)}
{...props}
/>
);

RouteNumberContainer.propTypes = {
alertSeverityLevel: PropTypes.string,
route: routeShape.isRequired,
interliningWithRoute: PropTypes.string,
isCallAgency: PropTypes.bool,
vertical: PropTypes.bool,
className: PropTypes.string,
fadeLong: PropTypes.bool,
withBicycle: PropTypes.bool,
occupancyStatus: PropTypes.string,
mode: PropTypes.string,
};

RouteNumberContainer.defaultProps = {
interliningWithRoute: undefined,
alertSeverityLevel: undefined,
isCallAgency: false,
vertical: false,
fadeLong: false,
className: '',
withBicycle: false,
occupancyStatus: undefined,
mode: undefined,
};

RouteNumberContainer.contextTypes = {
config: configShape.isRequired,
};

RouteNumberContainer.displayName = 'RouteNumberContainer';
export default RouteNumberContainer;
11 changes: 11 additions & 0 deletions app/component/itinerary/AlternativeItineraryBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function AlternativeItineraryBar(
bikePlan,
bikePublicPlan,
carPlan,
carPublicPlan,
parkRidePlan,
loading,
},
Expand Down Expand Up @@ -69,6 +70,14 @@ export default function AlternativeItineraryBar(
onClick={selectStreetMode}
/>
)}
{carPublicPlan?.edges?.length > 0 && (
<StreetModeSelectorButton
icon="icon-icon_car-withoutBox"
name={streetHash.carAndVehicle}
plan={carPublicPlan}
onClick={selectStreetMode}
/>
)}
{config.emphasizeOneWayJourney && (
<div style={{ alignSelf: 'center' }}>
<FormattedMessage
Expand All @@ -90,6 +99,7 @@ AlternativeItineraryBar.propTypes = {
bikePublicPlan: planShape,
parkRidePlan: planShape,
carPlan: planShape,
carPublicPlan: planShape,
weatherData: PropTypes.shape({
temperature: PropTypes.number,
windSpeed: PropTypes.number,
Expand All @@ -105,6 +115,7 @@ AlternativeItineraryBar.defaultProps = {
bikePublicPlan: undefined,
parkRidePlan: undefined,
carPlan: undefined,
carPublicPlan: undefined,
loading: undefined,
};

Expand Down
Loading

0 comments on commit 412fcfe

Please sign in to comment.