add ability tofilter by range

This commit is contained in:
Peter Clement 2022-10-20 16:10:09 +01:00
parent 872ba3f958
commit d138d5ebaa
6 changed files with 32 additions and 17 deletions

View File

@ -62,11 +62,9 @@
const [dates] = event.detail const [dates] = event.detail
const noTimezone = enableTime && !timeOnly && ignoreTimezones const noTimezone = enableTime && !timeOnly && ignoreTimezones
let newValue = dates[0] let newValue = dates[0]
if (newValue) { if (newValue) {
newValue = newValue.toISOString() newValue = newValue.toISOString()
} }
// If time only set date component to 2000-01-01 // If time only set date component to 2000-01-01
else if (timeOnly) { else if (timeOnly) {
// Classic flackpickr causing issues. // Classic flackpickr causing issues.
@ -95,11 +93,14 @@
newValue = new Date(dates[0].getTime() - offset) newValue = new Date(dates[0].getTime() - offset)
.toISOString() .toISOString()
.slice(0, -1) .slice(0, -1)
} else if (range) {
console.log("hello")
} }
if (range) {
dispatch("change", event.detail)
} else {
dispatch("change", newValue) dispatch("change", newValue)
} }
}
const clearDateOnBackspace = event => { const clearDateOnBackspace = event => {
if (["Backspace", "Clear", "Delete"].includes(event.key)) { if (["Backspace", "Clear", "Delete"].includes(event.key)) {
@ -163,7 +164,7 @@
{#key redrawOptions} {#key redrawOptions}
<Flatpickr <Flatpickr
bind:flatpickr bind:flatpickr
value={parseDate(value)} value={range ? value : parseDate(value)}
on:open={onOpen} on:open={onOpen}
on:close={onClose} on:close={onClose}
options={flatpickrOptions} options={flatpickrOptions}

View File

@ -18,7 +18,13 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const onChange = e => { const onChange = e => {
if (range) {
// Flatpickr cant take two dates and work out what to display, needs to be provided a string.
// Like - "Date1 to Date2". Hence passing in that specifically from the array
value = e.detail[1]
} else {
value = e.detail value = e.detail
}
dispatch("change", e.detail) dispatch("change", e.detail)
} }
</script> </script>

View File

@ -27,9 +27,11 @@
let modal let modal
let trigger = null let trigger = null
let pageInfo = createPaginationStore() let pageInfo = createPaginationStore()
$: page = $pageInfo.page let startDate
let endDate
$: fetchBackups(trigger, page) $: page = $pageInfo.page
$: fetchBackups(trigger, page, startDate, endDate)
const triggers = { const triggers = {
PUBLISH: "publish", PUBLISH: "publish",
@ -98,11 +100,13 @@
: 0 : 0
} }
async function fetchBackups(trigger, page) { async function fetchBackups(trigger, page, startDate, endDate) {
const response = await backups.searchBackups({ const response = await backups.searchBackups({
appId: app.instance._id, appId: app.instance._id,
trigger, trigger,
page, page,
startDate,
endDate,
}) })
pageInfo.fetched(response.hasNextPage, response.nextPage) pageInfo.fetched(response.hasNextPage, response.nextPage)
@ -158,9 +162,14 @@
</div> </div>
<div> <div>
<DatePicker <DatePicker
range range={true}
label={"Filter Range"} label={"Filter Range"}
on:change={e => console.log(e)} on:change={e => {
if (e.detail[0].length > 1) {
startDate = e.detail[0][0].toISOString()
endDate = e.detail[0][1].toISOString()
}
}}
/> />
</div> </div>

View File

@ -2,7 +2,7 @@
import { Icon } from "@budibase/bbui" import { Icon } from "@budibase/bbui"
export let value export let value
$: console.log(value)
let trigger = value?.charAt(0).toUpperCase() + value?.slice(1) let trigger = value?.charAt(0).toUpperCase() + value?.slice(1)
</script> </script>

View File

@ -11,8 +11,8 @@ export function createBackupsStore() {
}) })
} }
async function searchBackups({ appId, trigger, page } = {}) { async function searchBackups({ appId, trigger, page, startDate, endDate }) {
return API.searchBackups({ appId, trigger, page }) return API.searchBackups({ appId, trigger, page, startDate, endDate })
} }
async function restoreBackup({ appId, backupId }) { async function restoreBackup({ appId, backupId }) {

View File

@ -11,11 +11,10 @@ export const buildBackupsEndpoints = API => ({
opts.trigger = trigger.toLowerCase() opts.trigger = trigger.toLowerCase()
} }
if (startDate) { if (startDate && endDate) {
opts.startDate = startDate opts.startDate = startDate
opts.endDate = endDate opts.endDate = endDate
} }
console.log(opts)
return await API.post({ return await API.post({
url: `/api/apps/${appId}/backups/search`, url: `/api/apps/${appId}/backups/search`,
body: opts, body: opts,