Skip to content

Commit

Permalink
Add styling tweaks and note filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
e-halinen committed Nov 5, 2024
1 parent c9136b9 commit 5f1f172
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
8 changes: 2 additions & 6 deletions src/components/lineTimetable/lineTableColumns.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
min-width: 120px;
font-family: GothamRounded-Book;
margin: 0.5rem 0;
page-break-inside: avoid;
page-break-after: always;
}

.departureRow {
Expand Down Expand Up @@ -60,9 +62,3 @@
.departureRowContainer > *:nth-child(even) {
background-color: #eaeaea;
}

@media print {
.departureRow {
page-break-inside: avoid;
}
}
6 changes: 6 additions & 0 deletions src/components/lineTimetable/lineTableHeader.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@
font-family: GothamRounded-Medium;
font-size: 1rem;
}

@media print {
.headerContainer {
page-break-inside: avoid;
}
}
32 changes: 26 additions & 6 deletions src/components/lineTimetable/lineTimetable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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 => {
Expand Down
21 changes: 17 additions & 4 deletions src/components/lineTimetable/lineTimetableContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 5f1f172

Please sign in to comment.