1
0
Fork 0
mirror of synced 2024-06-27 18:40:42 +12: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>
import { ModalContent, Label, Input, Select, Dropzone } from "@budibase/bbui"
import {
ModalContent,
Label,
Input,
Select,
Dropzone,
notifications,
} from "@budibase/bbui"
import { plugins } from "stores/portal"
const Sources = {
@ -17,24 +24,29 @@
}
let file
let source = Sources.URL
let typeValue = "Component"
let dynamicValues = {}
let validation
$: validation = source === "File Upload" ? file : dynamicValues["URL"]
async function save() {
if (source === Sources.FILE) {
await plugins.uploadPlugin(file)
} else {
const url = dynamicValues["URL"]
let auth =
source === Sources.GITHUB
? dynamicValues["Github Token"]
: source === Sources.URL
? dynamicValues["Headers"]
: undefined
await plugins.createPlugin(typeValue, source, url, auth)
try {
if (source === Sources.FILE) {
await plugins.uploadPlugin(file)
} else {
const url = dynamicValues["URL"]
let auth =
source === Sources.GITHUB
? dynamicValues["Github Token"]
: source === Sources.URL
? dynamicValues["Headers"]
: 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>
@ -46,14 +58,6 @@
size="M"
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">
<Label size="M">Source</Label>
<Select
@ -67,7 +71,6 @@
{#if option === "File Upload"}
<div class="form-row">
<Label size="M">{option}</Label>
<Dropzone
gallery={false}
value={[file]}

View file

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

View file

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

View file

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

View file

@ -36,9 +36,9 @@ export const buildPluginEndpoints = API => ({
*
* * @param pluginId the revision of the plugin to delete
*/
deletePlugin: async (pluginId, pluginRev) => {
deletePlugin: async pluginId => {
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) {
const { type, source, url, headers, githubToken } = ctx.request.body
const { source, url, headers, githubToken } = ctx.request.body
if (!env.SELF_HOSTED) {
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) {
const db = getGlobalDB()
const { pluginId, pluginRev } = ctx.params
const { pluginId } = ctx.params
try {
const plugin = await db.get(pluginId)
const bucketPath = `${plugin.name}/`
await deleteFolder(ObjectStoreBuckets.PLUGINS, bucketPath)
await db.remove(pluginId, pluginRev)
await db.remove(pluginId, plugin._rev)
} catch (err: any) {
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", authorized(BUILDER), controller.create)
.get("/api/plugin", authorized(BUILDER), controller.fetch)
.delete(
"/api/plugin/:pluginId/:pluginRev",
authorized(BUILDER),
controller.destroy
)
.delete("/api/plugin/:pluginId", authorized(BUILDER), controller.destroy)
export default router