Skip to content

Commit c057a8f

Browse files
authored
Merge pull request #2620 from bcgov/release
Hotfix Release 1.0.5.2
2 parents d15c91d + a55dfc9 commit c057a8f

File tree

2 files changed

+86
-25
lines changed

2 files changed

+86
-25
lines changed

frontend/src/components/BCDataGrid/components/Editors/DateEditor.jsx

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ export const DateEditor = ({
1111
api,
1212
autoOpenLastRow
1313
}) => {
14+
// Handle initial value properly - use null if value is falsy
1415
const [selectedDate, setSelectedDate] = useState(
15-
value ? parseISO(value) : null
16+
value && value !== 'YYYY-MM-DD' ? parseISO(value) : null
1617
)
1718
const [isOpen, setIsOpen] = useState(() => {
1819
if (!autoOpenLastRow) return false
@@ -31,18 +32,32 @@ export const DateEditor = ({
3132
}
3233
}
3334

34-
document.addEventListener('mousedown', handleClickOutside)
35+
// Use the more cross-browser compatible approach
36+
document.addEventListener('mousedown', handleClickOutside, {
37+
passive: true
38+
})
3539
return () => {
3640
document.removeEventListener('mousedown', handleClickOutside)
3741
}
3842
}, [])
3943

44+
// Fixed updateValue function to handle null values properly
4045
const updateValue = (val) => {
41-
if (val) {
42-
val = new Date(val.getFullYear(), val.getMonth(), val.getDate())
46+
// If val is null or undefined, set it as null explicitly
47+
if (val === null || val === undefined) {
48+
setSelectedDate(null)
49+
onValueChange(null)
50+
return
4351
}
44-
setSelectedDate(val)
45-
onValueChange(val === null ? null : format(val, 'yyyy-MM-dd'))
52+
53+
// Normalize the date to avoid timezone issues (common cross-browser problem)
54+
const normalizedDate = new Date(
55+
val.getFullYear(),
56+
val.getMonth(),
57+
val.getDate()
58+
)
59+
setSelectedDate(normalizedDate)
60+
onValueChange(format(normalizedDate, 'yyyy-MM-dd'))
4661
}
4762

4863
const handleDatePickerOpen = () => {
@@ -53,17 +68,29 @@ export const DateEditor = ({
5368
setIsOpen(false)
5469
}
5570

71+
// Improved event handlers for better cross-browser support
5672
const stopPropagation = (e) => {
57-
e.stopPropagation()
73+
if (e && e.stopPropagation) {
74+
e.stopPropagation()
75+
}
76+
if (e && e.preventDefault) {
77+
e.preventDefault()
78+
}
79+
return false
5880
}
5981

6082
// Handler for the icon click that forces the calendar to open
6183
const handleIconClick = (e) => {
62-
e.stopPropagation()
63-
e.preventDefault()
84+
stopPropagation(e)
6485
setIsOpen(true)
6586
}
6687

88+
// Explicit handler for clearing the date
89+
const handleClear = () => {
90+
setSelectedDate(null)
91+
onValueChange(null)
92+
}
93+
6794
return (
6895
<div
6996
ref={containerRef}
@@ -77,7 +104,8 @@ export const DateEditor = ({
77104
top: 0,
78105
left: 0,
79106
right: 0,
80-
bottom: 0
107+
bottom: 0,
108+
zIndex: isOpen ? 1000 : 'auto'
81109
}}
82110
>
83111
<DatePicker
@@ -89,6 +117,7 @@ export const DateEditor = ({
89117
slotProps={{
90118
field: {
91119
clearable: true,
120+
onClear: handleClear,
92121
sx: {
93122
width: '100%',
94123
'& .MuiInputBase-root': {
@@ -97,12 +126,28 @@ export const DateEditor = ({
97126
},
98127
'& .MuiOutlinedInput-notchedOutline': {
99128
border: 'none'
129+
},
130+
'& .MuiIconButton-root': {
131+
padding: '2px',
132+
touchAction: 'manipulation'
100133
}
101134
}
102135
},
103-
popper: { placement: 'bottom-start' },
136+
popper: {
137+
placement: 'bottom-start',
138+
modifiers: [
139+
{
140+
name: 'preventOverflow',
141+
options: {
142+
boundary: document.body
143+
}
144+
}
145+
]
146+
},
104147
// Handle icon click specifically to open the calendar
105-
openPickerButton: { onClick: handleIconClick }
148+
openPickerButton: { onClick: handleIconClick },
149+
// Explicitly handle the clear button
150+
clearButton: { onClick: handleClear }
106151
}}
107152
value={selectedDate}
108153
onChange={updateValue}
@@ -119,6 +164,14 @@ export const DateEditor = ({
119164
'& .MuiInputBase-root': {
120165
padding: '0 5px',
121166
width: '100%'
167+
},
168+
'& .MuiButtonBase-root': {
169+
WebkitTouchCallout: 'none',
170+
WebkitUserSelect: 'none',
171+
KhtmlUserSelect: 'none',
172+
MozUserSelect: 'none',
173+
msUserSelect: 'none',
174+
userSelect: 'none'
122175
}
123176
}}
124177
/>

frontend/src/views/FinalSupplyEquipments/_schema.jsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,6 @@ export const finalSupplyEquipmentColDefs = (
225225
cellEditor: AutocompleteCellEditor,
226226
suppressKeyboardEvent,
227227
minWidth: 430,
228-
valueGetter: (params) => {
229-
return (
230-
params.data?.levelOfEquipment?.name ||
231-
params.data?.levelOfEquipment ||
232-
''
233-
)
234-
},
235228
cellEditorParams: {
236229
options: optionsData?.levelsOfEquipment.map((obj) => obj.name),
237230
multiple: false,
@@ -241,7 +234,22 @@ export const finalSupplyEquipmentColDefs = (
241234
},
242235
cellStyle: (params) =>
243236
StandardCellWarningAndErrors(params, errors, warnings),
244-
cellRenderer: SelectRenderer
237+
cellRenderer: SelectRenderer,
238+
valueGetter: (params) => {
239+
if (params.data?.levelOfEquipment) {
240+
return typeof params.data.levelOfEquipment === 'object'
241+
? params.data.levelOfEquipment.name
242+
: params.data.levelOfEquipment
243+
}
244+
return ''
245+
},
246+
valueSetter: (params) => {
247+
if (params.newValue) {
248+
params.data.levelOfEquipment = params.newValue
249+
return true
250+
}
251+
return false
252+
}
245253
},
246254
{
247255
field: 'ports',
@@ -269,6 +277,7 @@ export const finalSupplyEquipmentColDefs = (
269277
headerName: i18n.t(
270278
'finalSupplyEquipment:finalSupplyEquipmentColLabels.intendedUses'
271279
),
280+
valueGetter: (params) => params.data?.intendedUseTypes,
272281
cellEditor: AutocompleteCellEditor,
273282
cellEditorParams: {
274283
options: optionsData?.intendedUseTypes.map((obj) => obj.type) || [],
@@ -288,6 +297,7 @@ export const finalSupplyEquipmentColDefs = (
288297
headerName: i18n.t(
289298
'finalSupplyEquipment:finalSupplyEquipmentColLabels.intendedUsers'
290299
),
300+
valueGetter: (params) => params.data?.intendedUserTypes,
291301
cellEditor: AutocompleteCellEditor,
292302
cellEditorParams: {
293303
options: optionsData?.intendedUserTypes.map((obj) => obj.typeName) || [],
@@ -491,7 +501,7 @@ export const finalSupplyEquipmentSummaryColDefs = (t) => [
491501
'finalSupplyEquipment:finalSupplyEquipmentColLabels.levelOfEquipment'
492502
),
493503
field: 'levelOfEquipment',
494-
valueGetter: (params) => params.data.levelOfEquipment.name
504+
valueGetter: (params) => params.data.levelOfEquipment
495505
},
496506
{
497507
headerName: t('finalSupplyEquipment:finalSupplyEquipmentColLabels.ports'),
@@ -502,8 +512,7 @@ export const finalSupplyEquipmentSummaryColDefs = (t) => [
502512
'finalSupplyEquipment:finalSupplyEquipmentColLabels.intendedUses'
503513
),
504514
field: 'intendedUses',
505-
valueGetter: (params) =>
506-
params.data.intendedUseTypes.map((use) => use.type).join(', '),
515+
valueGetter: (params) => params.data.intendedUseTypes,
507516
cellRenderer: CommonArrayRenderer,
508517
cellRendererParams: { marginTop: '0.7em' }
509518
},
@@ -512,8 +521,7 @@ export const finalSupplyEquipmentSummaryColDefs = (t) => [
512521
'finalSupplyEquipment:finalSupplyEquipmentColLabels.intendedUsers'
513522
),
514523
field: 'intendedUsers',
515-
valueGetter: (params) =>
516-
params.data.intendedUserTypes.map((use) => use.typeName).join(', '),
524+
valueGetter: (params) => params.data.intendedUserTypes,
517525
cellRenderer: CommonArrayRenderer,
518526
cellRendererParams: { marginTop: '0.7em' }
519527
},

0 commit comments

Comments
 (0)