From 5f1f172f0c5a2f3c5cbdd90d17ccbf353a741815 Mon Sep 17 00:00:00 2001 From: e-halinen Date: Tue, 5 Nov 2024 16:55:19 +0200 Subject: [PATCH] Add styling tweaks and note filtering --- .../lineTimetable/lineTableColumns.css | 8 ++--- .../lineTimetable/lineTableHeader.css | 6 ++++ src/components/lineTimetable/lineTimetable.js | 32 +++++++++++++++---- .../lineTimetable/lineTimetableContainer.js | 21 +++++++++--- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/components/lineTimetable/lineTableColumns.css b/src/components/lineTimetable/lineTableColumns.css index 320a72c1..aebcd090 100644 --- a/src/components/lineTimetable/lineTableColumns.css +++ b/src/components/lineTimetable/lineTableColumns.css @@ -3,6 +3,8 @@ min-width: 120px; font-family: GothamRounded-Book; margin: 0.5rem 0; + page-break-inside: avoid; + page-break-after: always; } .departureRow { @@ -60,9 +62,3 @@ .departureRowContainer > *:nth-child(even) { background-color: #eaeaea; } - -@media print { - .departureRow { - page-break-inside: avoid; - } -} diff --git a/src/components/lineTimetable/lineTableHeader.css b/src/components/lineTimetable/lineTableHeader.css index 92b3e8f3..abdd139c 100644 --- a/src/components/lineTimetable/lineTableHeader.css +++ b/src/components/lineTimetable/lineTableHeader.css @@ -26,3 +26,9 @@ font-family: GothamRounded-Medium; font-size: 1rem; } + +@media print { + .headerContainer { + page-break-inside: avoid; + } +} diff --git a/src/components/lineTimetable/lineTimetable.js b/src/components/lineTimetable/lineTimetable.js index a3a7baff..f998ebf8 100644 --- a/src/components/lineTimetable/lineTimetable.js +++ b/src/components/lineTimetable/lineTimetable.js @@ -6,16 +6,15 @@ import LineTableColumns from './lineTableColumns'; import AllStopsList from './allStopsList'; import { filter, - isEmpty, uniqBy, flatten, forEach, groupBy, - find, unionWith, omit, isEqual, some, + uniq, } from 'lodash'; import { scheduleSegments } from '../../util/domain'; import { addMissingFridayNote, combineConsecutiveDays } from '../timetable/timetableContainer'; @@ -247,9 +246,27 @@ const checkForTrainRoutes = routes => { // Add note for friday departures because of merged timetables const addFridayNote = notes => { - return notes.splice(0, 0, { noteText: 'p) Vain perjantaisin' }); + const mutableArr = notes.splice(0); + return mutableArr.splice(0, 0, { noteText: 'p) Vain perjantaisin' }); }; +const hasFridayDepartures = routes => { + let hasFriDepartures = false; + forEach(routes, route => { + const departures = [...route.timedStopsDepartures.nodes]; + const fridayDepartures = departures.filter(departure => departure.dayType.includes('Pe')); + hasFriDepartures = hasFriDepartures ? true : fridayDepartures.length > 0; + }); + return hasFriDepartures; +}; + +const usesFridayDepartureNote = routes => { + let usesFridayDepartureNotation = true; + forEach(routes, route => { + usesFridayDepartureNotation = !usesFridayDepartureNotation ? false : route.mode !== 'TRAM'; + }); + return usesFridayDepartureNotation; +}; class LineTimetable extends Component { constructor(props) { super(props); @@ -267,10 +284,13 @@ class LineTimetable extends Component { render() { const { routes } = this.props; - const notes = this.props.line.notes.nodes; - addFridayNote(notes); - const showTimedStops = hasTimedStopRoutes(routes); + let { notes } = this.props.line; + if (hasFridayDepartures(routes) && usesFridayDepartureNote(routes)) { + const addedFridayNotes = addFridayNote(this.props.line.notes); + notes = uniq(addedFridayNotes); + } + const showTimedStops = hasTimedStopRoutes(routes); const checkedRoutes = checkForTrainRoutes(routes); const mappedNotes = notes.map(note => { diff --git a/src/components/lineTimetable/lineTimetableContainer.js b/src/components/lineTimetable/lineTimetableContainer.js index bdb54f4e..59ed2b76 100644 --- a/src/components/lineTimetable/lineTimetableContainer.js +++ b/src/components/lineTimetable/lineTimetableContainer.js @@ -4,7 +4,7 @@ import { graphql } from 'react-apollo'; import gql from 'graphql-tag'; import mapProps from 'recompose/mapProps'; import compose from 'recompose/compose'; -import { filter, forEach, isEmpty, uniqBy, some } from 'lodash'; +import { filter, forEach, isEmpty, uniqBy, some, uniqWith } from 'lodash'; import apolloWrapper from 'util/apolloWrapper'; @@ -207,6 +207,19 @@ const filterRoutes = routesWithGroupedDepartures => { }); }; +const filterNotes = (notes, dateBegin) => { + const timetableDateBegin = new Date(dateBegin); + const filteredNotes = notes.filter(note => { + if (note.dateEnd === null) { + return true; + } + const noteDateEnd = new Date(note.dateEnd); + return noteDateEnd > timetableDateBegin; + }); + const duplicatesRemoved = uniqWith(filteredNotes, (a, b) => a.noteText === b.noteText); + return duplicatesRemoved; +}; + const lineQueryMapper = mapProps(props => { const line = props.data.lines.nodes[0]; const { showPrintBtn, lang } = props; @@ -233,8 +246,10 @@ const lineQueryMapper = mapProps(props => { return { ...route, departuresByDateRanges: dateRangesGroupedByStopAndDay }; }); + const filteredNotes = filterNotes(line.notes.nodes, props.dateBegin); + return { - line, + line: { ...line, notes: filteredNotes }, routes: filterRoutes(routesWithGroupedDepartures), showPrintBtn, lang, @@ -246,7 +261,6 @@ const hoc = compose(graphql(lineQuery), apolloWrapper(lineQueryMapper)); const LineTimetableContainer = hoc(LineTimetable); LineTimetableContainer.defaultProps = { - date: null, showPrintBtn: false, lang: 'fi', printPageNumbers: true, @@ -256,7 +270,6 @@ LineTimetableContainer.propTypes = { lineId: PropTypes.string.isRequired, dateBegin: PropTypes.string.isRequired, dateEnd: PropTypes.string.isRequired, - date: PropTypes.string, showPrintBtn: PropTypes.bool, lang: PropTypes.string, printPageNumbers: PropTypes.bool,