feat: adjust Agency page
This commit is contained in:
parent
32abf8061b
commit
00988d3787
|
@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|||
|
||||
export default function AgencyPerDayTableEntries ({array}) {
|
||||
if ( array !== undefined && array !== null && array.length > 0 ) {
|
||||
//TODO Shall we switch from UTC to local time zone for item.timestamp_pgsql?
|
||||
//iterate over array
|
||||
return array.map((item, index) => {
|
||||
return (
|
||||
|
|
|
@ -4,7 +4,9 @@ import PropTypes from 'prop-types';
|
|||
import Badge from '../utils/badge';
|
||||
|
||||
export default function CountNext({ count }) {
|
||||
if (count === 0) {
|
||||
if (count === '0'
|
||||
|| count === null
|
||||
|| count === undefined) {
|
||||
return <Badge msg={count} modifier={'danger'} />;
|
||||
} else {
|
||||
return count;
|
||||
|
|
|
@ -4,14 +4,16 @@ import PropTypes from 'prop-types';
|
|||
import Count from './overview-next-table-count';
|
||||
|
||||
/*destructure props object*/
|
||||
export default function OverviewNextTableEntry ({ agencyName, routeCount, tripCount }) {
|
||||
export default function OverviewNextTableEntry ({ agencyName, routeCount, stopCount, tripCount }) {
|
||||
const routeCountBadge = <Count count={routeCount} />;
|
||||
const stopCountBadge = <Count count={stopCount} />;
|
||||
const tripCountBadge = <Count count={tripCount} />;
|
||||
return (
|
||||
<tr>
|
||||
<td>{agencyName}</td>
|
||||
<td>{routeCount === null ? 'loading...' : routeCountBadge}</td>
|
||||
<td>{tripCount === null ? 'loading...' : tripCountBadge}</td>
|
||||
<td>{routeCountBadge}</td>
|
||||
<td>{stopCountBadge}</td>
|
||||
<td>{tripCountBadge}</td>
|
||||
</tr>
|
||||
);
|
||||
};
|
||||
|
@ -19,5 +21,6 @@ export default function OverviewNextTableEntry ({ agencyName, routeCount, tripCo
|
|||
OverviewNextTableEntry.propTypes = {
|
||||
agencyName: PropTypes.string,
|
||||
routeCount: PropTypes.string,
|
||||
stopCount: PropTypes.string,
|
||||
tripCount: PropTypes.string
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@ export default function OverviewNextTableHead () {
|
|||
<tr>
|
||||
<th>Agency</th>
|
||||
<th>Route Count</th>
|
||||
<th>Stop Count</th>
|
||||
<th>Trip Count</th>
|
||||
</tr>
|
||||
);
|
||||
|
|
|
@ -16,8 +16,9 @@ export default function OverviewNextTable ({ overview }) {
|
|||
return (
|
||||
<Entry
|
||||
agencyName={item.agency_name}
|
||||
routeCount={item.route_count}
|
||||
tripCount={item.trip_count}
|
||||
routeCount={item.rts_cnt}
|
||||
stopCount={item.stps_cnt}
|
||||
tripCount={item.trps_cnt}
|
||||
key={item.agency_id}
|
||||
/>
|
||||
);
|
||||
|
|
|
@ -3,6 +3,8 @@ import PropTypes from 'prop-types';
|
|||
|
||||
export default function TripUpdatesRouteDayTableEntries ({array}) {
|
||||
if ( array !== undefined && array !== null && array.length > 0 ) {
|
||||
|
||||
//TODO Shall we switch from UTC to local time zone for item.timestamp_pgsql?
|
||||
//iterate over array
|
||||
return array.map((item, index) => {
|
||||
return (
|
||||
|
|
|
@ -6,17 +6,16 @@ import config from '../config';
|
|||
|
||||
export default function OverviewNext() {
|
||||
|
||||
const [trips, setTrips] = useState([]);
|
||||
const [cnts, setCnts] = useState([]);
|
||||
|
||||
const getTrips = async () => {
|
||||
const getCnts = async () => {
|
||||
try {
|
||||
//TODO Sort trips by agency name descending!
|
||||
/*get trips*/
|
||||
/*get cnts*/
|
||||
/*TODO handle errors: https://www.valentinog.com/blog/await-react/*/
|
||||
const res = await axios.get(`${config.API}number-of-trips`);
|
||||
const res = await axios.get(`${config.API}rts-stps-trps-cnt`);
|
||||
|
||||
if ( res !== null && res !== undefined ) {
|
||||
setTrips(res.data);
|
||||
setCnts(res.data);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
@ -25,13 +24,13 @@ export default function OverviewNext() {
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
getTrips();
|
||||
getCnts();
|
||||
}, []);
|
||||
|
||||
|
||||
if ( trips === null || trips === undefined || trips.length === 0 ) {
|
||||
if ( cnts === null || cnts === undefined || cnts.length === 0 ) {
|
||||
return <p>loading...</p>;
|
||||
} else {
|
||||
return <OverviewTable overview={trips} />;
|
||||
return <OverviewTable overview={cnts} />;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -3,11 +3,11 @@ import Badge from 'react-bootstrap/Badge';
|
|||
import PropTypes from 'prop-types';
|
||||
|
||||
const badge = ({ msg, modifier }) => {
|
||||
return <Badge bg={modifier}>{msg}</Badge>;
|
||||
return <Badge bg={modifier}>{msg === null ? '0' : msg}</Badge>;
|
||||
};
|
||||
|
||||
badge.propTypes = {
|
||||
msg: PropTypes.number,
|
||||
msg: PropTypes.string,
|
||||
modifier: PropTypes.string
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue