Skip to content

Commit 30d568f

Browse files
juancho0202JakobVogelsang
authored andcommitted
feat(menu/history): move history from log to own menu plugin
1 parent 5bfc3aa commit 30d568f

File tree

14 files changed

+456
-328
lines changed

14 files changed

+456
-328
lines changed

public/js/plugins.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ export const officialPlugins = [
186186
requireDoc: true,
187187
position: 'middle',
188188
},
189+
{
190+
name: 'Show SCL History',
191+
src: '/src/menu/SclHistory.js',
192+
icon: 'history_toggle_off',
193+
default: true,
194+
kind: 'menu',
195+
requireDoc: true,
196+
position: 'bottom',
197+
},
189198
{
190199
name: 'Help',
191200
src: '/src/menu/Help.js',

src/Logging.ts

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import {
3232
LogEvent,
3333
Mixin,
3434
newActionEvent,
35-
OpenDocEvent,
36-
SclhistoryEntry,
3735
} from './foundation.js';
3836
import { getFilterIcon, iconColors } from './icons/icons.js';
3937
import { Plugin } from './Plugging.js';
@@ -43,7 +41,6 @@ const icons = {
4341
warning: 'warning',
4442
error: 'report',
4543
action: 'history',
46-
sclhistory: 'history_toggle_off',
4744
};
4845

4946
function getPluginName(src: string): string {
@@ -113,58 +110,6 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
113110
return index;
114111
}
115112

116-
private convertToDate(when: string | null): Date | null {
117-
const convertedTime = new Date(when ?? '');
118-
if (!isNaN(convertedTime.getTime())) {
119-
return convertedTime;
120-
}
121-
return null;
122-
}
123-
124-
private createMessage(
125-
who: string | null,
126-
why: string | null
127-
): string | undefined {
128-
let message = who;
129-
if (message !== null && why !== null) {
130-
message += ' : ' + why;
131-
} else if (why !== null) {
132-
message = why;
133-
}
134-
return message ?? undefined;
135-
}
136-
137-
private createSclHistoryEntry(
138-
who: string | null,
139-
what: string | null,
140-
why: string | null,
141-
when: string | null
142-
): SclhistoryEntry {
143-
return {
144-
kind: 'sclhistory',
145-
title: what ?? 'UNDEFINED',
146-
message: this.createMessage(who, why),
147-
time: this.convertToDate(when),
148-
};
149-
}
150-
151-
private async onLoadHistoryFromDoc(event: OpenDocEvent) {
152-
const doc = event.detail.doc;
153-
154-
Array.from(
155-
doc.querySelectorAll(':root > Header > History > Hitem')
156-
).forEach(historyItem => {
157-
this.history.push(
158-
this.createSclHistoryEntry(
159-
historyItem.getAttribute('who'),
160-
historyItem.getAttribute('what'),
161-
historyItem.getAttribute('why'),
162-
historyItem.getAttribute('when')
163-
)
164-
);
165-
});
166-
}
167-
168113
private onIssue(de: IssueEvent): void {
169114
const issues = this.diagnoses.get(de.detail.validatorId);
170115

@@ -249,7 +194,6 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
249194

250195
this.addEventListener('log', this.onLog);
251196
this.addEventListener('issue', this.onIssue);
252-
this.addEventListener('open-doc', this.onLoadHistoryFromDoc);
253197
}
254198

255199
renderLogEntry(
@@ -330,9 +274,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
330274

331275
private renderFilterButtons() {
332276
return (<LogEntryType[]>Object.keys(icons)).map(
333-
kind => html`<mwc-icon-button-toggle
334-
id="${kind}filter"
335-
?on=${kind !== 'sclhistory'}
277+
kind => html`<mwc-icon-button-toggle id="${kind}filter" on
336278
>${getFilterIcon(kind, false)}
337279
${getFilterIcon(kind, true)}</mwc-icon-button-toggle
338280
>`
@@ -362,8 +304,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
362304
#content mwc-list-item.info,
363305
#content mwc-list-item.warning,
364306
#content mwc-list-item.error,
365-
#content mwc-list-item.action,
366-
#content mwc-list-item.sclhistory {
307+
#content mwc-list-item.action {
367308
display: none;
368309
}
369310
#infofilter[on] ~ #content mwc-list-item.info {
@@ -378,9 +319,6 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
378319
#actionfilter[on] ~ #content mwc-list-item.action {
379320
display: flex;
380321
}
381-
#sclhistoryfilter[on] ~ #content mwc-list-item.sclhistory {
382-
display: flex;
383-
}
384322
385323
#log {
386324
--mdc-dialog-min-width: 92vw;

src/foundation.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,7 @@ export function newSubWizardEvent(
362362

363363
type InfoEntryKind = 'info' | 'warning' | 'error';
364364

365-
export type LogEntryType =
366-
| 'info'
367-
| 'warning'
368-
| 'error'
369-
| 'action'
370-
| 'reset'
371-
| 'sclhistory';
365+
export type LogEntryType = 'info' | 'warning' | 'error' | 'action' | 'reset';
372366

373367
/** The basic information contained in each [[`LogEntry`]]. */
374368
export interface LogDetailBase {
@@ -385,10 +379,6 @@ export interface InfoDetail extends LogDetailBase {
385379
kind: InfoEntryKind;
386380
cause?: LogEntry;
387381
}
388-
/** A [[`LogEntry`]] create from the HItem Line (History) of the SCD File */
389-
export interface SclhistoryDetail extends LogDetailBase {
390-
kind: 'sclhistory';
391-
}
392382

393383
export interface ResetDetail {
394384
kind: 'reset';
@@ -431,9 +421,8 @@ interface Timestamped {
431421

432422
export type CommitEntry = Timestamped & CommitDetail;
433423
export type InfoEntry = Timestamped & InfoDetail;
434-
export type SclhistoryEntry = Timestamped & SclhistoryDetail;
435424

436-
export type LogEntry = InfoEntry | CommitEntry | SclhistoryEntry;
425+
export type LogEntry = InfoEntry | CommitEntry;
437426

438427
/** Represents some work pending completion, upon which `promise` resolves. */
439428
export interface PendingStateDetail {

src/icons/icons.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export const iconColors: { [key: string]: string;} = {
6060
warning: '--yellow',
6161
error: '--red',
6262
action: '--blue',
63-
sclhistory: '--cyan',
6463
};
6564

6665
export function getFilterIcon(

src/menu/SclHistory.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import {
2+
html,
3+
css,
4+
property,
5+
query,
6+
TemplateResult,
7+
LitElement,
8+
} from 'lit-element';
9+
import { translate } from 'lit-translate';
10+
11+
import '@material/mwc-button';
12+
import '@material/mwc-dialog';
13+
import '@material/mwc-list';
14+
import '@material/mwc-list/mwc-list-item';
15+
import { Dialog } from '@material/mwc-dialog';
16+
17+
export default class SclHistoryPlugin extends LitElement {
18+
@property({ attribute: false })
19+
doc!: XMLDocument;
20+
21+
@query('#historyLog') historyLog!: Dialog;
22+
23+
private createMessage(
24+
who: string | null,
25+
why: string | null
26+
): string | undefined {
27+
let message = who;
28+
if (message !== null && why !== null) {
29+
message += ' : ' + why;
30+
} else if (why !== null) {
31+
message = why;
32+
}
33+
return message ?? undefined;
34+
}
35+
36+
get sclHistory(): Element[] {
37+
if (this.doc) {
38+
return Array.from(
39+
this.doc.querySelectorAll(':root > Header > History > Hitem')
40+
);
41+
}
42+
return [];
43+
}
44+
45+
async run(): Promise<void> {
46+
this.historyLog.open = true;
47+
}
48+
49+
renderSclHistoryEntry(element: Element): TemplateResult {
50+
const message = this.createMessage(
51+
element.getAttribute('who'),
52+
element.getAttribute('why')
53+
);
54+
const title = element.getAttribute('what');
55+
return html` <abbr title="${title}">
56+
<mwc-list-item class="sclHistory" ?twoline=${!!message}>
57+
<span>
58+
<tt>${element.getAttribute('when')}</tt>
59+
${title}</span
60+
>
61+
<span slot="secondary">${message}</span>
62+
</mwc-list-item></abbr
63+
>`;
64+
}
65+
66+
private renderSclHistory(): TemplateResult[] | TemplateResult {
67+
if (this.sclHistory.length > 0)
68+
return this.sclHistory
69+
.slice()
70+
.reverse()
71+
.map(this.renderSclHistoryEntry, this);
72+
else
73+
return html`<mwc-list-item disabled>
74+
<span>${translate('history.noEntries')}</span>
75+
</mwc-list-item>`;
76+
}
77+
78+
render(): TemplateResult {
79+
return html` <mwc-dialog
80+
id="historyLog"
81+
heading="${translate('history.name')}"
82+
>
83+
<mwc-list id="historyLogContent" wrapFocus
84+
>${this.renderSclHistory()}</mwc-list
85+
>
86+
<mwc-button slot="secondaryAction" dialogaction="close"
87+
>${translate('close')}</mwc-button
88+
>
89+
</mwc-dialog>`;
90+
}
91+
92+
static styles = css`
93+
.sclHistory {
94+
display: flex;
95+
}
96+
#historyLog {
97+
--mdc-dialog-min-width: 92vw;
98+
}
99+
abbr {
100+
text-decoration: none;
101+
}
102+
`;
103+
}

src/translations/de.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ export const de: Translations = {
165165
placeholder: 'Keine Fehler',
166166
},
167167
},
168+
history: {
169+
name: 'SCL History',
170+
noEntries: 'Keine Einträge in der SCL History',
171+
},
168172
diag: {
169173
name: 'Daignoseübersicht',
170174
zeroissues: 'Es konnten keine Fehler in dem Projekt gefunden werden.',

src/translations/en.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ export const en = {
142142
placeholder: 'No errors',
143143
},
144144
},
145+
history: {
146+
name: 'SCL History',
147+
noEntries: 'No SCL history entries',
148+
},
145149
diag: {
146150
name: 'Diagnostics',
147151
zeroissues: 'No errors found in the project',

test/integration/Setting.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { html, fixture, expect } from '@open-wc/testing';
1+
import { expect, fixture, html } from '@open-wc/testing';
22

33
import '../mock-setter-logger.js';
44
import { MockSetterLogger } from '../mock-setter-logger.js';
@@ -28,7 +28,10 @@ describe('Setting', () => {
2828
await element.updateComplete;
2929

3030
expect(localStorage.getItem('IEC 61850-7-2')).to.eql(nsdocFile);
31-
await expect(element).shadowDom.to.equalSnapshot();
31+
// Create a snapshot of the Settings Dialog only, not the whole Mock Component.
32+
await expect(
33+
element.shadowRoot!.querySelector('mwc-dialog[id="settings"]')
34+
).to.equalSnapshot();
3235
});
3336

3437
it('upload invalid .nsdoc file using event and log event fired', async () => {

0 commit comments

Comments
 (0)