Skip to content

Commit 189dbe5

Browse files
sudo87dhslove
authored andcommitted
replace momentjs with dayjs and use watch instead of update (apache#12351)
1 parent ed0c11f commit 189dbe5

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

ui/src/components/view/DateTimeFilter.vue

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<script>
6363
import { ref, reactive, toRaw } from 'vue'
6464
// import moment from 'moment'
65+
import dayjs from 'dayjs'
6566
6667
export default {
6768
name: 'DateTimeFilter',
@@ -97,27 +98,40 @@ export default {
9798
submitButtonLabel: this.$t('label.ok')
9899
}
99100
},
100-
updated () {
101-
this.form.startDate = this.startDate
102-
this.form.endDate = this.endDate
103-
},
104101
created () {
105102
this.initForm()
106103
},
104+
watch: {
105+
startDateProp (newVal) {
106+
this.form.startDate = newVal ? dayjs(newVal) : null
107+
},
108+
endDateProp (newVal) {
109+
this.form.endDate = newVal ? dayjs(newVal) : null
110+
}
111+
},
107112
methods: {
108113
initForm () {
109114
this.formRef = ref()
115+
// Use dayjs instead of moment - Ant Design Vue requires dayjs
116+
const startDate = this.startDateProp ? dayjs(this.startDateProp) : null
117+
const endDate = this.endDateProp ? dayjs(this.endDateProp) : null
118+
110119
this.form = reactive({
111-
startDate: this.startDate,
112-
endDate: this.endDate
120+
startDate: startDate,
121+
endDate: endDate
113122
})
114123
},
115124
handleSubmit (e) {
116125
e.preventDefault()
117126
this.formRef.value.validate().then(() => {
118127
this.submitButtonLabel = this.$t('label.refresh')
119128
const values = toRaw(this.form)
120-
this.$emit('onSubmit', values)
129+
// Convert dayjs objects back to JavaScript Date objects
130+
const result = {
131+
startDate: values.startDate ? values.startDate.toDate() : null,
132+
endDate: values.endDate ? values.endDate.toDate() : null
133+
}
134+
this.$emit('onSubmit', result)
121135
}).catch(error => {
122136
this.formRef.value.scrollToField(error.errorFields[0].name)
123137
})

0 commit comments

Comments
 (0)