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 button for copying CID to listing in gateway #9254

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

eli1797
Copy link
Contributor

@eli1797 eli1797 commented Sep 8, 2022

  • add icon button to gateway
  • add title so hover on short hash shows full CID
  • add test to core expecting copy cid button

Closes #8812

* add icon button to gateway
* add title so hover on short hash shows full CID
* add test to core expecting copy cid button
@eli1797
Copy link
Contributor Author

eli1797 commented Sep 8, 2022

#8812

Copy link
Contributor

@Jorropo Jorropo left a comment

Choose a reason for hiding this comment

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

Thx for tackling this. 🙂

I have some minor comments

Comment on lines 89 to 91
<button class="type-icon" title="Copy CID" onclick="copyText('{{ .Hash }}')">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 115.77 122.88" style="enable-background:new 0 0 115.77 122.88" xml:space="preserve"><style type="text/css">.st0{fill-rule:evenodd;clip-rule:evenodd;}</style><g><path class="st0" d="M89.62,13.96v7.73h12.19h0.01v0.02c3.85,0.01,7.34,1.57,9.86,4.1c2.5,2.51,4.06,5.98,4.07,9.82h0.02v0.02 v73.27v0.01h-0.02c-0.01,3.84-1.57,7.33-4.1,9.86c-2.51,2.5-5.98,4.06-9.82,4.07v0.02h-0.02h-61.7H40.1v-0.02 c-3.84-0.01-7.34-1.57-9.86-4.1c-2.5-2.51-4.06-5.98-4.07-9.82h-0.02v-0.02V92.51H13.96h-0.01v-0.02c-3.84-0.01-7.34-1.57-9.86-4.1 c-2.5-2.51-4.06-5.98-4.07-9.82H0v-0.02V13.96v-0.01h0.02c0.01-3.85,1.58-7.34,4.1-9.86c2.51-2.5,5.98-4.06,9.82-4.07V0h0.02h61.7 h0.01v0.02c3.85,0.01,7.34,1.57,9.86,4.1c2.5,2.51,4.06,5.98,4.07,9.82h0.02V13.96L89.62,13.96z M79.04,21.69v-7.73v-0.02h0.02 c0-0.91-0.39-1.75-1.01-2.37c-0.61-0.61-1.46-1-2.37-1v0.02h-0.01h-61.7h-0.02v-0.02c-0.91,0-1.75,0.39-2.37,1.01 c-0.61,0.61-1,1.46-1,2.37h0.02v0.01v64.59v0.02h-0.02c0,0.91,0.39,1.75,1.01,2.37c0.61,0.61,1.46,1,2.37,1v-0.02h0.01h12.19V35.65 v-0.01h0.02c0.01-3.85,1.58-7.34,4.1-9.86c2.51-2.5,5.98-4.06,9.82-4.07v-0.02h0.02H79.04L79.04,21.69z M105.18,108.92V35.65v-0.02 h0.02c0-0.91-0.39-1.75-1.01-2.37c-0.61-0.61-1.46-1-2.37-1v0.02h-0.01h-61.7h-0.02v-0.02c-0.91,0-1.75,0.39-2.37,1.01 c-0.61,0.61-1,1.46-1,2.37h0.02v0.01v73.27v0.02h-0.02c0,0.91,0.39,1.75,1.01,2.37c0.61,0.61,1.46,1,2.37,1v-0.02h0.01h61.7h0.02 v0.02c0.91,0,1.75-0.39,2.37-1.01c0.61-0.61,1-1.46,1-2.37h-0.02V108.92L105.18,108.92z"/></g></svg>
</button>
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if it's a dumb question, but where is this icon coming from ? Attribution and licenses ?

Copy link
Contributor Author

@eli1797 eli1797 Nov 11, 2022

Choose a reason for hiding this comment

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

will add an icon with attribution that's under the MIT license

{{ .ShortHash }}
</a>
<button class="type-icon" title="Copy CID" onclick="copyText('{{ .Hash }}')">
Copy link
Contributor

@Jorropo Jorropo Sep 22, 2022

Choose a reason for hiding this comment

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

This code is not future proof, if the CID was encoded with some fancy encoding that contains ' it may break the string in the future.
You should encode the string in json to properly escape it 🙂 (so I would do copyText({{ .Hash | jsonEncode }}) or something like this).

core/corehttp/gateway_test.go Outdated Show resolved Hide resolved
* add jsonEncode function to future-proof for encodings
* switch copy icon to url encoded svg in css
* remove test for template checking that hash coppy exists
Comment on lines +100 to +104
encodedStr, err := json.Marshal(rawString)
if err != nil {
panic(err)
}
return string(encodedStr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
encodedStr, err := json.Marshal(rawString)
if err != nil {
panic(err)
}
return string(encodedStr)
var builder strings.Builder
err := json.NewEncoder(&builder).Encode(rawString)
if err != nil {
panic(err)
}
return builder.String()

Comment on lines +127 to +131
encodedStr, err := json.Marshal(rawString)
if err != nil {
panic(err)
}
return string(encodedStr)
Copy link
Contributor

@Jorropo Jorropo Nov 12, 2022

Choose a reason for hiding this comment

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

Suggested change
encodedStr, err := json.Marshal(rawString)
if err != nil {
panic(err)
}
return string(encodedStr)
var builder strings.Builder
err := json.NewEncoder(&builder).Encode(rawString)
if err != nil {
panic(err)
}
return builder.String()

@@ -401,3 +401,10 @@
background-repeat:no-repeat;
background-size:contain
}

/* Source - https://icons.radix-ui.com/.org */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/* Source - https://icons.radix-ui.com/.org */
/* Source - https://icons.radix-ui.com/ */

?

@@ -97,3 +100,8 @@
</div>
</body>
</html>
<script>
function copyText(text) {
navigator.clipboard.writeText(text);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should JSON.parse(text) first no ?

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

Successfully merging this pull request may close these issues.

dir-index-html: ability to copy CIDs
2 participants