DevTools: Navigate to History from last changed/last updated (#11133)

This commit is contained in:
Kuba Wolanin 2022-01-14 17:01:39 +01:00 committed by GitHub
parent ed462dc257
commit 6053b64b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
import { addHours } from "date-fns";
import "@material/mwc-button";
import {
mdiClipboardTextMultipleOutline,
@ -200,12 +201,18 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
<p>
<b
>[[localize('ui.panel.developer-tools.tabs.states.last_changed')]]:</b
><br />[[lastChangedString(_entity)]]
><br />
<a href="[[historyFromLastChanged(_entity)]]"
>[[lastChangedString(_entity)]]</a
>
</p>
<p>
<b
>[[localize('ui.panel.developer-tools.tabs.states.last_updated')]]:</b
><br />[[lastUpdatedString(_entity)]]
><br />
<a href="[[historyFromLastUpdated(_entity)]]"
>[[lastUpdatedString(_entity)]]</a
>
</p>
</template>
</div>
@ -407,6 +414,20 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
this._expanded = true;
}
_getHistoryURL(entityId, inputDate) {
const date = new Date(inputDate);
const hourBefore = addHours(date, -1).toISOString();
return `/history?entity_id=${entityId}&start_date=${hourBefore}`;
}
historyFromLastChanged(entity) {
return this._getHistoryURL(entity.entity_id, entity.last_changed);
}
historyFromLastUpdated(entity) {
return this._getHistoryURL(entity.entity_id, entity.last_updated);
}
expandedChanged(ev) {
this._expanded = ev.detail.expanded;
}