All files / applications/go-by-transit/src/view/stop/component StopLocationArrivalsTable.tsx

100% Statements 7/7
100% Branches 2/2
100% Functions 5/5
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                4x 6x         1x 2x                 4x   4x       4x                                    
import { Table } from "@wintermuted/ui-react";
import { map } from "lodash";
import React from "react";
import { useParams } from "react-router-dom";
import { Arrival, ArrivalData } from "../../../api/trimet/interfaces/arrivals";
import StopLocationArrivalRow from "./StopLocationArrivalRow";
 
function getArrivals(arrivals: Arrival[]) {
  return map(arrivals, (arrival) => {
    return <StopLocationArrivalRow key={arrival.id} arrival={arrival} />;
  });
}
 
function filterArrivals(arrivals: ArrivalData, id) {
  return arrivals.arrival.filter(
    (arrival) => arrival.route === parseInt(id, 10),
  );
}
 
interface Props {
  arrivalData: ArrivalData;
}
 
function StopLocationArrivalsTable({ arrivalData }: Props) {
  const { routeId } = useParams();
 
  const filteredArrivals = routeId
    ? filterArrivals(arrivalData, routeId)
    : arrivalData.arrival;
 
  return (
    <Table responsive={true}>
      <thead>
        <tr>
          <td />
          <td>Route</td>
          <td>Arriving In</td>
          <td>Early / Late by</td>
          <td>Scheduled / Estimated Arrivals </td>
          <td>Distance to stop</td>
        </tr>
      </thead>
      <tbody>{getArrivals(filteredArrivals)}</tbody>
    </Table>
  );
}
 
export default StopLocationArrivalsTable;