Skip to content

Commit be9a493

Browse files
committed
replace momentjs with dayjs and use watch instead of update
1 parent 56a39e6 commit be9a493

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

ui/src/components/view/DateTimeFilter.vue

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
<script>
6363
import { ref, reactive, toRaw } from 'vue'
64-
import moment from 'moment'
64+
import dayjs from 'dayjs'
6565
6666
export default {
6767
name: 'DateTimeFilter',
@@ -84,20 +84,6 @@ export default {
8484
value: ''
8585
}
8686
},
87-
computed: {
88-
startDate () {
89-
if (this.startDateProp) {
90-
return moment(this.startDateProp)
91-
}
92-
return null
93-
},
94-
endDate () {
95-
if (this.endDateProp) {
96-
return moment(this.endDateProp)
97-
}
98-
return null
99-
}
100-
},
10187
data () {
10288
return {
10389
allDataIsChecked: false,
@@ -110,27 +96,40 @@ export default {
11096
submitButtonLabel: this.$t('label.ok')
11197
}
11298
},
113-
updated () {
114-
this.form.startDate = this.startDate
115-
this.form.endDate = this.endDate
116-
},
11799
created () {
118100
this.initForm()
119101
},
102+
watch: {
103+
startDateProp (newVal) {
104+
this.form.startDate = newVal ? dayjs(newVal) : null
105+
},
106+
endDateProp (newVal) {
107+
this.form.endDate = newVal ? dayjs(newVal) : null
108+
}
109+
},
120110
methods: {
121111
initForm () {
122112
this.formRef = ref()
113+
// Use dayjs instead of moment - Ant Design Vue requires dayjs
114+
const startDate = this.startDateProp ? dayjs(this.startDateProp) : null
115+
const endDate = this.endDateProp ? dayjs(this.endDateProp) : null
116+
123117
this.form = reactive({
124-
startDate: this.startDate,
125-
endDate: this.endDate
118+
startDate: startDate,
119+
endDate: endDate
126120
})
127121
},
128122
handleSubmit (e) {
129123
e.preventDefault()
130124
this.formRef.value.validate().then(() => {
131125
this.submitButtonLabel = this.$t('label.refresh')
132126
const values = toRaw(this.form)
133-
this.$emit('onSubmit', values)
127+
// Convert dayjs objects back to JavaScript Date objects
128+
const result = {
129+
startDate: values.startDate ? values.startDate.toDate() : null,
130+
endDate: values.endDate ? values.endDate.toDate() : null
131+
}
132+
this.$emit('onSubmit', result)
134133
}).catch(error => {
135134
this.formRef.value.scrollToField(error.errorFields[0].name)
136135
})

0 commit comments

Comments
 (0)