-
Notifications
You must be signed in to change notification settings - Fork 841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up copy/pasting of tabular content in EuiDataGrid and EuiBasic/InMemoryTable #8019
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
86d48a5
[setup] Create new `copy/` dir in services
cee-chen dc87591
Create copy service
cee-chen 1b617a8
[EuiDataGrid] Set up copy markers for row cells
cee-chen f0b7d6e
[EuiDataGrid] Set up copy markers for header columns/row
cee-chen 8f1fd8b
[EuiDataGrid] Fix footer rows not appending last/first column classes
cee-chen 8a3f6e1
[EuiBasicTable] Set up copy markers for table cells
cee-chen 44f9338
Add E2E Cypress tests for checking final copied content
cee-chen 7089f50
Fix failing Cypress test due to new copy marker DOM
cee-chen fedb57d
Fix bizarre typescript complaint
cee-chen 729f192
changelog
cee-chen 9a22861
[PR feedback] Use non-invisible characters to reduce likelihood of co…
cee-chen 1e749f2
Rename exported noCopy marker util
cee-chen 5024aa8
Merge branch 'main' into tabular-copying
cee-chen 424cc63
sad prettier noises
cee-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went down so many google/stackoverflow rabbit holes to figure out how to get this working haha 🫠 honestly until the very end I wasn't really sure it was going to be, but very glad to have a regression test for this!