Skip to content
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

Add copy button #1073

Merged
merged 28 commits into from
Nov 25, 2021
Merged

Add copy button #1073

merged 28 commits into from
Nov 25, 2021

Conversation

rogermparent
Copy link
Contributor

@rogermparent rogermparent commented Nov 20, 2021

#1072 <- this

This PR adds a copy button similar to DVC Studio, lifting the svg from Studio to do so (and adding inline SVG support to the webview in the process).

Instead of indicating via notification (either by triggering a VSCode notification or adding a notification to the webview), this PR uses strategy of temporarily transforming the copy icon into a checkmark upon successful copy.

Example:

copy-button-demo.mp4

Sha and timestamp do not have this copy button, but this is also the case in Studio. This wasn't intentional, those cells are just processed differently from the normal ones. I can add the copy button to these cells if we'd like.

The last copying demonstration shows that there is no timer chaos when rapidly clicking the copy button, it's hard to portray on video alone. This specific behavior also has a unit test.

This PR uses svgr to turn the copy svg into a React component, the primary advantage being it can use currentColor to take on a theme color without needing any alternate versions:

light mode

Since this is mutually exclusive with the types/inline way of importing svgs, this PR configures Webpack to look for a ?svgr import query parameter to engage svgr on a per-import basis. If we want to make all svg imports consistent, I can make a follow-up PR to use svgr for all of them and change Webpack to not require the query. I'm fine either way, LMK what you think.
This PR now uses the CLI svgr to preprocess svgs, so no webpack shenanigans are required

Overall, I think it'll need a bit of tweaking- the unicode checkmarks may need to be changed to something else as well- I opted against making them green to make sure no theme would clash with them.

fixes #876

@rogermparent rogermparent linked an issue Nov 20, 2021 that may be closed by this pull request
@rogermparent rogermparent self-assigned this Nov 22, 2021
@rogermparent rogermparent added the product PR that affects product label Nov 22, 2021
Base automatically changed from refactor-table-cells to master November 22, 2021 20:59
webview/.storybook/main.ts Outdated Show resolved Hide resolved
@rogermparent rogermparent marked this pull request as ready for review November 23, 2021 00:46
.codeclimate.json Outdated Show resolved Hide resolved
webview/.storybook/main.ts Outdated Show resolved Hide resolved
webview/jest.config.js Outdated Show resolved Hide resolved
Comment on lines +42 to +44
.catch(() => {
setState(CopyButtonState.FAILURE)
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't know if this can even happen. In a browser clipboard.writeText rejects when the caller doesn't have permission to use the clipboard, but I don't think that's a thing in VSCode or Electron.

Still, just ignoring the error state makes me a tad uneasy. Open to other opinions.

webview/src/experiments/components/Table/copy.svg Outdated Show resolved Hide resolved
Comment on lines +26 to +29
const displayValue =
typeof value === 'number' && !Number.isInteger(value)
? formatFloat(value as number)
: String(value)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want to copy the raw or transformed value, it seems like studio uses what's displayed in the cell but maybe that's just the projects I'm viewing in it. Regardless, this is where it gets changed.

webview/webpack.config.ts Outdated Show resolved Hide resolved
const { test, ...rest } = existingSvgRule
const newSvgRule = {
test,
oneOf: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Q] Can this match the existing webpack config? Then we could export a function from there and use it here. Would mean that we are in some way testing the actual config against storybook. Might not be possible, but would be good to try.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had considered that, I'll try it out using our real webpack config in a follow-up PR. Changing to preprocessing SVGs will remove this so the two tasks will be more isolated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1085 is opened for this, it seems to work fine though obviously it's much less warranted given this PR doesn't add Webpack SVG logic anymore.

@@ -57,7 +58,7 @@ $spinner-color-light: #000;
}

.bullet {
color: var(--vscode-editor-foreground);
color: $fg-color;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a sense, at most only slightly related.

PR adds new styling rule that uses FG color -> add FG variable for consistency -> use FG variable. These kinds of refactors can wait for another PR though, so I'll clean it up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is reversed, I'll make a PR in the future dedicated solely to making the use of scss variables more consistent.

@codeclimate
Copy link

codeclimate bot commented Nov 25, 2021

Code Climate has analyzed commit 31ba0a9 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (85% is the threshold).

This pull request will bring the total coverage in the repository to 96.6% (0.0% change).

View more on Code Climate.

@rogermparent rogermparent merged commit 4dc2aa1 into master Nov 25, 2021
@rogermparent rogermparent deleted the add-copy-button branch November 25, 2021 04:21
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14" width="16" height="16" class="tw-inline-block tw-flex-shrink-0 tw-pointer-events-none"><path fill="currentColor" fill-rule="evenodd" d="M9.83 5.38H6.6c-.67 0-1.22.55-1.22 1.22v3.23c0 .67.55 1.2 1.22 1.2h3.23c.67 0 1.2-.53 1.2-1.2V6.6c0-.67-.53-1.22-1.2-1.22zM6.6 4.18A2.42 2.42 0 004.17 6.6v3.23a2.42 2.42 0 002.43 2.42h3.23a2.42 2.42 0 002.42-2.42V6.6a2.42 2.42 0 00-2.42-2.43H6.6z" clip-rule="evenodd"></path><path fill="currentColor" fill-rule="evenodd" d="M4.15 2.95h3.2c.36 0 .68.16.9.4h1.38a2.4 2.4 0 00-2.27-1.6h-3.2a2.4 2.4 0 00-2.41 2.4v3.2a2.4 2.4 0 001.6 2.28V8.25a1.2 1.2 0 01-.4-.9v-3.2c0-.66.54-1.2 1.2-1.2z" clip-rule="evenodd"></path></svg>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are both copy and check icons available from the codicons. Should we use those?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we use the codicon check already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I can handle that changeover.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product PR that affects product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add copy action to the table cells on hover
3 participants