Skip to content

Commit

Permalink
feat: dt-5325 emissions schema changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sharhio committed Oct 24, 2023
1 parent 5c06dbf commit 92eb64d
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ function ItinerarySummaryListContainer(
) {
const lowestCo2value = Math.round(
itineraries
.filter(itinerary => itinerary.emissionsPerPerson?.co2Grams >= 0)
.filter(itinerary => itinerary.emissionsPerPerson?.co2 >= 0)
.reduce((a, b) => {
return a.emissionsPerPerson?.co2Grams < b.emissionsPerPerson?.co2Grams
? a
: b;
}, 0).emissionsPerPerson?.co2Grams,
return a.emissionsPerPerson?.co2 < b.emissionsPerPerson?.co2 ? a : b;
}, 0).emissionsPerPerson?.co2,
);
const summaries = itineraries.map((itinerary, i) => (
<SummaryRow
Expand Down Expand Up @@ -345,7 +343,7 @@ const containerComponent = createFragmentContainer(
startTime
endTime
emissionsPerPerson {
co2Grams
co2
}
legs {
realTime
Expand Down
8 changes: 4 additions & 4 deletions app/component/ItineraryTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const ItineraryShape = PropTypes.shape({
),
fares: PropTypes.arrayOf(FareShape),
emissionsPerPerson: PropTypes.shape({
co2Grams: PropTypes.number,
co2: PropTypes.number,
}),
});

Expand Down Expand Up @@ -219,8 +219,8 @@ class ItineraryTab extends React.Component {
const suggestionIndex = this.context.match.params.secondHash
? Number(this.context.match.params.secondHash) + 1
: Number(this.context.match.params.hash) + 1;
const co2value = typeof itinerary.emissionsPerPerson?.co2Grams === 'number' && itinerary.emissionsPerPerson?.co2Grams >= 0 ? Math.round(itinerary.emissionsPerPerson?.co2Grams) : -1;
const carCo2Value = this.props.carItinerary && this.props.carItinerary.length > 0 ? Math.round(this.props.carItinerary[0].emissionsPerPerson?.co2Grams) : 0;
const co2value = typeof itinerary.emissionsPerPerson?.co2 === 'number' && itinerary.emissionsPerPerson?.co2 >= 0 ? Math.round(itinerary.emissionsPerPerson?.co2) : -1;
const carCo2Value = this.props.carItinerary && this.props.carItinerary.length > 0 ? Math.round(this.props.carItinerary[0].emissionsPerPerson?.co2) : 0;
const co2SimpleDesc = carCo2Value === 0;
return (
<div className="itinerary-tab">
Expand Down Expand Up @@ -451,7 +451,7 @@ const withRelay = createFragmentContainer(
type
}
emissionsPerPerson {
co2Grams
co2
}
legs {
mode
Expand Down
10 changes: 5 additions & 5 deletions app/component/SummaryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ class SummaryPage extends React.Component {
...ItineraryTab_itinerary
...SummaryPlanContainer_itineraries
emissionsPerPerson {
co2Grams
co2
}
legs {
mode
Expand Down Expand Up @@ -794,7 +794,7 @@ class SummaryPage extends React.Component {
...ItineraryTab_itinerary
...SummaryPlanContainer_itineraries
emissionsPerPerson {
co2Grams
co2
}
legs {
mode
Expand Down Expand Up @@ -856,7 +856,7 @@ class SummaryPage extends React.Component {
...ItineraryTab_itinerary
...SummaryPlanContainer_itineraries
emissionsPerPerson {
co2Grams
co2
}
legs {
mode
Expand Down Expand Up @@ -1039,7 +1039,7 @@ class SummaryPage extends React.Component {
...ItineraryTab_itinerary
...SummaryPlanContainer_itineraries
emissionsPerPerson {
co2Grams
co2
}
legs {
mode
Expand Down Expand Up @@ -2972,7 +2972,7 @@ const containerComponent = createRefetchContainer(
...ItineraryTab_itinerary
...SummaryPlanContainer_itineraries
emissionsPerPerson {
co2Grams
co2
}
legs {
mode
Expand Down
4 changes: 2 additions & 2 deletions app/component/SummaryPlanContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ const connectedContainer = createFragmentContainer(
startTime
endTime
emissionsPerPerson {
co2Grams
co2
}
legs {
mode
Expand Down Expand Up @@ -402,7 +402,7 @@ const connectedContainer = createFragmentContainer(
endTime
startTime
emissionsPerPerson {
co2Grams
co2
}
legs {
mode
Expand Down
6 changes: 3 additions & 3 deletions app/component/SummaryRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ const SummaryRow = (
const endTime = moment(data.endTime);
const duration = endTime.diff(startTime);
const co2value =
typeof data.emissionsPerPerson?.co2Grams === 'number' &&
data.emissionsPerPerson?.co2Grams >= 0
? Math.round(data.emissionsPerPerson?.co2Grams)
typeof data.emissionsPerPerson?.co2 === 'number' &&
data.emissionsPerPerson?.co2 >= 0
? Math.round(data.emissionsPerPerson?.co2)
: -1;
const mobile = bp => !(bp === 'large');
const legs = [];
Expand Down
2 changes: 1 addition & 1 deletion app/prop-types/ItineraryShape.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export default PropTypes.shape({
startTime: PropTypes.number,
legs: PropTypes.arrayOf(PropTypes.object),
emissionsPerPerson: PropTypes.shape({
co2Grams: PropTypes.number,
co2: PropTypes.number,
}),
});
2 changes: 1 addition & 1 deletion app/util/queryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export const moreItinerariesQuery = graphql`
...ItineraryTab_itinerary
...SummaryPlanContainer_itineraries
emissionsPerPerson {
co2Grams
co2
}
legs {
mode
Expand Down
4 changes: 3 additions & 1 deletion build/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ type Emissions {
"""
CO₂ emissions in grams.
"""
co2Grams: Float
co2: Grams
}

type fare {
Expand Down Expand Up @@ -1008,6 +1008,8 @@ type Geometry {

scalar GeoJson

scalar Grams

type StopGeometries {
"""Representation of the stop geometries as GeoJSON (https://geojson.org/)"""
geoJson: GeoJson,
Expand Down
16 changes: 13 additions & 3 deletions build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2179,12 +2179,12 @@
"description": null,
"fields": [
{
"name": "co2Grams",
"description": "CO₂ emissions of the trip on this itinerary, in grams per person.",
"name": "co2",
"description": "CO₂ emissions in grams.",
"args": [],
"type": {
"kind": "SCALAR",
"name": "Float",
"name": "Grams",
"ofType": null
},
"isDeprecated": false,
Expand Down Expand Up @@ -2609,6 +2609,16 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "Grams",
"description": "",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "ID",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ type Emissions {
"""
CO₂ emissions in grams.
"""
co2Grams: Float
co2: Grams
}

type fare {
Expand Down Expand Up @@ -1008,6 +1008,8 @@ type Geometry {

scalar GeoJson

scalar Grams

type StopGeometries {
"""Representation of the stop geometries as GeoJSON (https://geojson.org/)"""
geoJson: GeoJson,
Expand Down

0 comments on commit 92eb64d

Please sign in to comment.