Skip to content

Commit

Permalink
Re-implemented context items.
Browse files Browse the repository at this point in the history
  • Loading branch information
na9da committed Nov 3, 2021
1 parent b5d56c4 commit 3dcb14e
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 193 deletions.
4 changes: 4 additions & 0 deletions lib/Language/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,10 @@
"leftPanel": "Left panel",
"rightPanel": "Right panel",
"bothPanels": "Both panels",
"bothPanelsMenu": {
"browse": "Browse map data",
"hideAll": "Hide all"
},
"info": "Compare spatial datasets from your workbench side-by-side on the map.",
"dataset": {
"label": "Dataset",
Expand Down
36 changes: 36 additions & 0 deletions lib/Models/Comparable.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isArrayLike } from "mobx";
import { isJsonObject } from "../Core/Json";
import CatalogMemberMixin from "../ModelMixins/CatalogMemberMixin";
import MappableMixin from "../ModelMixins/MappableMixin";
import CatalogMemberTraits from "../Traits/TraitsClasses/CatalogMemberTraits";
Expand Down Expand Up @@ -25,3 +27,37 @@ export function isComparableItem(item: any): item is Comparable {
hasTraits(item, SplitterTraits, "splitDirection");
return isComparable;
}

/**
* Object used to store compare workflow configuration
*/
export type CompareConfig = {
// ID of the item to show in the left panel
leftPanelItemId: string | undefined;
// ID of the item to show in the right panel
rightPanelItemId: string | undefined;
// IDs of context items (items appearing in both panels).
contextItemIds: string[];
};

export function createCompareConfig(json: any = {}): CompareConfig | undefined {
if (!isJsonObject(json)) {
return undefined;
}

const leftPanelItemId =
typeof json.leftPanelItemId === "string" ? json.leftPanelItemId : undefined;
const rightPanelItemId =
typeof json.rightPanelItemId === "string"
? json.rightPanelItemId
: undefined;
const contextItemIds = isArrayLike(json.contextItemIds)
? (json.contextItemIds.filter(id => typeof id === "string") as string[])
: [];

return {
leftPanelItemId,
rightPanelItemId,
contextItemIds
};
}
18 changes: 5 additions & 13 deletions lib/Models/Terria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import MagdaReference, {
MagdaReferenceHeaders
} from "./Catalog/CatalogReferences/MagdaReference";
import SplitItemReference from "./Catalog/CatalogReferences/SplitItemReference";
import { CompareConfig, createCompareConfig } from "./Comparable";
import CommonStrata from "./Definition/CommonStrata";
import hasTraits from "./Definition/hasTraits";
import { BaseModel } from "./Definition/Model";
Expand Down Expand Up @@ -533,14 +534,9 @@ export default class Terria {
@observable catalogReferencesLoaded: boolean = false;

/**
* Left item in the compare workflow
* Configuration for the compare workflow
*/
@observable compareLeftItemId?: string;

/**
* Right item in the compare workflow
*/
@observable compareRightItemId?: string;
@observable compareConfig: CompareConfig | undefined = undefined;

augmentedVirtuality?: any;

Expand Down Expand Up @@ -1387,12 +1383,8 @@ export default class Terria {
this.splitPosition = initData.splitPosition;
}

if (isJsonString(initData.compareLeftItemId)) {
this.compareLeftItemId = initData.compareLeftItemId;
}

if (isJsonString(initData.compareRightItemId)) {
this.compareRightItemId = initData.compareRightItemId;
if (isJsonObject(initData.compareConfig)) {
this.compareConfig = createCompareConfig(initData.compareConfig);
}

// Copy but don't yet load the workbench.
Expand Down
Loading

0 comments on commit 3dcb14e

Please sign in to comment.