Skip to content

Commit

Permalink
feat: add offset and rename itemsCount to duration in relativePeriods
Browse files Browse the repository at this point in the history
  • Loading branch information
BRaimbault committed Dec 5, 2024
1 parent 3b7610d commit 38ebd10
Showing 1 changed file with 176 additions and 46 deletions.
222 changes: 176 additions & 46 deletions src/components/PeriodDimension/utils/relativePeriods.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,104 +13,227 @@ import {
} from './index.js'

const getDaysPeriodType = () => [
{ id: 'TODAY', name: i18n.t('Today'), itemsCount: 1 },
{ id: 'YESTERDAY', name: i18n.t('Yesterday'), itemsCount: 1 },
{ id: 'LAST_3_DAYS', name: i18n.t('Last 3 days'), itemsCount: 3 },
{ id: 'LAST_7_DAYS', name: i18n.t('Last 7 days'), itemsCount: 7 },
{ id: 'LAST_14_DAYS', name: i18n.t('Last 14 days'), itemsCount: 14 },
{ id: 'LAST_30_DAYS', name: i18n.t('Last 30 days'), itemsCount: 30 },
{ id: 'LAST_60_DAYS', name: i18n.t('Last 60 days'), itemsCount: 60 },
{ id: 'LAST_90_DAYS', name: i18n.t('Last 90 days'), itemsCount: 90 },
{ id: 'LAST_180_DAYS', name: i18n.t('Last 180 days'), itemsCount: 180 },
{ id: 'TODAY', name: i18n.t('Today'), offset: 0, duration: 1 },
{ id: 'YESTERDAY', name: i18n.t('Yesterday'), offset: -1, duration: 1 },
{ id: 'LAST_3_DAYS', name: i18n.t('Last 3 days'), offset: -1, duration: 3 },
{ id: 'LAST_7_DAYS', name: i18n.t('Last 7 days'), offset: -1, duration: 7 },
{
id: 'LAST_14_DAYS',
name: i18n.t('Last 14 days'),
offset: -1,
duration: 14,
},
{
id: 'LAST_30_DAYS',
name: i18n.t('Last 30 days'),
offset: -1,
duration: 30,
},
{
id: 'LAST_60_DAYS',
name: i18n.t('Last 60 days'),
offset: -1,
duration: 60,
},
{
id: 'LAST_90_DAYS',
name: i18n.t('Last 90 days'),
offset: -1,
duration: 90,
},
{
id: 'LAST_180_DAYS',
name: i18n.t('Last 180 days'),
offset: -1,
duration: 180,
},
]

const getWeeksPeriodType = () => [
{ id: 'THIS_WEEK', name: i18n.t('This week'), itemsCount: 1 },
{ id: 'LAST_WEEK', name: i18n.t('Last week'), itemsCount: 1 },
{ id: 'LAST_4_WEEKS', name: i18n.t('Last 4 weeks'), itemsCount: 4 },
{ id: 'LAST_12_WEEKS', name: i18n.t('Last 12 weeks'), itemsCount: 12 },
{ id: 'LAST_52_WEEKS', name: i18n.t('Last 52 weeks'), itemsCount: 52 },
{ id: WEEKS_THIS_YEAR, name: i18n.t('Weeks this year'), itemsCount: 52 },
{ id: 'THIS_WEEK', name: i18n.t('This week'), offset: 0, duration: 1 },
{ id: 'LAST_WEEK', name: i18n.t('Last week'), offset: -1, duration: 1 },
{
id: 'LAST_4_WEEKS',
name: i18n.t('Last 4 weeks'),
offset: -1,
duration: 4,
},
{
id: 'LAST_12_WEEKS',
name: i18n.t('Last 12 weeks'),
offset: -1,
duration: 12,
},
{
id: 'LAST_52_WEEKS',
name: i18n.t('Last 52 weeks'),
offset: -1,
duration: 52,
},
{
id: WEEKS_THIS_YEAR,
name: i18n.t('Weeks this year'),
offset: 0,
duration: 52,
},
]

const getBiWeeksPeriodType = () => [
{ id: 'THIS_BIWEEK', name: i18n.t('This bi-week'), itemsCount: 1 },
{ id: 'LAST_BIWEEK', name: i18n.t('Last bi-week'), itemsCount: 1 },
{ id: 'LAST_4_BIWEEKS', name: i18n.t('Last 4 bi-weeks'), itemsCount: 4 },
{ id: 'THIS_BIWEEK', name: i18n.t('This bi-week'), offset: 0, duration: 1 },
{
id: 'LAST_BIWEEK',
name: i18n.t('Last bi-week'),
offset: -1,
duration: 1,
},
{
id: 'LAST_4_BIWEEKS',
name: i18n.t('Last 4 bi-weeks'),
offset: -1,
duration: 4,
},
]

const getMonthsPeriodType = () => [
{ id: 'THIS_MONTH', name: i18n.t('This month'), itemsCount: 1 },
{ id: 'LAST_MONTH', name: i18n.t('Last month'), itemsCount: 1 },
{ id: 'LAST_3_MONTHS', name: i18n.t('Last 3 months'), itemsCount: 3 },
{ id: 'LAST_6_MONTHS', name: i18n.t('Last 6 months'), itemsCount: 6 },
{ id: 'LAST_12_MONTHS', name: i18n.t('Last 12 months'), itemsCount: 12 },
{ id: 'THIS_MONTH', name: i18n.t('This month'), offset: 0, duration: 1 },
{ id: 'LAST_MONTH', name: i18n.t('Last month'), offset: -1, duration: 1 },
{
id: 'LAST_3_MONTHS',
name: i18n.t('Last 3 months'),
offset: -1,
duration: 3,
},
{
id: 'LAST_6_MONTHS',
name: i18n.t('Last 6 months'),
offset: -1,
duration: 6,
},
{
id: 'LAST_12_MONTHS',
name: i18n.t('Last 12 months'),
offset: -1,
duration: 12,
},
{
id: 'MONTHS_THIS_YEAR',
name: i18n.t('Months this year'),
itemsCount: 12,
offset: 0,
duration: 12,
},
]

