Skip to content

Commit b01bed4

Browse files
committed
WIP fix when no departures
1 parent 185ca79 commit b01bed4

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

src/components/timetable/intervalTimetable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ IntervalDisplay.defaultProps = {
194194
isCompact: false,
195195
};
196196

197-
const partitionToIntervalAndNonIntervalRoutes = routeIdToModeMap => {
197+
export const partitionToIntervalAndNonIntervalRoutes = routeIdToModeMap => {
198198
const intervalRoutes = new Set();
199199
const normalBusRoutes = new Set();
200200

src/components/timetable/timetable.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import classNames from 'classnames';
77
import TableHeader from './tableHeader';
88
import TableRows from './tableRows';
99
import SimpleRoutes from './simpleRoutes';
10-
import IntervalTimetable from './intervalTimetable';
10+
import IntervalTimetable, { partitionToIntervalAndNonIntervalRoutes } from './intervalTimetable';
11+
import { trimRouteId } from 'util/domain';
1112

1213
import styles from './timetable.css';
1314

@@ -81,6 +82,19 @@ class Timetable extends Component {
8182
if (!this.props.hasDepartures) {
8283
return null;
8384
}
85+
86+
// Only treat this as an interval timetable if there are actually interval departures.
87+
// If intervalTimetable=true but all routes are normal buses, fall back to normal rendering.
88+
const intervalRoutes = intervalTimetable
89+
? partitionToIntervalAndNonIntervalRoutes(routeIdToModeMap).intervalRoutes
90+
: null;
91+
const effectiveInterval =
92+
intervalTimetable &&
93+
Object.values(combinedDays).some(dayDepartures =>
94+
dayDepartures.some(it =>
95+
intervalRoutes.has(trimRouteId(it.routeId).replace(/[^0-9]/g, '')),
96+
),
97+
);
8498
const opts = { year: 'numeric', month: 'numeric', day: 'numeric' };
8599
const today = new Date().toLocaleDateString('fi', opts);
86100
const address = this.props.addressFi ? ` ${this.props.addressFi},` : '';
@@ -107,7 +121,7 @@ class Timetable extends Component {
107121
[styles.printable]: this.props.printableAsA4,
108122
[styles.standalone]: this.props.standalone,
109123
[styles.greyscale]: this.props.greyscale,
110-
[styles.interval]: this.props.intervalTimetable,
124+
[styles.interval]: effectiveInterval,
111125
})}
112126
ref={ref => {
113127
this.content = ref;
@@ -144,7 +158,7 @@ class Timetable extends Component {
144158
{this.props.showPrintButton ? <PrintButton lang={this.props.lang} /> : ''}
145159
</div>
146160
)}
147-
{this.props.showValidityPeriod && !intervalTimetable && (
161+
{this.props.showValidityPeriod && !effectiveInterval && (
148162
<div
149163
className={classNames(styles.validity, {
150164
[styles.coverPageMargin]: this.props.showCoverPage,
@@ -167,14 +181,14 @@ class Timetable extends Component {
167181
</div>
168182
)}
169183
</div>
170-
{this.props.showComponentName && !intervalTimetable && (
184+
{this.props.showComponentName && !effectiveInterval && (
171185
<div className={styles.componentName}>
172186
<div className={styles.title}>Pysäkkiaikataulu&nbsp;&nbsp;</div>
173187
<div className={styles.subtitle}>Hållplatstidtabell</div>
174188
<div className={styles.subtitle}>Stop timetable</div>
175189
</div>
176190
)}
177-
{intervalTimetable && (
191+
{effectiveInterval && (
178192
<div className={styles.validFrom}>
179193
Aikataulu alkaen {formatDate(date)} - / Tidtabeller fran {formatDate(date)} -
180194
/Timetables from {formatDate(date)} -
@@ -218,9 +232,12 @@ class Timetable extends Component {
218232
subtitleEn={enTitle}
219233
printingAsA4={this.props.printableAsA4}
220234
useCompactLayout={this.props.useCompactLayout}
221-
intervalTimetable={intervalTimetable}
235+
intervalTimetable={effectiveInterval}
222236
/>
223-
{intervalTimetable ? (
237+
{effectiveInterval &&
238+
combinedDays[combinedDay].some(it =>
239+
intervalRoutes.has(trimRouteId(it.routeId).replace(/[^0-9]/g, '')),
240+
) ? (
224241
<IntervalTimetable
225242
combinedDay={combinedDay}
226243
routeIdToModeMap={routeIdToModeMap}

0 commit comments

Comments
 (0)