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

View File

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

View File

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

View File

@ -53,7 +53,9 @@ export function createPluginsStore() {
async function uploadPlugin(file, source) {
let data = new FormData()
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]
update(state => {
const currentIdx = state.findIndex(plugin => plugin._id === newPlugin._id)

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import { BUILDER } from "@budibase/backend-core/permissions"
const router = new 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)
.get("/api/plugin", authorized(BUILDER), controller.fetch)
.delete(