From 1f3e56fdc152f6768fc26737b4b04f42471bfbcc Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 9 Nov 2023 11:10:52 +0000 Subject: [PATCH] Allow grids to provide a refresh datasource action --- .../src/components/app/GridBlock.svelte | 20 ++++++++++++++----- packages/client/src/sdk.js | 2 ++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/client/src/components/app/GridBlock.svelte b/packages/client/src/components/app/GridBlock.svelte index 801e1a4d0a..0b1c12524a 100644 --- a/packages/client/src/components/app/GridBlock.svelte +++ b/packages/client/src/components/app/GridBlock.svelte @@ -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} >