Skip to content

Commit

Permalink
Add clipboard button (home-assistant#8411)
Browse files Browse the repository at this point in the history
  • Loading branch information
KTibow committed Feb 24, 2021
1 parent 13ac14d commit f42c0a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/panels/developer-tools/state/developer-tools-state.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import "@material/mwc-button";
import { mdiInformationOutline } from "@mdi/js";
import {
mdiInformationOutline,
mdiClipboardTextMultipleOutline
} from "@mdi/js";
import "@polymer/paper-checkbox/paper-checkbox";
import "@polymer/paper-input/paper-input";
import { html } from "@polymer/polymer/lib/utils/html-tag";
Expand All @@ -15,6 +18,7 @@ import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
import { EventsMixin } from "../../../mixins/events-mixin";
import LocalizeMixin from "../../../mixins/localize-mixin";
import "../../../styles/polymer-ha-style";
import { copyToClipboard } from "../../../common/util/copy-clipboard";

const ERROR_SENTINEL = {};
/*
Expand Down Expand Up @@ -205,6 +209,12 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
title="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]"
path="[[informationOutlineIcon()]]"
></ha-svg-icon>
<ha-svg-icon
on-click="copyEntity"
alt="[[localize('ui.panel.developer-tools.tabs.states.copy_id')]]"
title="[[localize('ui.panel.developer-tools.tabs.states.copy_id')]]"
path="[[clipboardOutlineIcon()]]"
></ha-svg-icon>
<a href="#" on-click="entitySelected">[[entity.entity_id]]</a>
</td>
<td>
Expand Down Expand Up @@ -296,6 +306,11 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
};
}

copyEntity(ev) {
ev.preventDefault();
copyToClipboard(ev.model.entity.entity_id);
}

entitySelected(ev) {
const state = ev.model.entity;
this._entityId = state.entity_id;
Expand Down Expand Up @@ -345,6 +360,10 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
return mdiInformationOutline;
}

clipboardOutlineIcon() {
return mdiClipboardTextMultipleOutline;
}

computeEntities(hass, _entityFilter, _stateFilter, _attributeFilter) {
return Object.keys(hass.states)
.map(function (key) {
Expand Down
3 changes: 2 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,8 @@
"more_info": "More Info",
"alert_entity_field": "Entity is a mandatory field",
"last_updated": "[%key:ui::dialogs::more_info_control::last_updated%]",
"last_changed": "[%key:ui::dialogs::more_info_control::last_changed%]"
"last_changed": "[%key:ui::dialogs::more_info_control::last_changed%]",
"copy_id": "Copy ID to clipboard"
},
"templates": {
"title": "Template",
Expand Down

0 comments on commit f42c0a0

Please sign in to comment.