From 44b4ea0027e430a429e37effe0309af67814e29d Mon Sep 17 00:00:00 2001 From: "Ivan Hrynevytskyi (FE-underwriting)" <83350900+im-ihrynevytskyi@users.noreply.github.com> Date: Thu, 19 May 2022 14:04:00 +0300 Subject: [PATCH] added copy text tool to workflow defenition info (#3043) Co-authored-by: Ivan Hrynevytskyi --- .../src/components.d.ts | 2 +- .../src/components/shared/forms/info-list.tsx | 29 +++++++++++++---- .../elsa-workflows-designer/src/utils/copy.ts | 32 +++++++++++++++++++ .../src/utils/index.ts | 1 + 4 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 src/designer/elsa-workflows-designer/src/utils/copy.ts diff --git a/src/designer/elsa-workflows-designer/src/components.d.ts b/src/designer/elsa-workflows-designer/src/components.d.ts index 9fd21f1d5..0f60a1827 100644 --- a/src/designer/elsa-workflows-designer/src/components.d.ts +++ b/src/designer/elsa-workflows-designer/src/components.d.ts @@ -162,7 +162,7 @@ export namespace Components { } interface ElsaTooltip { "tooltipContent": any; - "tooltipPosition": string; + "tooltipPosition"?: string; } interface ElsaWorkflowDefinitionBrowser { "hide": () => Promise; diff --git a/src/designer/elsa-workflows-designer/src/components/shared/forms/info-list.tsx b/src/designer/elsa-workflows-designer/src/components/shared/forms/info-list.tsx index e67509e43..8fd2fb794 100644 --- a/src/designer/elsa-workflows-designer/src/components/shared/forms/info-list.tsx +++ b/src/designer/elsa-workflows-designer/src/components/shared/forms/info-list.tsx @@ -1,4 +1,5 @@ -import {FunctionalComponent, h} from "@stencil/core"; +import { FunctionalComponent, h } from '@stencil/core'; +import { copyTextToClipboard } from '../../../utils'; export interface InfoListProps { title: string; @@ -11,17 +12,33 @@ export const InfoList: FunctionalComponent = ({title, dictionary}
-

- {title} -

+

{title}

{Object.entries(dictionary).map(([k, v]) => (
{k}
-
{v}
-
))} +
+ {v} + copyTextToClipboard(v as string)} + class="cursor-pointer inline-block ml-2 h-6 w-6 text-blue-500" + width="24" + height="24" + viewBox="0 0 24 24" + stroke-width="2" + stroke="currentColor" + fill="none" + stroke-linecap="round" + stroke-linejoin="round" + > + + + +
+
+ ))}
diff --git a/src/designer/elsa-workflows-designer/src/utils/copy.ts b/src/designer/elsa-workflows-designer/src/utils/copy.ts new file mode 100644 index 000000000..dc25198b8 --- /dev/null +++ b/src/designer/elsa-workflows-designer/src/utils/copy.ts @@ -0,0 +1,32 @@ +function fallbackCopyTextToClipboard(text: string) { + const textArea = document.createElement('textarea'); + textArea.value = text; + + textArea.style.top = '0'; + textArea.style.left = '0'; + textArea.style.position = 'fixed'; + + document.body.appendChild(textArea); + + textArea.focus(); + textArea.select(); + + try { + document.execCommand('copy'); + } catch (err) { + console.error('Fallback: Oops, unable to copy', err); + } + + document.body.removeChild(textArea); +} + +export function copyTextToClipboard(text: string) { + if (!navigator.clipboard) { + fallbackCopyTextToClipboard(text); + return; + } + + navigator.clipboard.writeText(text).catch(function (err) { + console.error('Async: Could not copy text: ', err); + }); +} diff --git a/src/designer/elsa-workflows-designer/src/utils/index.ts b/src/designer/elsa-workflows-designer/src/utils/index.ts index 4608687ff..d3353fddf 100644 --- a/src/designer/elsa-workflows-designer/src/utils/index.ts +++ b/src/designer/elsa-workflows-designer/src/utils/index.ts @@ -1,3 +1,4 @@ export * from './download'; export * from './select-list-items'; export * from './utils'; +export * from './copy';