Add confirmation before bulk duplicating rows and loading spinner
This commit is contained in:
parent
64cc3efc2a
commit
8a8d835a1a
|
@ -0,0 +1,53 @@
|
||||||
|
<script>
|
||||||
|
import { Modal, ModalContent } from "@budibase/bbui"
|
||||||
|
import { getContext, onMount } from "svelte"
|
||||||
|
import { getCellID } from "../lib/utils"
|
||||||
|
|
||||||
|
const {
|
||||||
|
selectedRows,
|
||||||
|
rows,
|
||||||
|
subscribe,
|
||||||
|
focusedCellId,
|
||||||
|
stickyColumn,
|
||||||
|
columns,
|
||||||
|
menu,
|
||||||
|
selectedRowCount,
|
||||||
|
} = getContext("grid")
|
||||||
|
|
||||||
|
let modal
|
||||||
|
|
||||||
|
// Deletion callback when confirmed
|
||||||
|
const performDuplication = async () => {
|
||||||
|
menu.actions.close()
|
||||||
|
const rowsToDuplicate = Object.keys($selectedRows).map(id => {
|
||||||
|
return rows.actions.getRow(id)
|
||||||
|
})
|
||||||
|
const newRows = await rows.actions.bulkDuplicate(rowsToDuplicate)
|
||||||
|
if (newRows[0]) {
|
||||||
|
const column = $stickyColumn?.name || $columns[0].name
|
||||||
|
$focusedCellId = getCellID(newRows[0]._id, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure menu is closed, as we may have triggered this from there
|
||||||
|
menu.actions.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => subscribe("request-bulk-duplicate", () => modal?.show()))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Modal bind:this={modal}>
|
||||||
|
<ModalContent
|
||||||
|
title="Duplicate rows"
|
||||||
|
confirmText="Continue"
|
||||||
|
cancelText="Cancel"
|
||||||
|
onConfirm={performDuplication}
|
||||||
|
size="M"
|
||||||
|
>
|
||||||
|
Are you sure you want to duplicate {$selectedRowCount}
|
||||||
|
row{$selectedRowCount === 1 ? "" : "s"}?
|
||||||
|
{#if $selectedRowCount >= 10}
|
||||||
|
<br /><br />
|
||||||
|
This may take a few seconds.
|
||||||
|
{/if}
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
|
@ -7,6 +7,7 @@
|
||||||
import { createAPIClient } from "../../../api"
|
import { createAPIClient } from "../../../api"
|
||||||
import { attachStores } from "../stores"
|
import { attachStores } from "../stores"
|
||||||
import BulkDeleteHandler from "../controls/BulkDeleteHandler.svelte"
|
import BulkDeleteHandler from "../controls/BulkDeleteHandler.svelte"
|
||||||
|
import BulkDuplicationHandler from "../controls/BulkDuplicationHandler.svelte"
|
||||||
import GridBody from "./GridBody.svelte"
|
import GridBody from "./GridBody.svelte"
|
||||||
import ResizeOverlay from "../overlays/ResizeOverlay.svelte"
|
import ResizeOverlay from "../overlays/ResizeOverlay.svelte"
|
||||||
import ReorderOverlay from "../overlays/ReorderOverlay.svelte"
|
import ReorderOverlay from "../overlays/ReorderOverlay.svelte"
|
||||||
|
@ -212,6 +213,9 @@
|
||||||
{#if $config.canDeleteRows}
|
{#if $config.canDeleteRows}
|
||||||
<BulkDeleteHandler />
|
<BulkDeleteHandler />
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if $config.canAddRows}
|
||||||
|
<BulkDuplicationHandler />
|
||||||
|
{/if}
|
||||||
<KeyboardManager />
|
<KeyboardManager />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -52,16 +52,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bulkDuplicate = async () => {
|
const bulkDuplicate = () => {
|
||||||
menu.actions.close()
|
dispatch("request-bulk-duplicate")
|
||||||
const rowsToDuplicate = Object.keys($selectedRows).map(id => {
|
|
||||||
return rows.actions.getRow(id)
|
|
||||||
})
|
|
||||||
const newRows = await rows.actions.bulkDuplicate(rowsToDuplicate)
|
|
||||||
if (newRows[0]) {
|
|
||||||
const column = $stickyColumn?.name || $columns[0].name
|
|
||||||
$focusedCellId = getCellID(newRows[0]._id, column)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const copyToClipboard = async value => {
|
const copyToClipboard = async value => {
|
||||||
|
@ -79,7 +71,7 @@
|
||||||
{#if $menu.multiRowMode}
|
{#if $menu.multiRowMode}
|
||||||
<MenuItem
|
<MenuItem
|
||||||
icon="Duplicate"
|
icon="Duplicate"
|
||||||
disabled={!$config.canAddRows}
|
disabled={!$config.canAddRows || $selectedRowCount > 50}
|
||||||
on:click={bulkDuplicate}
|
on:click={bulkDuplicate}
|
||||||
>
|
>
|
||||||
Duplicate {$selectedRowCount} rows
|
Duplicate {$selectedRowCount} rows
|
||||||
|
|
Loading…
Reference in New Issue