Skip to content

Commit

Permalink
Preserve date filter on registration table (#2047)
Browse files Browse the repository at this point in the history
Preserve date filter on registration table
  • Loading branch information
flutistar authored Oct 25, 2024
1 parent 3d59dbf commit 967bdab
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions ppr-ui/src/components/common/RangeDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</b>
<BaseDatePicker
class="date-selection__picker mt-2"
:default-selected-date="startDate"
:error="startDate === null && datePickerErr"
:resetTrigger="resetTrigger"
:setMaxDate="endDate || defaultMaxDate"
Expand All @@ -30,6 +31,7 @@
</b>
<BaseDatePicker
class="date-selection__picker mt-2"
:default-selected-date="endDate"
:error="endDate === null && datePickerErr"
:resetTrigger="resetTrigger"
:setMinDate="startDate"
Expand Down
19 changes: 16 additions & 3 deletions ppr-ui/src/components/tables/RegistrationTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
v-if="showDatePicker"
id="ranged-date-picker"
ref="datePicker"
:defaultStartDate="getPstDateObj(submittedStartDate)"
:defaultEndDate="getPstDateObj(submittedEndDate)"
:defaultMaxDate="new Date()"
@submit="updateDateRange($event)"
/>
Expand Down Expand Up @@ -419,7 +421,7 @@ import {
import { storeToRefs } from 'pinia'
import { useTableFeatures, useTransferOwners } from '@/composables'
import { RangeDatePicker } from '@/components/common'
import { dateToYyyyMmDd, localTodayDate } from '@/utils'
import { dateToYyyyMmDd, yyyyMmDdToPacificDate, localTodayDate } from '@/utils'
import TableObserver from '@/components/tables/common/TableObserver.vue'
export default defineComponent({
Expand Down Expand Up @@ -728,7 +730,7 @@ export default defineComponent({
const updateDateRange = (dates: { endDate: Date, startDate: Date }) => {
if (!(dates.endDate && dates.startDate)) dateTxt.value = ''
else dateTxt.value = 'Custom'
submittedStartDate.value = dateToYyyyMmDd(dates.startDate)
submittedEndDate.value = dateToYyyyMmDd(dates.endDate)
localState.showDatePicker = false
Expand All @@ -755,7 +757,16 @@ export default defineComponent({
}, 2000)
}
})
const getPstDateObj = (date: string): Date => {
if(!date) return null
// Regular expression to match timezone offset (e.g., +05:00 or Z for UTC)
const timeZoneRegex = /([+-]\d{2}:\d{2}|Z)$/;
if(timeZoneRegex.test(date)) {
return new Date(date)
}
return new Date(yyyyMmDdToPacificDate(date))
}
watch(() => dateTxt.value, (val) => {
if (!val) {
submittedStartDate.value = null
Expand Down Expand Up @@ -845,6 +856,7 @@ export default defineComponent({
isMiscTransfersEnabled,
getNext,
localTodayDate,
yyyyMmDdToPacificDate,
dateSortHandler,
datePicker,
dateTxt,
Expand Down Expand Up @@ -888,6 +900,7 @@ export default defineComponent({
clientReferenceIdRef,
toggleGroup,
hideAllGroups,
getPstDateObj,
...toRefs(localState)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ppr-ui/src/composables/useRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { RegistrationSortIF, RegistrationSummaryIF } from '@/interfaces'

export const useRegistration = (setSort: RegistrationSortIF) => {
const localState = reactive({
dateTxt: '',
dateTxt: (setSort?.startDate && setSort.endDate) ? 'Custom' : '',
registrationNumber: setSort?.regNum || '',
registrationType: setSort?.regType || '',
status: setSort?.status || '',
Expand Down
2 changes: 1 addition & 1 deletion ppr-ui/src/utils/date-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function dateToYyyyMmDd (date: Date): string {
day: 'numeric', // 31
year: 'numeric' // 2020
})

return convertDateFormat(localDate)
}

Expand Down

0 comments on commit 967bdab

Please sign in to comment.