Replace other usages of manual row actions API calls with store usage
This commit is contained in:
parent
53ff7e1167
commit
872446e524
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { automationStore } from "stores/builder"
|
import { automationStore, rowActions } from "stores/builder"
|
||||||
import {
|
import {
|
||||||
notifications,
|
notifications,
|
||||||
Icon,
|
Icon,
|
||||||
|
@ -26,12 +26,11 @@
|
||||||
|
|
||||||
async function saveAutomation() {
|
async function saveAutomation() {
|
||||||
try {
|
try {
|
||||||
await API.rowActions.update({
|
await rowActions.rename(
|
||||||
rowActionId: automation.definition.trigger.inputs.rowActionId,
|
automation.definition.trigger.inputs.tableId,
|
||||||
tableId: automation.definition.trigger.inputs.tableId,
|
automation.definition.trigger.inputs.rowActionId,
|
||||||
name,
|
name
|
||||||
})
|
)
|
||||||
await automationStore.actions.fetch()
|
|
||||||
notifications.success(`Row action updated successfully`)
|
notifications.success(`Row action updated successfully`)
|
||||||
hide()
|
hide()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
<script>
|
<script>
|
||||||
import { Select, Label, Checkbox, Body } from "@budibase/bbui"
|
import { Select, Label, Checkbox } from "@budibase/bbui"
|
||||||
import { tables, viewsV2 } from "stores/builder"
|
import { tables, viewsV2, rowActions } from "stores/builder"
|
||||||
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||||
import { API } from "api"
|
|
||||||
|
|
||||||
export let parameters
|
export let parameters
|
||||||
export let bindings = []
|
export let bindings = []
|
||||||
|
|
||||||
let rowActions = []
|
|
||||||
|
|
||||||
$: tableOptions = $tables.list.map(table => ({
|
$: tableOptions = $tables.list.map(table => ({
|
||||||
label: table.name,
|
label: table.name,
|
||||||
resourceId: table._id,
|
resourceId: table._id,
|
||||||
|
@ -20,35 +17,12 @@
|
||||||
}))
|
}))
|
||||||
$: datasourceOptions = [...(tableOptions || []), ...(viewOptions || [])]
|
$: datasourceOptions = [...(tableOptions || []), ...(viewOptions || [])]
|
||||||
$: resourceId = parameters.resourceId
|
$: resourceId = parameters.resourceId
|
||||||
$: fetchRowActions(resourceId)
|
$: rowActions.refreshRowActions(resourceId)
|
||||||
$: rowActionOptions = rowActions.map(action => ({
|
$: enabledRowActions = $rowActions[resourceId] || []
|
||||||
|
$: rowActionOptions = enabledRowActions.map(action => ({
|
||||||
label: action.name,
|
label: action.name,
|
||||||
value: action.id,
|
value: action.id,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const fetchRowActions = async resourceId => {
|
|
||||||
if (!resourceId) {
|
|
||||||
rowActions = []
|
|
||||||
return
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const isView = resourceId.startsWith("view_")
|
|
||||||
let tableId = resourceId
|
|
||||||
if (isView) {
|
|
||||||
tableId = viewOptions.find(x => x.resourceId === resourceId).tableId
|
|
||||||
}
|
|
||||||
const res = await API.rowActions.fetch(tableId)
|
|
||||||
rowActions = Object.values(res || {}).filter(action => {
|
|
||||||
return !isView || action.allowedViews?.includes(resourceId)
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
rowActions = []
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auto select first action
|
|
||||||
parameters.rowActionId = rowActions[0]?.id
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="root">
|
<div class="root">
|
||||||
|
|
|
@ -28,11 +28,7 @@
|
||||||
return (rowActions || []).map(action => ({
|
return (rowActions || []).map(action => ({
|
||||||
text: action.name,
|
text: action.name,
|
||||||
onClick: async row => {
|
onClick: async row => {
|
||||||
await API.rowActions.trigger({
|
await rowActions.trigger(id, action.id, row._id)
|
||||||
rowActionId: action.id,
|
|
||||||
sourceId: id,
|
|
||||||
rowId: row._id,
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,11 +66,7 @@
|
||||||
return (rowActions || []).map(action => ({
|
return (rowActions || []).map(action => ({
|
||||||
text: action.name,
|
text: action.name,
|
||||||
onClick: async row => {
|
onClick: async row => {
|
||||||
await API.rowActions.trigger({
|
await rowActions.trigger(id, action.id, row._id)
|
||||||
rowActionId: action.id,
|
|
||||||
sourceId: id,
|
|
||||||
rowId: row._id,
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { notifications } from "@budibase/bbui"
|
||||||
import { updateReferencesInObject } from "dataBinding"
|
import { updateReferencesInObject } from "dataBinding"
|
||||||
import { AutomationTriggerStepId } from "@budibase/types"
|
import { AutomationTriggerStepId } from "@budibase/types"
|
||||||
import { sdk } from "@budibase/shared-core"
|
import { sdk } from "@budibase/shared-core"
|
||||||
|
import { rowActions } from "./rowActions"
|
||||||
|
|
||||||
const initialAutomationState = {
|
const initialAutomationState = {
|
||||||
automations: [],
|
automations: [],
|
||||||
|
@ -126,10 +127,10 @@ const automationActions = store => ({
|
||||||
delete: async automation => {
|
delete: async automation => {
|
||||||
const isRowAction = sdk.automations.isRowAction(automation)
|
const isRowAction = sdk.automations.isRowAction(automation)
|
||||||
if (isRowAction) {
|
if (isRowAction) {
|
||||||
await API.rowActions.delete({
|
await rowActions.delete(
|
||||||
tableId: automation.definition.trigger.inputs.tableId,
|
automation.definition.trigger.inputs.tableId,
|
||||||
rowActionId: automation.definition.trigger.inputs.rowActionId,
|
automation.definition.trigger.inputs.rowActionId
|
||||||
})
|
)
|
||||||
} else {
|
} else {
|
||||||
await API.deleteAutomation({
|
await API.deleteAutomation({
|
||||||
automationId: automation?._id,
|
automationId: automation?._id,
|
||||||
|
|
|
@ -86,6 +86,36 @@ export class RowActionStore extends BudiStore {
|
||||||
})
|
})
|
||||||
await this.refreshRowActions(tableId)
|
await this.refreshRowActions(tableId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rename = async (tableId, rowActionId, name) => {
|
||||||
|
await API.rowActions.update({
|
||||||
|
tableId,
|
||||||
|
rowActionId,
|
||||||
|
name,
|
||||||
|
})
|
||||||
|
await Promise.all([
|
||||||
|
this.refreshRowActions(tableId),
|
||||||
|
automationStore.actions.fetch(),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
delete = async (tableId, rowActionId) => {
|
||||||
|
await API.rowActions.delete({
|
||||||
|
tableId,
|
||||||
|
rowActionId,
|
||||||
|
})
|
||||||
|
await this.refreshRowActions(tableId)
|
||||||
|
// We don't need to refresh automations as we can only delete row actions
|
||||||
|
// from the automations store, so we already handle the state update there
|
||||||
|
}
|
||||||
|
|
||||||
|
trigger = async (sourceId, rowActionId, rowId) => {
|
||||||
|
await API.rowActions.trigger({
|
||||||
|
sourceId,
|
||||||
|
rowActionId,
|
||||||
|
rowId,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const store = new RowActionStore()
|
const store = new RowActionStore()
|
||||||
|
|
Loading…
Reference in New Issue