Add auto-refresh setting to data providers and all blocks

This commit is contained in:
Andrew Kingston 2024-03-04 09:34:58 +00:00
parent 33f03f91f3
commit 051f997047
8 changed files with 193 additions and 13 deletions

View File

@ -4571,6 +4571,34 @@
"key": "dataSource", "key": "dataSource",
"required": true "required": true
}, },
{
"type": "select",
"label": "Auto-refresh",
"key": "refresh",
"placeholder": "Never",
"options": [
{
"label": "10 seconds",
"value": 10
},
{
"label": "30 seconds",
"value": 30
},
{
"label": "1 minute",
"value": 60
},
{
"label": "5 minutes",
"value": 300
},
{
"label": "10 minutes",
"value": 600
}
]
},
{ {
"type": "filter", "type": "filter",
"label": "Filtering", "label": "Filtering",
@ -4937,6 +4965,34 @@
"key": "dataSource", "key": "dataSource",
"required": true "required": true
}, },
{
"type": "select",
"label": "Auto-refresh",
"key": "refresh",
"placeholder": "Never",
"options": [
{
"label": "10 seconds",
"value": 10
},
{
"label": "30 seconds",
"value": 30
},
{
"label": "1 minute",
"value": 60
},
{
"label": "5 minutes",
"value": 300
},
{
"label": "10 minutes",
"value": 600
}
]
},
{ {
"type": "text", "type": "text",
"label": "Title", "label": "Title",
@ -5404,6 +5460,34 @@
"key": "dataSource", "key": "dataSource",
"required": true "required": true
}, },
{
"type": "select",
"label": "Auto-refresh",
"key": "refresh",
"placeholder": "Never",
"options": [
{
"label": "10 seconds",
"value": 10
},
{
"label": "30 seconds",
"value": 30
},
{
"label": "1 minute",
"value": 60
},
{
"label": "5 minutes",
"value": 300
},
{
"label": "10 minutes",
"value": 600
}
]
},
{ {
"type": "columns", "type": "columns",
"label": "Columns", "label": "Columns",
@ -5690,6 +5774,34 @@
"key": "dataSource", "key": "dataSource",
"required": true "required": true
}, },
{
"type": "select",
"label": "Auto-refresh",
"key": "refresh",
"placeholder": "Never",
"options": [
{
"label": "10 seconds",
"value": 10
},
{
"label": "30 seconds",
"value": 30
},
{
"label": "1 minute",
"value": 60
},
{
"label": "5 minutes",
"value": 300
},
{
"label": "10 minutes",
"value": 600
}
]
},
{ {
"type": "searchfield", "type": "searchfield",
"label": "Search columns", "label": "Search columns",
@ -5867,6 +5979,34 @@
"key": "dataSource", "key": "dataSource",
"required": true "required": true
}, },
{
"type": "select",
"label": "Auto-refresh",
"key": "refresh",
"placeholder": "Never",
"options": [
{
"label": "10 seconds",
"value": 10
},
{
"label": "30 seconds",
"value": 30
},
{
"label": "1 minute",
"value": 60
},
{
"label": "5 minutes",
"value": 300
},
{
"label": "10 minutes",
"value": 600
}
]
},
{ {
"type": "filter", "type": "filter",
"label": "Filtering", "label": "Filtering",
@ -6571,6 +6711,34 @@
"key": "table", "key": "table",
"required": true "required": true
}, },
{
"type": "select",
"label": "Auto-refresh",
"key": "refresh",
"placeholder": "Never",
"options": [
{
"label": "10 seconds",
"value": 10
},
{
"label": "30 seconds",
"value": 30
},
{
"label": "1 minute",
"value": 60
},
{
"label": "5 minutes",
"value": 300
},
{
"label": "10 minutes",
"value": 600
}
]
},
{ {
"type": "filter", "type": "filter",
"label": "Filtering", "label": "Filtering",

View File

@ -1,5 +1,5 @@
<script> <script>
import { getContext } from "svelte" import { getContext, onMount } from "svelte"
import { Pagination, ProgressCircle } from "@budibase/bbui" import { Pagination, ProgressCircle } from "@budibase/bbui"
import { fetchData, LuceneUtils } from "@budibase/frontend-core" import { fetchData, LuceneUtils } from "@budibase/frontend-core"
@ -9,17 +9,18 @@
export let sortOrder export let sortOrder
export let limit export let limit
export let paginate export let paginate
export let refresh
const { styleable, Provider, ActionTypes, API } = getContext("sdk") const { styleable, Provider, ActionTypes, API } = getContext("sdk")
const component = getContext("component") const component = getContext("component")
let interval
let queryExtensions = {}
// We need to manage our lucene query manually as we want to allow components // We need to manage our lucene query manually as we want to allow components
// to extend it // to extend it
let queryExtensions = {}
$: defaultQuery = LuceneUtils.buildLuceneQuery(filter) $: defaultQuery = LuceneUtils.buildLuceneQuery(filter)
$: query = extendQuery(defaultQuery, queryExtensions) $: query = extendQuery(defaultQuery, queryExtensions)
// Fetch data and refresh when needed
$: fetch = createFetch(dataSource) $: fetch = createFetch(dataSource)
$: fetch.update({ $: fetch.update({
query, query,
@ -28,11 +29,8 @@
limit, limit,
paginate, paginate,
}) })
// Sanitize schema to remove hidden fields
$: schema = sanitizeSchema($fetch.schema) $: schema = sanitizeSchema($fetch.schema)
$: setUpAutoRefresh(refresh)
// Build our action context
$: actions = [ $: actions = [
{ {
type: ActionTypes.RefreshDatasource, type: ActionTypes.RefreshDatasource,
@ -63,8 +61,6 @@
}, },
}, },
] ]
// Build our data context
$: dataContext = { $: dataContext = {
rows: $fetch.rows, rows: $fetch.rows,
info: $fetch.info, info: $fetch.info,
@ -140,6 +136,13 @@
}) })
return extendedQuery return extendedQuery
} }
const setUpAutoRefresh = refresh => {
clearInterval(interval)
if (refresh) {
interval = setInterval(fetch.refresh, Math.max(10000, refresh * 1000))
}
}
</script> </script>
<div use:styleable={$component.styles} class="container"> <div use:styleable={$component.styles} class="container">

