Skip to content

Commit cc417f4

Browse files
committed
improve the copy to clipboard flow
1 parent 59ccff9 commit cc417f4

3 files changed

Lines changed: 64 additions & 35 deletions

File tree

src/components/molecules/flow/nodes/RequestBody.js

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Fragment, useState, useRef } from 'react';
22
import { PropTypes } from 'prop-types';
33
import { EllipsisVerticalIcon } from '@heroicons/react/24/solid';
4-
import { DocumentArrowUpIcon, ClipboardDocumentCheckIcon } from '@heroicons/react/24/outline';
4+
import { DocumentArrowUpIcon, ClipboardDocumentCheckIcon, ClipboardDocumentIcon } from '@heroicons/react/24/outline';
55
import { Menu, Transition } from '@headlessui/react';
66
import useCanvasStore from 'stores/CanvasStore';
77
import { toast } from 'react-toastify';
@@ -22,9 +22,7 @@ const RequestBody = ({ nodeId, nodeData }) => {
2222
const setRequestNodeBody = useCanvasStore((state) => state.setRequestNodeBody);
2323
const [cachedValues, setCachedValues] = React.useState({});
2424

25-
const [textToCopy, setTextToCopy] = useState(nodeData.requestBody.body); // The text you want to copy
2625
const [copyStatus, setCopyStatus] = useState(false); // To indicate if the text was copied
27-
const [showCopiedToClipboardToolTip, setShowCopiedToClipboardToolTip] = useState(false);
2826

2927
const uploadFileForRequestNode = useRef(null);
3028

@@ -73,7 +71,7 @@ const RequestBody = ({ nodeId, nodeData }) => {
7371
});
7472
};
7573

