From 99ae0fd0ff73ec6c6841dcbfda2ede46cd88c716 Mon Sep 17 00:00:00 2001 From: Bruno Raimbault Date: Tue, 19 Nov 2024 15:07:33 +0100 Subject: [PATCH 01/11] feat: add height property to PeriodDimension --- src/components/PeriodDimension/PeriodDimension.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/PeriodDimension/PeriodDimension.js b/src/components/PeriodDimension/PeriodDimension.js index 7e20dbc6e..47b340591 100644 --- a/src/components/PeriodDimension/PeriodDimension.js +++ b/src/components/PeriodDimension/PeriodDimension.js @@ -19,6 +19,7 @@ const PeriodDimension = ({ rightFooter, excludedPeriodTypes, infoBoxMessage, + height, }) => { const { systemInfo } = useConfig() const result = useDataQuery(userSettingsQuery) @@ -43,6 +44,7 @@ const PeriodDimension = ({ dataTest={'period-dimension'} excludedPeriodTypes={excludedPeriodTypes} periodsSettings={periodsSettings} + height={height} /> ) } @@ -53,6 +55,7 @@ PeriodDimension.propTypes = { infoBoxMessage: PropTypes.string, rightFooter: PropTypes.node, selectedPeriods: PropTypes.array, + height: PropTypes.string, } PeriodDimension.defaultProps = { From 5ea80373e76090aab21c520f7e3a739dd9f8e438 Mon Sep 17 00:00:00 2001 From: Bruno Raimbault Date: Tue, 19 Nov 2024 15:10:06 +0100 Subject: [PATCH 02/11] feat: add height property to PeriodTransfer --- src/components/PeriodDimension/PeriodTransfer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/PeriodDimension/PeriodTransfer.js b/src/components/PeriodDimension/PeriodTransfer.js index cd4095484..9a6727252 100644 --- a/src/components/PeriodDimension/PeriodTransfer.js +++ b/src/components/PeriodDimension/PeriodTransfer.js @@ -44,6 +44,7 @@ const PeriodTransfer = ({ excludedPeriodTypes, periodsSettings, infoBoxMessage, + height = TRANSFER_HEIGHT, }) => { const defaultRelativePeriodType = excludedPeriodTypes.includes(MONTHLY) ? getRelativePeriodsOptionsById(QUARTERLY) @@ -196,7 +197,7 @@ const PeriodTransfer = ({ selected={selectedItems.map((period) => period.id)} leftHeader={renderLeftHeader()} enableOrderChange - height={TRANSFER_HEIGHT} + height={height} optionsWidth={TRANSFER_OPTIONS_WIDTH} selectedWidth={TRANSFER_SELECTED_WIDTH} selectedEmptyComponent={renderEmptySelection()} @@ -246,6 +247,7 @@ PeriodTransfer.propTypes = { name: PropTypes.string, }) ), + height: PropTypes.string, } export default PeriodTransfer From 7c1938b0a4bb184122fc2180610f74c92e2f7f1a Mon Sep 17 00:00:00 2001 From: braimbault Date: Mon, 25 Nov 2024 15:26:41 +0100 Subject: [PATCH 03/11] feat: expose getRelativePeriodsOptionsById --- src/components/PeriodDimension/PeriodDimension.js | 2 +- src/components/PeriodDimension/PeriodTransfer.js | 2 +- src/index.js | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/PeriodDimension/PeriodDimension.js b/src/components/PeriodDimension/PeriodDimension.js index 47b340591..264ef36d2 100644 --- a/src/components/PeriodDimension/PeriodDimension.js +++ b/src/components/PeriodDimension/PeriodDimension.js @@ -52,10 +52,10 @@ const PeriodDimension = ({ PeriodDimension.propTypes = { onSelect: PropTypes.func.isRequired, excludedPeriodTypes: PropTypes.arrayOf(PropTypes.string), + height: PropTypes.string, infoBoxMessage: PropTypes.string, rightFooter: PropTypes.node, selectedPeriods: PropTypes.array, - height: PropTypes.string, } PeriodDimension.defaultProps = { diff --git a/src/components/PeriodDimension/PeriodTransfer.js b/src/components/PeriodDimension/PeriodTransfer.js index 9a6727252..5c9d495e0 100644 --- a/src/components/PeriodDimension/PeriodTransfer.js +++ b/src/components/PeriodDimension/PeriodTransfer.js @@ -234,6 +234,7 @@ PeriodTransfer.propTypes = { onSelect: PropTypes.func.isRequired, dataTest: PropTypes.string, excludedPeriodTypes: PropTypes.arrayOf(PropTypes.string), + height: PropTypes.string, infoBoxMessage: PropTypes.string, periodsSettings: PropTypes.shape({ calendar: PropTypes.string, @@ -247,7 +248,6 @@ PeriodTransfer.propTypes = { name: PropTypes.string, }) ), - height: PropTypes.string, } export default PeriodTransfer diff --git a/src/index.js b/src/index.js index 1202981b5..4518b2c1a 100644 --- a/src/index.js +++ b/src/index.js @@ -336,7 +336,10 @@ export { FYJUL, FYAPR, } from './components/PeriodDimension/utils/index.js' -export { getRelativePeriodsOptionsById } from './components/PeriodDimension/utils/relativePeriods.js' +export { + getRelativePeriodsOptionsById, + getRelativePeriodIds, +} from './components/PeriodDimension/utils/relativePeriods.js' export { getFixedPeriodsOptionsById } from './components/PeriodDimension/utils/fixedPeriods.js' export { default as VisualizationOptions } from './components/Options/VisualizationOptions.js' From a307042abd26d58c953c570a652d11e81782baa6 Mon Sep 17 00:00:00 2001 From: braimbault Date: Mon, 25 Nov 2024 16:39:10 +0100 Subject: [PATCH 04/11] feat: getRelativePeriodsMap --- src/components/PeriodDimension/utils/relativePeriods.js | 9 +++++++++ src/index.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/PeriodDimension/utils/relativePeriods.js b/src/components/PeriodDimension/utils/relativePeriods.js index a0fb2463a..6789f2934 100644 --- a/src/components/PeriodDimension/utils/relativePeriods.js +++ b/src/components/PeriodDimension/utils/relativePeriods.js @@ -162,3 +162,12 @@ export const getRelativePeriodIds = () => Object.values(getOptions()) .map((option) => option.getPeriods().map((period) => period.id)) .flat() + +export const getRelativePeriodsMap = () => + Object.values(getOptions()) + .map((option) => option.getPeriods()) + .flat() + .reduce((acc, period) => { + acc[period.id] = period.name + return acc + }, {}) diff --git a/src/index.js b/src/index.js index 4518b2c1a..2484bfc11 100644 --- a/src/index.js +++ b/src/index.js @@ -338,7 +338,7 @@ export { } from './components/PeriodDimension/utils/index.js' export { getRelativePeriodsOptionsById, - getRelativePeriodIds, + getRelativePeriodsMap, } from './components/PeriodDimension/utils/relativePeriods.js' export { getFixedPeriodsOptionsById } from './components/PeriodDimension/utils/fixedPeriods.js' From 3b7610d9747a115465f3fa6c39141f68e5645255 Mon Sep 17 00:00:00 2001 From: braimbault Date: Wed, 4 Dec 2024 13:27:53 +0100 Subject: [PATCH 05/11] feat: add itemsCount to relativePeriods --- .../PeriodDimension/utils/relativePeriods.js | 87 +++++++++------ src/index.js | 3 +- yarn.lock | 104 ++++-------------- 3 files changed, 75 insertions(+), 119 deletions(-) diff --git a/src/components/PeriodDimension/utils/relativePeriods.js b/src/components/PeriodDimension/utils/relativePeriods.js index 6789f2934..2675d985d 100644 --- a/src/components/PeriodDimension/utils/relativePeriods.js +++ b/src/components/PeriodDimension/utils/relativePeriods.js @@ -13,73 +13,78 @@ import { } from './index.js' const getDaysPeriodType = () => [ - { id: 'TODAY', name: i18n.t('Today') }, - { id: 'YESTERDAY', name: i18n.t('Yesterday') }, - { id: 'LAST_3_DAYS', name: i18n.t('Last 3 days') }, - { id: 'LAST_7_DAYS', name: i18n.t('Last 7 days') }, - { id: 'LAST_14_DAYS', name: i18n.t('Last 14 days') }, - { id: 'LAST_30_DAYS', name: i18n.t('Last 30 days') }, - { id: 'LAST_60_DAYS', name: i18n.t('Last 60 days') }, - { id: 'LAST_90_DAYS', name: i18n.t('Last 90 days') }, - { id: 'LAST_180_DAYS', name: i18n.t('Last 180 days') }, + { 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 }, ] const getWeeksPeriodType = () => [ - { id: 'THIS_WEEK', name: i18n.t('This week') }, - { id: 'LAST_WEEK', name: i18n.t('Last week') }, - { id: 'LAST_4_WEEKS', name: i18n.t('Last 4 weeks') }, - { id: 'LAST_12_WEEKS', name: i18n.t('Last 12 weeks') }, - { id: 'LAST_52_WEEKS', name: i18n.t('Last 52 weeks') }, - { id: WEEKS_THIS_YEAR, name: i18n.t('Weeks this year') }, + { 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 }, ] const getBiWeeksPeriodType = () => [ - { id: 'THIS_BIWEEK', name: i18n.t('This bi-week') }, - { id: 'LAST_BIWEEK', name: i18n.t('Last bi-week') }, - { id: 'LAST_4_BIWEEKS', name: i18n.t('Last 4 bi-weeks') }, + { 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 }, ] const getMonthsPeriodType = () => [ - { id: 'THIS_MONTH', name: i18n.t('This month') }, - { id: 'LAST_MONTH', name: i18n.t('Last month') }, - { id: 'LAST_3_MONTHS', name: i18n.t('Last 3 months') }, - { id: 'LAST_6_MONTHS', name: i18n.t('Last 6 months') }, - { id: 'LAST_12_MONTHS', name: i18n.t('Last 12 months') }, + { 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: 'MONTHS_THIS_YEAR', name: i18n.t('Months this year'), + itemsCount: 12, }, ] const getBiMonthsPeriodType = () => [ - { id: 'THIS_BIMONTH', name: i18n.t('This bi-month') }, - { id: 'LAST_BIMONTH', name: i18n.t('Last bi-month') }, + { id: 'THIS_BIMONTH', name: i18n.t('This bi-month'), itemsCount: 1 }, + { id: 'LAST_BIMONTH', name: i18n.t('Last bi-month'), itemsCount: 1 }, { id: 'LAST_6_BIMONTHS', name: i18n.t('Last 6 bi-months'), + itemsCount: 6, }, { id: 'BIMONTHS_THIS_YEAR', name: i18n.t('Bi-months this year'), + itemsCount: 6, }, ] const getQuartersPeriodType = () => [ - { id: 'THIS_QUARTER', name: i18n.t('This quarter') }, - { id: 'LAST_QUARTER', name: i18n.t('Last quarter') }, - { id: 'LAST_4_QUARTERS', name: i18n.t('Last 4 quarters') }, + { 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: 'QUARTERS_THIS_YEAR', name: i18n.t('Quarters this year'), + itemsCount: 4, }, ] const getSixMonthsPeriodType = () => [ - { id: 'THIS_SIX_MONTH', name: i18n.t('This six-month') }, - { id: 'LAST_SIX_MONTH', name: i18n.t('Last six-month') }, + { 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: 'LAST_2_SIXMONTHS', name: i18n.t('Last 2 six-month'), + itemsCount: 2, }, ] @@ -87,22 +92,25 @@ const getFinancialYearsPeriodType = () => [ { id: 'THIS_FINANCIAL_YEAR', name: i18n.t('This financial year'), + itemsCount: 1, }, { id: 'LAST_FINANCIAL_YEAR', name: i18n.t('Last financial year'), + itemsCount: 1, }, { id: 'LAST_5_FINANCIAL_YEARS', name: i18n.t('Last 5 financial years'), + itemsCount: 5, }, ] const getYearsPeriodType = () => [ - { id: 'THIS_YEAR', name: i18n.t('This year') }, - { id: 'LAST_YEAR', name: i18n.t('Last year') }, - { id: 'LAST_5_YEARS', name: i18n.t('Last 5 years') }, - { id: 'LAST_10_YEARS', name: i18n.t('Last 10 years') }, + { 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 }, ] const getOptions = () => [ @@ -163,7 +171,7 @@ export const getRelativePeriodIds = () => .map((option) => option.getPeriods().map((period) => period.id)) .flat() -export const getRelativePeriodsMap = () => +export const getRelativePeriodsName = () => Object.values(getOptions()) .map((option) => option.getPeriods()) .flat() @@ -171,3 +179,12 @@ export const getRelativePeriodsMap = () => acc[period.id] = period.name return acc }, {}) + +export const getRelativePeriodsItemsCount = () => + Object.values(getOptions()) + .map((option) => option.getPeriods()) + .flat() + .reduce((acc, period) => { + acc[period.id] = period.itemsCount + return acc + }, {}) diff --git a/src/index.js b/src/index.js index 2484bfc11..eb4c3dbfc 100644 --- a/src/index.js +++ b/src/index.js @@ -338,7 +338,8 @@ export { } from './components/PeriodDimension/utils/index.js' export { getRelativePeriodsOptionsById, - getRelativePeriodsMap, + getRelativePeriodsName, + getRelativePeriodsItemsCount, } from './components/PeriodDimension/utils/relativePeriods.js' export { getFixedPeriodsOptionsById } from './components/PeriodDimension/utils/fixedPeriods.js' diff --git a/yarn.lock b/yarn.lock index be96f5b14..11e797b2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -36,7 +36,7 @@ dependencies: "@babel/highlight" "^7.10.4" -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.16.0", "@babel/code-frame@^7.16.7", "@babel/code-frame@^7.22.13", "@babel/code-frame@^7.22.5", "@babel/code-frame@^7.23.5", "@babel/code-frame@^7.25.9", "@babel/code-frame@^7.8.3": +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.16.0", "@babel/code-frame@^7.16.7", "@babel/code-frame@^7.25.9", "@babel/code-frame@^7.8.3": version "7.26.2" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.26.2.tgz#4b5fab97d33338eff916235055f0ebc21e573a85" integrity sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ== @@ -80,7 +80,7 @@ eslint-visitor-keys "^2.1.0" semver "^6.3.1" -"@babel/generator@^7.22.5", "@babel/generator@^7.23.6", "@babel/generator@^7.25.9", "@babel/generator@^7.4.0", "@babel/generator@^7.7.2": +"@babel/generator@^7.25.9", "@babel/generator@^7.4.0", "@babel/generator@^7.7.2": version "7.26.2" resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.26.2.tgz#87b75813bec87916210e5e01939a4c823d6bb74f" integrity sha512-zevQbhbau95nkoxSq3f/DC/SC+EEOUZd3DYqfSkMhY2/wfSeaHV1Ew4vk8e+x8lja31IbyuUa2uQ3JONqKbysw== @@ -106,7 +106,7 @@ "@babel/traverse" "^7.25.9" "@babel/types" "^7.25.9" -"@babel/helper-compilation-targets@^7.22.5", "@babel/helper-compilation-targets@^7.22.6", "@babel/helper-compilation-targets@^7.25.9": +"@babel/helper-compilation-targets@^7.22.6", "@babel/helper-compilation-targets@^7.25.9": version "7.25.9" resolved "https://registry.yarnpkg.com/@babel/helper-compilation-targets/-/helper-compilation-targets-7.25.9.tgz#55af025ce365be3cdc0c1c1e56c6af617ce88875" integrity sha512-j9Db8Suy6yV/VHa4qzrj9yZfZxhLWQdVnRlXxmKLYlhWUVB1sB2G5sxuWYXk/whHD9iW76PmNzxZ4UCnTQTVEQ== @@ -150,26 +150,6 @@ lodash.debounce "^4.0.8" resolve "^1.14.2" -"@babel/helper-environment-visitor@^7.22.20": - version "7.22.20" - resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz#96159db61d34a29dba454c959f5ae4a649ba9167" - integrity sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA== - -"@babel/helper-function-name@^7.23.0": - version "7.23.0" - resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz#1f9a3cdbd5b2698a670c30d2735f9af95ed52759" - integrity sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw== - dependencies: - "@babel/template" "^7.22.15" - "@babel/types" "^7.23.0" - -"@babel/helper-hoist-variables@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz#c01a007dac05c085914e8fb652b339db50d823bb" - integrity sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw== - dependencies: - "@babel/types" "^7.22.5" - "@babel/helper-member-expression-to-functions@^7.25.9": version "7.25.9" resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.25.9.tgz#9dfffe46f727005a5ea29051ac835fb735e4c1a3" @@ -186,7 +166,7 @@ "@babel/traverse" "^7.25.9" "@babel/types" "^7.25.9" -"@babel/helper-module-transforms@^7.22.5", "@babel/helper-module-transforms@^7.25.9": +"@babel/helper-module-transforms@^7.25.9": version "7.26.0" resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.26.0.tgz#8ce54ec9d592695e58d84cd884b7b5c6a2fdeeae" integrity sha512-xO+xu6B5K2czEnQye6BHA7DolFFmS3LB7stHZFaOLb1pAwO1HWLS8fXA+eh0A2yIvltPVmx3eNNDBJA2SLHXFw== @@ -241,19 +221,12 @@ "@babel/traverse" "^7.25.9" "@babel/types" "^7.25.9" -"@babel/helper-split-export-declaration@^7.22.6": - version "7.22.6" - resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz#322c61b7310c0997fe4c323955667f18fcefb91c" - integrity sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g== - dependencies: - "@babel/types" "^7.22.5" - -"@babel/helper-string-parser@^7.23.4", "@babel/helper-string-parser@^7.25.9": +"@babel/helper-string-parser@^7.25.9": version "7.25.9" resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz#1aabb72ee72ed35789b4bbcad3ca2862ce614e8c" integrity sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA== -"@babel/helper-validator-identifier@^7.14.9", "@babel/helper-validator-identifier@^7.22.20", "@babel/helper-validator-identifier@^7.22.5", "@babel/helper-validator-identifier@^7.25.9": +"@babel/helper-validator-identifier@^7.14.9", "@babel/helper-validator-identifier@^7.25.9": version "7.25.9" resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz#24b64e2c3ec7cd3b3c547729b8d16871f22cbdc7" integrity sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ== @@ -272,7 +245,7 @@ "@babel/traverse" "^7.25.9" "@babel/types" "^7.25.9" -"@babel/helpers@^7.22.5", "@babel/helpers@^7.25.9": +"@babel/helpers@^7.25.9": version "7.26.0" resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.26.0.tgz#30e621f1eba5aa45fe6f4868d2e9154d884119a4" integrity sha512-tbhNuIxNcVb21pInl3ZSjksLCvgdZy9KwJ8brv993QtIVKJBBkYXz4q4ZbAv31GdnC+R90np23L5FbEBlthAEw== @@ -280,7 +253,7 @@ "@babel/template" "^7.25.9" "@babel/types" "^7.26.0" -"@babel/highlight@^7.10.4", "@babel/highlight@^7.23.4", "@babel/highlight@^7.25.9": +"@babel/highlight@^7.10.4": version "7.25.9" resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.25.9.tgz#8141ce68fc73757946f983b343f1231f4691acc6" integrity sha512-llL88JShoCsth8fF8R4SJnIn+WLvR6ccFxu1H3FlMhDontdcmZWf2HgIZ7AIqV3Xcck1idlohrN4EUBQz6klbw== @@ -290,7 +263,7 @@ js-tokens "^4.0.0" picocolors "^1.0.0" -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.22.15", "@babel/parser@^7.22.5", "@babel/parser@^7.23.6", "@babel/parser@^7.25.9", "@babel/parser@^7.26.2", "@babel/parser@^7.4.3", "@babel/parser@^7.7.0": +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.25.9", "@babel/parser@^7.26.2", "@babel/parser@^7.4.3", "@babel/parser@^7.7.0": version "7.26.2" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.26.2.tgz#fd7b6f487cfea09889557ef5d4eeb9ff9a5abd11" integrity sha512-DWMCZH9WA4Maitz2q21SRKHo9QXZxkDsbNZoVD62gusNtNBBqDg9i7uOhASfTfIGNzW+O+r7+jAlM8dwphcJKQ== @@ -1112,7 +1085,7 @@ dependencies: regenerator-runtime "^0.14.0" -"@babel/template@^7.22.15", "@babel/template@^7.22.5", "@babel/template@^7.25.9", "@babel/template@^7.3.3", "@babel/template@^7.4.0": +"@babel/template@^7.25.9", "@babel/template@^7.3.3", "@babel/template@^7.4.0": version "7.25.9" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.25.9.tgz#ecb62d81a8a6f5dc5fe8abfc3901fc52ddf15016" integrity sha512-9DGttpmPvIxBb/2uwpVo3dqJ+O6RooAFOS+lB+xDqoE2PVCE8nfoHMdZLpfCQRLwvohzXISPZcgxt80xLfsuwg== @@ -1121,7 +1094,7 @@ "@babel/parser" "^7.25.9" "@babel/types" "^7.25.9" -"@babel/traverse@^7.18.9", "@babel/traverse@^7.22.5", "@babel/traverse@^7.25.9", "@babel/traverse@^7.4.3", "@babel/traverse@^7.7.0", "@babel/traverse@^7.7.2": +"@babel/traverse@^7.18.9", "@babel/traverse@^7.25.9", "@babel/traverse@^7.4.3", "@babel/traverse@^7.7.0", "@babel/traverse@^7.7.2": version "7.25.9" resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.25.9.tgz#a50f8fe49e7f69f53de5bea7e413cd35c5e13c84" integrity sha512-ZCuvfwOwlz/bawvAuvcj8rrithP2/N55Tzz342AkTvq4qaWbGfmCk/tKhNaV2cthijKrPAA8SRJV5WWe7IBMJw== @@ -1142,7 +1115,7 @@ "@babel/helper-validator-identifier" "^7.14.9" to-fast-properties "^2.0.0" -"@babel/types@^7.0.0", "@babel/types@^7.12.6", "@babel/types@^7.18.9", "@babel/types@^7.20.7", "@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.23.0", "@babel/types@^7.23.6", "@babel/types@^7.25.9", "@babel/types@^7.26.0", "@babel/types@^7.3.3", "@babel/types@^7.4.0", "@babel/types@^7.4.4", "@babel/types@^7.7.0": +"@babel/types@^7.0.0", "@babel/types@^7.12.6", "@babel/types@^7.18.9", "@babel/types@^7.20.7", "@babel/types@^7.25.9", "@babel/types@^7.26.0", "@babel/types@^7.3.3", "@babel/types@^7.4.0", "@babel/types@^7.4.4", "@babel/types@^7.7.0": version "7.26.0" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.26.0.tgz#deabd08d6b753bc8e0f198f8709fb575e31774ff" integrity sha512-Z/yiTPj+lDVnF7lWeKCIJzaIkI0vYO87dMpZ4bg4TDrFe4XXLFWL1TbXU27gBP3QccxV9mZICCrnjnYlJjXHOA== @@ -2880,7 +2853,7 @@ resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz#3188bcb273a414b0d215fd22a58540b989b9409a" integrity sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ== -"@jridgewell/trace-mapping@^0.3.17", "@jridgewell/trace-mapping@^0.3.20", "@jridgewell/trace-mapping@^0.3.24", "@jridgewell/trace-mapping@^0.3.25", "@jridgewell/trace-mapping@^0.3.9": +"@jridgewell/trace-mapping@^0.3.20", "@jridgewell/trace-mapping@^0.3.24", "@jridgewell/trace-mapping@^0.3.25", "@jridgewell/trace-mapping@^0.3.9": version "0.3.25" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz#15f190e98895f3fc23276ee14bc76b675c2e50f0" integrity sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ== @@ -5199,7 +5172,7 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001503, caniuse-lite@^1.0.30001646, caniuse-lite@^1.0.30001669: +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001646, caniuse-lite@^1.0.30001669: version "1.0.30001678" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001678.tgz#b930b04cd0b295136405634aa32ad540d7eeb71e" integrity sha512-RR+4U/05gNtps58PEBDZcPWTgEO2MBeoPZ96aQcjmfkBWRIDfN451fW2qyDA9/+HohLLIL5GqiMwA+IB1pWarw== @@ -5221,7 +5194,7 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= -chalk@^2.0.0, chalk@^2.0.1, chalk@^2.4.1, chalk@^2.4.2: +chalk@^2.0.1, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -6576,7 +6549,7 @@ ejs@^3.0.1, ejs@^3.1.6: dependencies: jake "^10.8.5" -electron-to-chromium@^1.4.431, electron-to-chromium@^1.5.41: +electron-to-chromium@^1.5.41: version "1.5.52" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.52.tgz#2bed832c95a56a195504f918150e548474687da8" integrity sha512-xtoijJTZ+qeucLBDNztDOuQBE1ksqjvNjvqFoST3nGC7fSpqJ+X6BdTBaY5BHG+IhWWmpc6b/KfpeuEDupEPOQ== @@ -10069,11 +10042,6 @@ jsdom@^16.6.0: ws "^7.4.6" xml-name-validator "^3.0.0" -jsesc@^2.5.1: - version "2.5.2" - resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4" - integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== - jsesc@^3.0.2, jsesc@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-3.0.2.tgz#bb8b09a6597ba426425f2e4a07245c3d00b9343e" @@ -10975,11 +10943,6 @@ ms@2.0.0: resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" integrity sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A== -ms@2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" - integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== - ms@2.1.3, ms@^2.1.1, ms@^2.1.3: version "2.1.3" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" @@ -11115,7 +11078,7 @@ node-int64@^0.4.0: resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" integrity sha1-h6kGXNs1XTGC2PlM4RGIuCXGijs= -node-releases@^2.0.12, node-releases@^2.0.18: +node-releases@^2.0.18: version "2.0.18" resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.18.tgz#f010e8d35e2fe8d6b2944f03f70213ecedc4ca3f" integrity sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g== @@ -13984,7 +13947,7 @@ string-natural-compare@^3.0.1: resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4" integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw== -"string-width-cjs@npm:string-width@^4.2.0": +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -14010,15 +13973,6 @@ string-width@^3.0.0, string-width@^3.1.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^5.1.0" -string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - string-width@^5.0.1, string-width@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" @@ -14106,7 +14060,7 @@ stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -14127,13 +14081,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -15064,7 +15011,7 @@ upath@^1.2.0: resolved "https://registry.yarnpkg.com/upath/-/upath-1.2.0.tgz#8f66dbcd55a883acdae4408af8b035a5044c1894" integrity sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg== -update-browserslist-db@^1.0.11, update-browserslist-db@^1.1.1: +update-browserslist-db@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz#80846fba1d79e82547fb661f8d141e0945755fe5" integrity sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A== @@ -15758,7 +15705,7 @@ workbox-window@6.6.1: "@types/trusted-types" "^2.0.2" workbox-core "6.6.1" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -15785,15 +15732,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" From 38ebd10508335a33666fc4f0d181227665174719 Mon Sep 17 00:00:00 2001 From: braimbault Date: Thu, 5 Dec 2024 15:30:03 +0100 Subject: [PATCH 06/11] feat: add offset and rename itemsCount to duration in relativePeriods --- .../PeriodDimension/utils/relativePeriods.js | 222 ++++++++++++++---- 1 file changed, 176 insertions(+), 46 deletions(-) diff --git a/src/components/PeriodDimension/utils/relativePeriods.js b/src/components/PeriodDimension/utils/relativePeriods.js index 2675d985d..4b23e9daa 100644 --- a/src/components/PeriodDimension/utils/relativePeriods.js +++ b/src/components/PeriodDimension/utils/relativePeriods.js @@ -13,78 +13,188 @@ 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, }, ] @@ -92,25 +202,38 @@ 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 = () => [ @@ -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 }, {}) From 501a5bf8dfee0534ee3ccbc0b756b0e15dd474f3 Mon Sep 17 00:00:00 2001 From: braimbault Date: Thu, 5 Dec 2024 15:41:58 +0100 Subject: [PATCH 07/11] fix: getRelativePeriodsDetails export --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index eb4c3dbfc..c919ab55f 100644 --- a/src/index.js +++ b/src/index.js @@ -339,7 +339,7 @@ export { export { getRelativePeriodsOptionsById, getRelativePeriodsName, - getRelativePeriodsItemsCount, + getRelativePeriodsDetails, } from './components/PeriodDimension/utils/relativePeriods.js' export { getFixedPeriodsOptionsById } from './components/PeriodDimension/utils/fixedPeriods.js' From b50ecdc42c5ac359485b74890dbe3003c9fc1588 Mon Sep 17 00:00:00 2001 From: braimbault Date: Thu, 5 Dec 2024 16:01:04 +0100 Subject: [PATCH 08/11] fix: getRelativePeriodsDetails --- src/components/PeriodDimension/utils/relativePeriods.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/PeriodDimension/utils/relativePeriods.js b/src/components/PeriodDimension/utils/relativePeriods.js index 4b23e9daa..37814bb37 100644 --- a/src/components/PeriodDimension/utils/relativePeriods.js +++ b/src/components/PeriodDimension/utils/relativePeriods.js @@ -299,6 +299,7 @@ export const getRelativePeriodsDetails = () => .map((option) => option.getPeriods().map((period) => ({ id: period.id, + name: period.name, offset: period.offset, duration: period.duration, type: option.id, @@ -306,7 +307,7 @@ export const getRelativePeriodsDetails = () => ) .flat() .reduce((acc, period) => { - acc[period.id] = period.name + acc[period.id] = period return acc }, {}) From 6b591a830d4d6859c919b58061dd93767701a604 Mon Sep 17 00:00:00 2001 From: Bruno Raimbault Date: Fri, 6 Dec 2024 11:29:15 +0100 Subject: [PATCH 09/11] fix: update relativePeriods offsets --- src/components/PeriodDimension/utils/relativePeriods.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/PeriodDimension/utils/relativePeriods.js b/src/components/PeriodDimension/utils/relativePeriods.js index 37814bb37..cbccde9cc 100644 --- a/src/components/PeriodDimension/utils/relativePeriods.js +++ b/src/components/PeriodDimension/utils/relativePeriods.js @@ -73,7 +73,7 @@ const getWeeksPeriodType = () => [ { id: WEEKS_THIS_YEAR, name: i18n.t('Weeks this year'), - offset: 0, + offset: 51, duration: 52, }, ] @@ -118,7 +118,7 @@ const getMonthsPeriodType = () => [ { id: 'MONTHS_THIS_YEAR', name: i18n.t('Months this year'), - offset: 0, + offset: 11, duration: 12, }, ] @@ -145,7 +145,7 @@ const getBiMonthsPeriodType = () => [ { id: 'BIMONTHS_THIS_YEAR', name: i18n.t('Bi-months this year'), - offset: 0, + offset: 5, duration: 6, }, ] @@ -172,7 +172,7 @@ const getQuartersPeriodType = () => [ { id: 'QUARTERS_THIS_YEAR', name: i18n.t('Quarters this year'), - offset: 0, + offset: 3, duration: 4, }, ] From 832238afa54bb5a898f6be037a2ade422a5f052a Mon Sep 17 00:00:00 2001 From: braimbault Date: Fri, 6 Dec 2024 15:19:42 +0100 Subject: [PATCH 10/11] feat: export PERIOD_TYPE_REGEX --- src/components/PeriodDimension/utils/fixedPeriods.js | 2 +- src/index.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/PeriodDimension/utils/fixedPeriods.js b/src/components/PeriodDimension/utils/fixedPeriods.js index d3e1fc1a9..a6cff6bba 100644 --- a/src/components/PeriodDimension/utils/fixedPeriods.js +++ b/src/components/PeriodDimension/utils/fixedPeriods.js @@ -23,7 +23,7 @@ import { FYAPR, } from './index.js' -const PERIOD_TYPE_REGEX = { +export const PERIOD_TYPE_REGEX = { [DAILY]: /^([0-9]{4})([0-9]{2})([0-9]{2})$/, // YYYYMMDD [WEEKLY]: /^([0-9]{4})()W([0-9]{1,2})$/, // YYYY"W"[1-53] [BIWEEKLY]: /^([0-9]{4})BiW([0-9]{1,2})$/, // YYYY"BiW"[1-27] diff --git a/src/index.js b/src/index.js index c919ab55f..e31bc8fbd 100644 --- a/src/index.js +++ b/src/index.js @@ -341,7 +341,10 @@ export { getRelativePeriodsName, getRelativePeriodsDetails, } from './components/PeriodDimension/utils/relativePeriods.js' -export { getFixedPeriodsOptionsById } from './components/PeriodDimension/utils/fixedPeriods.js' +export { + getFixedPeriodsOptionsById, + PERIOD_TYPE_REGEX, +} from './components/PeriodDimension/utils/fixedPeriods.js' export { default as VisualizationOptions } from './components/Options/VisualizationOptions.js' From 6bf23fdac0033a55ebb6d77ec497a655eef0264d Mon Sep 17 00:00:00 2001 From: braimbault Date: Tue, 7 Jan 2025 17:33:41 +0100 Subject: [PATCH 11/11] chore: relativePeriods utils improvement - add tests to getRelativePeriodsDetails and getRelativePeriodsName - add description for duration and offset properties --- .../relativePeriods.spec.js.snap | 347 ++++++++++++++++++ .../__tests__/relativePeriods.spec.js | 16 + .../PeriodDimension/utils/relativePeriods.js | 14 + 3 files changed, 377 insertions(+) create mode 100644 src/components/PeriodDimension/__tests__/__snapshots__/relativePeriods.spec.js.snap create mode 100644 src/components/PeriodDimension/__tests__/relativePeriods.spec.js diff --git a/src/components/PeriodDimension/__tests__/__snapshots__/relativePeriods.spec.js.snap b/src/components/PeriodDimension/__tests__/__snapshots__/relativePeriods.spec.js.snap new file mode 100644 index 000000000..b56fc6351 --- /dev/null +++ b/src/components/PeriodDimension/__tests__/__snapshots__/relativePeriods.spec.js.snap @@ -0,0 +1,347 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`relativePeriods utils should correctly return relative periods details 1`] = ` +Object { + "BIMONTHS_THIS_YEAR": Object { + "duration": 6, + "id": "BIMONTHS_THIS_YEAR", + "name": "Bi-months this year", + "offset": 5, + "type": "BIMONTHLY", + }, + "LAST_10_YEARS": Object { + "duration": 10, + "id": "LAST_10_YEARS", + "name": "Last 10 years", + "offset": -1, + "type": "YEARLY", + }, + "LAST_12_MONTHS": Object { + "duration": 12, + "id": "LAST_12_MONTHS", + "name": "Last 12 months", + "offset": -1, + "type": "MONTHLY", + }, + "LAST_12_WEEKS": Object { + "duration": 12, + "id": "LAST_12_WEEKS", + "name": "Last 12 weeks", + "offset": -1, + "type": "WEEKLY", + }, + "LAST_14_DAYS": Object { + "duration": 14, + "id": "LAST_14_DAYS", + "name": "Last 14 days", + "offset": -1, + "type": "DAILY", + }, + "LAST_180_DAYS": Object { + "duration": 180, + "id": "LAST_180_DAYS", + "name": "Last 180 days", + "offset": -1, + "type": "DAILY", + }, + "LAST_2_SIXMONTHS": Object { + "duration": 2, + "id": "LAST_2_SIXMONTHS", + "name": "Last 2 six-month", + "offset": -1, + "type": "SIXMONTHLY", + }, + "LAST_30_DAYS": Object { + "duration": 30, + "id": "LAST_30_DAYS", + "name": "Last 30 days", + "offset": -1, + "type": "DAILY", + }, + "LAST_3_DAYS": Object { + "duration": 3, + "id": "LAST_3_DAYS", + "name": "Last 3 days", + "offset": -1, + "type": "DAILY", + }, + "LAST_3_MONTHS": Object { + "duration": 3, + "id": "LAST_3_MONTHS", + "name": "Last 3 months", + "offset": -1, + "type": "MONTHLY", + }, + "LAST_4_BIWEEKS": Object { + "duration": 4, + "id": "LAST_4_BIWEEKS", + "name": "Last 4 bi-weeks", + "offset": -1, + "type": "BIWEEKLY", + }, + "LAST_4_QUARTERS": Object { + "duration": 4, + "id": "LAST_4_QUARTERS", + "name": "Last 4 quarters", + "offset": -1, + "type": "QUARTERLY", + }, + "LAST_4_WEEKS": Object { + "duration": 4, + "id": "LAST_4_WEEKS", + "name": "Last 4 weeks", + "offset": -1, + "type": "WEEKLY", + }, + "LAST_52_WEEKS": Object { + "duration": 52, + "id": "LAST_52_WEEKS", + "name": "Last 52 weeks", + "offset": -1, + "type": "WEEKLY", + }, + "LAST_5_FINANCIAL_YEARS": Object { + "duration": 5, + "id": "LAST_5_FINANCIAL_YEARS", + "name": "Last 5 financial years", + "offset": -1, + "type": "FINANCIAL", + }, + "LAST_5_YEARS": Object { + "duration": 5, + "id": "LAST_5_YEARS", + "name": "Last 5 years", + "offset": -1, + "type": "YEARLY", + }, + "LAST_60_DAYS": Object { + "duration": 60, + "id": "LAST_60_DAYS", + "name": "Last 60 days", + "offset": -1, + "type": "DAILY", + }, + "LAST_6_BIMONTHS": Object { + "duration": 6, + "id": "LAST_6_BIMONTHS", + "name": "Last 6 bi-months", + "offset": -1, + "type": "BIMONTHLY", + }, + "LAST_6_MONTHS": Object { + "duration": 6, + "id": "LAST_6_MONTHS", + "name": "Last 6 months", + "offset": -1, + "type": "MONTHLY", + }, + "LAST_7_DAYS": Object { + "duration": 7, + "id": "LAST_7_DAYS", + "name": "Last 7 days", + "offset": -1, + "type": "DAILY", + }, + "LAST_90_DAYS": Object { + "duration": 90, + "id": "LAST_90_DAYS", + "name": "Last 90 days", + "offset": -1, + "type": "DAILY", + }, + "LAST_BIMONTH": Object { + "duration": 1, + "id": "LAST_BIMONTH", + "name": "Last bi-month", + "offset": -1, + "type": "BIMONTHLY", + }, + "LAST_BIWEEK": Object { + "duration": 1, + "id": "LAST_BIWEEK", + "name": "Last bi-week", + "offset": -1, + "type": "BIWEEKLY", + }, + "LAST_FINANCIAL_YEAR": Object { + "duration": 1, + "id": "LAST_FINANCIAL_YEAR", + "name": "Last financial year", + "offset": -1, + "type": "FINANCIAL", + }, + "LAST_MONTH": Object { + "duration": 1, + "id": "LAST_MONTH", + "name": "Last month", + "offset": -1, + "type": "MONTHLY", + }, + "LAST_QUARTER": Object { + "duration": 1, + "id": "LAST_QUARTER", + "name": "Last quarter", + "offset": -1, + "type": "QUARTERLY", + }, + "LAST_SIX_MONTH": Object { + "duration": 1, + "id": "LAST_SIX_MONTH", + "name": "Last six-month", + "offset": -1, + "type": "SIXMONTHLY", + }, + "LAST_WEEK": Object { + "duration": 1, + "id": "LAST_WEEK", + "name": "Last week", + "offset": -1, + "type": "WEEKLY", + }, + "LAST_YEAR": Object { + "duration": 1, + "id": "LAST_YEAR", + "name": "Last year", + "offset": -1, + "type": "YEARLY", + }, + "MONTHS_THIS_YEAR": Object { + "duration": 12, + "id": "MONTHS_THIS_YEAR", + "name": "Months this year", + "offset": 11, + "type": "MONTHLY", + }, + "QUARTERS_THIS_YEAR": Object { + "duration": 4, + "id": "QUARTERS_THIS_YEAR", + "name": "Quarters this year", + "offset": 3, + "type": "QUARTERLY", + }, + "THIS_BIMONTH": Object { + "duration": 1, + "id": "THIS_BIMONTH", + "name": "This bi-month", + "offset": 0, + "type": "BIMONTHLY", + }, + "THIS_BIWEEK": Object { + "duration": 1, + "id": "THIS_BIWEEK", + "name": "This bi-week", + "offset": 0, + "type": "BIWEEKLY", + }, + "THIS_FINANCIAL_YEAR": Object { + "duration": 1, + "id": "THIS_FINANCIAL_YEAR", + "name": "This financial year", + "offset": 0, + "type": "FINANCIAL", + }, + "THIS_MONTH": Object { + "duration": 1, + "id": "THIS_MONTH", + "name": "This month", + "offset": 0, + "type": "MONTHLY", + }, + "THIS_QUARTER": Object { + "duration": 1, + "id": "THIS_QUARTER", + "name": "This quarter", + "offset": 0, + "type": "QUARTERLY", + }, + "THIS_SIX_MONTH": Object { + "duration": 1, + "id": "THIS_SIX_MONTH", + "name": "This six-month", + "offset": 0, + "type": "SIXMONTHLY", + }, + "THIS_WEEK": Object { + "duration": 1, + "id": "THIS_WEEK", + "name": "This week", + "offset": 0, + "type": "WEEKLY", + }, + "THIS_YEAR": Object { + "duration": 1, + "id": "THIS_YEAR", + "name": "This year", + "offset": 0, + "type": "YEARLY", + }, + "TODAY": Object { + "duration": 1, + "id": "TODAY", + "name": "Today", + "offset": 0, + "type": "DAILY", + }, + "WEEKS_THIS_YEAR": Object { + "duration": 52, + "id": "WEEKS_THIS_YEAR", + "name": "Weeks this year", + "offset": 51, + "type": "WEEKLY", + }, + "YESTERDAY": Object { + "duration": 1, + "id": "YESTERDAY", + "name": "Yesterday", + "offset": -1, + "type": "DAILY", + }, +} +`; + +exports[`relativePeriods utils should correctly return relative periods names 1`] = ` +Object { + "BIMONTHS_THIS_YEAR": "Bi-months this year", + "LAST_10_YEARS": "Last 10 years", + "LAST_12_MONTHS": "Last 12 months", + "LAST_12_WEEKS": "Last 12 weeks", + "LAST_14_DAYS": "Last 14 days", + "LAST_180_DAYS": "Last 180 days", + "LAST_2_SIXMONTHS": "Last 2 six-month", + "LAST_30_DAYS": "Last 30 days", + "LAST_3_DAYS": "Last 3 days", + "LAST_3_MONTHS": "Last 3 months", + "LAST_4_BIWEEKS": "Last 4 bi-weeks", + "LAST_4_QUARTERS": "Last 4 quarters", + "LAST_4_WEEKS": "Last 4 weeks", + "LAST_52_WEEKS": "Last 52 weeks", + "LAST_5_FINANCIAL_YEARS": "Last 5 financial years", + "LAST_5_YEARS": "Last 5 years", + "LAST_60_DAYS": "Last 60 days", + "LAST_6_BIMONTHS": "Last 6 bi-months", + "LAST_6_MONTHS": "Last 6 months", + "LAST_7_DAYS": "Last 7 days", + "LAST_90_DAYS": "Last 90 days", + "LAST_BIMONTH": "Last bi-month", + "LAST_BIWEEK": "Last bi-week", + "LAST_FINANCIAL_YEAR": "Last financial year", + "LAST_MONTH": "Last month", + "LAST_QUARTER": "Last quarter", + "LAST_SIX_MONTH": "Last six-month", + "LAST_WEEK": "Last week", + "LAST_YEAR": "Last year", + "MONTHS_THIS_YEAR": "Months this year", + "QUARTERS_THIS_YEAR": "Quarters this year", + "THIS_BIMONTH": "This bi-month", + "THIS_BIWEEK": "This bi-week", + "THIS_FINANCIAL_YEAR": "This financial year", + "THIS_MONTH": "This month", + "THIS_QUARTER": "This quarter", + "THIS_SIX_MONTH": "This six-month", + "THIS_WEEK": "This week", + "THIS_YEAR": "This year", + "TODAY": "Today", + "WEEKS_THIS_YEAR": "Weeks this year", + "YESTERDAY": "Yesterday", +} +`; diff --git a/src/components/PeriodDimension/__tests__/relativePeriods.spec.js b/src/components/PeriodDimension/__tests__/relativePeriods.spec.js new file mode 100644 index 000000000..5d5aea596 --- /dev/null +++ b/src/components/PeriodDimension/__tests__/relativePeriods.spec.js @@ -0,0 +1,16 @@ +import { + getRelativePeriodsDetails, + getRelativePeriodsName, +} from '../utils/relativePeriods.js' + +describe('relativePeriods utils', () => { + it('should correctly return relative periods details', () => { + const details = getRelativePeriodsDetails() + expect(details).toMatchSnapshot() + }) + + it('should correctly return relative periods names', () => { + const names = getRelativePeriodsName() + expect(names).toMatchSnapshot() + }) +}) diff --git a/src/components/PeriodDimension/utils/relativePeriods.js b/src/components/PeriodDimension/utils/relativePeriods.js index cbccde9cc..431ec6554 100644 --- a/src/components/PeriodDimension/utils/relativePeriods.js +++ b/src/components/PeriodDimension/utils/relativePeriods.js @@ -12,6 +12,20 @@ import { YEARLY, } from './index.js' +/* +In getDaysPeriodType, getWeeksPeriodType, getBiWeeksPeriodType, +getBiWeeksPeriodType, getMonthsPeriodType, getBiMonthsPeriodType, +getQuartersPeriodType, getSixMonthsPeriodType, +getFinancialYearsPeriodType, and getYearsPeriodType: +- duration: The number of individual periods in the preset + (the maximum when the duration is variable). + eg: LAST_14_DAYS duration is 14 +- offset: The position of the most recent individual period + relative to THIS period in the preset, earlier periods are + negative (the maximum when the offset is variable). + eg: LAST_BIMONTH offset is -1 +*/ + const getDaysPeriodType = () => [ { id: 'TODAY', name: i18n.t('Today'), offset: 0, duration: 1 }, { id: 'YESTERDAY', name: i18n.t('Yesterday'), offset: -1, duration: 1 },