1
0
Fork 0
mirror of synced 2024-06-02 02:25:17 +12:00

Adding ability for datasource plugins to have a custom icon svg.

This commit is contained in:
mike12345567 2022-09-29 19:30:53 +01:00
parent 56559510fd
commit 1f5de9b71d
9 changed files with 88 additions and 14 deletions

View file

@ -182,6 +182,11 @@ export const streamUpload = async (
...extra,
ContentType: "application/javascript",
}
} else if (filename?.endsWith(".svg")) {
extra = {
...extra,
ContentType: "image",
}
}
const params = {

View file

@ -13,7 +13,7 @@
customQueryIconColor,
customQueryText,
} from "helpers/data/utils"
import { getIcon } from "./icons"
import IntegrationIcon from "./IntegrationIcon.svelte"
import { notifications } from "@budibase/bbui"
let openDataSources = []
@ -123,10 +123,10 @@
on:iconClick={() => toggleNode(datasource)}
>
<div class="datasource-icon" slot="icon">
<svelte:component
this={getIcon(datasource.source, datasource.schema)}
height="18"
width="18"
<IntegrationIcon
integrationType={datasource.source}
schema={datasource.schema}
size="18"
/>
</div>
{#if datasource._id !== BUDIBASE_INTERNAL_DB}

View file

@ -0,0 +1,40 @@
<script>
import { getIcon } from "./icons"
import CustomSVG from "components/common/CustomSVG.svelte"
import { admin } from "stores/portal"
export let integrationType
export let schema
export let size = "18"
$: objectStoreUrl = $admin.cloud ? "https://cdn.budi.live" : ""
$: pluginsUrl = `${objectStoreUrl}/plugins`
$: iconInfo = getIcon(integrationType, schema)
async function getSvgFromUrl(info) {
const url = `${pluginsUrl}/${info.url}`
const resp = await fetch(url, {
headers: {
pragma: "no-cache",
"cache-control": "no-cache",
},
})
let text = await resp.text()
// explicitly only want to replace the first instance
if (text.includes("height=")) {
text = text.replace(/height="\d*"/, `height="${size}"`)
}
if (text.includes("width=")) {
text = text.replace(/width="\d*"/, `width="${size}"`)
}
return text
}
</script>
{#if iconInfo.icon}
<svelte:component this={iconInfo.icon} height={size} width={size} />
{:else if iconInfo.url}
{#await getSvgFromUrl(iconInfo) then retrievedSvg}
<CustomSVG {size} svgHtml={retrievedSvg} />
{/await}
{/if}

View file

@ -1,7 +1,7 @@
<script>
import { createEventDispatcher } from "svelte"
import { Heading, Detail } from "@budibase/bbui"
import { getIcon } from "../icons"
import IntegrationIcon from "../IntegrationIcon.svelte"
export let integration
export let integrationType
@ -16,11 +16,7 @@
class="item hoverable"
>
<div class="item-body" class:with-type={!!schema.type}>
<svelte:component
this={getIcon(integrationType, schema)}
height="20"
width="20"
/>
<IntegrationIcon {integrationType} {schema} size="25" />
<div class="text">
<Heading size="XXS">{schema.friendlyName}</Heading>
{#if schema.type}

View file

@ -16,6 +16,8 @@ import Firebase from "./Firebase.svelte"
import Redis from "./Redis.svelte"
import Snowflake from "./Snowflake.svelte"
import Custom from "./Custom.svelte"
import { integrations } from "stores/backend"
import { get } from "svelte/store"
const ICONS = {
BUDIBASE: Budibase,
@ -41,9 +43,12 @@ const ICONS = {
export default ICONS
export function getIcon(integrationType, schema) {
if (schema?.custom || !ICONS[integrationType]) {
return ICONS.CUSTOM
const integrationList = get(integrations)
if (integrationList[integrationType]?.iconUrl) {
return { url: integrationList[integrationType].iconUrl }
} else if (schema?.custom || !ICONS[integrationType]) {
return { icon: ICONS.CUSTOM }
} else {
return ICONS[integrationType]
return { icon: ICONS[integrationType] }
}
}

View file

@ -0,0 +1,23 @@
<script>
import { Helpers } from "@budibase/bbui"
export let size
export let svgHtml
function substituteSize(svg) {
if (svg.includes("height=")) {
svg = svg.replace(/height="\d*"/, `height="${size}"`)
}
if (svg.includes("width=")) {
svg = svg.replace(/width="\d*"/, `width="${size}"`)
}
if (svg.includes("id=")) {
const matches = svg.match(/id="(.*)"/g)
for (let match of matches) {
svg = svg.replace(new RegExp(match, "g"), Helpers.uuid())
}
}
return svg
}
</script>
{@html substituteSize(svgHtml)}

View file

@ -78,6 +78,9 @@ module.exports = {
...plugin.schema["schema"],
custom: true,
}
if (plugin.iconUrl) {
pluginSchemas[sourceId].iconUrl = plugin.iconUrl
}
}
}
return {

View file

@ -21,6 +21,7 @@ export interface Plugin extends Document {
name: string
version: string
jsUrl?: string
iconUrl?: string
source: PluginSource
package: { [key: string]: any }
hash: string

View file

@ -96,6 +96,7 @@ export interface Integration {
description: string
friendlyName: string
type?: string
iconUrl?: string
datasource: {}
query: {
[key: string]: QueryDefinition