Skip to content

Commit

Permalink
Fix final bugs with multiple-OA custom scenario UI
Browse files Browse the repository at this point in the history
Closes #49
  • Loading branch information
yongrenjie committed Oct 6, 2023
1 parent bf3398a commit 939a71c
Showing 1 changed file with 45 additions and 42 deletions.
87 changes: 45 additions & 42 deletions web/src/lib/leftSidebar/create/ModifyOutputAreas.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
// Get changes belonging to a single OA. If none, return null for all
// editable layers
function getSingleOAChanges(oaName: string): Map<MacroVar, number | null> {
function getSingleOAChanges(
oaName: string
): Map<MacroVar | "baseline_sig", number | null> {
if (changes.has(oaName)) {
return changes.get(oaName);
} else {
Expand All @@ -35,6 +37,13 @@
["job_types", null],
["use", null],
["greenspace", null],
[
"baseline_sig",
$allScenarios
.get("baseline")
.values.get(oaName)
.get("signature_type"),
],
]);
}
}
Expand Down Expand Up @@ -113,6 +122,7 @@
function loadOAChangesToUI(oas: Array<{ name: string }>) {
if (oas.length === 0) return;
else if (oas.length === 1) {
// Exactly one OA selected
const oaName = oas[0].name;
const oaChanges = getSingleOAChanges(oaName);
sig = oaChanges.get("signature_type");
Expand All @@ -123,28 +133,47 @@
useModified = use !== null;
green = oaChanges.get("greenspace");
greenModified = green !== null;
baselineSig = getBaselineSig(oas);
baselineSig = oaChanges.get("baseline_sig");
} else {
// More than one OA selected
const allSigs: Array<number | null> = oas.map((oa) =>
getSingleOAChanges(oa.name).get("signature_type")
);
// If none of the values were changed, check if the baseline value
// is the same. If so, display that
const allBaselineSigs: Array<number> = oas.map((oa) =>
getSingleOAChanges(oa.name).get("baseline_sig")
);
console.log("allSigs", allSigs);
console.log("allBaselineSigs", allBaselineSigs);
// If none of the values were changed, check if the baseline values
// are all the same. If so, display that
if (allSigs.every((s) => s === null)) {
sig = getBaselineSig(oas);
sigModified = false;
if (allBaselineSigs.every((s) => s === allBaselineSigs[0])) {
baselineSig = allBaselineSigs[0];
} else {
baselineSig = null;
}
}
// If all the values were changed to be the same thing, then we can
// display that value.
else if (allSigs.every((s) => s === allSigs[0])) {
sig = allSigs[0];
sigModified = true;
}
// Otherwise just dim the value
// TODO: Show the baseline value if they are all the same
else {
// If some of the values were changed, but not all, display an unchecked checkbox
else if (allSigs.some((s) => s !== null)) {
sig = null;
sigModified = false;
baselineSig = null;
}
// If we reached here, then that means that all of the values were
// changed to something else.
else {
// If they were all changed to the same thing, display that value.
if (allSigs.every((s) => s === allSigs[0])) {
sig = allSigs[0];
sigModified = true;
}
// Otherwise, they were all changed to different things. Just
// default to an unchecked box
else {
sig = null;
sigModified = false;
}
}
const allJobs: Array<number | null> = oas.map((oa) =>
getSingleOAChanges(oa.name).get("job_types")
Expand Down Expand Up @@ -179,36 +208,10 @@
}
}
function getBaselineSig(oas: Array<{ name: string }>): null | number {
if (oas.length === 0) {
return null;
} else if (oas.length === 1) {
const oaName = oas[0].name;
return $allScenarios
.get("baseline")
.values.get(oaName)
.get("signature_type");
} else {
const oaNames = oas.map((oa) => oa.name);
const baselineSigs = oaNames.map((oaName) =>
$allScenarios
.get("baseline")
.values.get(oaName)
.get("signature_type")
);
console.log(baselineSigs);
if (baselineSigs.every((s) => s === baselineSigs[0])) {
return baselineSigs[0];
} else {
return null;
}
}
}
// Variables for OA modifiers
let sig: number | null = null;
let sigModified: boolean;
let baselineSig: null | number | "different"; // Only shown when sigModified is false
let baselineSig: null | number;
let job: number | null = null;
let jobModified: boolean;
let use: number | null = null;
Expand Down Expand Up @@ -270,7 +273,7 @@
bind:checked={sigModified}
on:change={() => {
if (sigModified) {
sig = getBaselineSig($clickedOAs);
sig = baselineSig;
}
if ($clickedOAs.length > 1 && !sigModified) {
sig = null;
Expand Down

0 comments on commit 939a71c

Please sign in to comment.