Client - display ascent record depending on user preference

This commit is contained in:
Sam 2022-07-23 08:20:02 +02:00
parent 81efdf53d5
commit 49b4c279cf
3 changed files with 105 additions and 19 deletions

View File

@ -42,7 +42,8 @@
props.user.records, props.user.records,
translateSports(props.sports, t), translateSports(props.sports, t),
props.user.timezone, props.user.timezone,
props.user.imperial_units props.user.imperial_units,
props.user.display_ascent
) )
) )
</script> </script>

View File

@ -29,10 +29,20 @@ export const formatRecord = (
)} ${distanceUnitTo}/h` )} ${distanceUnitTo}/h`
break break
case 'FD': case 'FD':
value = `${convertDistance(+record.value, distanceUnitFrom, distanceUnitTo, 3)} ${distanceUnitTo}` value = `${convertDistance(
+record.value,
distanceUnitFrom,
distanceUnitTo,
3
)} ${distanceUnitTo}`
break break
case 'HA': case 'HA':
value = `${convertDistance(+record.value, ascentUnitFrom, ascentUnitTo, 2)} ${ascentUnitTo}` value = `${convertDistance(
+record.value,
ascentUnitFrom,
ascentUnitTo,
2
)} ${ascentUnitTo}`
break break
case 'LD': case 'LD':
value = record.value value = record.value
@ -62,9 +72,12 @@ export const getRecordsBySports = (
records: IRecord[], records: IRecord[],
translatedSports: ITranslatedSport[], translatedSports: ITranslatedSport[],
tz: string, tz: string,
useImperialUnits: boolean useImperialUnits: boolean,
display_ascent: boolean
): IRecordsBySports => ): IRecordsBySports =>
records.reduce((sportList: IRecordsBySports, record) => { records
.filter((r) => (display_ascent ? true : r.record_type !== 'HA'))
.reduce((sportList: IRecordsBySports, record) => {
const sport = translatedSports.find((s) => s.id === record.sport_id) const sport = translatedSports.find((s) => s.id === record.sport_id)
if (sport && sport.label) { if (sport && sport.label) {
if (sportList[sport.translatedLabel] === void 0) { if (sportList[sport.translatedLabel] === void 0) {

View File

@ -400,7 +400,8 @@ describe('getRecordsBySports', () => {
testParams.input.records, testParams.input.records,
translatedSports, translatedSports,
testParams.input.tz, testParams.input.tz,
false false,
true
), ),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
@ -530,6 +531,7 @@ describe('getRecordsBySports after conversion', () => {
testParams.input.records, testParams.input.records,
translatedSports, translatedSports,
testParams.input.tz, testParams.input.tz,
true,
true true
), ),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@ -539,3 +541,73 @@ describe('getRecordsBySports after conversion', () => {
}) })
) )
}) })
describe('getRecordsBySports with HA record', () => {
const testsParams = [
{
description: 'returns empty object if no records',
input: {
records: [],
tz: 'Europe/Paris',
},
expected: {},
},
{
description: 'returns records except HA record',
input: {
records: [
{
id: 9,
record_type: 'AS',
sport_id: 1,
user: 'admin',
value: 18,
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
{
id: 9,
record_type: 'HA',
sport_id: 1,
user: 'admin',
value: 235,
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
],
tz: 'Europe/Paris',
},
expected: {
'Cycling (Sport)': {
color: null,
label: 'Cycling (Sport)',
records: [
{
id: 9,
record_type: 'AS',
value: '18 km/h',
workout_date: '2019/07/07',
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
],
},
},
},
]
testsParams.map((testParams) =>
it(testParams.description, () => {
assert.deepEqual(
getRecordsBySports(
testParams.input.records,
translatedSports,
testParams.input.tz,
false,
false
),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testParams.expected
)
})
)
})