Skip to content

Commit

Permalink
add force constraint re-check button
Browse files Browse the repository at this point in the history
  • Loading branch information
duranb committed Dec 6, 2024
1 parent 0a4da27 commit ba9cccc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
25 changes: 23 additions & 2 deletions src/components/constraints/ConstraintsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import FilterIcon from '@nasa-jpl/stellar/icons/filter.svg?component';
import PlanLeftArrow from '@nasa-jpl/stellar/icons/plan_with_left_arrow.svg?component';
import PlanRightArrow from '@nasa-jpl/stellar/icons/plan_with_right_arrow.svg?component';
import RefreshIcon from '@nasa-jpl/stellar/icons/refresh.svg?component';
import VisibleHideIcon from '@nasa-jpl/stellar/icons/visible_hide.svg?component';
import VisibleShowIcon from '@nasa-jpl/stellar/icons/visible_show.svg?component';
import { PlanStatusMessages } from '../../enums/planStatusMessages';
Expand Down Expand Up @@ -261,10 +262,30 @@
<GridMenu {gridSection} title="Constraints" />
<PanelHeaderActions status={$constraintsStatus} indeterminate>
<PanelHeaderActionButton
disabled={$simulationStatus !== Status.Complete}
title="Re-Check"
disabled={$simulationStatus !== Status.Complete || $constraintsStatus !== Status.Complete}
tooltipContent="Re-check constraints"
showLabel
use={[
[
permissionHandler,
{
hasPermission: $plan
? featurePermissions.constraintRuns.canCreate(user, $plan, $plan.model) && !$planReadOnly
: false,
permissionError: $planReadOnly
? PlanStatusMessages.READ_ONLY
: 'You do not have permission to run constraint checks',
},
],
]}
on:click={() => $plan && effects.checkConstraints($plan, true, user)}><RefreshIcon /></PanelHeaderActionButton
>
<PanelHeaderActionButton
disabled={$simulationStatus !== Status.Complete || $constraintsStatus === Status.Complete}
tooltipContent={$simulationStatus !== Status.Complete ? 'Completed simulation required' : ''}
title="Check Constraints"
on:click={() => $plan && effects.checkConstraints($plan, user)}
on:click={() => $plan && effects.checkConstraints($plan, false, user)}
use={[
[
permissionHandler,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@
: 'You do not have permission to run a constraint check'}
status={$constraintsStatus}
showStatusInMenu={false}
on:click={() => $plan && effects.checkConstraints($plan, data.user)}
on:click={() => $plan && effects.checkConstraints($plan, false, data.user)}
indeterminate
>
<VerticalCollapseIcon />
Expand Down
1 change: 1 addition & 0 deletions src/utilities/effects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ describe('Handle modal and requests in effects', () => {
id: 1,
owner: 'test',
} as Plan,
false,
mockUser,
);

Expand Down
3 changes: 2 additions & 1 deletion src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,15 @@ const effects = {
}
},

async checkConstraints(plan: Plan, user: User | null): Promise<void> {
async checkConstraints(plan: Plan, force: boolean = false, user: User | null): Promise<void> {
try {
rawCheckConstraintsStatus.set(Status.Incomplete);
if (plan !== null) {
const { id: planId } = plan;
const data = await reqHasura<ConstraintResponse[]>(
gql.CHECK_CONSTRAINTS,
{
force,
planId,
},
user,
Expand Down
5 changes: 3 additions & 2 deletions src/utilities/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ const gql = {
`,

CHECK_CONSTRAINTS: `#graphql
query CheckConstraints($planId: Int!) {
constraintResponses: ${Queries.CONSTRAINT_VIOLATIONS}(planId: $planId) {
query CheckConstraints($planId: Int!, $force: Boolean!) {
constraintResponses: ${Queries.CONSTRAINT_VIOLATIONS}(planId: $planId, force: $force) {
success
constraintId
constraintInvocationId
Expand Down Expand Up @@ -2398,6 +2398,7 @@ const gql = {
SUB_CONSTRAINT_RUNS: `#graphql
subscription SubConstraintRuns($simulationDatasetId: Int!) {
constraintRuns: ${Queries.CONSTRAINT_RUN}(where: { simulation_dataset_id: { _eq: $simulationDatasetId }}) {
arguments
constraint_id
constraint_invocation_id
constraint_revision
Expand Down

0 comments on commit ba9cccc

Please sign in to comment.