From f6e5524b0770ddbe783b74eaf7340acb32b9e691 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 12 Sep 2022 17:04:27 +0100 Subject: [PATCH] Refactoring some plugin adding work - changing how source is specified to remove lower casing. --- .../plugins/_components/AddPluginModal.svelte | 64 ++++++++----------- packages/builder/src/stores/portal/plugins.js | 6 +- .../src/api/controllers/plugin/index.ts | 10 +-- packages/types/src/documents/plugin/index.ts | 8 ++- 4 files changed, 43 insertions(+), 45 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/plugins/_components/AddPluginModal.svelte b/packages/builder/src/pages/builder/portal/manage/plugins/_components/AddPluginModal.svelte index 3520c18991..ade5f14c9f 100644 --- a/packages/builder/src/pages/builder/portal/manage/plugins/_components/AddPluginModal.svelte +++ b/packages/builder/src/pages/builder/portal/manage/plugins/_components/AddPluginModal.svelte @@ -2,49 +2,39 @@ import { ModalContent, Label, Input, Select, Dropzone } from "@budibase/bbui" import { plugins } from "stores/portal" + const Sources = { + NPM: "NPM", + GITHUB: "Github", + URL: "URL", + FILE: "File Upload", + } + let authOptions = { - URL: ["Headers", "URL"], - NPM: ["URL"], - Github: ["Github Token", "URL"], - "File Upload": ["File Upload"], + [Sources.NPM]: ["URL"], + [Sources.GITHUB]: ["Github Token", "URL"], + [Sources.URL]: ["Headers", "URL"], + [Sources.FILE]: ["File Upload"], } let file - let sourceValue = "URL" + let source = Sources.URL let typeValue = "Component" let dynamicValues = {} let validation - $: validation = sourceValue === "File Upload" ? file : dynamicValues["URL"] + $: validation = source === "File Upload" ? file : dynamicValues["URL"] async function save() { - const source = sourceValue.toLocaleLowerCase() - const url = dynamicValues["URL"] - - switch (source) { - case "file upload": - if (file) { - await plugins.uploadPlugin(file, sourceValue) - } - break - case "github": - await plugins.createPlugin( - typeValue, - source, - url, - dynamicValues["Github Token"] - ) - break - case "url": - await plugins.createPlugin( - typeValue, - source, - url, - dynamicValues["Headers"] - ) - break - case "npm": - await plugins.createPlugin(typeValue, source, url) - break + 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) } } @@ -68,12 +58,12 @@