Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve date filter on registration table #2047

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small thing but in this project we've been going with camelCase for the prop names

: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"
:default-start-date="getPstDateObj(submittedStartDate)"
:default-end-date="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