Merge branch 'feature/plugin-management-ui' of https://github.com/Budibase/budibase into feature/plugin-management-ui

This commit is contained in:
NEOLPAR 2022-09-06 12:50:48 +01:00
commit b8dc676120
7 changed files with 30 additions and 31 deletions

View File

@ -4,12 +4,12 @@
import { plugins } from "stores/portal" import { plugins } from "stores/portal"
export let removePlugin export let plugin
async function deletePlugin() { async function deletePlugin() {
try { try {
await plugins.deletePlugin(removePlugin._id, removePlugin._rev) await plugins.deletePlugin(plugin._id, plugin._rev)
notifications.success(`Plugin ${removePlugin?.name} deleted.`) notifications.success(`Plugin ${plugin?.name} deleted.`)
$goto("./") $goto("./")
} catch (error) { } catch (error) {
notifications.error("Error deleting plugin") notifications.error("Error deleting plugin")
@ -26,6 +26,6 @@
showCloseIcon={false} showCloseIcon={false}
> >
<Body> <Body>
Are you sure you want to delete <strong>{removePlugin?.name}</strong> Are you sure you want to delete <strong>{plugin?.name}</strong>
</Body> </Body>
</ModalContent> </ModalContent>

View File

@ -8,16 +8,17 @@
Label, Label,
Input, Input,
} from "@budibase/bbui" } from "@budibase/bbui"
import DeletePluginModal from "../_components/DeletePluginModal.svelte"
export let plugin export let plugin
export let deletePlugin
let detailsModal
let deleteModal
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"
let detailsModal
</script> </script>
<div class="row"> <div class="row">
@ -69,7 +70,7 @@
</div> </div>
<div class="details-row"> <div class="details-row">
<Label size="M">Source</Label> <Label size="M">Source</Label>
<Input disabled value={plugin.source} /> <Input disabled value={plugin.source || "N/A"} />
</div> </div>
<div class="details-row"> <div class="details-row">
<Label size="M">Version</Label> <Label size="M">Version</Label>
@ -85,15 +86,17 @@
</div> </div>
<div class="footer" slot="footer"> <div class="footer" slot="footer">
<Button newStyles on:click={() => deletePlugin(plugin)} warning <Button newStyles on:click={deleteModal.show()} warning>Delete</Button>
>Delete</Button
>
<Button newStyles>Update</Button> <Button newStyles>Update</Button>
<Button cta newStyles on:click={detailsModal.hide()}>Done</Button> <Button cta newStyles on:click={detailsModal.hide()}>Done</Button>
</div> </div>
</ModalContent> </ModalContent>
<Modal bind:this={deleteModal}>
<DeletePluginModal {plugin} />
</Modal>
</Modal> </Modal>
<style> <style>

View File

@ -13,12 +13,9 @@
import { plugins } from "stores/portal" import { plugins } from "stores/portal"
import PluginRow from "./_components/PluginRow.svelte" import PluginRow from "./_components/PluginRow.svelte"
import AddPluginModal from "./_components/AddPluginModal.svelte" import AddPluginModal from "./_components/AddPluginModal.svelte"
import DeletePluginModal from "./_components/DeletePluginModal.svelte"
let modal let modal
let deleteModal
let searchTerm = "" let searchTerm = ""
let removePlugin
let filterOptions = [ let filterOptions = [
{ label: "All Plugins", value: "all" }, { label: "All Plugins", value: "all" },
@ -35,11 +32,6 @@
plugin?.name?.toLowerCase().includes(searchTerm.toLowerCase()) plugin?.name?.toLowerCase().includes(searchTerm.toLowerCase())
) )
const deletePlugin = plugin => {
deleteModal.show()
removePlugin = plugin
}
onMount(async () => { onMount(async () => {
await plugins.load() await plugins.load()
}) })
@ -75,7 +67,7 @@
{#if $plugins} {#if $plugins}
{#each filteredPlugins as plugin} {#each filteredPlugins as plugin}
<PluginRow {plugin} {deletePlugin} /> <PluginRow {plugin} />
{/each} {/each}
{/if} {/if}
</Layout> </Layout>
@ -84,9 +76,6 @@
<Modal bind:this={modal}> <Modal bind:this={modal}>
<AddPluginModal /> <AddPluginModal />
</Modal> </Modal>
<Modal bind:this={deleteModal}>
<DeletePluginModal {removePlugin} />
</Modal>
<style> <style>
.filters { .filters {

View File

@ -53,7 +53,9 @@ export function createPluginsStore() {
async function uploadPlugin(file, source) { async function uploadPlugin(file, source) {
let data = new FormData() let data = new FormData()
data.append("file", file) data.append("file", file)
let resp = await API.uploadPlugin(data, source) data.append("source", source)
let resp = await API.uploadPlugin(data)
let newPlugin = resp.plugins[0] let newPlugin = resp.plugins[0]
update(state => { update(state => {
const currentIdx = state.findIndex(plugin => plugin._id === newPlugin._id) const currentIdx = state.findIndex(plugin => plugin._id === newPlugin._id)

View File

@ -3,9 +3,9 @@ export const buildPluginEndpoints = API => ({
* Uploads a plugin tarball bundle * Uploads a plugin tarball bundle
* @param data the plugin tarball bundle to upload * @param data the plugin tarball bundle to upload
*/ */
uploadPlugin: async (data, source) => { uploadPlugin: async data => {
return await API.post({ return await API.post({
url: `/api/plugin/upload/${source}`, url: `/api/plugin/upload`,
body: data, body: data,
json: false, json: false,
}) })

View File

@ -31,7 +31,6 @@ export async function getPlugins(type?: PluginType) {
} }
export async function upload(ctx: any) { export async function upload(ctx: any) {
const { source } = ctx.params
const plugins: FileType[] = const plugins: FileType[] =
ctx.request.files.file.length > 1 ctx.request.files.file.length > 1
? Array.from(ctx.request.files.file) ? Array.from(ctx.request.files.file)
@ -40,7 +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(plugin, source) const doc = await processPlugin(plugin, ctx.request.body.source)
docs.push(doc) docs.push(doc)
} }
ctx.body = { ctx.body = {
@ -165,16 +164,22 @@ export async function storePlugin(
} catch (err) { } catch (err) {
rev = undefined rev = undefined
} }
const doc = { let doc = {
_id: pluginId, _id: pluginId,
_rev: rev, _rev: rev,
source,
...metadata, ...metadata,
name, name,
version, version,
description, description,
jsUrl: `${bucketPath}${jsFileName}`, jsUrl: `${bucketPath}${jsFileName}`,
} }
if (source) {
doc = {
...doc,
source,
}
}
const response = await db.put(doc) const response = await db.put(doc)
return { return {
...doc, ...doc,

View File

@ -6,7 +6,7 @@ import { BUILDER } from "@budibase/backend-core/permissions"
const router = new Router() const router = new Router()
router router
.post("/api/plugin/upload/:source", 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(