-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathdebug-dialog.html
191 lines (167 loc) · 5.32 KB
/
debug-dialog.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<template id="debug-dialog-template">
<style>
@import "css/style.css";
@import "css/toggle.css";
#logs-loading,
#logs-success {
display: none;
}
:host([state="logs-loading"]) #logs-loading,
:host([state="logs-success"]) #logs-success {
display: block;
}
.action-buttons {
display: flex;
flex-direction: row;
}
.action-buttons button {
margin: 0 1rem 0 0;
}
#logs-success .logs {
max-height: 600px;
}
.toggle-container {
display: flex;
align-items: center;
}
.toggle {
margin: 0 0.5rem;
}
</style>
<div id="logs-loading">
<h3>Retrieving Debug Logs</h3>
<progress-spinner></progress-spinner>
</div>
<div id="logs-success">
<h3>Debug Logs</h3>
<div class="action-buttons">
<share-logs-button id="share-logs-button"></share-logs-button>
<div style="flex: 1"><!-- Spacer --></div>
<div class="toggle-container">
Hide Sensitive Data
<label class="toggle">
<input type="checkbox" id="include-sensitive-data" />
<span class="toggle-slider"></span>
</label>
</div>
</div>
<p class="logs logs-output monospace"></p>
<button class="close-btn" type="button">Close</button>
</div>
</template>
<script type="module">
import {
DialogClosedEvent,
DialogFailedEvent,
DialogCloseStateChangedEvent,
} from "/js/events.js";
import { getDebugLogs } from "/js/controllers.js";
import { redactSensitiveData } from "/js/logs.js";
(function () {
const template = document.querySelector("#debug-dialog-template");
customElements.define(
"debug-dialog",
class DebugDialog extends HTMLElement {
_states = {
LOGS_LOADING: "logs-loading",
LOGS_SUCCESS: "logs-success",
};
_statesWithoutDialogClose = new Set([this._states.LOGS_LOADING]);
constructor() {
super();
this.attachShadow({ mode: "open" });
}
connectedCallback() {
this.shadowRoot.appendChild(template.content.cloneNode(true));
// Set the default to include sensitive data.
this.includeSensitiveData = true;
this._logText = {
original: null, // The text including all sensitive data as is.
redacted: null, // The text with sensitive data being redacted.
};
this._elements = {
includeSensitiveData: this.shadowRoot.getElementById(
"include-sensitive-data"
),
logsText: this.shadowRoot.querySelector("#logs-success .logs"),
shareLogsButton:
this.shadowRoot.querySelector("#share-logs-button"),
};
this.addEventListener("overlay-shown", () => this._initialize());
this._elements.includeSensitiveData.addEventListener(
"input",
(event) => {
this.includeSensitiveData = !event.target.checked;
this._renderLogDisplayText();
}
);
this.shadowRoot.querySelectorAll(".close-btn").forEach((el) => {
el.addEventListener("click", () =>
this.dispatchEvent(new DialogClosedEvent())
);
});
}
get _state() {
return this.getAttribute("state");
}
set _state(newValue) {
this.setAttribute("state", newValue);
this.dispatchEvent(
new DialogCloseStateChangedEvent(
!this._statesWithoutDialogClose.has(newValue)
)
);
}
set includeSensitiveData(isIncluded) {
if (isIncluded) {
this.setAttribute("include-sensitive-data", "");
} else {
this.removeAttribute("include-sensitive-data");
}
}
get includeSensitiveData() {
return this.hasAttribute("include-sensitive-data");
}
_initialize() {
this._state = this._states.LOGS_LOADING;
getDebugLogs()
.then((text) => {
this._logText = {
original: text,
redacted: redactSensitiveData(text),
};
this._renderLogDisplayText();
this._state = this._states.LOGS_SUCCESS;
})
.catch((error) => {
this.dispatchEvent(
new DialogFailedEvent({
title: "Error Retrieving Debug Logs",
details: error,
})
);
});
}
_getLogTextAsDisplayed() {
return this._elements.logsText.textContent;
}
/**
* (Re-)renders the log text panel, taking into account the current
* sensitivity settings.
* Note: calling this method will reset the state of the
* <share-logs-button> component, since the uploaded URL is stale when
* changing the logs display text.
*/
_renderLogDisplayText() {
const logsDisplayText = this.includeSensitiveData
? this._logText.original
: this._logText.redacted;
this._elements.logsText.textContent = logsDisplayText;
this._elements.shareLogsButton.initialize(
/*getLogsTextCb=*/ () => logsDisplayText
);
}
}
);
})();
</script>