Merge pull request #728 from Budibase/feature/add-delete-button-to-attachments

Feature/add delete button to attachments
This commit is contained in:
Kevin Åberg Kultalahti 2020-10-15 16:05:48 +02:00 committed by GitHub
commit 3174441e4c
5 changed files with 84 additions and 36 deletions

View File

@ -242,7 +242,10 @@
"type": "number",
"default": "500"
},
"pagination": "bool"
"pagination": {
"type": "bool",
"default": true
},
}
},
"dataform": {

View File

@ -1,29 +1,6 @@
<script>
import { createEventDispatcher } from "svelte"
import { DropdownMenu, TextButton as Button, Icon } from "@budibase/bbui"
import AttachmentList from "../../attachments/AttachmentList.svelte"
// import Modal from "./Modal.svelte"
const dispatch = createEventDispatcher()
let anchor
let dropdown
export let files
</script>
<AttachmentList {files} />
<!-- <div bind:this={anchor}>
<Button text small on:click={dropdown.show}>
<Icon name="edit" />
</Button>
</div>
<DropdownMenu bind:this={dropdown} {anchor} align="left">
<h5>Edit Attachment(s)</h5>
<Modal
{_bb}
{table}
onClosed={dropdown.hide}
on:newRow={() => dispatch('newRow')} />
</DropdownMenu> -->
<AttachmentList {files} on:delete />

View File

@ -12,7 +12,7 @@
import AgGrid from "@budibase/svelte-ag-grid"
import CreateRowButton from "./CreateRow/Button.svelte"
import { TextButton as DeleteButton, Icon } from "@budibase/bbui"
import { TextButton as DeleteButton, Icon, Modal, ModalContent } from "@budibase/bbui"
export let _bb
export let datasource = {}
@ -25,6 +25,8 @@
let canEdit = editable && datasource && datasource.type !== "view"
let canAddDelete = editable && datasource && datasource.type === "table"
let modal;
let store = _bb.store
let dataLoaded = false
let data
@ -133,7 +135,7 @@
<div class="controls">
<CreateRowButton {_bb} {table} on:newRow={handleNewRow} />
{#if selectedRows.length > 0}
<DeleteButton text small on:click={deleteRows}>
<DeleteButton text small on:click={modal.show()}>
<Icon name="addrow" />
Delete
{selectedRows.length}
@ -150,13 +152,14 @@
on:update={handleUpdate}
on:select={({ detail }) => (selectedRows = detail)} />
{/if}
<Modal bind:this={modal}>
<ModalContent title="Confirm Row Deletion" confirmText="Delete" onConfirm={deleteRows} >
<span>Are you sure you want to delete {selectedRows.length} row(s)?</span>
</ModalContent>
</Modal>
</div>
<style>
.container :global(form) {
display: grid;
grid-template-columns: repeat(2);
}
.controls {
margin-bottom: var(--spacing-s);
display: grid;

View File

@ -55,6 +55,13 @@ function attachmentRenderer(constraints, editable) {
},
})
const deleteFile = event => {
const newFilesArray = params.value.filter(file => file !== event.detail)
params.setValue(newFilesArray)
}
attachmentInstance.$on("delete", deleteFile)
return container
}
}

View File

@ -1,30 +1,53 @@
<script>
import { Modal, ModalContent, Icon } from '@budibase/bbui'
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher()
import { FILE_TYPES } from "./fileTypes"
export let files = []
export let height = "70"
export let width = "70"
let modal;
let currentFile;
const openModal = (file) => {
currentFile = file
modal.show()
}
const handleConfirm = () => {
dispatch('delete', currentFile)
}
</script>
<div class="file-list">
{#each files as file}
<a href={file.url} target="_blank">
<div class="file">
<div class="file-container">
<a href={file.url} target="_blank" class="file">
{#if FILE_TYPES.IMAGE.includes(file.extension.toLowerCase())}
<img {width} {height} src={file.url} alt="preview of {file.name}" />
{:else}<i class="far fa-file" />{/if}
</div>
<span>{file.name}</span>
</a>
<span>{file.name}</span>
<div class="button-placement"><button primary on:click|stopPropagation={() => openModal(file)}>×</button></div>
</div>
{/each}
</div>
<Modal bind:this={modal}>
<ModalContent title="Confirm File Deletion" confirmText="Delete" onConfirm={handleConfirm} >
<span>Are you sure you want to delete this attachment?</span>
</ModalContent>
</Modal>
<style>
.file-list {
display: grid;
justify-content: start;
grid-auto-flow: column;
grid-gap: var(--spacing-m);
grid-template-columns: repeat(10, 1fr);
grid-template-columns: repeat(auto-fill, 1fr);
}
img {
@ -40,6 +63,41 @@
text-decoration: none;
}
.file-container {
position: relative;
}
button {
display: block;
box-sizing: border-box;
position: absolute;
font-size: var(--font-size-m);
line-height: 110%;
z-index: 1000;
top: 4px;
left: 50px;
margin: 0;
padding: 0;
width: 1.3rem;
height: 1.3rem;
border: 0;
color: white;
border-radius: var(--border-radius-xl);
background: black;
transition: transform 0.2s cubic-bezier(0.25, 0.1, 0.25, 1),
background 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
-webkit-appearance: none;
outline: none;
}
button:hover {
background-color: var(--grey-8);
cursor: pointer;
}
button:active {
background-color: var(--grey-9);
cursor: pointer;
}
.file {
position: relative;
height: 75px;