Merge pull request #14706 from Budibase/row-action/allow-running-from-tables

Run rowAction from table only if allowed
This commit is contained in:
Adria Navarro 2024-10-04 16:54:43 +02:00 committed by GitHub
commit 821176784a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 13 deletions

View File

@ -95,7 +95,7 @@
{#if isView} {#if isView}
<span> <span>
<Toggle <Toggle
value={action.allowedViews?.includes(viewId)} value={action.allowedSources?.includes(viewId)}
on:change={e => toggleAction(action, e.detail)} on:change={e => toggleAction(action, e.detail)}
/> />
</span> </span>

View File

@ -63,13 +63,15 @@
$: rowActions.refreshRowActions(id) $: rowActions.refreshRowActions(id)
const makeRowActionButtons = actions => { const makeRowActionButtons = actions => {
return (actions || []).map(action => ({ return (actions || [])
text: action.name, .filter(action => action.allowedSources?.includes(id))
onClick: async row => { .map(action => ({
await rowActions.trigger(id, action.id, row._id) text: action.name,
notifications.success("Row action triggered successfully") onClick: async row => {
}, await rowActions.trigger(id, action.id, row._id)
})) notifications.success("Row action triggered successfully")
},
}))
} }
const relationshipSupport = datasource => { const relationshipSupport = datasource => {

View File

@ -129,13 +129,15 @@ const derivedStore = derived(store, $store => {
// Generate an entry for every view as well // Generate an entry for every view as well
Object.keys($store || {}).forEach(tableId => { Object.keys($store || {}).forEach(tableId => {
// We need to have all the actions for the table in order to be displayed in the crud section
map[tableId] = $store[tableId] map[tableId] = $store[tableId]
for (let action of $store[tableId]) { for (let action of $store[tableId]) {
for (let viewId of action.allowedViews || []) { const otherSources = (action.allowedSources || []).filter(
if (!map[viewId]) { sourceId => sourceId !== tableId
map[viewId] = [] )
} for (let source of otherSources) {
map[viewId].push(action) map[source] ??= []
map[source].push(action)
} }
} }
}) })