add paging and add more custom table renderers

This commit is contained in:
Peter Clement 2022-10-19 16:08:34 +01:00
parent 969218ce74
commit 3e7d631031
10 changed files with 111 additions and 33 deletions

View File

@ -21,5 +21,6 @@
flex-direction: row; flex-direction: row;
gap: var(--spacing-m); gap: var(--spacing-m);
align-items: center; align-items: center;
margin-left: auto;
} }
</style> </style>

View File

@ -2,12 +2,11 @@
import { Icon } from "@budibase/bbui" import { Icon } from "@budibase/bbui"
export let value export let value
$: console.log(value)
</script> </script>
<div class="cell"> <div class="cell">
<Icon name="JourneyVoyager" /> <Icon name="JourneyVoyager" />
<div>{value.length}</div> <div>{value?.length}</div>
</div> </div>
<style> <style>

View File

@ -3,6 +3,7 @@
ActionButton, ActionButton,
DatePicker, DatePicker,
Layout, Layout,
notifications,
Pagination, Pagination,
Select, Select,
Table, Table,
@ -10,16 +11,26 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import { onMount } from "svelte" import { onMount } from "svelte"
import { backups } from "stores/portal" import { backups } from "stores/portal"
import { createPaginationStore } from "helpers/pagination"
import DatasourceRenderer from "./DatasourceRenderer.svelte" import DatasourceRenderer from "./DatasourceRenderer.svelte"
import ScreensRenderer from "./ScreensRenderer.svelte" import ScreensRenderer from "./ScreensRenderer.svelte"
import AutomationsRenderer from "./AutomationsRenderer.svelte" import AutomationsRenderer from "./AutomationsRenderer.svelte"
import CreateBackupModal from "./CreateBackupModal.svelte" import CreateBackupModal from "./CreateBackupModal.svelte"
import TriggerRenderer from "./TriggerRenderer.svelte" import TriggerRenderer from "./TriggerRenderer.svelte"
import ActionsRenderer from "./ActionsRenderer.svelte" import ActionsRenderer from "./ActionsRenderer.svelte"
import DateRenderer from "./DateRenderer.svelte"
import DaysRenderer from "./DaysRenderer.svelte"
export let app export let app
let backupData = null let backupData = null
let modal let modal
let trigger = null
let pageInfo = createPaginationStore()
$: page = $pageInfo.page
$: console.log(page)
$: fetchBackups(app.instance._id, trigger, page)
const triggers = { const triggers = {
PUBLISH: "Publish", PUBLISH: "Publish",
@ -31,10 +42,14 @@
trigger: { trigger: {
displayName: "Trigger", displayName: "Trigger",
}, },
days: {
displayName: null,
},
name: { name: {
displayName: "Name", displayName: "Name",
}, },
date: { createdAt: {
displayName: "Date", displayName: "Date",
}, },
datasources: { datasources: {
@ -60,33 +75,52 @@
{ column: "automations", component: AutomationsRenderer }, { column: "automations", component: AutomationsRenderer },
{ column: "trigger", component: TriggerRenderer }, { column: "trigger", component: TriggerRenderer },
{ column: "actions", component: ActionsRenderer }, { column: "actions", component: ActionsRenderer },
{ column: "createdAt", component: DateRenderer },
{ column: "days", component: DaysRenderer },
] ]
async function fetchBackups() { function flattenBackups(backups) {
backups.load() let flattened = backups.map(backup => {
backupData = enrichBackupData($backups)
}
function enrichBackupData(backups) {
let enrichedBackups = backups.map(backup => {
return { return {
...backup, ...backup,
...Object.assign(...backup.contents), days: getDaysBetween(backup.createdAt),
//...Object.assign(...backup?.contents),
} }
}) })
return enrichedBackups return flattened
} }
function createManualBackup(name) { function getDaysBetween(date) {
backups.createManualBackup({ appId: app.appId, name }) const now = new Date()
const backupDate = new Date(date)
backupDate.setDate(backupDate.getDate() - 1)
console.log(backupDate)
const oneDay = 24 * 60 * 60 * 1000
return now > backupDate
? Math.round(Math.abs((now - backupDate) / oneDay))
: 0
} }
onMount(async () => { async function fetchBackups(appId, trigger, page) {
console.log(await backups.searchBackups(app.appId)) const response = await backups.searchBackups(appId, trigger, page)
pageInfo.fetched(response.hasNextPage, response.nextPage)
await fetchBackups() // flatten so we have an easier structure to use for the table schema
backupData = flattenBackups(response.data)
}
async function createManualBackup(name) {
try {
let response = await backups.createManualBackup({
appId: app.instance._id,
name,
}) })
notifications.success(response.message)
} catch {
notifications.error("Unable to create backup")
}
}
</script> </script>
<div class="root"> <div class="root">
@ -122,7 +156,13 @@
border={false} border={false}
/> />
<div class="pagination"> <div class="pagination">
<Pagination page={1} /> <Pagination
page={$pageInfo.pageNumber}
hasPrevPage={$pageInfo.loading ? false : $pageInfo.hasPrevPage}
hasNextPage={$pageInfo.loading ? false : $pageInfo.hasNextPage}
goToPrevPage={pageInfo.prevPage}
goToNextPage={pageInfo.nextPage}
/>
</div> </div>
</div> </div>
{/if} {/if}

View File

@ -6,7 +6,7 @@
<div class="cell"> <div class="cell">
<Icon name="Data" /> <Icon name="Data" />
<div>{value.length}</div> <div>{value?.length}</div>
</div> </div>
<style> <style>

View File

@ -0,0 +1,17 @@
<script>
import DateTimeRenderer from "components/common/renderers/DateTimeRenderer.svelte"
export let value
</script>
<div class="cell">
<DateTimeRenderer {value} />
</div>
<style>
.cell {
display: flex;
flex-direction: row;
gap: var(--spacing-m);
align-items: center;
}
</style>

View File

@ -0,0 +1,18 @@
<script>
export let value
$: console.log(value)
</script>
<div class="cell">
{value}
{`day${value == 1 ? "" : "s"} ago`}
</div>
<style>
.cell {
display: flex;
flex-direction: row;
gap: var(--spacing-m);
align-items: center;
}
</style>

View File

@ -6,7 +6,7 @@
<div class="cell"> <div class="cell">
<Icon name="WebPage" /> <Icon name="WebPage" />
<div>{value.length}</div> <div>{value?.length}</div>
</div> </div>
<style> <style>

View File

@ -2,18 +2,20 @@
import { Icon } from "@budibase/bbui" import { Icon } from "@budibase/bbui"
export let value export let value
let trigger = value.charAt(0).toUpperCase() + value.slice(1)
</script> </script>
<div class="cell"> <div class="cell">
{#if value === "PUBLISH"} {#if value === "publish"}
<Icon name="GlobeCheck" /> <Icon name="GlobeCheck" />
<div>{value}</div> <div>{trigger}</div>
{:else if value === "MANUAL"} {:else if value === "manual"}
<Icon name="Floppy" /> <Icon name="SaveFloppy" />
<div>{value}</div> <div>{trigger}</div>
{:else if value === "SCHEDULED"} {:else if value === "scheduled"}
<Icon name="Clock" /> <Icon name="Clock" />
<div>{value}</div> <div>{trigger}</div>
{/if} {/if}
</div> </div>

View File

@ -20,8 +20,8 @@ export function createBackupsStore() {
]) ])
} }
async function searchBackups(appId) { async function searchBackups(appId, trigger, page) {
return API.searchBackups(appId) return API.searchBackups({appId, trigger, page})
} }
async function createManualBackup(appId, name) { async function createManualBackup(appId, name) {

View File

@ -2,12 +2,13 @@ export const buildBackupsEndpoints = API => ({
/** /**
* Gets a list of users in the current tenant. * Gets a list of users in the current tenant.
*/ */
searchBackups: async appId => { searchBackups: async ({appId, trigger, page}) => {
console.log(page)
return await API.post({ return await API.post({
url: `/api/apps/${appId}/backups/search`, url: `/api/apps/${appId}/backups/search`,
body: { body: {
trigger: "MANUAL", page,
}, }
}) })
}, },