Binding selection fixes, delete controller refactor and some fixes
This commit is contained in:
parent
ccb82e5575
commit
a481eee39e
|
@ -491,6 +491,7 @@ const getSelectedRowsBindings = asset => {
|
|||
readableBinding: `${table._instanceName}.Selected rows`,
|
||||
category: "Selected rows",
|
||||
icon: "ViewRow",
|
||||
display: { name: table._instanceName },
|
||||
}))
|
||||
)
|
||||
|
||||
|
@ -506,6 +507,7 @@ const getSelectedRowsBindings = asset => {
|
|||
)}.${makePropSafe("selectedRows")}`,
|
||||
readableBinding: `${block._instanceName}.Selected rows`,
|
||||
category: "Selected rows",
|
||||
display: { name: block._instanceName },
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script>
|
||||
import { Select, Label, Checkbox, Input } from "@budibase/bbui"
|
||||
import { Select, Label, Checkbox, Input, Body } from "@budibase/bbui"
|
||||
import { tables } from "stores/backend"
|
||||
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||
|
||||
|
@ -10,6 +10,8 @@
|
|||
</script>
|
||||
|
||||
<div class="root">
|
||||
<Body size="small">Please specify one or more rows to delete.</Body>
|
||||
<div class="params">
|
||||
<Label>Table</Label>
|
||||
<Select
|
||||
bind:value={parameters.tableId}
|
||||
|
@ -18,10 +20,10 @@
|
|||
getOptionValue={table => table._id}
|
||||
/>
|
||||
|
||||
<Label small>Row ID</Label>
|
||||
<Label small>Row IDs</Label>
|
||||
<DrawerBindableInput
|
||||
{bindings}
|
||||
title="Row ID to delete"
|
||||
title="Rows to delete"
|
||||
value={parameters.rowId}
|
||||
on:change={value => (parameters.rowId = value.detail)}
|
||||
/>
|
||||
|
@ -37,20 +39,30 @@
|
|||
{#if parameters.confirm}
|
||||
<Label small>Confirm text</Label>
|
||||
<Input
|
||||
placeholder="Are you sure you want to delete this row?"
|
||||
placeholder="Are you sure you want to delete?"
|
||||
bind:value={parameters.confirmText}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.root {
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
align-items: stretch;
|
||||
gap: var(--spacing-xl);
|
||||
}
|
||||
|
||||
.params {
|
||||
display: grid;
|
||||
column-gap: var(--spacing-l);
|
||||
row-gap: var(--spacing-s);
|
||||
grid-template-columns: 60px 1fr;
|
||||
align-items: center;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
},
|
||||
{
|
||||
"name": "Delete Row",
|
||||
"displayName": "Delete Rows",
|
||||
"type": "data",
|
||||
"component": "DeleteRow"
|
||||
},
|
||||
|
|
|
@ -47,6 +47,14 @@
|
|||
)
|
||||
}
|
||||
|
||||
// If the data changes, double check that the selected elements are still present.
|
||||
$: if (data) {
|
||||
let rowIds = data.map(row => row._id)
|
||||
if (rowIds.length) {
|
||||
selectedRows = selectedRows.filter(row => rowIds.includes(row._id))
|
||||
}
|
||||
}
|
||||
|
||||
const getFields = (schema, customColumns, showAutoColumns) => {
|
||||
// Check for an invalid column selection
|
||||
let invalid = false
|
||||
|
|
|
@ -101,13 +101,47 @@ const fetchRowHandler = async action => {
|
|||
}
|
||||
}
|
||||
|
||||
const deleteRowHandler = async action => {
|
||||
const { tableId, revId, rowId, notificationOverride } = action.parameters
|
||||
if (tableId && rowId) {
|
||||
const deleteRowHandler = async (action, context) => {
|
||||
const { tableId, rowId: rowConfig, notificationOverride } = action.parameters
|
||||
|
||||
if (tableId && rowConfig) {
|
||||
try {
|
||||
await API.deleteRow({ tableId, rowId, revId })
|
||||
let requestConfig
|
||||
|
||||
let parsedRowConfig = []
|
||||
if (typeof rowConfig === "string") {
|
||||
try {
|
||||
parsedRowConfig = JSON.parse(rowConfig)
|
||||
} catch (e) {
|
||||
parsedRowConfig = rowConfig
|
||||
.split(",")
|
||||
.map(id => id.trim())
|
||||
.filter(id => id)
|
||||
}
|
||||
} else {
|
||||
parsedRowConfig = rowConfig
|
||||
}
|
||||
|
||||
if (
|
||||
typeof parsedRowConfig === "object" &&
|
||||
parsedRowConfig.constructor === Object
|
||||
) {
|
||||
requestConfig = [parsedRowConfig]
|
||||
} else if (Array.isArray(parsedRowConfig)) {
|
||||
requestConfig = parsedRowConfig
|
||||
}
|
||||
|
||||
if (!requestConfig.length) {
|
||||
notificationStore.actions.warning("No valid rows were supplied")
|
||||
return false
|
||||
}
|
||||
|
||||
const resp = await API.deleteRows({ tableId, rows: requestConfig })
|
||||
|
||||
if (!notificationOverride) {
|
||||
notificationStore.actions.success("Row deleted")
|
||||
notificationStore.actions.success(
|
||||
resp?.length == 1 ? "Row deleted" : `${resp.length} Rows deleted`
|
||||
)
|
||||
}
|
||||
|
||||
// Refresh related datasources
|
||||
|
@ -115,8 +149,10 @@ const deleteRowHandler = async action => {
|
|||
invalidateRelationships: true,
|
||||
})
|
||||
} catch (error) {
|
||||
// Abort next actions
|
||||
return false
|
||||
console.error(error)
|
||||
notificationStore.actions.error(
|
||||
"An error occurred while executing the query"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import { convertBookmark } from "../../../utilities"
|
|||
|
||||
// makes sure that the user doesn't need to pass in the type, tableId or _id params for
|
||||
// the call to be correct
|
||||
function fixRow(row: Row, params: any) {
|
||||
export function fixRow(row: Row, params: any) {
|
||||
if (!params || !row) {
|
||||
return row
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import { isExternalTable } from "../../../integrations/utils"
|
|||
import { Ctx } from "@budibase/types"
|
||||
import * as utils from "./utils"
|
||||
import { gridSocket } from "../../../websockets"
|
||||
import { addRev } from "../public/utils"
|
||||
import { fixRow } from "../public/rows"
|
||||
|
||||
function pickApi(tableId: any) {
|
||||
if (isExternalTable(tableId)) {
|
||||
|
@ -88,7 +90,22 @@ export async function destroy(ctx: any) {
|
|||
const inputs = ctx.request.body
|
||||
const tableId = utils.getTableId(ctx)
|
||||
let response, row
|
||||
|
||||
if (inputs.rows) {
|
||||
const targetRows = inputs.rows.map(
|
||||
(row: { [key: string]: string | string }) => {
|
||||
let processedRow = typeof row == "string" ? { _id: row } : row
|
||||
return !processedRow._rev
|
||||
? addRev(fixRow(processedRow, ctx.params), tableId)
|
||||
: fixRow(processedRow, ctx.params)
|
||||
}
|
||||
)
|
||||
|
||||
const rowDeletes = await Promise.all(targetRows)
|
||||
if (rowDeletes) {
|
||||
ctx.request.body.rows = rowDeletes
|
||||
}
|
||||
|
||||
let { rows } = await quotas.addQuery(
|
||||
() => pickApi(tableId).bulkDestroy(ctx),
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue