-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up copy/pasting of tabular content in EuiDataGrid and EuiBasic/…
…InMemoryTable (#8019)
- Loading branch information
Showing
41 changed files
with
1,380 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Enhanced `EuiDataGrid` and `EuiBasic/InMemoryTable` to clean content newlines/tabs when users copy and paste from their tabular data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
const selectAndCopy = (selectorToCopy: string) => { | ||
// Force Chrome devtools to allow reading from the clipboard | ||
cy.wrap( | ||
Cypress.automation('remote:debugger:protocol', { | ||
command: 'Browser.grantPermissions', | ||
params: { | ||
permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'], | ||
origin: window.location.origin, | ||
}, | ||
}) | ||
); | ||
|
||
// For some annoying reason, mocking selection+copying throws a bunch | ||
// of document errors from the code coverage reporter - just ignore them | ||
Cypress.on('uncaught:exception', (err) => { | ||
console.log(err.message); | ||
if ( | ||
err.message.includes( | ||
"Cannot read properties of null (reading 'document')" | ||
) | ||
) { | ||
return false; | ||
} | ||
}); | ||
|
||
cy.get(selectorToCopy).then(($el) => { | ||
const el = $el[0]; | ||
const document = el.ownerDocument; | ||
const range = document.createRange(); | ||
range.selectNodeContents(el); | ||
document.getSelection()!.removeAllRanges(); | ||
document.getSelection()!.addRange(range); | ||
}); | ||
|
||
return cy.window().then((window) => { | ||
document.execCommand('copy'); | ||
return window.navigator.clipboard.readText(); | ||
}); | ||
}; | ||
|
||
Cypress.Commands.add('selectAndCopy', selectAndCopy); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.