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

View File

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

View File

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

View File

@ -7,27 +7,18 @@
Button, Button,
Label, Label,
Input, Input,
Dropzone,
} from "@budibase/bbui" } from "@budibase/bbui"
import DeletePluginModal from "../_components/DeletePluginModal.svelte" import DeletePluginModal from "../_components/DeletePluginModal.svelte"
import { plugins } from "stores/portal"
export let plugin export let plugin
let detailsModal let detailsModal
let deleteModal let deleteModal
let updateModal
let file
let icon = let icon =
plugin.schema.type === "component" plugin.schema.type === "component"
? plugin.schema.schema.icon || "Book" ? plugin.schema.schema.icon || "Book"
: plugin.schema.schema.icon || "Beaker" : plugin.schema.schema.icon || "Beaker"
async function save() {
let update = true
await plugins.uploadPlugin(file, plugin.source, update)
}
</script> </script>
<div class="row"> <div class="row">
@ -96,54 +87,14 @@
<div class="footer" slot="footer"> <div class="footer" slot="footer">
<Button newStyles on:click={deleteModal.show()} warning>Delete</Button> <Button newStyles on:click={deleteModal.show()} warning>Delete</Button>
<Button
on:click={() => {
detailsModal.hide()
updateModal.show()
}}
newStyles>Update</Button
>
</div> </div>
</ModalContent> </ModalContent>
<Modal bind:this={deleteModal}> <Modal bind:this={deleteModal}>
<DeletePluginModal {plugin} /> <DeletePluginModal {detailsModal} {plugin} />
</Modal> </Modal>
</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> <style>
.row { .row {
display: grid; display: grid;
@ -180,11 +131,4 @@
display: flex; display: flex;
gap: var(--spacing-l); gap: var(--spacing-l);
} }
.form-row {
display: grid;
grid-template-columns: 60px 1fr;
grid-gap: var(--spacing-l);
align-items: center;
}
</style> </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() let data = new FormData()
data.append("file", file) data.append("file", file)
data.append("source", source) data.append("source", source)
data.append("update", updatePlugin)
let resp = await API.uploadPlugin(data) let resp = await API.uploadPlugin(data)
let newPlugin = resp.plugins[0] let newPlugin = resp.plugins[0]
update(state => { update(state => {

View File

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