Allow grids to provide a refresh datasource action
This commit is contained in:
parent
223a82f717
commit
1f3e56fdc1
|
@ -27,8 +27,12 @@
|
||||||
builderStore,
|
builderStore,
|
||||||
notificationStore,
|
notificationStore,
|
||||||
enrichButtonActions,
|
enrichButtonActions,
|
||||||
|
ActionTypes,
|
||||||
|
createContextStore,
|
||||||
} = getContext("sdk")
|
} = getContext("sdk")
|
||||||
|
|
||||||
|
let grid
|
||||||
|
|
||||||
$: columnWhitelist = columns?.map(col => col.name)
|
$: columnWhitelist = columns?.map(col => col.name)
|
||||||
$: schemaOverrides = getSchemaOverrides(columns)
|
$: schemaOverrides = getSchemaOverrides(columns)
|
||||||
$: enrichedButtons = enrichButtons(buttons)
|
$: enrichedButtons = enrichButtons(buttons)
|
||||||
|
@ -53,11 +57,16 @@
|
||||||
text: settings.text,
|
text: settings.text,
|
||||||
type: settings.type,
|
type: settings.type,
|
||||||
onClick: async row => {
|
onClick: async row => {
|
||||||
// We add a fake context binding in here, which allows us to pretend
|
// Create a fake, ephemeral context to run the buttons actions with
|
||||||
// that the grid provides a "schema" binding - that lets us use the
|
const id = get(component).id
|
||||||
// clicked row in things like save row actions
|
const gridContext = createContextStore(context)
|
||||||
const enrichedContext = { ...get(context), [get(component).id]: row }
|
gridContext.actions.provideData(id, row)
|
||||||
const fn = enrichButtonActions(settings.onClick, enrichedContext)
|
gridContext.actions.provideAction(
|
||||||
|
id,
|
||||||
|
ActionTypes.RefreshDatasource,
|
||||||
|
() => grid?.getContext()?.rows.actions.refreshData()
|
||||||
|
)
|
||||||
|
const fn = enrichButtonActions(settings.onClick, get(gridContext))
|
||||||
return await fn?.({ row })
|
return await fn?.({ row })
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
@ -69,6 +78,7 @@
|
||||||
class:in-builder={$builderStore.inBuilder}
|
class:in-builder={$builderStore.inBuilder}
|
||||||
>
|
>
|
||||||
<Grid
|
<Grid
|
||||||
|
bind:this={grid}
|
||||||
datasource={table}
|
datasource={table}
|
||||||
{API}
|
{API}
|
||||||
{stripeRows}
|
{stripeRows}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
confirmationStore,
|
confirmationStore,
|
||||||
roleStore,
|
roleStore,
|
||||||
stateStore,
|
stateStore,
|
||||||
|
createContextStore,
|
||||||
} from "stores"
|
} from "stores"
|
||||||
import { styleable } from "utils/styleable"
|
import { styleable } from "utils/styleable"
|
||||||
import { linkable } from "utils/linkable"
|
import { linkable } from "utils/linkable"
|
||||||
|
@ -56,6 +57,7 @@ export default {
|
||||||
getAPIKey,
|
getAPIKey,
|
||||||
enrichButtonActions,
|
enrichButtonActions,
|
||||||
processStringSync,
|
processStringSync,
|
||||||
|
createContextStore,
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
Provider,
|
Provider,
|
||||||
|
|
Loading…
Reference in New Issue