Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix command z not working in connection string input (#63689)

Jakub Chodorowicz2be60d80c3b5
diff --git a/e2e/support/commands/ui/paste.ts b/e2e/support/commands/ui/paste.ts
index baf73dd29f5..6a4fc5b8ca0 100644
--- a/e2e/support/commands/ui/paste.ts
+++ b/e2e/support/commands/ui/paste.ts
@@ -1,19 +1,43 @@
+const nodes = {
+ INPUT: window.HTMLInputElement.prototype,
+ TEXTAREA: window.HTMLTextAreaElement.prototype,
+} as const;
+
+function getPrototype(
+ node: string,
+): (typeof nodes)[keyof typeof nodes] | undefined {
+ return nodes[node as keyof typeof nodes];
+}
+
Cypress.Commands.add(
"paste",
{ prevSubject: "element" },
(subject, text: string) => {
cy.wrap(subject).then(($element) => {
+ // Since Cypress cannot simulate native paste events, that are handled by React onChange,
+ // we need to set the value manually and dispatch a change event.
+ const nodeName = $element[0].nodeName;
+ const prototype = getPrototype(nodeName);
+
+ if (!prototype) {
+ throw new Error(`Unsupported node type: ${nodeName}`);
+ }
+
+ const nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(
+ prototype,
+ "value",
+ )?.set;
+ nativeTextAreaValueSetter?.call($element[0], text);
+ $element[0].dispatchEvent(new Event("change", { bubbles: true }));
+
+ // Let's dispatch the simulated paste event in case components have onPaste handlers.dfs
const clipboardData = new DataTransfer();
clipboardData.setData("text/plain", text);
-
const pasteEvent = new ClipboardEvent("paste", {
bubbles: true,
cancelable: true,
clipboardData,
});
-
- console.log({ $element, element: $element[0], pasteEvent });
-
$element[0].dispatchEvent(pasteEvent);
});
diff --git a/frontend/src/metabase/databases/components/DatabaseConnectionUri/DatabaseConnectionStringField.tsx b/frontend/src/metabase/databases/components/DatabaseConnectionUri/DatabaseConnectionStringField.tsx
index 4a3dae3a2c4..8b825e6c9f4 100644
--- a/frontend/src/metabase/databases/components/DatabaseConnectionUri/DatabaseConnectionStringField.tsx
+++ b/frontend/src/metabase/databases/components/DatabaseConnectionUri/DatabaseConnectionStringField.tsx
@@ -133,11 +133,6 @@ export function DatabaseConnectionStringField({
onChange={(event: React.ChangeEvent<HTMLTextAreaElement>) => {
setConnectionString(event.target.value);
}}
- onPaste={(event: React.ClipboardEvent<HTMLTextAreaElement>) => {
- event.preventDefault();
- const clipboardData = event.clipboardData.getData("Text");
- setConnectionString(clipboardData);
- }}
mb="md"
placeholder={placeholder}
name="connection-string"