Skip to content

Commit e043ac3

Browse files
Fix copy to clipboard (#83)
* Fixed copying to clipboard * Fixed width for form and guide * Removed cancel button
1 parent e7e7cf9 commit e043ac3

File tree

9 files changed

+34
-96
lines changed

9 files changed

+34
-96
lines changed

etc/plugin-config-ui-lib.api.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,13 @@ export interface FormFieldResetProps {
381381
}
382382

383383
// @public
384-
export function FormFooter({ isUpdating, isSubmitting, isTestingConnection, testConnectionError, pluginKind, submitPayload, onCancel, onCancelTestConnection, onDelete, onGoToPreviousStep, onTestConnectionSuccess, submitLabel, submitDisabled, showPreviousStepButton, pluginName, teamName, testConnectionId, }: FormFooterProps): JSX_2.Element;
384+
export function FormFooter({ isUpdating, isSubmitting, isTestingConnection, testConnectionError, pluginKind, submitPayload, onCancelTestConnection, onDelete, onGoToPreviousStep, onTestConnectionSuccess, submitLabel, submitDisabled, showPreviousStepButton, pluginName, teamName, testConnectionId, }: FormFooterProps): JSX_2.Element;
385385

386386
// @public (undocumented)
387387
export interface FormFooterProps {
388388
isSubmitting: boolean;
389389
isTestingConnection: boolean;
390390
isUpdating: boolean;
391-
onCancel: () => void;
392391
onCancelTestConnection: () => void;
393392
onDelete: () => Promise<void>;
394393
onGoToPreviousStep: () => void;
@@ -926,7 +925,6 @@ export function useFormActions<PluginKind extends 'source' | 'destination'>({ ge
926925
apiBaseUrl?: string;
927926
}): {
928927
submitError: any;
929-
handleCancel: () => void;
930928
handleCancelTestConnection: () => void;
931929
handleDelete: () => Promise<void>;
932930
handleGoToPreviousStep: () => void;

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@cloudquery/plugin-config-ui-lib",
33
"description": "Plugin configuration UI library for CloudQuery Cloud App",
4-
"version": "7.0.0",
4+
"version": "7.0.1",
55
"private": false,
66
"main": "dist/index.cjs.js",
77
"module": "dist/index.esm.js",

src/components/display/codeSnippet/copyToClipboard.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@ export function CopyToClipboardButton({ sx, text }: Props) {
1515
const [wasCopied, setWasCopied] = useState(false);
1616

1717
const handleClick = () => {
18+
// Because the code is running in an iframe but elements
19+
// are rendered in the parent window, we need to create a button
20+
// to focus and click it to establish user activation
21+
const button = document.createElement('button');
22+
button.style.position = 'fixed';
23+
button.style.opacity = '0';
24+
button.style.pointerEvents = 'none';
25+
document.body.append(button);
26+
button.focus();
27+
button.click();
28+
1829
navigator.clipboard.writeText(text);
30+
31+
button.remove();
1932
setWasCopied(true);
2033
};
2134

src/components/display/formFooter/index.tsx

+9-23
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export interface FormFooterProps {
2222
pluginKind: 'source' | 'destination';
2323
/** Payload to be submitted, containing form values and connection ID */
2424
submitPayload: (FormValues & { connectionId: string }) | undefined;
25-
/** Callback to cancel the current action */
26-
onCancel: () => void;
2725
/** Callback to cancel the connection test */
2826
onCancelTestConnection: () => void;
2927
/** Callback to handle delete action */
@@ -60,7 +58,6 @@ export function FormFooter({
6058
testConnectionError,
6159
pluginKind,
6260
submitPayload,
63-
onCancel,
6461
onCancelTestConnection,
6562
onDelete,
6663
onGoToPreviousStep,
@@ -100,7 +97,7 @@ export function FormFooter({
10097
size="medium"
10198
variant="contained"
10299
>
103-
Delete this {pluginKind === 'source' ? 'integration' : 'destination'}
100+
Delete {pluginKind === 'source' ? 'integration' : 'destination'}
104101
</Button>
105102
)}
106103
{showPreviousStepButton && (
@@ -109,26 +106,15 @@ export function FormFooter({
109106
</Button>
110107
)}
111108
</Stack>
112-
<Stack
113-
direction="row"
114-
spacing={2}
115-
sx={{
116-
alignItems: 'center',
117-
}}
109+
<Button
110+
loading={isBusy}
111+
size="medium"
112+
variant="contained"
113+
type="submit"
114+
disabled={submitDisabled}
118115
>
119-
<Button disabled={isBusy} onClick={onCancel} size="medium">
120-
Cancel
121-
</Button>
122-
<Button
123-
loading={isBusy}
124-
size="medium"
125-
variant="contained"
126-
type="submit"
127-
disabled={submitDisabled}
128-
>
129-
{submitLabel || 'Test connection and save'}
130-
</Button>
131-
</Stack>
116+
{submitLabel || 'Test and save'}
117+
</Button>
132118
</Stack>
133119
{(isTestingConnection || testConnectionError || submitPayload) && (
134120
<FormFooterTestConnectionResult

src/components/form/configUIForm.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export function ConfigUIForm({ prepareSubmitValues, container }: ConfigUIFormPro
6868
useFormCurrentValues(pluginUiMessageHandler, getCurrentValues);
6969

7070
const {
71-
handleCancel,
7271
handleCancelTestConnection,
7372
handleDelete,
7473
handleGoToPreviousStep,
@@ -221,7 +220,7 @@ export function ConfigUIForm({ prepareSubmitValues, container }: ConfigUIFormPro
221220
<Box
222221
sx={{
223222
flex: '1 1 0',
224-
minWidth: 0,
223+
minWidth: 435,
225224
position: 'relative',
226225
zIndex: 2,
227226
}}
@@ -262,7 +261,6 @@ export function ConfigUIForm({ prepareSubmitValues, container }: ConfigUIFormPro
262261
isSubmitting={isSubmitting || submitGuardLoading}
263262
testConnectionError={parsedTestConnectionError}
264263
submitPayload={submitPayload}
265-
onCancel={handleCancel}
266264
onCancelTestConnection={handleCancelTestConnection}
267265
onTestConnectionSuccess={onTestConnectionSuccess}
268266
onDelete={handleDelete}
@@ -278,7 +276,12 @@ export function ConfigUIForm({ prepareSubmitValues, container }: ConfigUIFormPro
278276
</Box>
279277
<Box
280278
sx={{
281-
width: { xs: 360, lg: 500, xl: '40%' },
279+
width: {
280+
xs: 360,
281+
lg: `calc(50% - (${theme.spacing(5)} / 2))`,
282+
xl: '500px',
283+
xxl: '40%',
284+
},
282285
minWidth: 360,
283286
position: 'sticky',
284287
top: 10,

src/components/utils/cloudAppMock.tsx

-57
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
formMessageTypes,
1010
pluginUiMessageTypes,
1111
} from '@cloudquery/plugin-config-ui-connector';
12-
import Button from '@mui/material/Button';
1312
import Stack from '@mui/material/Stack';
1413
import Typography from '@mui/material/Typography';
1514

@@ -61,50 +60,8 @@ export function CloudAppMock({
6160
}: CloudAppMockProps) {
6261
const [testConnectionValues, setTestConnectionValues] = useState<Record<string, any>>();
6362
const [submitValues, setSubmitValues] = useState<Record<string, any>>();
64-
const [errors, setErrors] = useState<string>('');
6563
const searchParams = useMemo(() => new URLSearchParams(window.location.search), []);
6664

67-
const handleSubmit = async () => {
68-
formMessageHandler.sendMessage('validate');
69-
let unsubscribeValidationPassed: (() => void) | undefined;
70-
let unsubscribeValidationFailed: (() => void) | undefined;
71-
72-
formMessageHandler.sendMessage('is_busy', {
73-
status: true,
74-
});
75-
76-
try {
77-
const values = await new Promise((resolve, reject) => {
78-
unsubscribeValidationPassed = formMessageHandler.subscribeToMessageOnce(
79-
'validation_passed',
80-
({ values }) => {
81-
resolve(values);
82-
},
83-
);
84-
unsubscribeValidationFailed = formMessageHandler.subscribeToMessageOnce(
85-
'validation_failed',
86-
({ errors }) => reject(errors),
87-
);
88-
}).finally(() => {
89-
unsubscribeValidationPassed?.();
90-
unsubscribeValidationFailed?.();
91-
});
92-
93-
setErrors('');
94-
setSubmitValues(values as Record<string, any>);
95-
} catch (error) {
96-
unsubscribeValidationPassed?.();
97-
unsubscribeValidationFailed?.();
98-
99-
setSubmitValues(undefined);
100-
setErrors(JSON.stringify(error, null, 2));
101-
}
102-
103-
formMessageHandler.sendMessage('is_busy', {
104-
status: false,
105-
});
106-
};
107-
10865
useEffect(() => {
10966
formMessageHandler.sendMessage('init', {
11067
initialValues: initialValues
@@ -244,18 +201,6 @@ export function CloudAppMock({
244201
>
245202
{children}
246203
</Stack>
247-
<Stack
248-
direction="row"
249-
spacing={2}
250-
sx={{
251-
justifyContent: 'flex-end',
252-
padding: 2,
253-
}}
254-
>
255-
<Button onClick={handleSubmit} variant="contained">
256-
Submit
257-
</Button>
258-
</Stack>
259204
<Stack
260205
sx={{
261206
padding: 2,
@@ -273,8 +218,6 @@ export function CloudAppMock({
273218
<pre style={{ wordBreak: 'break-all', whiteSpace: 'break-spaces' }}>
274219
{JSON.stringify(submitValues, null, 2) || '-'}
275220
</pre>
276-
<div>Errors:</div>
277-
<pre style={{ wordBreak: 'break-all', whiteSpace: 'break-spaces' }}>{errors || '-'}</pre>
278221
</Stack>
279222
</>
280223
);

src/e2e-utils/plugin-ui-e2e-helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export const deletePlugin = async ({
174174
}),
175175
).toHaveValue(pluginNewName);
176176

177-
await iframeElement.getByRole('button', { name: `Delete this ${kind}` }).click();
177+
await iframeElement.getByRole('button', { name: `Delete ${kind}` }).click();
178178
await click(page, page.getByText(`Delete ${kind}`));
179179

180180
await expect(page.getByText(pluginNewName)).toHaveCount(0, { timeout: 15_000 });

src/hooks/useFormActions.ts

-5
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,12 @@ export function useFormActions<PluginKind extends 'source' | 'destination'>({
197197
pluginUiMessageHandler.sendMessage('go_to_previous_step');
198198
};
199199

200-
const handleCancel = () => {
201-
pluginUiMessageHandler.sendMessage('cancel');
202-
};
203-
204200
const handleDelete = async () => {
205201
pluginUiMessageHandler.sendMessage('delete');
206202
};
207203

208204
return {
209205
submitError,
210-
handleCancel,
211206
handleCancelTestConnection,
212207
handleDelete,
213208
handleGoToPreviousStep,

0 commit comments

Comments
 (0)