Skip to content

Commit

Permalink
pull complicated prop logic out into reactive variable
Browse files Browse the repository at this point in the history
  • Loading branch information
duranb committed Aug 27, 2024
1 parent 02a8d44 commit 0b0ae7a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
let compactNavMode = false;
let errorConsole: Console;
let consoleHeightString = '36px';
let constraintsStatusText: string | undefined;
let hasCreateViewPermission: boolean = false;
let hasUpdateViewPermission: boolean = false;
let hasExpandPermission: boolean = false;
Expand Down Expand Up @@ -399,10 +400,16 @@
$: numConstraintsViolated = Object.values($constraintResponseMap).filter(
response => response.results.violations?.length,
).length;
$: numConstraintsWithErrors = Object.values($constraintResponseMap).filter(
response => response.errors?.length,
).length;
$: constraintsStatusText =
($constraintsStatus === Status.Complete ||
$constraintsStatus === Status.Failed ||
$constraintsStatus === Status.PartialSuccess) &&
numConstraintsViolated + numConstraintsWithErrors + $uncheckedConstraintCount > 0
? `${numConstraintsViolated + numConstraintsWithErrors + $uncheckedConstraintCount}`
: undefined;
$: if ($initialPlan && browser) {
// Asynchronously fetch resource types
Expand Down Expand Up @@ -699,12 +706,7 @@
buttonText="Check Constraints"
hasPermission={hasCheckConstraintsPermission}
disabled={$simulationStatus !== Status.Complete}
statusBadgeText={($constraintsStatus === Status.Complete ||
$constraintsStatus === Status.Failed ||
$constraintsStatus === Status.PartialSuccess) &&
numConstraintsViolated + numConstraintsWithErrors + $uncheckedConstraintCount > 0
? `${numConstraintsViolated + numConstraintsWithErrors + $uncheckedConstraintCount}`
: undefined}
statusBadgeText={constraintsStatusText}
buttonTooltipContent={$simulationStatus !== Status.Complete ? 'Completed simulation required' : ''}
permissionError={$planReadOnly
? PlanStatusMessages.READ_ONLY
Expand Down

0 comments on commit 0b0ae7a

Please sign in to comment.