feat: add date math for filters #1342

Merged
konrad merged 88 commits from feature/date-math into main 2022-03-28 17:30:43 +00:00
2 changed files with 44 additions and 19 deletions
Showing only changes of commit 3d1c1e41c7 - Show all commits

View File

@ -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

Provide buttonText as slot prop aswell

Provide `buttonText` as slot prop aswell

Done.

Done.
</button>
konrad marked this conversation as resolved Outdated

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.

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

Use BaseButton

Use BaseButton

Done.

Done.
</button>
</div>
<div class="flatpickr-container">
konrad marked this conversation as resolved Outdated

Use BaseButton

Use BaseButton

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
Review

Use BaseButton

Use BaseButton
Review

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

The whole explanation card should be its own component.

The whole explanation card should be its own component.

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

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.

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?

I didn't even check to be honest.
Was just something I though of while reading this.

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%;

This is triggered three times!

Once for each of these lines:

from.value = fromDate
to.value = toDate

in the called function inputChanged of the watcher.
And then here again.

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.

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);
}
}

View File

@ -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",