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 Nov 27, 2024
2 parents 3196cab + e3294c8 commit 490ded8
Show file tree
Hide file tree
Showing 125 changed files with 1,823 additions and 1,276 deletions.
24 changes: 12 additions & 12 deletions app/component/DepartureListContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const asDepartures = stoptimes =>
(!canceled
? stoptime.realtimeDeparture
: stoptime.scheduledDeparture);
const stoptimeTime = isArrival ? arrivalTime : departureTime;
const time = isArrival ? arrivalTime : departureTime;

const { pattern } = stoptime.trip;
return {
Expand All @@ -60,7 +60,7 @@ const asDepartures = stoptimes =>
hasNoStop,
hasOnlyDropoff,
isLastStop,
stoptime: stoptimeTime,
time,
stop: stoptime.stop,
realtime: stoptime.realtime,
pattern,
Expand Down Expand Up @@ -246,21 +246,21 @@ class DepartureListContainer extends Component {
let dayCutoff = moment.unix(currentTime).startOf('day').unix();
const departures = asDepartures(stoptimes)
.filter(departure => !(isTerminal && departure.isArrival))
.filter(departure => currentTime < departure.stoptime)
.filter(departure => currentTime < departure.time)
.slice(0, limit);

// Add day dividers when day changes and add service day divider after service day changes.
// If day divider and service day dividers are added with same departure only show day divider.
const departuresWithDayDividers = departures.map(departure => {
const serviceDate = moment.unix(departure.serviceDay).format('DDMMYYYY');
const dayCutoffDate = moment.unix(dayCutoff).format('DDMMYYYY');
const stoptimeDate = moment.unix(departure.stoptime).format('DDMMYYYY');
const date = moment.unix(departure.time).format('DDMMYYYY');
const serviceDayCutoffDate = moment
.unix(serviceDayCutoff)
.format('DDMMYYYY');

if (stoptimeDate !== dayCutoffDate && departure.stoptime > dayCutoff) {
dayCutoff = moment.unix(departure.stoptime).startOf('day').unix();
if (date !== dayCutoffDate && departure.time > dayCutoff) {
dayCutoff = moment.unix(departure.time).startOf('day').unix();
// eslint-disable-next-line no-param-reassign
departure.addDayDivider = true;
}
Expand All @@ -283,14 +283,14 @@ class DepartureListContainer extends Component {

let firstDayDepartureCount = 0;
departuresWithDayDividers.forEach((departure, index) => {
const departureDate = moment.unix(departure.stoptime).format('DDMMYYYY');
const departureDate = moment.unix(departure.time).format('DDMMYYYY');
const nextDay = moment.unix(currentTime).add(1, 'day').unix();
if (departure.stoptime < nextDay) {
if (departure.time < nextDay) {
firstDayDepartureCount += 1;
}

// If next 24h has more than 10 departures only show stops for the next 24h
if (departure.stoptime > nextDay && firstDayDepartureCount >= 10) {
if (departure.time > nextDay && firstDayDepartureCount >= 10) {
return;
}

Expand All @@ -299,7 +299,7 @@ class DepartureListContainer extends Component {
<tr key={departureDate}>
<td colSpan={isTerminal ? 4 : 3}>
<div className="date-row border-bottom">
{moment.unix(departure.stoptime).format('dddd D.M.YYYY')}
{moment.unix(departure.time).format('dddd D.M.YYYY')}
</div>
</td>
</tr>,
Expand All @@ -314,7 +314,7 @@ class DepartureListContainer extends Component {
);
}

const id = `${departure.pattern.code}:${departure.stoptime}`;
const id = `${departure.pattern.code}:${departure.time}:${departure.trip.gtfsId}`;
const dropoffMessage = getDropoffMessage(
departure.hasOnlyDropoff,
departure.hasNoStop,
Expand Down Expand Up @@ -344,7 +344,7 @@ class DepartureListContainer extends Component {
<DepartureRow
key={id}
departure={row}
departureTime={departure.stoptime}
departureTime={departure.time}
currentTime={this.props.currentTime}
showPlatformCode={isTerminal}
canceled={departure.canceled}
Expand Down
20 changes: 8 additions & 12 deletions app/component/EmbeddedSearch/EmbeddedSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import CtrlPanel from '@digitransit-component/digitransit-component-control-pane
import i18next from 'i18next';
import { configShape } from '../../util/shapes';
import { getRefPoint } from '../../util/apiUtils';
import withSearchContext from '../WithSearchContext';
import {
withSearchContext,
getLocationSearchTargets,
} from '../WithSearchContext';
import {
buildQueryString,
buildURL,
Expand All @@ -21,6 +24,8 @@ import useUTMCampaignParams from './hooks/useUTMCampaignParams';

const LocationSearch = withSearchContext(DTAutosuggestPanel, true);

const sources = ['Favourite', 'History', 'Datasource'];

const translations = {
fi: {
'own-position': 'Nykyinen sijaintisi',
Expand Down Expand Up @@ -173,13 +178,6 @@ const EmbeddedSearch = (props, context) => {
titleText = i18next.t('find-route');
}

const locationSearchTargets = [
'Locations',
'CurrentPosition',
'FutureRoutes',
'Stops',
];
const sources = ['Favourite', 'History', 'Datasource'];
const refPoint = getRefPoint(origin, destination, {});

const onSelectLocation = (item, id) => {
Expand Down Expand Up @@ -215,6 +213,7 @@ const EmbeddedSearch = (props, context) => {
destination,
lang,
sources,
targets: getLocationSearchTargets(config, false),
color,
hoverColor,
refPoint,
Expand Down Expand Up @@ -325,10 +324,7 @@ const EmbeddedSearch = (props, context) => {
<span className="sr-only">
{i18next.t('search-fields-sr-instructions')}
</span>
<LocationSearch
targets={locationSearchTargets}
{...locationSearchProps}
/>
<LocationSearch {...locationSearchProps} />
<div className="embedded-search-button-container">
{logo ? (
<img
Expand Down
15 changes: 5 additions & 10 deletions app/component/EmbeddedSearchGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ import DTAutosuggest from '@digitransit-component/digitransit-component-autosugg
import { configShape } from '../util/shapes';
import EmbeddedSearch from './EmbeddedSearch';
import { EMBEDDED_SEARCH_PATH } from '../util/path';
import withSearchContext from './WithSearchContext';
import { getRefPoint } from '../util/apiUtils';
import withBreakpoint from '../util/withBreakpoint';
import {
withSearchContext,
getLocationSearchTargets,
} from './WithSearchContext';
import { isBrowser } from '../util/browser';

const LocationSearch = withSearchContext(DTAutosuggest, true);

const locationSearchTargets = [
'Locations',
'CurrentPosition',
'Stations',
'Stops',
];
const sources = ['Favourite', 'History', 'Datasource'];

const languages = [
Expand Down Expand Up @@ -83,7 +80,7 @@ const EmbeddedSearchGenerator = (props, context) => {
refPoint,
lang,
sources,
targets: locationSearchTargets,
targets: getLocationSearchTargets(config, false),
isMobile: breakpoint !== 'large',
color: colors.primary,
hoverColor: colors.hover,
Expand Down Expand Up @@ -356,7 +353,6 @@ const EmbeddedSearchGenerator = (props, context) => {
{searchOriginDefined && (
<div className="location-search-wrapper">
<LocationSearch
targets={locationSearchTargets}
id="origin"
placeholder="search-origin-index"
className="origin-search"
Expand Down Expand Up @@ -393,7 +389,6 @@ const EmbeddedSearchGenerator = (props, context) => {
{searchDestinationDefined && (
<div className="location-search-wrapper">
<LocationSearch
targets={locationSearchTargets}
id="destination"
placeholder="search-destination-index"
className="destination-search"
Expand Down
28 changes: 9 additions & 19 deletions app/component/FavouritesContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import FavouriteModal from '@digitransit-component/digitransit-component-favouri
import FavouriteEditModal from '@digitransit-component/digitransit-component-favourite-editing-modal';
import DialogModal from '@digitransit-component/digitransit-component-dialog-modal';
import { configShape } from '../util/shapes';
import withSearchContext from './WithSearchContext';

import {
withSearchContext,
getLocationSearchTargets,
} from './WithSearchContext';
import {
saveFavourite,
updateFavourites,
Expand All @@ -19,7 +21,6 @@ import {
import FavouriteStore from '../store/FavouriteStore';
import { addAnalyticsEvent } from '../util/analyticsUtils';
import { LightenDarkenColor } from '../util/colorUtils';
import { useCitybikes } from '../util/modeUtils';

const AutoSuggestWithSearchContext = withSearchContext(AutoSuggest);

Expand Down Expand Up @@ -325,22 +326,11 @@ class FavouritesContainer extends React.Component {
const isLoading =
this.props.favouriteStatus === FavouriteStore.STATUS_FETCHING_OR_UPDATING;
const { requireLoggedIn, isLoggedIn } = this.props;
const targets = ['Locations', 'Stations', 'CurrentPosition', 'MapPosition'];
const { fontWeights } = this.context.config;
const { config } = this.context;
const { fontWeights } = config;
const favouritePlaces = this.props.favourites.filter(
item => item.type === 'place',
);
if (
useCitybikes(
this.context.config.vehicleRental?.networks,
this.context.config,
)
) {
targets.push('VehicleRentalStations');
}
if (this.context.config.includeParkAndRideSuggestions) {
targets.push('ParkingAreas');
}
return (
<React.Fragment>
<FavouriteBar
Expand Down Expand Up @@ -385,22 +375,22 @@ class FavouritesContainer extends React.Component {
<AutoSuggestWithSearchContext
appElement="#app"
sources={['History', 'Datasource']}
targets={targets}
targets={getLocationSearchTargets(config, true)}
id="favourite"
icon="search"
placeholder="search-address-or-place"
value={
(this.state.favourite && this.state.favourite.address) || ''
}
selectHandler={this.setLocationProperties}
getAutoSuggestIcons={this.context.config.getAutoSuggestIcons}
getAutoSuggestIcons={config.getAutoSuggestIcons}
lang={this.props.lang}
isMobile={this.props.isMobile}
color={this.props.color}
hoverColor={this.props.hoverColor}
fontWeights={fontWeights}
required
modeSet={this.context.config.iconModeSet}
modeSet={config.iconModeSet}
favouriteContext
/>
}
Expand Down
39 changes: 11 additions & 28 deletions app/component/IndexPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import inside from 'point-in-polygon';
import { configShape, locationShape } from '../util/shapes';
import storeOrigin from '../action/originActions';
import storeDestination from '../action/destinationActions';
import withSearchContext from './WithSearchContext';
import {
withSearchContext,
getLocationSearchTargets,
} from './WithSearchContext';
import {
getPathWithEndpointObjects,
getStopRoutePath,
Expand Down Expand Up @@ -300,35 +303,18 @@ class IndexPage extends React.Component {
const destination = this.pendingDestination || this.props.destination;
const sources = ['Favourite', 'History', 'Datasource'];
const stopAndRouteSearchTargets = ['Stations', 'Stops', 'Routes'];
let locationSearchTargets = [
'Locations',
'CurrentPosition',
'FutureRoutes',
];

if (config.locationSearchTargetsFromOTP) {
// configurable setup
locationSearchTargets = [
...locationSearchTargets,
...config.locationSearchTargetsFromOTP,
];
} else {
// default setup
locationSearchTargets.push('Stations');
locationSearchTargets.push('Stops');
const targets = getLocationSearchTargets(config, breakpoint !== 'large');

targets.push('FutureRoutes');

if (!config.targetsFromOTP) {
if (useCitybikes(config.vehicleRental?.networks, config)) {
stopAndRouteSearchTargets.push('VehicleRentalStations');
locationSearchTargets.push('VehicleRentalStations');
}
if (config.includeParkAndRideSuggestions) {
stopAndRouteSearchTargets.push('ParkingAreas');
locationSearchTargets.push('ParkingAreas');
}
}
const locationSearchTargetsMobile = [
...locationSearchTargets,
'MapPosition',
];

const showSpinner =
(origin.type === 'CurrentLocation' && !origin.address) ||
Expand All @@ -340,6 +326,7 @@ class IndexPage extends React.Component {
destination,
lang,
sources,
targets,
color,
hoverColor,
accessiblePrimaryColor,
Expand Down Expand Up @@ -426,10 +413,7 @@ class IndexPage extends React.Component {
defaultMessage="The search is triggered automatically when origin and destination are set. Changing any search parameters triggers a new search"
/>
</span>
<LocationSearch
targets={locationSearchTargets}
{...locationSearchProps}
/>
<LocationSearch {...locationSearchProps} />
<div className="datetimepicker-container">
<DatetimepickerContainer realtime color={color} />
</div>
Expand Down Expand Up @@ -483,7 +467,6 @@ class IndexPage extends React.Component {
<LocationSearch
disableAutoFocus
isMobile
targets={locationSearchTargetsMobile}
{...locationSearchProps}
/>
<div className="datetimepicker-container">
Expand Down
10 changes: 0 additions & 10 deletions app/component/RentalVehiclePageMapContainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types';
import React from 'react';
import { createFragmentContainer, graphql } from 'react-relay';
import { FormattedMessage } from 'react-intl';
Expand All @@ -18,15 +17,6 @@ const RentalVehiclePageMapContainer = ({ rentalVehicle }) => {
return <StopPageMap stop={rentalVehicle} stopName={stopName} scooter />;
};

RentalVehiclePageMapContainer.contextTypes = {
config: PropTypes.shape({
map: PropTypes.shape({
tileSize: PropTypes.number,
zoom: PropTypes.number,
}),
}),
};

RentalVehiclePageMapContainer.propTypes = {
rentalVehicle: rentalVehicleShape,
};
Expand Down
Loading

0 comments on commit 490ded8

Please sign in to comment.