From 03b3049572a1161102be50d368c2c772a11dfb10 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 4 Feb 2022 08:50:36 +0000 Subject: [PATCH 1/2] Fix copy to clipboard not working without a secure context and add better notifications --- .../bbui/src/Table/InternalRenderer.svelte | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/bbui/src/Table/InternalRenderer.svelte b/packages/bbui/src/Table/InternalRenderer.svelte index 0f894ac853..858d51f128 100644 --- a/packages/bbui/src/Table/InternalRenderer.svelte +++ b/packages/bbui/src/Table/InternalRenderer.svelte @@ -8,10 +8,35 @@ copyToClipboard(value) } - function copyToClipboard(value) { - navigator.clipboard.writeText(value).then(() => { - notifications.success("Copied") + const copyToClipboard = value => { + return new Promise(res => { + if (navigator.clipboard && window.isSecureContext) { + // Try using the clipboard API first + navigator.clipboard.writeText(value).then(res) + } else { + // Fall back to the textarea hack + let textArea = document.createElement("textarea") + textArea.value = value + textArea.style.position = "fixed" + textArea.style.left = "-9999px" + textArea.style.top = "-9999px" + document.body.appendChild(textArea) + textArea.focus() + textArea.select() + document.execCommand("copy") + textArea.remove() + res() + } }) + .then(() => { + notifications.success("Copied to clipboard") + }) + .catch(() => { + notifications.error( + "Failed to copy to clipboard. Check the dev console for the value." + ) + console.warn("Failed to copy the value", value) + }) } From a2a3b276d068835237dbcbb808d666e89ffe8034 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 4 Feb 2022 08:50:56 +0000 Subject: [PATCH 2/2] Add default value for relationship fields --- packages/client/manifest.json | 5 +++++ .../components/app/forms/RelationshipField.svelte | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 04ffdffa21..1b83577564 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -2537,6 +2537,11 @@ "label": "Placeholder", "key": "placeholder" }, + { + "type": "text", + "label": "Default value", + "key": "defaultValue" + }, { "type": "boolean", "label": "Autocomplete", diff --git a/packages/client/src/components/app/forms/RelationshipField.svelte b/packages/client/src/components/app/forms/RelationshipField.svelte index dbf708f893..e36e438db7 100644 --- a/packages/client/src/components/app/forms/RelationshipField.svelte +++ b/packages/client/src/components/app/forms/RelationshipField.svelte @@ -12,6 +12,7 @@ export let disabled = false export let validation export let autocomplete = false + export let defaultValue let fieldState let fieldApi @@ -27,6 +28,7 @@ $: singleValue = flatten(fieldState?.value)?.[0] $: multiValue = flatten(fieldState?.value) ?? [] $: component = multiselect ? CoreMultiselect : CoreSelect + $: expandedDefaultValue = expand(defaultValue) const fetchTable = async id => { if (id) { @@ -62,6 +64,16 @@ const multiHandler = e => { fieldApi.setValue(e.detail) } + + const expand = values => { + if (!values) { + return [] + } + if (Array.isArray(values)) { + return values + } + return values.split(",").map(value => value.trim()) + } {#if fieldState}