remove verify and fix deletion bug

This commit is contained in:
Peter Clement 2022-09-07 16:08:29 +01:00
parent 6a28feb46c
commit 1e75e7c1e3
6 changed files with 15 additions and 123 deletions

View File

@ -24,7 +24,6 @@
export let secondaryAction = undefined
export let secondaryButtonWarning = false
export let dataCy = null
export let buttonCta = true
const { hide, cancel } = getContext(Context.Modal)
let loading = false
$: confirmDisabled = disabled || loading
@ -113,7 +112,7 @@
<span class="confirm-wrap">
<Button
group
cta={buttonCta}
cta
{...$$restProps}
disabled={confirmDisabled}
on:click={confirm}

View File

@ -1,13 +1,5 @@
<script>
import {
ModalContent,
Label,
Input,
Select,
Body,
StatusLight,
Dropzone,
} from "@budibase/bbui"
import { ModalContent, Label, Input, Select, Dropzone } from "@budibase/bbui"
import { plugins } from "stores/portal"
let authOptions = {
@ -21,7 +13,8 @@
let typeValue = "Datasource"
let dynamicValues = {}
let verificationSuccessful = false
let validation
$: validation = sourceValue === "File Upload" ? file : dynamicValues["URL"]
async function save() {
const source = sourceValue.toLocaleLowerCase()
@ -54,18 +47,12 @@
break
}
}
function verify() {
verificationSuccessful = true
// return false so modal doesn't exit
return false
}
</script>
<ModalContent
confirmText={verificationSuccessful ? "Save" : "Verify"}
buttonCta={verificationSuccessful}
onConfirm={verificationSuccessful ? save : verify}
confirmText={"Save"}
onConfirm={save}
disabled={!validation}
size="M"
title="Add new plugin"
>
@ -110,33 +97,9 @@
</div>
{/if}
{/each}
<div class="verification" slot="footer">
<div>
<StatusLight
positive={verificationSuccessful}
neutral={!verificationSuccessful}
/>
</div>
<div class="verification-spacing">
{#if verificationSuccessful}
<Body size="XS">Verification Successful</Body>
{:else}
<Body size="XS"><i>Verify your source</i></Body>
{/if}
</div>
</div>
</ModalContent>
<style>
.verification-spacing {
padding-left: var(--spacing-s);
}
.verification {
display: flex;
margin-right: auto;
align-items: center;
}
.form-row {
display: grid;
grid-template-columns: 60px 1fr;

View File

@ -1,16 +1,15 @@
<script>
import { goto } from "@roxi/routify"
import { Body, ModalContent, notifications } from "@budibase/bbui"
import { plugins } from "stores/portal"
export let plugin
export let detailsModal
async function deletePlugin() {
try {
await plugins.deletePlugin(plugin._id, plugin._rev)
detailsModal.hide()
notifications.success(`Plugin ${plugin?.name} deleted.`)
$goto("./")
} catch (error) {
notifications.error("Error deleting plugin")
}

View File

@ -7,27 +7,18 @@
Button,
Label,
Input,
Dropzone,
} from "@budibase/bbui"
import DeletePluginModal from "../_components/DeletePluginModal.svelte"
import { plugins } from "stores/portal"
export let plugin
let detailsModal
let deleteModal
let updateModal
let file
let icon =
plugin.schema.type === "component"
? plugin.schema.schema.icon || "Book"
: plugin.schema.schema.icon || "Beaker"
async function save() {
let update = true
await plugins.uploadPlugin(file, plugin.source, update)
}
</script>
<div class="row">
@ -96,54 +87,14 @@
<div class="footer" slot="footer">
<Button newStyles on:click={deleteModal.show()} warning>Delete</Button>
<Button
on:click={() => {
detailsModal.hide()
updateModal.show()
}}
newStyles>Update</Button
>
</div>
</ModalContent>
<Modal bind:this={deleteModal}>
<DeletePluginModal {plugin} />
<DeletePluginModal {detailsModal} {plugin} />
</Modal>
</Modal>
<Modal bind:this={updateModal}>
<ModalContent
size="M"
title="Update Plugin"
showConfirmButton={true}
showCancelButton={true}
cancelText="Back"
onConfirm={() => save()}
onCancel={() => {
updateModal.hide()
detailsModal.show()
}}
>
{#if plugin.source === "File Upload"}
<div class="form-row">
<Label size="M">File Upload</Label>
</div>
<Dropzone
gallery={false}
value={[file]}
on:change={e => {
if (!e.detail || e.detail.length === 0) {
file = null
} else {
file = e.detail[0]
}
}}
/>
{/if}
</ModalContent>
</Modal>
<style>
.row {
display: grid;
@ -180,11 +131,4 @@
display: flex;
gap: var(--spacing-l);
}
.form-row {
display: grid;
grid-template-columns: 60px 1fr;
grid-gap: var(--spacing-l);
align-items: center;
}
</style>

View File

@ -50,11 +50,10 @@ export function createPluginsStore() {
})
}
async function uploadPlugin(file, source, updatePlugin) {
async function uploadPlugin(file, source) {
let data = new FormData()
data.append("file", file)
data.append("source", source)
data.append("update", updatePlugin)
let resp = await API.uploadPlugin(data)
let newPlugin = resp.plugins[0]
update(state => {

View File

@ -39,11 +39,7 @@ export async function upload(ctx: any) {
let docs = []
// can do single or multiple plugins
for (let plugin of plugins) {
const doc = await processPlugin(
plugin,
ctx.request.body.source,
ctx.request.body.update
)
const doc = await processPlugin(plugin, ctx.request.body.source)
docs.push(doc)
}
ctx.body = {
@ -132,8 +128,7 @@ export async function destroy(ctx: any) {
export async function storePlugin(
metadata: any,
directory: any,
source?: string,
update?: boolean
source?: string
) {
const db = getGlobalDB()
const version = metadata.package.version,
@ -172,9 +167,6 @@ export async function storePlugin(
const existing = await db.get(pluginId)
rev = existing._rev
} catch (err) {
if (update) {
throw new Error("Unable to update. Plugin does not exist")
}
rev = undefined
}
let doc = {
@ -201,15 +193,11 @@ export async function storePlugin(
}
}
export async function processPlugin(
plugin: FileType,
source?: string,
update?: boolean
) {
export async function processPlugin(plugin: FileType, source?: string) {
if (!env.SELF_HOSTED) {
throw new Error("Plugins not supported outside of self-host.")
}
const { metadata, directory } = await uploadedFilePlugin(plugin)
return await storePlugin(metadata, directory, source, update)
return await storePlugin(metadata, directory, source)
}