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

MAINT: add copy button to properties table #898

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions core/src/zeit/cms/repository/browser/property.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import html

import zc.table.column
import zc.table.interfaces
import zope.interface
Expand All @@ -11,6 +13,23 @@ class GetterColumn(zc.table.column.GetterColumn):
pass


class ActionsColumn(zc.table.column.Column):
def renderCell(self, item, formatter):
selector = f'copy_{item[0][0]}'
copy_translation = _('Copy')
return (
f'<pre style="display: none" id="{selector}">'
f'{html.escape(str(item[1]))}'
f'</pre>'
f'<button style="display: flex" onclick="'
f"try{{navigator.clipboard.writeText(document.getElementById('{selector}').textContent);}}"
f'catch(e){{console.error(e);}}">'
f'<img src="/fanstatic/zeit.cms/icons/insert.png"/>'
f'{copy_translation}'
f'</button>'
)


class MetadataColumn(GetterColumn):
def __init__(self):
super().__init__(title='')
Expand All @@ -30,6 +49,7 @@ class Listing(zeit.cms.browser.listing.Listing):
GetterColumn(title=_('Namespace'), getter=lambda t, c: t[0][1]),
GetterColumn(title=_('Name'), getter=lambda t, c: t[0][0]),
GetterColumn(title=_('Value'), getter=lambda t, c: str(t[1])),
ActionsColumn(title=_('Actions')),
MetadataColumn(),
)

Expand Down
Loading