const getBiMonthsPeriodType = () => [
{ id: 'THIS_BIMONTH', name: i18n.t('This bi-month'), itemsCount: 1 },
{ id: 'LAST_BIMONTH', name: i18n.t('Last bi-month'), itemsCount: 1 },
{
id: 'THIS_BIMONTH',
name: i18n.t('This bi-month'),
offset: 0,
duration: 1,
},
{
id: 'LAST_BIMONTH',
name: i18n.t('Last bi-month'),
offset: -1,
duration: 1,
},
{
id: 'LAST_6_BIMONTHS',
name: i18n.t('Last 6 bi-months'),
itemsCount: 6,
offset: -1,
duration: 6,
},
{
id: 'BIMONTHS_THIS_YEAR',
name: i18n.t('Bi-months this year'),
itemsCount: 6,
offset: 0,
duration: 6,
},
]

const getQuartersPeriodType = () => [
{ id: 'THIS_QUARTER', name: i18n.t('This quarter'), itemsCount: 1 },
{ id: 'LAST_QUARTER', name: i18n.t('Last quarter'), itemsCount: 1 },
{ id: 'LAST_4_QUARTERS', name: i18n.t('Last 4 quarters'), itemsCount: 4 },
{
id: 'THIS_QUARTER',
name: i18n.t('This quarter'),
offset: 0,
duration: 1,
},
{
id: 'LAST_QUARTER',
name: i18n.t('Last quarter'),
offset: -1,
duration: 1,
},
{
id: 'LAST_4_QUARTERS',
name: i18n.t('Last 4 quarters'),
offset: -1,
duration: 4,
},
{
id: 'QUARTERS_THIS_YEAR',
name: i18n.t('Quarters this year'),
itemsCount: 4,
offset: 0,
duration: 4,
},
]

const getSixMonthsPeriodType = () => [
{ id: 'THIS_SIX_MONTH', name: i18n.t('This six-month'), itemsCount: 1 },
{ id: 'LAST_SIX_MONTH', name: i18n.t('Last six-month'), itemsCount: 1 },
{
id: 'THIS_SIX_MONTH',
name: i18n.t('This six-month'),
offset: 0,
duration: 1,
},
{
id: 'LAST_SIX_MONTH',
name: i18n.t('Last six-month'),
offset: -1,
duration: 1,
},
{
id: 'LAST_2_SIXMONTHS',
name: i18n.t('Last 2 six-month'),
itemsCount: 2,
offset: -1,
duration: 2,
},
]

const getFinancialYearsPeriodType = () => [
{
id: 'THIS_FINANCIAL_YEAR',
name: i18n.t('This financial year'),
itemsCount: 1,
offset: 0,
duration: 1,
},
{
id: 'LAST_FINANCIAL_YEAR',
name: i18n.t('Last financial year'),
itemsCount: 1,
offset: -1,
duration: 1,
},
{
id: 'LAST_5_FINANCIAL_YEARS',
name: i18n.t('Last 5 financial years'),
itemsCount: 5,
offset: -1,
duration: 5,
},
]

const getYearsPeriodType = () => [
{ id: 'THIS_YEAR', name: i18n.t('This year'), itemsCount: 1 },
{ id: 'LAST_YEAR', name: i18n.t('Last year'), itemsCount: 1 },
{ id: 'LAST_5_YEARS', name: i18n.t('Last 5 years'), itemsCount: 5 },
{ id: 'LAST_10_YEARS', name: i18n.t('Last 10 years'), itemsCount: 10 },
{ id: 'THIS_YEAR', name: i18n.t('This year'), offset: 0, duration: 1 },
{ id: 'LAST_YEAR', name: i18n.t('Last year'), offset: -1, duration: 1 },
{
id: 'LAST_5_YEARS',
name: i18n.t('Last 5 years'),
offset: -1,
duration: 5,
},
{
id: 'LAST_10_YEARS',
name: i18n.t('Last 10 years'),
offset: -1,
duration: 10,
},
]

const getOptions = () => [
Expand Down Expand Up @@ -171,20 +294,27 @@ export const getRelativePeriodIds = () =>
.map((option) => option.getPeriods().map((period) => period.id))
.flat()

export const getRelativePeriodsName = () =>
export const getRelativePeriodsDetails = () =>
Object.values(getOptions())
.map((option) => option.getPeriods())
.map((option) =>
option.getPeriods().map((period) => ({
id: period.id,
offset: period.offset,
duration: period.duration,
type: option.id,
}))
)
.flat()
.reduce((acc, period) => {
acc[period.id] = period.name
return acc
}, {})

export const getRelativePeriodsItemsCount = () =>
export const getRelativePeriodsName = () =>
Object.values(getOptions())
.map((option) => option.getPeriods())
.flat()
.reduce((acc, period) => {
acc[period.id] = period.itemsCount
acc[period.id] = period.name
return acc
}, {})

0 comments on commit 38ebd10

Please sign in to comment.