1
0
Fork 0
mirror of synced 2024-09-29 16:51:33 +13:00

Updating add/delete process to have better notifications, removing some errors.

This commit is contained in:
mike12345567 2022-09-12 17:43:13 +01:00
parent 036487378c
commit 40e579e0b7
7 changed files with 49 additions and 42 deletions

View file

@ -1,5 +1,12 @@
<script> <script>
import { ModalContent, Label, Input, Select, Dropzone } from "@budibase/bbui" import {
ModalContent,
Label,
Input,
Select,
Dropzone,
notifications,
} from "@budibase/bbui"
import { plugins } from "stores/portal" import { plugins } from "stores/portal"
const Sources = { const Sources = {
@ -17,24 +24,29 @@
} }
let file let file
let source = Sources.URL let source = Sources.URL
let typeValue = "Component"
let dynamicValues = {} let dynamicValues = {}
let validation let validation
$: validation = source === "File Upload" ? file : dynamicValues["URL"] $: validation = source === "File Upload" ? file : dynamicValues["URL"]
async function save() { async function save() {
if (source === Sources.FILE) { try {
await plugins.uploadPlugin(file) if (source === Sources.FILE) {
} else { await plugins.uploadPlugin(file)
const url = dynamicValues["URL"] } else {
let auth = const url = dynamicValues["URL"]
source === Sources.GITHUB let auth =
? dynamicValues["Github Token"] source === Sources.GITHUB
: source === Sources.URL ? dynamicValues["Github Token"]
? dynamicValues["Headers"] : source === Sources.URL
: undefined ? dynamicValues["Headers"]
await plugins.createPlugin(typeValue, source, url, auth) : undefined
await plugins.createPlugin(source, url, auth)
}
notifications.success("Plugin added successfully.")
} catch (err) {
const msg = err?.message ? err.message : JSON.stringify(err)
notifications.error(`Failed to add plugin: ${msg}`)
} }
} }
</script> </script>
@ -46,14 +58,6 @@
size="M" size="M"
title="Add new plugin" title="Add new plugin"
> >
<div class="form-row">
<Label size="M">Type</Label>
<Select
bind:value={typeValue}
placeholder={null}
options={["Component", "Datasource"]}
/>
</div>
<div class="form-row"> <div class="form-row">
<Label size="M">Source</Label> <Label size="M">Source</Label>
<Select <Select
@ -67,7 +71,6 @@
{#if option === "File Upload"} {#if option === "File Upload"}
<div class="form-row"> <div class="form-row">
<Label size="M">{option}</Label> <Label size="M">{option}</Label>
<Dropzone <Dropzone
gallery={false} gallery={false}
value={[file]} value={[file]}

View file

@ -1,17 +1,20 @@
<script> <script>
import { Body, ModalContent, notifications } from "@budibase/bbui" import { Body, ModalContent, notifications } from "@budibase/bbui"
import { plugins } from "stores/portal" import { plugins } from "stores/portal"
import { createEventDispatcher } from "svelte"
export let plugin export let plugin
export let detailsModal
let dispatch = createEventDispatcher()
async function deletePlugin() { async function deletePlugin() {
try { try {
await plugins.deletePlugin(plugin._id, plugin._rev) await plugins.deletePlugin(plugin._id)
detailsModal.hide()
notifications.success(`Plugin ${plugin?.name} deleted.`) notifications.success(`Plugin ${plugin?.name} deleted.`)
dispatch("deleted")
} catch (error) { } catch (error) {
notifications.error("Error deleting plugin") const msg = error?.message ? error.message : JSON.stringify(error)
notifications.error(`Error deleting plugin: ${msg}`)
} }
} }
</script> </script>

View file

@ -19,6 +19,12 @@
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"
function pluginDeleted() {
if (detailsModal) {
detailsModal.hide()
}
}
</script> </script>
<div class="row" on:click={() => detailsModal.show()}> <div class="row" on:click={() => detailsModal.show()}>
@ -90,7 +96,7 @@
</ModalContent> </ModalContent>
<Modal bind:this={deleteModal}> <Modal bind:this={deleteModal}>
<DeletePluginModal {detailsModal} {plugin} /> <DeletePluginModal {plugin} on:deleted={pluginDeleted} />
</Modal> </Modal>
</Modal> </Modal>

View file

@ -9,17 +9,16 @@ export function createPluginsStore() {
set(plugins) set(plugins)
} }
async function deletePlugin(pluginId, pluginRev) { async function deletePlugin(pluginId) {
await API.deletePlugin(pluginId, pluginRev) await API.deletePlugin(pluginId)
update(state => { update(state => {
state = state.filter(existing => existing._id !== pluginId) state = state.filter(existing => existing._id !== pluginId)
return state return state
}) })
} }
async function createPlugin(type, source, url, auth = null) { async function createPlugin(source, url, auth = null) {
let pluginData = { let pluginData = {
type,
source, source,
url, url,
} }

View file

@ -36,9 +36,9 @@ export const buildPluginEndpoints = API => ({
* *
* * @param pluginId the revision of the plugin to delete * * @param pluginId the revision of the plugin to delete
*/ */
deletePlugin: async (pluginId, pluginRev) => { deletePlugin: async pluginId => {
return await API.delete({ return await API.delete({
url: `/api/plugin/${pluginId}/${pluginRev}`, url: `/api/plugin/${pluginId}`,
}) })
}, },
}) })

View file

@ -55,7 +55,7 @@ export async function upload(ctx: any) {
} }
export async function create(ctx: any) { export async function create(ctx: any) {
const { type, source, url, headers, githubToken } = ctx.request.body const { source, url, headers, githubToken } = ctx.request.body
if (!env.SELF_HOSTED) { if (!env.SELF_HOSTED) {
ctx.throw(400, "Plugins not supported outside of self-host.") ctx.throw(400, "Plugins not supported outside of self-host.")
@ -111,14 +111,14 @@ export async function fetch(ctx: any) {
export async function destroy(ctx: any) { export async function destroy(ctx: any) {
const db = getGlobalDB() const db = getGlobalDB()
const { pluginId, pluginRev } = ctx.params const { pluginId } = ctx.params
try { try {
const plugin = await db.get(pluginId) const plugin = await db.get(pluginId)
const bucketPath = `${plugin.name}/` const bucketPath = `${plugin.name}/`
await deleteFolder(ObjectStoreBuckets.PLUGINS, bucketPath) await deleteFolder(ObjectStoreBuckets.PLUGINS, bucketPath)
await db.remove(pluginId, pluginRev) await db.remove(pluginId, plugin._rev)
} catch (err: any) { } catch (err: any) {
const errMsg = err?.message ? err?.message : err const errMsg = err?.message ? err?.message : err

View file

@ -9,10 +9,6 @@ router
.post("/api/plugin/upload", authorized(BUILDER), controller.upload) .post("/api/plugin/upload", authorized(BUILDER), controller.upload)
.post("/api/plugin", authorized(BUILDER), controller.create) .post("/api/plugin", authorized(BUILDER), controller.create)
.get("/api/plugin", authorized(BUILDER), controller.fetch) .get("/api/plugin", authorized(BUILDER), controller.fetch)
.delete( .delete("/api/plugin/:pluginId", authorized(BUILDER), controller.destroy)
"/api/plugin/:pluginId/:pluginRev",
authorized(BUILDER),
controller.destroy
)
export default router export default router