From decb43512cb0afe1113f8e008602ac761675e8af Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Wed, 24 Jan 2024 15:07:30 +0100 Subject: [PATCH] fix: handle date splitting in one place only --- .../Dialogs/PeriodDimension/PeriodDimension.js | 16 +++++----------- .../Dialogs/PeriodDimension/StartEndDate.js | 8 +++++--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/Dialogs/PeriodDimension/PeriodDimension.js b/src/components/Dialogs/PeriodDimension/PeriodDimension.js index e9146c22a..e741a6ac9 100644 --- a/src/components/Dialogs/PeriodDimension/PeriodDimension.js +++ b/src/components/Dialogs/PeriodDimension/PeriodDimension.js @@ -167,15 +167,6 @@ export const PeriodDimension = ({ dimension, onClose }) => { updatePeriodDimensionItems([]) } - const selectedPeriods = selectedIds.map((id) => ({ - id, - name: getNameFromMetadata(id), - })) - - const { dimensionId: selectedStartEndDate } = extractDimensionIdParts( - selectedIds[0] || '' - ) - return dimension ? ( {
{entryMethod === OPTION_PRESETS && ( ({ + id, + name: getNameFromMetadata(id), + }))} onSelect={({ items }) => updatePeriodDimensionItems(items) } @@ -209,7 +203,7 @@ export const PeriodDimension = ({ dimension, onClose }) => { )} {entryMethod === OPTION_START_END_DATES && ( { if (!value && selectedIds.length) { updatePeriodDimensionItems([]) diff --git a/src/components/Dialogs/PeriodDimension/StartEndDate.js b/src/components/Dialogs/PeriodDimension/StartEndDate.js index d786d99cf..320d4c97f 100644 --- a/src/components/Dialogs/PeriodDimension/StartEndDate.js +++ b/src/components/Dialogs/PeriodDimension/StartEndDate.js @@ -4,8 +4,10 @@ import PropTypes from 'prop-types' import React, { useEffect, useState } from 'react' import styles from './StartEndDate.module.css' -export const StartEndDate = ({ value, setValue }) => { - const [startDateStr, endDateStr] = value ? value.split('_') : [] +export const StartEndDate = ({ + value: [startDateStr, endDateStr], + setValue, +}) => { const [startDate, setStartDate] = useState(startDateStr) const [endDate, setEndDate] = useState(endDateStr) @@ -54,5 +56,5 @@ export const StartEndDate = ({ value, setValue }) => { } StartEndDate.propTypes = { setValue: PropTypes.func.isRequired, - value: PropTypes.string.isRequired, + value: PropTypes.array.isRequired, }