mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Replaced if/else by functional matcher
This commit is contained in:
parent
32cc1cc580
commit
73e55cc742
1 changed files with 7 additions and 11 deletions
|
@ -10,7 +10,7 @@ import {
|
|||
DropdownItem,
|
||||
} from 'reactstrap';
|
||||
import { Line } from 'react-chartjs-2';
|
||||
import { reverse } from 'ramda';
|
||||
import { always, cond, reverse } from 'ramda';
|
||||
import moment from 'moment';
|
||||
import { VisitType } from '../types';
|
||||
import { fillTheGaps } from '../../utils/helpers/visits';
|
||||
|
@ -55,17 +55,13 @@ const STEP_TO_DATE_FORMAT = {
|
|||
const determineInitialStep = (oldestVisitDate) => {
|
||||
const now = moment();
|
||||
const oldestDate = moment(oldestVisitDate);
|
||||
const matcher = cond([
|
||||
[ () => now.diff(oldestDate, 'day') <= 2, always('hourly') ], // Less than 2 days
|
||||
[ () => now.diff(oldestDate, 'month') <= 1, always('daily') ], // Between 2 days and 1 month
|
||||
[ () => now.diff(oldestDate, 'month') <= 6, always('weekly') ], // Between 1 and 6 months
|
||||
]);
|
||||
|
||||
if (now.diff(oldestDate, 'day') <= 2) { // Less than 2 days
|
||||
return 'hourly';
|
||||
} else if (now.diff(oldestDate, 'month') <= 1) { // Between 2 days and 1 month
|
||||
return 'daily';
|
||||
} else if (now.diff(oldestDate, 'month') <= 6) { // Between 1 and 6 months
|
||||
return 'weekly';
|
||||
}
|
||||
|
||||
// Older than 6 months
|
||||
return 'monthly';
|
||||
return matcher() || 'monthly';
|
||||
};
|
||||
|
||||
const groupVisitsByStep = (step, visits) => visits.reduce((acc, visit) => {
|
||||
|
|
Loading…
Reference in a new issue