Merge pull request #8789 from Budibase/feature/add-delete-to-row-edit-modal
Add delete to row edit modal
This commit is contained in:
commit
9c923c7f8c
|
@ -28,9 +28,9 @@
|
||||||
let loading = false
|
let loading = false
|
||||||
$: confirmDisabled = disabled || loading
|
$: confirmDisabled = disabled || loading
|
||||||
|
|
||||||
async function secondary() {
|
async function secondary(e) {
|
||||||
loading = true
|
loading = true
|
||||||
if (!secondaryAction || (await secondaryAction()) !== false) {
|
if (!secondaryAction || (await secondaryAction(e)) !== false) {
|
||||||
hide()
|
hide()
|
||||||
}
|
}
|
||||||
loading = false
|
loading = false
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import { Table, Modal, Heading, notifications, Layout } from "@budibase/bbui"
|
import { Table, Modal, Heading, notifications, Layout } from "@budibase/bbui"
|
||||||
import { API } from "api"
|
import { API } from "api"
|
||||||
import Spinner from "components/common/Spinner.svelte"
|
import Spinner from "components/common/Spinner.svelte"
|
||||||
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
import DeleteRowsButton from "./buttons/DeleteRowsButton.svelte"
|
import DeleteRowsButton from "./buttons/DeleteRowsButton.svelte"
|
||||||
import CreateEditRow from "./modals/CreateEditRow.svelte"
|
import CreateEditRow from "./modals/CreateEditRow.svelte"
|
||||||
import CreateEditUser from "./modals/CreateEditUser.svelte"
|
import CreateEditUser from "./modals/CreateEditUser.svelte"
|
||||||
|
@ -34,8 +35,8 @@
|
||||||
let editRowModal
|
let editRowModal
|
||||||
let editColumnModal
|
let editColumnModal
|
||||||
let customRenderers = []
|
let customRenderers = []
|
||||||
|
let confirmDelete
|
||||||
|
|
||||||
$: isInternal = type !== "external"
|
|
||||||
$: isUsersTable = tableId === TableNames.USERS
|
$: isUsersTable = tableId === TableNames.USERS
|
||||||
$: data && resetSelectedRows()
|
$: data && resetSelectedRows()
|
||||||
$: editRowComponent = isUsersTable ? CreateEditUser : CreateEditRow
|
$: editRowComponent = isUsersTable ? CreateEditUser : CreateEditRow
|
||||||
|
@ -89,15 +90,17 @@
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteRows = async () => {
|
const deleteRows = async targetRows => {
|
||||||
try {
|
try {
|
||||||
await API.deleteRows({
|
await API.deleteRows({
|
||||||
tableId,
|
tableId,
|
||||||
rows: selectedRows,
|
rows: targetRows,
|
||||||
})
|
})
|
||||||
data = data.filter(row => !selectedRows.includes(row))
|
|
||||||
notifications.success(`Successfully deleted ${selectedRows.length} rows`)
|
const deletedRowIds = targetRows.map(row => row._id)
|
||||||
selectedRows = []
|
data = data.filter(row => deletedRowIds.indexOf(row._id))
|
||||||
|
|
||||||
|
notifications.success(`Successfully deleted ${targetRows.length} rows`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error("Error deleting rows")
|
notifications.error("Error deleting rows")
|
||||||
}
|
}
|
||||||
|
@ -133,7 +136,14 @@
|
||||||
<div class="popovers">
|
<div class="popovers">
|
||||||
<slot />
|
<slot />
|
||||||
{#if !isUsersTable && selectedRows.length > 0}
|
{#if !isUsersTable && selectedRows.length > 0}
|
||||||
<DeleteRowsButton on:updaterows {selectedRows} {deleteRows} />
|
<DeleteRowsButton
|
||||||
|
on:updaterows
|
||||||
|
{selectedRows}
|
||||||
|
deleteRows={async rows => {
|
||||||
|
await deleteRows(rows)
|
||||||
|
resetSelectedRows()
|
||||||
|
}}
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
@ -164,8 +174,33 @@
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
<Modal bind:this={editRowModal}>
|
<Modal bind:this={editRowModal}>
|
||||||
<svelte:component this={editRowComponent} on:updaterows row={editableRow} />
|
<svelte:component
|
||||||
|
this={editRowComponent}
|
||||||
|
on:updaterows
|
||||||
|
on:deleteRows={() => {
|
||||||
|
confirmDelete.show()
|
||||||
|
}}
|
||||||
|
row={editableRow}
|
||||||
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<ConfirmDialog
|
||||||
|
bind:this={confirmDelete}
|
||||||
|
okText="Delete"
|
||||||
|
onOk={async () => {
|
||||||
|
if (editableRow) {
|
||||||
|
await deleteRows([editableRow])
|
||||||
|
}
|
||||||
|
editableRow = undefined
|
||||||
|
}}
|
||||||
|
onCancel={async () => {
|
||||||
|
editRow(editableRow)
|
||||||
|
}}
|
||||||
|
title="Confirm Deletion"
|
||||||
|
>
|
||||||
|
Are you sure you want to delete this row?
|
||||||
|
</ConfirmDialog>
|
||||||
|
|
||||||
<Modal bind:this={editColumnModal}>
|
<Modal bind:this={editColumnModal}>
|
||||||
<CreateEditColumn
|
<CreateEditColumn
|
||||||
field={editableColumn}
|
field={editableColumn}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
let modal
|
let modal
|
||||||
|
|
||||||
async function confirmDeletion() {
|
async function confirmDeletion() {
|
||||||
await deleteRows()
|
await deleteRows(selectedRows)
|
||||||
modal?.hide()
|
modal?.hide()
|
||||||
dispatch("updaterows")
|
dispatch("updaterows")
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,22 +50,34 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ModalContent
|
<span class="modal-wrap">
|
||||||
title={creating ? "Create Row" : "Edit Row"}
|
<ModalContent
|
||||||
confirmText={creating ? "Create Row" : "Save Row"}
|
title={creating ? "Create Row" : "Edit Row"}
|
||||||
onConfirm={saveRow}
|
confirmText={creating ? "Create Row" : "Save Row"}
|
||||||
>
|
onConfirm={saveRow}
|
||||||
{#each tableSchema as [key, meta]}
|
showCancelButton={creating}
|
||||||
{#if !meta.autocolumn && meta.type !== FORMULA_TYPE}
|
showSecondaryButton={!creating}
|
||||||
<div>
|
secondaryButtonWarning={!creating}
|
||||||
<RowFieldControl error={errors[key]} {meta} bind:value={row[key]} />
|
secondaryButtonText="Delete"
|
||||||
</div>
|
secondaryAction={() => {
|
||||||
{/if}
|
dispatch("deleteRows", row)
|
||||||
{/each}
|
}}
|
||||||
</ModalContent>
|
>
|
||||||
|
{#each tableSchema as [key, meta]}
|
||||||
|
{#if !meta.autocolumn && meta.type !== FORMULA_TYPE}
|
||||||
|
<div>
|
||||||
|
<RowFieldControl error={errors[key]} {meta} bind:value={row[key]} />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</ModalContent>
|
||||||
|
</span>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
div {
|
div {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
.modal-wrap :global(.secondary-action) {
|
||||||
|
margin-right: unset;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue