Skip to content

Commit 370f47a

Browse files
Split logging (openscd#1334)
* Chore: Renamed Logging to Historing * Fixed tests * Fixed german translation * Update packages/open-scd/src/Historing.ts Co-authored-by: Juan Munoz <[email protected]> --------- Co-authored-by: Juan Munoz <[email protected]>
1 parent 74fa468 commit 370f47a

24 files changed

+372
-140
lines changed

packages/open-scd/src/Logging.ts renamed to packages/open-scd/src/Historing.ts

Lines changed: 140 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ import { Snackbar } from '@material/mwc-snackbar';
2121

2222
import './filtered-list.js';
2323
import {
24+
CommitDetail,
2425
CommitEntry,
2526
ifImplemented,
27+
InfoDetail,
28+
InfoEntry,
2629
invert,
2730
IssueDetail,
2831
IssueEvent,
@@ -40,7 +43,6 @@ const icons = {
4043
info: 'info',
4144
warning: 'warning',
4245
error: 'report',
43-
action: 'history',
4446
};
4547

4648
function getPluginName(src: string): string {
@@ -66,13 +68,18 @@ function getPluginName(src: string): string {
6668
* Renders the `history` to `logUI` and the latest `'error'` [[`LogEntry`]] to
6769
* `messageUI`.
6870
*/
69-
export type LoggingElement = Mixin<typeof Logging>;
71+
export type HistoringElement = Mixin<typeof Historing>;
7072

71-
export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
72-
class LoggingElement extends Base {
73+
export function Historing<TBase extends LitElementConstructor>(Base: TBase) {
74+
class HistoringElement extends Base {
7375
/** All [[`LogEntry`]]s received so far through [[`LogEvent`]]s. */
7476
@property({ type: Array })
75-
history: LogEntry[] = [];
77+
log: InfoEntry[] = [];
78+
79+
/** All [[`CommitEntry`]]s received so far through [[`LogEvent`]]s */
80+
@property({ type: Array })
81+
history: CommitEntry[] = [];
82+
7683
/** Index of the last [[`EditorAction`]] applied. */
7784
@property({ type: Number })
7885
editCount = -1;
@@ -82,6 +89,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
8289
latestIssue!: IssueDetail;
8390

8491
@query('#log') logUI!: Dialog;
92+
@query('#history') historyUI!: Dialog;
8593
@query('#diagnostic') diagnosticUI!: Dialog;
8694
@query('#error') errorUI!: Snackbar;
8795
@query('#warning') warningUI!: Snackbar;
@@ -140,16 +148,10 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
140148
return true;
141149
}
142150

143-
private onLog(le: LogEvent): void {
144-
if (le.detail.kind === 'reset') {
145-
this.history = [];
146-
this.editCount = -1;
147-
return;
148-
}
149-
150-
const entry: LogEntry = {
151+
private onHistory(detail: CommitDetail) {
152+
const entry: CommitEntry = {
151153
time: new Date(),
152-
...le.detail,
154+
...detail,
153155
};
154156

155157
if (entry.kind === 'action') {
@@ -160,22 +162,51 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
160162
}
161163

162164
this.history.push(entry);
165+
this.requestUpdate('history', []);
166+
}
167+
168+
private onReset() {
169+
this.log = [];
170+
this.history = [];
171+
this.editCount = -1;
172+
}
173+
174+
private onInfo(detail: InfoDetail) {
175+
const entry: InfoEntry = {
176+
time: new Date(),
177+
...detail,
178+
};
179+
180+
this.log.push(entry);
163181
if (!this.logUI.open) {
164182
const ui = {
165183
error: this.errorUI,
166184
warning: this.warningUI,
167185
info: this.infoUI,
168-
action: this.infoUI,
169-
}[le.detail.kind];
186+
}[detail.kind];
170187

171188
ui.close();
172189
ui.show();
173190
}
174-
if (le.detail.kind == 'error') {
191+
if (detail.kind == 'error') {
175192
this.errorUI.close(); // hack to reset timeout
176193
this.errorUI.show();
177194
}
178-
this.requestUpdate('history', []);
195+
this.requestUpdate('log', []);
196+
}
197+
198+
private onLog(le: LogEvent): void {
199+
switch (le.detail.kind) {
200+
case 'reset':
201+
this.onReset();
202+
break;
203+
case 'action':
204+
this.onHistory(le.detail);
205+
break;
206+
default:
207+
this.onInfo(le.detail);
208+
break;
209+
}
179210
}
180211

181212
async performUpdate() {
@@ -197,7 +228,36 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
197228
}
198229

199230
renderLogEntry(
200-
entry: LogEntry,
231+
entry: InfoEntry,
232+
index: number,
233+
log: LogEntry[]
234+
): TemplateResult {
235+
return html` <abbr title="${entry.title}">
236+
<mwc-list-item
237+
class="${entry.kind}"
238+
graphic="icon"
239+
?twoline=${!!entry.message}
240+
?activated=${this.editCount == log.length - index - 1}
241+
>
242+
<span>
243+
<!-- FIXME: replace tt with mwc-chip asap -->
244+
<tt>${entry.time?.toLocaleString()}</tt>
245+
${entry.title}</span
246+
>
247+
<span slot="secondary">${entry.message}</span>
248+
<mwc-icon
249+
slot="graphic"
250+
style="--mdc-theme-text-icon-on-background:var(${ifDefined(
251+
iconColors[entry.kind]
252+
)})"
253+
>${icons[entry.kind]}</mwc-icon
254+
>
255+
</mwc-list-item></abbr
256+
>`;
257+
}
258+
259+
renderHistoryEntry(
260+
entry: CommitEntry,
201261
index: number,
202262
history: LogEntry[]
203263
): TemplateResult {
@@ -219,18 +279,31 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
219279
style="--mdc-theme-text-icon-on-background:var(${ifDefined(
220280
iconColors[entry.kind]
221281
)})"
222-
>${icons[entry.kind]}</mwc-icon
282+
>history</mwc-icon
223283
>
224284
</mwc-list-item></abbr
225285
>`;
226286
}
227287

288+
private renderLog(): TemplateResult[] | TemplateResult {
289+
if (this.log.length > 0)
290+
return this.log.slice().reverse().map(this.renderLogEntry, this);
291+
else
292+
return html`<mwc-list-item disabled graphic="icon">
293+
<span>${translate('log.placeholder')}</span>
294+
<mwc-icon slot="graphic">info</mwc-icon>
295+
</mwc-list-item>`;
296+
}
297+
228298
private renderHistory(): TemplateResult[] | TemplateResult {
229299
if (this.history.length > 0)
230-
return this.history.slice().reverse().map(this.renderLogEntry, this);
300+
return this.history
301+
.slice()
302+
.reverse()
303+
.map(this.renderHistoryEntry, this);
231304
else
232305
return html`<mwc-list-item disabled graphic="icon">
233-
<span>${translate('log.placeholder')}</span>
306+
<span>${translate('history.placeholder')}</span>
234307
<mwc-icon slot="graphic">info</mwc-icon>
235308
</mwc-list-item>`;
236309
}
@@ -281,6 +354,42 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
281354
);
282355
}
283356

357+
private renderLogDialog(): TemplateResult {
358+
return html` <mwc-dialog id="log" heading="${translate('log.name')}">
359+
${this.renderFilterButtons()}
360+
<mwc-list id="content" wrapFocus>${this.renderLog()}</mwc-list>
361+
<mwc-button slot="primaryAction" dialogaction="close"
362+
>${translate('close')}</mwc-button
363+
>
364+
</mwc-dialog>`;
365+
}
366+
367+
private renderHistoryDialog(): TemplateResult {
368+
return html` <mwc-dialog
369+
id="history"
370+
heading="${translate('history.name')}"
371+
>
372+
<mwc-list id="content" wrapFocus>${this.renderHistory()}</mwc-list>
373+
<mwc-button
374+
icon="undo"
375+
label="${translate('undo')}"
376+
?disabled=${!this.canUndo}
377+
@click=${this.undo}
378+
slot="secondaryAction"
379+
></mwc-button>
380+
<mwc-button
381+
icon="redo"
382+
label="${translate('redo')}"
383+
?disabled=${!this.canRedo}
384+
@click=${this.redo}
385+
slot="secondaryAction"
386+
></mwc-button>
387+
<mwc-button slot="primaryAction" dialogaction="close"
388+
>${translate('close')}</mwc-button
389+
>
390+
</mwc-dialog>`;
391+
}
392+
284393
render(): TemplateResult {
285394
return html`${ifImplemented(super.render())}
286395
<style>
@@ -298,13 +407,9 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
298407
#log > mwc-icon-button-toggle:nth-child(4) {
299408
right: 158px;
300409
}
301-
#log > mwc-icon-button-toggle:nth-child(5) {
302-
right: 206px;
303-
}
304410
#content mwc-list-item.info,
305411
#content mwc-list-item.warning,
306-
#content mwc-list-item.error,
307-
#content mwc-list-item.action {
412+
#content mwc-list-item.error {
308413
display: none;
309414
}
310415
#infofilter[on] ~ #content mwc-list-item.info {
@@ -316,9 +421,6 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
316421
#errorfilter[on] ~ #content mwc-list-item.error {
317422
display: flex;
318423
}
319-
#actionfilter[on] ~ #content mwc-list-item.action {
320-
display: flex;
321-
}
322424
323425
#infofilter[on] {
324426
color: var(--cyan);
@@ -336,7 +438,8 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
336438
color: var(--blue);
337439
}
338440
339-
#log {
441+
#log,
442+
#history {
340443
--mdc-dialog-min-width: 92vw;
341444
}
342445
@@ -346,28 +449,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
346449
right: 14px;
347450
}
348451
</style>
349-
<mwc-dialog id="log" heading="${translate('log.name')}">
350-
${this.renderFilterButtons()}
351-
<mwc-list id="content" wrapFocus>${this.renderHistory()}</mwc-list>
352-
<mwc-button
353-
icon="undo"
354-
label="${translate('undo')}"
355-
?disabled=${!this.canUndo}
356-
@click=${this.undo}
357-
slot="secondaryAction"
358-
></mwc-button>
359-
<mwc-button
360-
icon="redo"
361-
label="${translate('redo')}"
362-
?disabled=${!this.canRedo}
363-
@click=${this.redo}
364-
slot="secondaryAction"
365-
></mwc-button>
366-
<mwc-button slot="primaryAction" dialogaction="close"
367-
>${translate('close')}</mwc-button
368-
>
369-
</mwc-dialog>
370-
452+
${this.renderLogDialog()} ${this.renderHistoryDialog()}
371453
<mwc-dialog id="diagnostic" heading="${translate('diag.name')}">
372454
<filtered-list id="content" wrapFocus
373455
>${this.renderIssues()}</filtered-list
@@ -380,18 +462,18 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
380462
<mwc-snackbar
381463
id="info"
382464
timeoutMs="4000"
383-
labelText="${this.history
465+
labelText="${this.log
384466
.slice()
385467
.reverse()
386-
.find(le => le.kind === 'info' || le.kind === 'action')?.title ??
468+
.find(le => le.kind === 'info')?.title ??
387469
get('log.snackbar.placeholder')}"
388470
>
389471
<mwc-icon-button icon="close" slot="dismiss"></mwc-icon-button>
390472
</mwc-snackbar>
391473
<mwc-snackbar
392474
id="warning"
393475
timeoutMs="6000"
394-
labelText="${this.history
476+
labelText="${this.log
395477
.slice()
396478
.reverse()
397479
.find(le => le.kind === 'warning')?.title ??
@@ -408,7 +490,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
408490
<mwc-snackbar
409491
id="error"
410492
timeoutMs="10000"
411-
labelText="${this.history
493+
labelText="${this.log
412494
.slice()
413495
.reverse()
414496
.find(le => le.kind === 'error')?.title ??
@@ -439,5 +521,5 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
439521
}
440522
}
441523

442-
return LoggingElement;
524+
return HistoringElement;
443525
}

packages/open-scd/src/Hosting.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ActionDetail, List } from '@material/mwc-list';
1616
import { ListItem } from '@material/mwc-list/mwc-list-item';
1717

1818
import { Mixin, newPendingStateEvent } from './foundation.js';
19-
import { LoggingElement } from './Logging.js';
19+
import { HistoringElement } from './Historing.js';
2020
import { Plugin, PluggingElement, pluginIcons } from './Plugging.js';
2121
import { SettingElement } from './Setting.js';
2222

@@ -39,12 +39,12 @@ interface MenuPlugin {
3939
run: () => Promise<void>;
4040
}
4141

42-
/** Mixin that hosts the UI for Plugins, Settings and Logging */
42+
/** Mixin that hosts the UI for Plugins, Settings and Historing */
4343
export type HostingElement = Mixin<typeof Hosting>;
4444

4545
export function Hosting<
4646
TBase extends new (...args: any[]) => PluggingElement &
47-
LoggingElement &
47+
HistoringElement &
4848
SettingElement
4949
>(Base: TBase) {
5050
class HostingElement extends Base {
@@ -176,12 +176,19 @@ export function Hosting<
176176
},
177177
...validators,
178178
{
179-
icon: 'history',
179+
icon: 'list',
180180
name: 'menu.viewLog',
181181
actionItem: true,
182182
action: (): void => this.logUI.show(),
183183
kind: 'static',
184184
},
185+
{
186+
icon: 'history',
187+
name: 'menu.viewHistory',
188+
actionItem: true,
189+
action: (): void => this.historyUI.show(),
190+
kind: 'static',
191+
},
185192
{
186193
icon: 'rule',
187194
name: 'menu.viewDiag',

0 commit comments

Comments
 (0)