Adding info to the table deletion about screens that will be deleted and deleted template screens when table deleted.

This commit is contained in:
mike12345567 2020-10-13 19:37:52 +01:00
parent 686d85f07e
commit 7e70eb0f20
2 changed files with 47 additions and 4 deletions

View File

@ -1,9 +1,11 @@
<script> <script>
import { backendUiStore } from "builderStore" import { backendUiStore, store } from "builderStore"
import { notifier } from "builderStore/store/notifications" import { notifier } from "builderStore/store/notifications"
import { DropdownMenu, Button, Icon, Input, Select } from "@budibase/bbui" import { DropdownMenu, Button, Icon, Input, Select } from "@budibase/bbui"
import { FIELDS } from "constants/backend" import { FIELDS } from "constants/backend"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import screenTemplates from "builderStore/store/screenTemplates"
import api from "builderStore/api"
export let table export let table
@ -11,6 +13,8 @@
let dropdown let dropdown
let editing let editing
let confirmDeleteDialog let confirmDeleteDialog
let templateScreens
let willBeDeleted
$: fields = Object.keys(table.schema) $: fields = Object.keys(table.schema)
@ -24,12 +28,31 @@
} }
function showModal() { function showModal() {
const screens = $store.allScreens
templateScreens = screens.filter(screen => screen.props.table === table._id)
willBeDeleted = ["All table data"].concat(templateScreens.map(screen => `Screen ${screen.props._instanceName}`))
hideEditor() hideEditor()
confirmDeleteDialog.show() confirmDeleteDialog.show()
} }
function deleteTemplateScreens() {
store.update(state => {
for (let screen of templateScreens) {
const mainPageName = state.pages.main.name
state.screens = state.screens.filter(c => c.name !== screen.name)
// Remove screen from current page as well
state.pages[state.currentPageName]._screens = state.pages[mainPageName]._screens.filter(
scr => scr.name !== screen.name
)
api.delete(`/_builder/api/pages/${mainPageName}/screens/${screen.name}`)
}
return state
})
}
async function deleteTable() { async function deleteTable() {
await backendUiStore.actions.tables.delete(table) await backendUiStore.actions.tables.delete(table)
deleteTemplateScreens()
notifier.success("Table deleted") notifier.success("Table deleted")
hideEditor() hideEditor()
} }
@ -79,10 +102,20 @@
</DropdownMenu> </DropdownMenu>
<ConfirmDialog <ConfirmDialog
bind:this={confirmDeleteDialog} bind:this={confirmDeleteDialog}
body={`Are you sure you wish to delete the table '${table.name}'? Your data will be deleted and this action cannot be undone.`} body={`Are you sure you wish to delete the table '${table.name}'?`}
okText="Delete Table" okText="Delete Table"
onOk={deleteTable} onOk={deleteTable}
title="Confirm Delete" /> title="Confirm Delete">
The following will also be deleted:
<b>
<div class="delete-items">
{#each willBeDeleted as item}
<div>{item}</div>
{/each}
</div>
</b>
This action cannot be undone.
</ConfirmDialog>
<style> <style>
div.icon { div.icon {
@ -96,6 +129,16 @@
font-size: 16px; font-size: 16px;
} }
div.delete-items {
margin-top: 10px;
margin-bottom: 10px;
margin-left: 10px;
}
div.delete-items div {
margin-top: 4px;
}
.actions { .actions {
padding: var(--spacing-xl); padding: var(--spacing-xl);
display: grid; display: grid;

View File

@ -20,7 +20,7 @@
<Modal bind:this={modal} on:hide={onCancel}> <Modal bind:this={modal} on:hide={onCancel}>
<ModalContent onConfirm={onOk} {title} confirmText={okText} {cancelText} red> <ModalContent onConfirm={onOk} {title} confirmText={okText} {cancelText} red>
<div class="body">{body}</div> <div class="body">{body}<slot/></div>
</ModalContent> </ModalContent>
</Modal> </Modal>