76-
const handleRawJson = async (value) => {
74+
const handleRawJson = (value) => {
7775
setRequestNodeBody(nodeId, 'raw-json', value);
7876
};
7977

@@ -114,13 +112,6 @@ const RequestBody = ({ nodeId, nodeData }) => {
114112
return [];
115113
};
116114

117-
const onCopyText = () => {
118-
setCopyStatus(true);
119-
setShowCopiedToClipboardToolTip(true);
120-
setTimeout(() => setCopyStatus(false), 2000); // Reset status after 2 seconds
121-
setTimeout(() => setShowCopiedToClipboardToolTip(false), 2000); // Reset status after 2 seconds
122-
};
123-
124115
return (
125116
<>
126117
<div className='flex items-center justify-between bg-background p-4'>
@@ -164,26 +155,30 @@ const RequestBody = ({ nodeId, nodeData }) => {
164155
<div className='relative bg-background-lighter'>
165156
<Editor
166157
name='request-body-json'
167-
onChange={async (e) => {
168-
await handleRawJson(e);
169-
setTextToCopy(e);
170-
}}
158+
onChange={(e) => handleRawJson(e)}
171159
value={nodeData.requestBody.body}
172160
classes={'w-full max-h-96'}
173161
completionOptions={getActiveVariables()}
174162
/>
175163

176164
<div className='absolute right-5 top-0 cursor-pointer text-slate-400 hover:text-cyan-900'>
177-
<CopyToClipboard text={textToCopy} onCopy={onCopyText}>
165+
<CopyToClipboard
166+
text={nodeData.requestBody.body}
167+
onCopy={() => {
168+
setCopyStatus(true);
169+
setTimeout(() => setCopyStatus(false), 2000); // Reset status after 2 seconds
170+
}}
171+
>
178172
<button>
179-
<Tippy
180-
content='Copied to Clipboard'
181-
placement='top'
182-
visible={showCopiedToClipboardToolTip}
183-
onClickOutside={() => setShowCopiedToClipboardToolTip(false)}
184-
>
185-
<ClipboardDocumentCheckIcon className='h-6 w-6' />
186-
</Tippy>
173+
{copyStatus ? (
174+
<Tippy content='Copied to Clipboard' placement='top'>
175+
<ClipboardDocumentCheckIcon className='h-6 w-6' />
176+
</Tippy>
177+
) : (
178+
<Tippy content='Copy to Clipboard' placement='top'>
179+
<ClipboardDocumentIcon className='h-6 w-6' />
180+
</Tippy>
181+
)}
187182
</button>
188183
</CopyToClipboard>
189184
</div>

src/components/molecules/headers/TabPanelHeader.js

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import HorizontalDivider from 'components/atoms/common/HorizontalDivider';
1616
import { JsonView, allExpanded, collapseAllNested, darkStyles, defaultStyles } from 'react-json-view-lite';
1717
import 'react-json-view-lite/dist/index.css';
1818
import { LogLevel } from '../flow/graph/GraphLogger';
19+
import { ShieldCheckIcon, BarsArrowUpIcon, ExclamationTriangleIcon } from '@heroicons/react/24/outline';
1920
import GenAIUsageDisclaimer from '../modals/GenAIUsageDisclaimer';
2021
import { getLocalStorageItem } from 'utils/common';
2122

@@ -37,6 +38,34 @@ const TabPanelHeader = () => {
3738
const [genAiUsageDisclaimerModalOpen, setGenAiUsageDisclaimerModalOpen] = useState(false);
3839
const [generateFlowTestModalOpen, setGenerateFlowTestModalOpen] = useState(false);
3940

41+
const renderFlowScan = (flowScan) => {
42+
if (flowScan.upload === 'disabled') {
43+
return (
44+
<div className='flex flex-col items-start'>
45+
<Tippy content={flowScan.message} placement='top'>
46+
<BarsArrowUpIcon className='h-4 w-4' />
47+
</Tippy>
48+
{'Activate Flow Scan'}
49+
</div>
50+
);
51+
} else if (flowScan.upload === 'success') {
52+
return (
53+
<div className='flex flex-col items-start'>
54+
<ShieldCheckIcon className='h-4 w-4' />
55+
{flowScan.url}
56+
</div>
57+
);
58+
} else if (flowScan.upload === 'fail') {
59+
return (
60+
<div className='flex flex-col items-start'>
61+
<ExclamationTriangleIcon className='h-4 w-4' />
62+
{flowScan.message}
63+
{flowScan?.reason}
64+
</div>
65+
);
66+
}
67+
};
68+
4069
const renderLog = (log) => {
4170
if (log.logLevel === LogLevel.INFO) {
4271
let message = '';
@@ -47,28 +76,30 @@ const TabPanelHeader = () => {
4776

4877
if (log.node != undefined) {
4978
const type = log.node.type;
79+
const data = log.node.data;
5080
if (type === 'outputNode') {
5181
json = {
52-
output: log.node.data,
82+
output: data.output,
5383
};
5484
}
5585

86+
if (type === 'authNode') {
87+
message = `${data.authType}`;
88+
}
89+
5690
if (type === 'assertNode') {
57-
const data = log.node.data;
5891
message = `Assert : ${data.var1} of type ${typeof data.var1} ${data.operator} ${data.var2} of type ${typeof data.var2} = ${data.result}`;
5992
}
6093

6194
if (type === 'delayNode') {
62-
message = `Waiting for ${log.node.data} ms`;
95+
message = `Waiting for ${data.delay} ms`;
6396
}
6497

6598
if (type === 'setVarNode') {
66-
const data = log.node.data;
6799
message = `Setting Variable: ${data.name} = ${data.value}`;
68100
}
69101

70102
if (type === 'requestNode') {
71-
const data = log.node.data;
72103
message = `${data.request.type.toUpperCase()} ${data.request.url}`;
73104
json = data;
74105
}
@@ -142,7 +173,7 @@ const TabPanelHeader = () => {
142173
<div className='flex h-12 items-center justify-center'>
143174
<SaveFlowModal tab={focusTab} />
144175
</div>
145-
{focusTab.type === OBJ_TYPES.flowtest && graphRunLogs.length != 0 ? (
176+
{focusTab.type === OBJ_TYPES.flowtest && focusTab.run.logs && focusTab.run.logs.length != 0 ? (
146177
<div>
147178
<Button
148179
id='graph-logs-side-sheet'
@@ -186,7 +217,8 @@ const TabPanelHeader = () => {
186217
className='drawer-overlay'
187218
></label>
188219
<ul className='menu min-h-full bg-base-200 p-4 text-base-content'>
189-
{graphRunLogs.map((item, index) => (
220+
<li key='scan'>{renderFlowScan(focusTab.run.scan)}</li>
221+
{focusTab.run.logs.map((item, index) => (
190222
<li key={index}>{renderLog(item)}</li>
191223
))}
192224
</ul>

src/components/molecules/modals/GenerateFlowTestModal.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Fragment, useState } from 'react';
1+
import React, { Fragment, useState, useEffect } from 'react';
22
import { PropTypes } from 'prop-types';
33
import { Dialog, Transition, Listbox } from '@headlessui/react';
44
import Button from 'components/atoms/common/Button';
@@ -35,9 +35,7 @@ const GenerateFlowTestModal = ({ closeFn = () => null, open = false, collectionI
3535
const [bedrockSecretAccessKey, setBedrockSecretAccessKey] = useState('');
3636

3737
const [flowtestName, setFlowtestName] = useState('');
38-
const [selectedCollection, setSelectionCollection] = useState(
39-
collectionId ? collections.find((c) => c.id === collectionId) : {},
40-
);
38+
const [selectedCollection, setSelectionCollection] = useState({});
4139
const [selectedFolder, setSelectedFolder] = useState('');
4240

4341
// Error flags
@@ -50,6 +48,10 @@ const GenerateFlowTestModal = ({ closeFn = () => null, open = false, collectionI
5048
const [showBedrockSecretAccessKeyError, setShowBedrockSecretAccessKeyError] = useState(false);
5149
//const [showFolderSelectionError, setShowFolderSelectionError] = useState(false);
5250

51+
useEffect(() => {
52+
setSelectionCollection(collectionId ? collections.find((c) => c.id === collectionId) : {});
53+
}, [collectionId]);
54+
5355
const resetFields = () => {
5456
if (!collectionId) {
5557
setFlowtestName('');

0 commit comments

Comments
 (0)