Skip to content

Commit

Permalink
fix: handle date splitting in one place only
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferarnesen committed Jan 24, 2024
1 parent 2513cb0 commit decb435
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
16 changes: 5 additions & 11 deletions src/components/Dialogs/PeriodDimension/PeriodDimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? (
<DimensionModal
dataTest={'period-dimension-modal'}
Expand All @@ -200,7 +191,10 @@ export const PeriodDimension = ({ dimension, onClose }) => {
<div className={styles.entry}>
{entryMethod === OPTION_PRESETS && (
<BasePeriodDimension
selectedPeriods={selectedPeriods}
selectedPeriods={selectedIds.map((id) => ({
id,
name: getNameFromMetadata(id),
}))}
onSelect={({ items }) =>
updatePeriodDimensionItems(items)
}
Expand All @@ -209,7 +203,7 @@ export const PeriodDimension = ({ dimension, onClose }) => {
)}
{entryMethod === OPTION_START_END_DATES && (
<StartEndDate
value={selectedStartEndDate}
value={getStartEndDate(selectedIds[0] || '')}
setValue={(value) => {
if (!value && selectedIds.length) {
updatePeriodDimensionItems([])
Expand Down
8 changes: 5 additions & 3 deletions src/components/Dialogs/PeriodDimension/StartEndDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -54,5 +56,5 @@ export const StartEndDate = ({ value, setValue }) => {
}
StartEndDate.propTypes = {
setValue: PropTypes.func.isRequired,
value: PropTypes.string.isRequired,
value: PropTypes.array.isRequired,
}

0 comments on commit decb435

Please sign in to comment.