Allow grids to provide a refresh datasource action
This commit is contained in:
parent
223a82f717
commit
1f3e56fdc1
|
@ -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}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue