Skip to content

Commit

Permalink
EDSC-4125 granule filters form fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-zamora committed Jan 27, 2025
1 parent 118854f commit 9101855
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions static/src/js/components/GranuleFilters/GranuleFiltersForm.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React from 'react'
import PropTypes from 'prop-types'
import { Form as FormikForm } from 'formik'
import {
Expand Down Expand Up @@ -71,11 +71,6 @@ export const GranuleFiltersForm = (props) => {
temporal = {}
} = values

const [datesSelected, setDatesSelected] = useState({
start: false,
end: false
})

const { isRecurring } = temporal

// For recurring dates we don't show the year, it's displayed on the slider
Expand Down Expand Up @@ -451,8 +446,8 @@ export const GranuleFiltersForm = (props) => {
size="sm"
format={temporalDateFormat}
temporal={temporal}
displayStartDate={datesSelected.start ? temporal.startDate : ''}
displayEndDate={datesSelected.end ? temporal.endDate : ''}
displayStartDate={temporal.startDate}
displayEndDate={temporal.endDate}
validate={false}
onSliderChange={
(value) => {
Expand Down Expand Up @@ -528,18 +523,20 @@ export const GranuleFiltersForm = (props) => {
}
onSubmitStart={
(startDate, shouldSubmit) => {
const { temporal: newTemporal } = values
if (newTemporal.isRecurring) {
const existingStartDate = moment(values.temporal.startDate)
if (existingStartDate.isValid()) {
const existingStartDateYear = existingStartDate.year()
startDate.year(existingStartDateYear)
}
}

const { input } = startDate.creationData()
const value = startDate.isValid() ? startDate.toISOString() : input

setFieldValue('temporal.startDate', value)
setFieldTouched('temporal.startDate')

setDatesSelected((prev) => ({
...prev,
start: true
}))

const { temporal: newTemporal } = values
if (newTemporal.isRecurring && newTemporal.endDate && startDate.isValid()) {
const endDate = moment(newTemporal.endDate).utc()

Expand Down Expand Up @@ -570,11 +567,6 @@ export const GranuleFiltersForm = (props) => {
setFieldValue('temporal.endDate', value)
setFieldTouched('temporal.endDate')

setDatesSelected((prev) => ({
...prev,
end: true
}))

const { temporal: newTemporal } = values
if (newTemporal.isRecurring && newTemporal.startDate && endDate.isValid()) {
const startDate = moment(newTemporal.startDate).utc()
Expand Down

0 comments on commit 9101855

Please sign in to comment.