Skip to content

Commit

Permalink
fix: Query timeseries in desc but display in asc
Browse files Browse the repository at this point in the history
We want the latest timeseries but we display them in ascending
order in the carrousel
  • Loading branch information
ptbrowne committed Mar 9, 2021
1 parent c281dd7 commit f55b695
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/cozy-harvest-lib/src/datacards/GeoDataCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Skeleton from '@material-ui/lab/Skeleton'
import IconButton from '@material-ui/core/IconButton'
import SwipeableViews from 'react-swipeable-views'

import sortBy from 'lodash/sortBy'
import isSameDay from 'date-fns/is_same_day'
import isSameYear from 'date-fns/is_same_year'
import format from 'date-fns/format'
Expand Down Expand Up @@ -259,7 +260,7 @@ const makeQueryFromProps = ({ accountId }) => ({
.where({
'cozyMetadata.sourceAccount': accountId
})
.sortBy([{ 'cozyMetadata.sourceAccount': 'asc' }, { startDate: 'asc' }])
.sortBy([{ 'cozyMetadata.sourceAccount': 'desc' }, { startDate: 'desc' }])
.indexFields(['cozyMetadata.sourceAccount', 'startDate'])
.limitBy(5),
as: `io.cozy.accounts/${accountId}/io.cozy.timeseries.geojson`,
Expand All @@ -275,11 +276,18 @@ const DataGeoDataCard = ({ timeseriesCol, konnector }) => {
return transformTimeSeriesToTrips(timeseries)
}
}, [timeseries])
const ascendingTrips = useMemo(() => {
return sortBy(trips, t => t.properties.enter_fmt_time).reverse()
}, [trips])
const noTimeseries =
hasQueryBeenLoaded(timeseriesCol) && timeseries.length == 0
const isLoading = isQueryLoading(timeseriesCol)
return noTimeseries ? null : (
<GeoDataCard trips={trips} loading={isLoading} konnector={konnector} />
<GeoDataCard
trips={ascendingTrips}
loading={isLoading}
konnector={konnector}
/>
)
}

Expand Down

0 comments on commit f55b695

Please sign in to comment.