1
0
Fork 0
mirror of synced 2024-10-04 03:54:37 +13:00

Allow grids to provide a refresh datasource action

This commit is contained in:
Andrew Kingston 2023-11-09 11:10:52 +00:00
parent 223a82f717
commit 1f3e56fdc1
2 changed files with 17 additions and 5 deletions

View file

@ -27,8 +27,12 @@
builderStore,
notificationStore,
enrichButtonActions,
ActionTypes,
createContextStore,
} = getContext("sdk")
let grid
$: columnWhitelist = columns?.map(col => col.name)
$: schemaOverrides = getSchemaOverrides(columns)
$: enrichedButtons = enrichButtons(buttons)
@ -53,11 +57,16 @@
text: settings.text,
type: settings.type,
onClick: async row => {
// We add a fake context binding in here, which allows us to pretend
// that the grid provides a "schema" binding - that lets us use the
// clicked row in things like save row actions
const enrichedContext = { ...get(context), [get(component).id]: row }
const fn = enrichButtonActions(settings.onClick, enrichedContext)
// Create a fake, ephemeral context to run the buttons actions with
const id = get(component).id
const gridContext = createContextStore(context)
gridContext.actions.provideData(id, row)
gridContext.actions.provideAction(
id,
ActionTypes.RefreshDatasource,
() => grid?.getContext()?.rows.actions.refreshData()
)
const fn = enrichButtonActions(settings.onClick, get(gridContext))
return await fn?.({ row })
},
}))
@ -69,6 +78,7 @@
class:in-builder={$builderStore.inBuilder}
>
<Grid
bind:this={grid}
datasource={table}
{API}
{stripeRows}

View file

@ -15,6 +15,7 @@ import {
confirmationStore,
roleStore,
stateStore,
createContextStore,
} from "stores"
import { styleable } from "utils/styleable"
import { linkable } from "utils/linkable"
@ -56,6 +57,7 @@ export default {
getAPIKey,
enrichButtonActions,
processStringSync,
createContextStore,
// Components
Provider,