feat: add date math for filters #1342
|
@ -1,17 +1,24 @@
|
|||
<template>
|
||||
<div class="datepicker-with-range">
|
||||
<div class="selections">
|
||||
<a @click="setDatesToToday">Today</a>
|
||||
<a @click="setDatesToNextWeek">Next Week</a>
|
||||
<a @click="setDatesToNextMonth">Next Month</a>
|
||||
<a>Custom</a>
|
||||
<button @click="setDateRange(datesToday)" :class="{'is-active': dateRange === datesToday}">
|
||||
{{ $t('task.show.today') }}
|
||||
konrad marked this conversation as resolved
Outdated
|
||||
</button>
|
||||
konrad marked this conversation as resolved
Outdated
dpschen
commented
The styles (=props) selected for the button are hightly specific and create an indirect dependency to its indented use case. The latter might change in the future and then we have to remember this dependency. This is why I think it makes sense to remove at least the specific use case of this button. Since we wouldn't use it then at all anymore (since you need to overwrite the default slot) it might make it simpler to only define the slot. The styles (=props) selected for the button are hightly specific and create an indirect dependency to its indented use case. The latter might change in the future and then we have to remember this dependency. This is why I think it makes sense to remove at least the specific use case of this button. Since we wouldn't use it then at all anymore (since you need to overwrite the default slot) it might make it simpler to only define the slot.
konrad
commented
Moved everything to a slot. Moved everything to a slot.
|
||||
<button @click="setDateRange(datesNextWeek)" :class="{'is-active': dateRange === datesNextWeek}">
|
||||
{{ $t('task.show.nextWeek') }}
|
||||
</button>
|
||||
<button @click="setDateRange(datesNextMonth)" :class="{'is-active': dateRange === datesNextMonth}">
|
||||
{{ $t('task.show.nextMonth') }}
|
||||
</button>
|
||||
<button :class="{'is-active': customRangeActive}">
|
||||
{{ $t('misc.custom') }}
|
||||
konrad marked this conversation as resolved
Outdated
dpschen
commented
Use BaseButton Use BaseButton
konrad
commented
Done. Done.
|
||||
</button>
|
||||
</div>
|
||||
<div class="flatpickr-container">
|
||||
konrad marked this conversation as resolved
Outdated
dpschen
commented
Use BaseButton Use BaseButton
konrad
commented
Done. Done.
|
||||
<flat-pickr
|
||||
:config="flatPickerConfig"
|
||||
v-model="dateRange"
|
||||
/>
|
||||
{{ dateRange }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -48,12 +55,16 @@ const dateRange = ref('')
|
|||
watch(
|
||||
konrad marked this conversation as resolved
dpschen
commented
Use BaseButton Use BaseButton
konrad
commented
Done. Done.
|
||||
() => dateRange.value,
|
||||
newVal => {
|
||||
if (newVal === null) {
|
||||
return
|
||||
}
|
||||
|
||||
const [fromDate, toDate] = newVal.split(' to ')
|
||||
|
||||
|
||||
if (typeof fromDate === 'undefined' || typeof toDate === 'undefined') {
|
||||
return
|
||||
konrad marked this conversation as resolved
Outdated
dpschen
commented
The whole explanation card should be its own component. The whole explanation card should be its own component.
konrad
commented
Done! Done!
|
||||
}
|
||||
|
||||
|
||||
emit('dateChanged', {
|
||||
dateFrom: new Date(fromDate),
|
||||
dateTo: new Date(toDate),
|
||||
|
@ -65,23 +76,33 @@ function formatDate(date) {
|
|||
return format(date, 'yyyy-MM-dd HH:mm')
|
||||
dpschen marked this conversation as resolved
Outdated
dpschen
commented
I think it's really cool, that we support this, but it would be cool, if we could break this down and explain it in our / simpler terms. I think it's really cool, that we support this, but it would be cool, if we could break this down and explain it in our / simpler terms.
konrad
commented
I think I'm already doing that but wanted to highlight for people who know the syntax from Elasticsearch or Grafana they can use it here as well. Was there anything in the explanation you noticed as not quite understandable? I think I'm already doing that but wanted to highlight for people who know the syntax from Elasticsearch or Grafana they can use it here as well.
Was there anything in the explanation you noticed as not quite understandable?
dpschen
commented
I didn't even check to be honest. I didn't even check to be honest.
Was just something I though of while reading this.
|
||||
}
|
||||
|
||||
function setDatesToToday() {
|
||||
const datesToday = computed(() => {
|
||||
const startDate = new Date()
|
||||
const endDate = new Date((new Date()).setDate((new Date()).getDate() + 1))
|
||||
dateRange.value = `${formatDate(startDate)} to ${formatDate(endDate)}`
|
||||
}
|
||||
return `${formatDate(startDate)} to ${formatDate(endDate)}`
|
||||
})
|
||||
|
||||
function setDatesToNextWeek() {
|
||||
const datesNextWeek = computed(() => {
|
||||
const startDate = new Date()
|
||||
const endDate = new Date((new Date()).getTime() + 7 * 24 * 60 * 60 * 1000)
|
||||
dateRange.value = `${formatDate(startDate)} to ${formatDate(endDate)}`
|
||||
}
|
||||
return `${formatDate(startDate)} to ${formatDate(endDate)}`
|
||||
})
|
||||
|
||||
function setDatesToNextMonth() {
|
||||
const datesNextMonth = computed(() => {
|
||||
const startDate = new Date()
|
||||
const endDate = new Date((new Date()).setMonth((new Date()).getMonth() + 1))
|
||||
dateRange.value = `${formatDate(startDate)} to ${formatDate(endDate)}`
|
||||
return `${formatDate(startDate)} to ${formatDate(endDate)}`
|
||||
})
|
||||
|
||||
function setDateRange(range) {
|
||||
dateRange.value = range
|
||||
}
|
||||
|
||||
const customRangeActive = computed(() => {
|
||||
return dateRange.value !== datesToday.value &&
|
||||
dateRange.value !== datesNextWeek.value &&
|
||||
dateRange.value !== datesNextMonth.value
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
@ -113,7 +134,7 @@ function setDatesToNextMonth() {
|
|||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
a {
|
||||
button {
|
||||
display: block;
|
||||
width: 100%;
|
||||
dpschen
commented
This is triggered three times! Once for each of these lines:
in the called function inputChanged of the watcher. This is triggered three times!
Once for each of these lines:
```js
from.value = fromDate
to.value = toDate
```
in the called function inputChanged of the watcher.
And then here again.
konrad
commented
mhh how can we fix this? Using a debounce to prevent it getting called three times if it changed all values at once? Or removing the watchers again? It looks like the tasks are only loaded once, not three times. Maybe that's already enough? mhh how can we fix this? Using a debounce to prevent it getting called three times if it changed all values at once? Or removing the watchers again?
It looks like the tasks are only loaded once, not three times. Maybe that's already enough?
|
||||
text-align: left;
|
||||
|
@ -121,12 +142,15 @@ function setDatesToNextMonth() {
|
|||
transition: $transition;
|
||||
font-size: .9rem;
|
||||
color: var(--text);
|
||||
background: transparent;
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
|
||||
&.active {
|
||||
&.is-active {
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
&:hover, &.active {
|
||||
&:hover, &.is-active {
|
||||
background-color: var(--grey-100);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -476,7 +476,8 @@
|
|||
"showMenu": "Show the menu",
|
||||
"hideMenu": "Hide the menu",
|
||||
"forExample": "For example:",
|
||||
"welcomeBack": "Welcome Back!"
|
||||
"welcomeBack": "Welcome Back!",
|
||||
"custom": "Custom"
|
||||
},
|
||||
"input": {
|
||||
"resetColor": "Reset Color",
|
||||
|
|
Provide
buttonText
as slot prop aswellDone.