From d9a89fd759dcecc979f81205c5cc8edc56db0af0 Mon Sep 17 00:00:00 2001 From: Topi Koivunen Date: Wed, 28 Sep 2022 10:49:25 +0300 Subject: [PATCH 1/2] feat: show timetables 60 days into the future --- app/component/DateSelect.js | 2 +- .../ItinerarySummaryListContainer.js | 8 +++ app/component/Timetable.js | 65 +++++++++++++++---- app/component/timetable.scss | 38 +++++++++++ app/configurations/config.default.js | 4 +- app/translations.js | 18 +++++ 6 files changed, 120 insertions(+), 15 deletions(-) diff --git a/app/component/DateSelect.js b/app/component/DateSelect.js index 421763af86..5da48dbaea 100644 --- a/app/component/DateSelect.js +++ b/app/component/DateSelect.js @@ -28,7 +28,7 @@ function DateSelect(props, context) { value: date.add(1, 'd').format(props.dateFormat), }); - for (let i = 0; i < 28; i++) { + for (let i = 0; i < 58; i++) { dates.push({ value: date.add(1, 'd').format(props.dateFormat), label: date.format('dd D.M.'), diff --git a/app/component/ItinerarySummaryListContainer.js b/app/component/ItinerarySummaryListContainer.js index 9563910701..643879b883 100644 --- a/app/component/ItinerarySummaryListContainer.js +++ b/app/component/ItinerarySummaryListContainer.js @@ -9,6 +9,7 @@ import { matchShape } from 'found'; import isEqual from 'lodash/isEqual'; import distance from '@digitransit-search-util/digitransit-search-util-distance'; +import moment from 'moment'; import Icon from './Icon'; import SummaryRow from './SummaryRow'; import { isBrowser } from '../util/browser'; @@ -268,6 +269,13 @@ function ItinerarySummaryListContainer( } else { msgId = 'walk-bike-itinerary-3'; } + // Show different message if trip is >30 days in the future + const timeDifferenceDays = moment + .duration(moment(searchTime).diff(moment())) + .asDays(); + if (timeDifferenceDays > 30) { + msgId = 'no-route-msg-time-threshold'; + } } else { const hasChanges = !isEqual( getCurrentSettings(config), diff --git a/app/component/Timetable.js b/app/component/Timetable.js index 8fd894a5f6..4ec8f3f956 100644 --- a/app/component/Timetable.js +++ b/app/component/Timetable.js @@ -7,6 +7,7 @@ import groupBy from 'lodash/groupBy'; import padStart from 'lodash/padStart'; import { FormattedMessage } from 'react-intl'; import { matchShape, routerShape } from 'found'; +import cx from 'classnames'; import Icon from './Icon'; import FilterTimeTableModal from './FilterTimeTableModal'; import TimeTableOptionsPanel from './TimeTableOptionsPanel'; @@ -291,6 +292,12 @@ class Timetable extends React.Component { const virtualMonitorUrl = this.context.config?.stopCard?.header?.virtualMonitorBaseUrl && `${this.context.config.stopCard.header.virtualMonitorBaseUrl}${this.props.stop.gtfsId}`; + const timeTableRows = this.createTimeTableRows(timetableMap); + const timeDifferenceDays = moment + .duration( + moment(this.props.propsForDateSelect.selectedDate).diff(moment()), + ) + .asDays(); return ( <> @@ -335,18 +342,50 @@ class Timetable extends React.Component {
{this.dateForPrinting()}
-
-

- {' '} - -

-
+ + {timeTableRows.length > 0 ? ( +
+

+ {' '} + +

+
+ ) : ( +
+
+
+ + {timeDifferenceDays > 30 ? ( + + ) : ( + + )} +
+
+
+ )}
@@ -359,7 +398,7 @@ class Timetable extends React.Component { />
- {this.createTimeTableRows(timetableMap)} + {timeTableRows}
Date: Wed, 28 Sep 2022 11:53:44 +0300 Subject: [PATCH 2/2] fix: fix test and make timetable notification wider --- app/component/timetable.scss | 4 ++-- test/unit/component/DateSelect.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/component/timetable.scss b/app/component/timetable.scss index 6ac776b428..b2fddadd32 100644 --- a/app/component/timetable.scss +++ b/app/component/timetable.scss @@ -179,7 +179,7 @@ .no-timetable-found-container { border-top: 1px solid $light-gray; - margin: 8px 64px 0 64px; + margin-top: 8px; font-weight: $font-weight-medium; font-size: $font-size-normal; line-height: 18px; @@ -189,7 +189,7 @@ .no-timetable-found { display: flex; justify-content: center; - padding: 1em; + padding-top: 1em; .no-timetable-icon { margin-right: 1em; margin-top: 0.5em; diff --git a/test/unit/component/DateSelect.test.js b/test/unit/component/DateSelect.test.js index 7cd2806a82..687e6960b5 100644 --- a/test/unit/component/DateSelect.test.js +++ b/test/unit/component/DateSelect.test.js @@ -21,9 +21,9 @@ describe('', () => { moment.tz.setDefault(); }); - it('should render 30 options', () => { + it('should render 60 options', () => { const wrapper = shallowWithIntl(); - expect(wrapper.find(Select).props().options).to.have.lengthOf(30); + expect(wrapper.find(Select).props().options).to.have.lengthOf(60); }); it('should render today and tomorrow as text, others as weekday abbreviation with date', () => {