View File

@ -18,6 +18,7 @@
export let columns = null export let columns = null
export let onRowClick = null export let onRowClick = null
export let buttons = null export let buttons = null
export let repeat = null
const context = getContext("context") const context = getContext("context")
const component = getContext("component") const component = getContext("component")
@ -108,6 +109,7 @@
{fixedRowHeight} {fixedRowHeight}
{columnWhitelist} {columnWhitelist}
{schemaOverrides} {schemaOverrides}
{repeat}
canAddRows={allowAddRows} canAddRows={allowAddRows}
canEditRows={allowEditRows} canEditRows={allowEditRows}
canDeleteRows={allowDeleteRows} canDeleteRows={allowDeleteRows}

View File

@ -30,6 +30,7 @@
export let cardButtonOnClick export let cardButtonOnClick
export let linkColumn export let linkColumn
export let noRowsMessage export let noRowsMessage
export let repeat
const { fetchDatasourceSchema } = getContext("sdk") const { fetchDatasourceSchema } = getContext("sdk")
@ -171,6 +172,7 @@
sortOrder, sortOrder,
paginate, paginate,
limit, limit,
repeat,
}} }}
order={1} order={1}
> >

View File

@ -8,6 +8,7 @@
export let sortColumn export let sortColumn
export let sortOrder export let sortOrder
export let limit export let limit
export let repeat
// Block // Block
export let chartTitle export let chartTitle
@ -65,6 +66,7 @@
sortColumn, sortColumn,
sortOrder, sortOrder,
limit, limit,
repeat,
}} }}
> >
{#if dataProviderId && chartType} {#if dataProviderId && chartType}

View File

@ -16,6 +16,7 @@
export let hAlign export let hAlign
export let vAlign export let vAlign
export let gap export let gap
export let repeat
const component = getContext("component") const component = getContext("component")
@ -34,6 +35,7 @@
sortOrder, sortOrder,
limit, limit,
paginate, paginate,
repeat,
}} }}
> >
{#if $component.empty} {#if $component.empty}

View File

@ -6,17 +6,15 @@
export let dataSource export let dataSource
export let height export let height
export let cardTitle export let cardTitle
export let cardSubtitle export let cardSubtitle
export let cardDescription export let cardDescription
export let cardImageURL export let cardImageURL
export let cardSearchField export let cardSearchField
export let detailFields export let detailFields
export let detailTitle export let detailTitle
export let noRowsMessage export let noRowsMessage
export let repeat
const stateKey = generate() const stateKey = generate()
@ -56,6 +54,7 @@
noValue: false, noValue: false,
}, },
], ],
repeat,
}} }}
styles={{ styles={{
custom: ` custom: `

View File

@ -32,6 +32,7 @@
export let sidePanelSaveLabel export let sidePanelSaveLabel
export let sidePanelDeleteLabel export let sidePanelDeleteLabel
export let notificationOverride export let notificationOverride
export let repeat
const { fetchDatasourceSchema, API } = getContext("sdk") const { fetchDatasourceSchema, API } = getContext("sdk")
const component = getContext("component") const component = getContext("component")
@ -230,6 +231,7 @@
sortOrder, sortOrder,
paginate, paginate,
limit: rowCount, limit: rowCount,
repeat,
}} }}
context="provider" context="provider"
order={1} order={1}