Skip to content

Commit 4860329

Browse files
author
Dennis Labordus
committed
Small change to naming.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent d75dcb7 commit 4860329

File tree

3 files changed

+67
-66
lines changed

3 files changed

+67
-66
lines changed

src/compas-editors/CompasVersions.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export default class CompasVersionsPlugin extends LitElement {
2929
super();
3030

3131
// Add event to get a notification when a new document is opened.
32-
getOpenScdElement().addEventListener('open-doc', this.resetSelection);
32+
const openSCD = getOpenScdElement();
33+
if (openSCD) {
34+
openSCD.addEventListener('open-doc', this.resetSelection);
35+
}
3336
}
3437

3538
resetSelection() {
@@ -81,14 +84,13 @@ export default class CompasVersionsPlugin extends LitElement {
8184
async compareCurrentVersion(): Promise<void> {
8285
const selectedVersions = this.getSelectedVersions();
8386
if (selectedVersions.length === 1) {
84-
const rightVersion = selectedVersions[0];
85-
86-
const leftScl = this.doc.documentElement;
87-
const rightScl = await this.getVersion(rightVersion);
87+
const oldVersion = selectedVersions[0];
88+
const oldScl = await this.getVersion(oldVersion);
89+
const newScl = this.doc.documentElement;
8890

8991
this.dispatchEvent(newWizardEvent(
90-
compareWizard(leftScl, rightScl,
91-
{title: get('compas.compare.title', {leftVersion: 'current', rightVersion: rightVersion})})));
92+
compareWizard(oldScl, newScl,
93+
{title: get('compas.compare.title', {oldVersion: oldVersion, newVersion: 'current'})})));
9294
} else {
9395
this.dispatchEvent(newWizardEvent(
9496
showMessageWizard(get("compas.versions.selectOneVersionsTitle"),
@@ -99,15 +101,15 @@ export default class CompasVersionsPlugin extends LitElement {
99101
async compareVersions(): Promise<void> {
100102
const selectedVersions = this.getSelectedVersions();
101103
if (selectedVersions.length === 2) {
102-
const leftVersion = selectedVersions[0];
103-
const rightVersion = selectedVersions[1];
104+
const oldVersion = selectedVersions[0];
105+
const newVersion = selectedVersions[1];
104106

105-
const leftScl = await this.getVersion(leftVersion);
106-
const rightScl = await this.getVersion(rightVersion);
107+
const oldScl = await this.getVersion(oldVersion);
108+
const newScl = await this.getVersion(newVersion);
107109

108110
this.dispatchEvent(newWizardEvent(
109-
compareWizard(leftScl, rightScl,
110-
{title: get('compas.compare.title', {leftVersion: leftVersion, rightVersion: rightVersion})})));
111+
compareWizard(oldScl, newScl,
112+
{title: get('compas.compare.title', {oldVersion: oldVersion, newVersion: newVersion})})));
111113
} else {
112114
this.dispatchEvent(newWizardEvent(
113115
showMessageWizard(get("compas.versions.selectTwoVersionsTitle"),

src/compas/CompasCompareDialog.ts

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
isEqual,
99
isSame,
1010
newWizardEvent,
11-
SimpleAction,
1211
Wizard,
1312
WizardActor
1413
} from "../foundation.js";
@@ -19,13 +18,13 @@ import {ListItem} from "@material/mwc-list/mwc-list-item";
1918
interface MergeOptions {
2019
title?: string;
2120
selected?: (diff: Diff<Element | string>) => boolean;
22-
auto?: (sink: Element, source: Element) => boolean;
21+
auto?: (oldValue: Element, newValue: Element) => boolean;
2322
}
2423

2524
export type Diff<T> =
26-
| { ours: T; theirs: null }
27-
| { ours: null; theirs: T }
28-
| { ours: T; theirs: T };
25+
| { oldValue: T; newValue: null }
26+
| { oldValue: null; newValue: T }
27+
| { oldValue: T; newValue: T };
2928

3029
function describe(element: Element): string {
3130
const id = identity(element);
@@ -36,8 +35,8 @@ function describe(element: Element): string {
3635
function compareWizardAction(
3736
attrDiffs: [string, Diff<string>][],
3837
childDiffs: Diff<Element>[],
39-
sink: Element,
40-
source: Element,
38+
oldValue: Element,
39+
newValue: Element,
4140
options?: MergeOptions
4241
): WizardActor {
4342
return (_, wizard: Element): EditorAction[] => {
@@ -49,11 +48,11 @@ function compareWizardAction(
4948
.map(item => childDiffs[item.value as unknown as number]);
5049
if (selectedChildDiffs.length) {
5150
for (const diff of selectedChildDiffs)
52-
if (diff.ours && diff.theirs) {
51+
if (diff.oldValue && diff.newValue) {
5352
acted = true;
5453
wizard.dispatchEvent(
5554
newWizardEvent(
56-
compareWizard(diff.ours, diff.theirs, {
55+
compareWizard(diff.oldValue, diff.newValue, {
5756
...options,
5857
title: undefined,
5958
})
@@ -70,75 +69,75 @@ function compareWizardAction(
7069
{
7170
actions: [],
7271
title: get('compas.compare.elementTitle', {
73-
sink: describe(sink),
74-
source: describe(source),
75-
tag: sink.tagName,
72+
oldValue: describe(oldValue),
73+
newValue: describe(newValue),
74+
tag: oldValue.tagName,
7675
}),
7776
},
7877
];
7978
};
8079
}
8180

8281
export function compareWizard(
83-
sink: Element,
84-
source: Element,
82+
oldElement: Element,
83+
newElement: Element,
8584
options?: MergeOptions
8685
): Wizard {
8786
const attrDiffs: [string, Diff<string>][] = [];
88-
const ourText = sink.textContent ?? '';
89-
const theirText = source.textContent ?? '';
87+
const oldText = oldElement.textContent ?? '';
88+
const newText = newElement.textContent ?? '';
9089

91-
if (sink.childElementCount === 0 &&
92-
source.childElementCount === 0 &&
93-
theirText !== ourText
90+
if (oldElement.childElementCount === 0 &&
91+
newElement.childElementCount === 0 &&
92+
newText !== oldText
9493
) {
95-
attrDiffs.push(['value', {ours: ourText, theirs: theirText}]);
94+
attrDiffs.push(['value', {oldValue: oldText, newValue: newText}]);
9695
}
9796

98-
const attributeNames = new Set(source.getAttributeNames().concat(sink.getAttributeNames()));
97+
const attributeNames = new Set(newElement.getAttributeNames().concat(oldElement.getAttributeNames()));
9998

10099
for (const name of attributeNames)
101-
if (source.getAttribute(name) !== sink.getAttribute(name))
100+
if (newElement.getAttribute(name) !== oldElement.getAttribute(name))
102101
attrDiffs.push([
103102
name,
104103
<Diff<string>>{
105-
theirs: source.getAttribute(name),
106-
ours: sink.getAttribute(name),
104+
newValue: newElement.getAttribute(name),
105+
oldValue: oldElement.getAttribute(name),
107106
},
108107
]);
109108

110109
const childDiffs: Diff<Element>[] = [];
111-
const ourChildren = Array.from(sink.children);
112-
const theirChildren = Array.from(source.children);
110+
const ourChildren = Array.from(oldElement.children);
111+
const theirChildren = Array.from(newElement.children);
113112

114-
theirChildren.forEach(theirs => {
113+
theirChildren.forEach(newValue => {
115114
const twinIndex = ourChildren.findIndex(ourChild =>
116-
isSame(theirs, ourChild)
115+
isSame(newValue, ourChild)
117116
);
118-
const ours = twinIndex > -1 ? ourChildren[twinIndex] : null;
117+
const oldValue = twinIndex > -1 ? ourChildren[twinIndex] : null;
119118

120-
if (ours) ourChildren.splice(twinIndex, 1);
121-
if (ours && isEqual(theirs, ours)) return;
119+
if (oldValue) ourChildren.splice(twinIndex, 1);
120+
if (oldValue && isEqual(newValue, oldValue)) return;
122121

123-
if (!ours || !isEqual(theirs, ours)) childDiffs.push({ theirs, ours });
122+
if (!oldValue || !isEqual(newValue, oldValue)) childDiffs.push({ newValue, oldValue });
124123
});
125124

126-
ourChildren.forEach(ours => childDiffs.push({ theirs: null, ours }));
125+
ourChildren.forEach(oldValue => childDiffs.push({ newValue: null, oldValue }));
127126

128127
return [
129128
{
130129
title:
131130
options?.title ??
132131
get('compas.compare.elementTitle', {
133-
sink: describe(sink),
134-
source: describe(source),
135-
tag: sink.tagName,
132+
oldValue: describe(oldElement),
133+
newValue: describe(newElement),
134+
tag: oldElement.tagName,
136135
}),
137136
primary: {
138137
label: get('compas.compare.primaryButton'),
139138
icon: 'compare',
140-
action: compareWizardAction(attrDiffs, childDiffs, sink, source, options),
141-
auto: options?.auto?.(sink, source) ?? false,
139+
action: compareWizardAction(attrDiffs, childDiffs, oldElement, newElement, options),
140+
auto: options?.auto?.(oldElement, newElement) ?? false,
142141
},
143142
content: [
144143
html`
@@ -151,12 +150,12 @@ export function compareWizard(
151150
left
152151
hasMeta>
153152
<span>${name}</span>
154-
<span slot="secondary">${diff.ours ?? ''}
155-
${diff.ours && diff.theirs ? html`&cularr;` : ' '}
156-
${diff.theirs ?? ''}</span>
153+
<span slot="secondary">${diff.oldValue ?? ''}
154+
${diff.oldValue && diff.newValue ? html`&cularr;` : ' '}
155+
${diff.newValue ?? ''}</span>
157156
<mwc-icon slot="meta">
158-
${diff.ours
159-
? diff.theirs
157+
${diff.oldValue
158+
? diff.newValue
160159
? 'edit'
161160
: 'delete'
162161
: 'add'}</mwc-icon>
@@ -171,7 +170,7 @@ export function compareWizard(
171170
childDiffs,
172171
e => e,
173172
(diff, index) => {
174-
if (diff.ours && diff.theirs) {
173+
if (diff.oldValue && diff.newValue) {
175174
return html`
176175
<mwc-check-list-item value=${index}
177176
class="child"
@@ -180,14 +179,14 @@ export function compareWizard(
180179
hasMeta
181180
.selected=${options?.selected?.(diff) ?? false}
182181
style="--mdc-checkbox-checked-color: var(--mdc-theme-
183-
${diff.ours
184-
? diff.theirs
182+
${diff.oldValue
183+
? diff.newValue
185184
? 'secondary'
186185
: 'error'
187186
: 'primary'});">
188-
<span>${diff.ours?.tagName ?? diff.theirs?.tagName}</span>
187+
<span>${diff.oldValue?.tagName ?? diff.newValue?.tagName}</span>
189188
<span slot="secondary">
190-
${describe(diff.ours)}&cularr;${describe(diff.theirs)}
189+
${describe(diff.oldValue)}&cularr;${describe(diff.newValue)}
191190
</span>
192191
<mwc-icon slot="meta">compare</mwc-icon>
193192
</mwc-check-list-item>`
@@ -196,12 +195,12 @@ export function compareWizard(
196195
<mwc-list-item twoline
197196
left
198197
hasMeta>
199-
<span>${diff.ours?.tagName ?? diff.theirs?.tagName}</span>
198+
<span>${diff.oldValue?.tagName ?? diff.newValue?.tagName}</span>
200199
<span slot="secondary">
201-
${diff.ours ? describe(diff.ours) : describe(diff.theirs)}
200+
${diff.oldValue ? describe(diff.oldValue) : describe(diff.newValue)}
202201
</span>
203202
<mwc-icon slot="meta">
204-
${diff.ours ? 'delete' : 'add'}
203+
${diff.oldValue ? 'delete' : 'add'}
205204
</mwc-icon>
206205
</mwc-list-item>`
207206
}

src/translations/en.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ export const en = {
435435
selectOneVersionsMessage: 'Select maximum one version to compare the current project against. Currently selected: {{size}}.',
436436
},
437437
compare: {
438-
title: 'Compare version {{leftVersion}} with version {{rightVersion}}',
439-
elementTitle: 'Compare {{sink}} with {{source}} ({{tag}})',
438+
title: 'Compare version {{oldVersion}} with version {{newVersion}}',
439+
elementTitle: 'Compare {{oldValue}} with {{newValue}} ({{tag}})',
440440
primaryButton: 'Show details',
441441
children: 'Child elements',
442442
},

0 commit comments

Comments
 (0)