Skip to content

Commit

Permalink
merge: friendly display #2
Browse files Browse the repository at this point in the history
+ remove duplicate links
  • Loading branch information
le-jeu committed Jan 14, 2022
1 parent d997172 commit 0fa8482
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 14 deletions.
59 changes: 47 additions & 12 deletions src/code/dialogs/mergeDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { computeRebaseChanges, applyRebaseChanges } from "../model/changes";

import PortalUI from "../ui/portal";
import LinkUI from "../ui/link";
import MarkerUI from "../ui/marker";

const MergeDialog = WDialog.extend({
statics: {
Expand Down Expand Up @@ -255,19 +256,53 @@ const MergeDialog = WDialog.extend({
},

formatConflict(conflict, change, op, container) {
if (conflict.kind === "link") {
const link = this._origin.getLinkById(change.id);
const linkDisplay = LinkUI.displayFormat(link, this._origin);
container.appendChild(linkDisplay);
if (change.type === "deletion") linkDisplay.classList.add("strike");
else {
// fail safe for now
try {
if (conflict.kind === "link") {
const link = this._origin.getLinkById(change.id);
const linkDisplay = LinkUI.displayFormat(link, this._origin);
container.appendChild(linkDisplay);
if (change.type === "deletion") linkDisplay.classList.add("strike");
else {
const list = L.DomUtil.create("ul", "", container);
for (const k in change.props) {
this.formatProp(k, link, change.props, op, list);
}
}
} else if (conflict.kind === "marker") {
const marker = this._origin.getMarker(change.id);
const markerDisplay = MarkerUI.displayFormat(marker, this._origin);
container.appendChild(markerDisplay);
if (change.type === "deletion") markerDisplay.classList.add("strike");
else {
const list = L.DomUtil.create("ul", "", container);
for (const k in change.props) {
this.formatProp(k, marker, change.props, op, list);
}
}
} else if (conflict.kind === "portal") {
const portal = this._origin.getPortal(change.id);
const portalDisplay = PortalUI.displayFormat(portal);
container.appendChild(portalDisplay);
// only edition/edition
const list = L.DomUtil.create("ul", "", container);
for (const k in change.props) {
this.formatProp(k, link, change.props, op, list);
this.formatProp(k, portal, change.props, op, list);
}
} else if (conflict.kind === "zone") {
const zone = this._origin.getZone(change.id);
const zoneDisplay = L.DomUtil.create("span");
zoneDisplay.textContent = "Zone: " + zone.name;
container.appendChild(zoneDisplay);
// only edition/edition
const list = L.DomUtil.create("ul", "", container);
for (const k in change.props) {
this.formatProp(k, zone, change.props, op, list);
}
}
} else {
container.append(JSON.stringify(conflict.c.props));
} catch (e) {
console.error(e);
container.append(JSON.stringify(change.props));
}
},

Expand Down Expand Up @@ -298,9 +333,9 @@ const MergeDialog = WDialog.extend({
} else if (key === "zone") {
keySpan.textContent = "Zone: ";
} else if (key === "points") {
keySpan.textContent = "Shape: ";
oldSpan.textContent = JSON.stringify(old[key]);
newSpan.textContent = JSON.stringify(next[key]);
keySpan.textContent = "Shape has changed";
oldSpan.textContent = "";
newSpan.textContent = "";
} else if (key === "fromPortalId") {
keySpan.textContent = "From: ";
} else if (key === "toPortalId") {
Expand Down
10 changes: 8 additions & 2 deletions src/code/model/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function rebaseDiff<T>(master: Partial<T>, follower: Partial<T>) {
const props: Partial<T> = {};
let once = false;
for (const k in follower) {
if (JSON.stringify(master[k]) !== JSON.stringify(follower[k])) {
if (!master || JSON.stringify(master[k]) !== JSON.stringify(follower[k])) {
props[k] = follower[k];
once = true;
}
Expand All @@ -213,13 +213,14 @@ function rebaseDiff<T>(master: Partial<T>, follower: Partial<T>) {
return null;
}

// asume changes sorted by id
function rebaseChanges<T, K extends keyof T>(
master: Change<T, K>[],
follower: Change<T, K>[],
conflictOnDoubleEditOnly = false, // portal and zone
concurrentEditKeys: K[] = []
) {
master.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
follower.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
const result: Change<T, K>[] = [];
const conflict: {
id: string | number;
Expand Down Expand Up @@ -520,6 +521,11 @@ export function applyRebaseChanges(
if (lc.value) master.links.push(lc.value);
}

// remove duplicates
master.links = master.links.filter(
(l) => master.getLinkByPortalIDs(l.fromPortalId, l.toPortalId) === l
);

master.cleanAnchorList();
master.cleanPortalList();
}
3 changes: 3 additions & 0 deletions src/code/ui/marker.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { WLPortal } from "./portal";
import type WasabeeMarker from "../model/marker";
import type WasabeeOp from "../model/operation";

export class WLMarker extends WLPortal {
state: string;
Expand All @@ -13,3 +14,5 @@ export class WLMarker extends WLPortal {
_setComment(ev: any): void;
_setMarkerType(ev: any): void;
}

export function displayFormat(marker: WasabeeMarker, operation: WasabeeOp): HTMLSpanElement;
16 changes: 16 additions & 0 deletions src/code/ui/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ import PortalUI from "./portal";

import wX from "../wX";

function displayFormat(marker, operation) {
const portal = operation.getPortal(marker.portalId);

if (portal == null) {
console.log("null portal getting marker popup");
return (L.DomUtil.create("div", "").textContent = "invalid portal");
}

const desc = L.DomUtil.create("span");
const kind = L.DomUtil.create("span", `${marker.type}`, desc);
kind.textContent = wX(marker.type);
desc.appendChild(PortalUI.displayFormat(portal));
return desc;
}

const WLMarker = PortalUI.WLPortal.extend({
type: "marker",

Expand Down Expand Up @@ -166,4 +181,5 @@ const WLMarker = PortalUI.WLPortal.extend({

export default {
WLMarker,
displayFormat,
};

0 comments on commit 0fa8482

Please sign in to comment.