Skip to content

Commit

Permalink
fix constraint duplication
Browse files Browse the repository at this point in the history
fix constraint context menu
  • Loading branch information
duranb committed Oct 31, 2024
1 parent 6c5dfcb commit ef5c351
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 42 deletions.
9 changes: 4 additions & 5 deletions src/components/constraints/ConstraintListItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,12 @@
>
View Constraint
</ContextMenuItem>
{#if version?.type === 'JAR'}
<ContextMenuItem on:click={onDuplicateConstraintInvocation}>Duplicate Invocation</ContextMenuItem>
<ContextMenuItem on:click={onDeleteConstraintInvocation}>Delete Invocation</ContextMenuItem>
{/if}
</svelte:fragment>

{#if version?.type === 'JAR'}
<ContextMenuItem on:click={onDuplicateConstraintInvocation}>Duplicate Invocation</ContextMenuItem>
<ContextMenuItem on:click={onDeleteConstraintInvocation}>Delete Invocation</ContextMenuItem>
{/if}

<Collapse title="Description" defaultExpanded={false}>
<div class="st-typography-label">
{#if constraint.description}
Expand Down
4 changes: 2 additions & 2 deletions src/components/constraints/ConstraintsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@
async function onDeleteConstraintInvocation(event: CustomEvent<ConstraintPlanSpecification>) {
const {
detail: { constraint_metadata, specification_id, ...constraintPlanSpec },
detail: { constraint_metadata, ...constraintPlanSpec },
} = event;
if ($plan) {
await effects.deleteConstraintInvocations($plan, specification_id, [constraintPlanSpec.invocation_id], user);
await effects.deleteConstraintInvocations($plan, [constraintPlanSpec.invocation_id], user);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/types/constraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export type ConstraintPlanSpecification = {
enabled: boolean;
invocation_id?: number;
plan_id: number;
specification_id: number;
// constraint_definition: ConstraintDefinition;
// plan: Plan;
};
Expand Down
16 changes: 6 additions & 10 deletions src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,24 +718,23 @@ const effects = {
},

async createConstraintPlanSpecification(
spec_goal: ConstraintPlanSpecInsertInput,
constraintPlanSpecification: ConstraintPlanSpecInsertInput,
user: User | null,
): Promise<number | null> {
try {
if (!queryPermissions.CREATE_CONSTRAINT_PLAN_SPECIFICATION(user)) {
throwPermissionError('create a scheduling spec goal');
}

const data = await reqHasura<ConstraintPlanSpecification>(
gql.CREATE_CONSTRAINT_PLAN_SPECIFICATION,
{ spec_goal },
{ constraintPlanSpecification },
user,
);
const { createConstraintSpec } = data;
if (createConstraintSpec != null) {
const { specification_id } = createConstraintSpec;
const { invocation_id } = createConstraintSpec;
showSuccessToast('New Constraint Invocation Created Successfully');
return specification_id;
return invocation_id ?? null;
} else {
throw Error('Unable to create a constraint spec invocation');
}
Expand Down Expand Up @@ -2357,7 +2356,6 @@ const effects = {

async deleteConstraintInvocations(
plan: Plan,
constraintSpecificationId: number,
constraintInvocationIdsToDelete: (number | undefined)[],
user: User | null,
) {
Expand All @@ -2368,8 +2366,7 @@ const effects = {
const { deleteConstraintPlanSpecifications } = await reqHasura(
gql.DELETE_CONSTRAINT_INVOCATIONS,
{
constraintInvocationIdsToDelete: constraintInvocationIdsToDelete,
specificationId: constraintSpecificationId,
constraintInvocationIdsToDelete,
},
user,
);
Expand Down Expand Up @@ -5703,7 +5700,6 @@ const effects = {
enabled,
id: constraintId,
invocation_id,
planId: plan.id,
revision,
},
user,
Expand Down Expand Up @@ -5733,7 +5729,7 @@ const effects = {

const { deleteConstraintPlanSpecifications, insertConstraintPlanSpecifications } = await reqHasura(
gql.UPDATE_CONSTRAINT_PLAN_SPECIFICATIONS,
{ constraintSpecIdsToDelete, constraintSpecsToInsert, planId: plan.id },
{ constraintSpecIdsToDelete, constraintSpecsToInsert },
user,
);

Expand Down
33 changes: 9 additions & 24 deletions src/utilities/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,11 @@ const gql = {

CREATE_CONSTRAINT_PLAN_SPECIFICATION: `#graphql
mutation CreateConstraintSpecification($constraintPlanSpecification: constraint_specification_insert_input!) {
createConstraintSpec: ${Queries.INSERT_CONSTRAINT_SPECIFICATION}(object: $spec_goal) {
createConstraintSpec: ${Queries.INSERT_CONSTRAINT_SPECIFICATION}(object: $constraintPlanSpecification) {
arguments
constraint_id
enabled
goal_id
priority
specification_id
invocation_id
}
}
`,
Expand Down Expand Up @@ -913,7 +913,7 @@ const gql = {
mutation DeleteConstraintInvocations($constraintInvocationIdsToDelete: [Int!]! = [], $specificationId: Int!) {
deleteConstraintPlanSpecifications: ${Queries.DELETE_CONSTRAINT_SPECIFICATIONS}(
where: {
constraint_invocation_id: { _in: $constraintInvocationIdsToDelete },
invocation_id: { _in: $constraintInvocationIdsToDelete },
_and: {
specification_id: { _eq: $specificationId },
}
Expand Down Expand Up @@ -1220,21 +1220,6 @@ const gql = {
}
`,

// DELETE_SCHEDULING_GOAL_PLAN_SPECIFICATIONS: `#graphql
// mutation DeleteSchedulingGoalPlanSpecification($goalIds: [Int!]!, $planId: Int!) {
// ${Queries.DELETE_SCHEDULING_SPECIFICATION_GOALS}(
// where: {
// goal_id: { _in: $goalIds },
// _and: {
// plan_id: { _eq: $planId },
// }
// }
// ) {
// affected_rows
// }
// }
// `,

DELETE_SEQUENCE_ADAPTATION: `#graphql
mutation DeleteSequenceAdaptation($id: Int!) {
deleteSequenceAdaptation: ${Queries.DELETE_SEQUENCE_ADAPTATION}(id: $id) {
Expand Down Expand Up @@ -2366,7 +2351,7 @@ const gql = {
${Queries.CONSTRAINT_SPECIFICATIONS} (where: {specification: {plan_id: {_eq: $planId}}}) {
arguments
constraint_id
constraint_invocation_id
invocation_id
constraint_revision
enabled
specification_id
Expand All @@ -2390,7 +2375,7 @@ const gql = {
order_by: { constraint_id: desc }
) {
constraint_id
constraint_invocation_id
invocation_id
constraint_revision
enabled
constraint_metadata {
Expand Down Expand Up @@ -3573,9 +3558,9 @@ const gql = {
`,

UPDATE_CONSTRAINT_PLAN_SPECIFICATION: `#graphql
mutation UpdateConstraintPlanSpecification($arguments: jsonb, $constraint_invocation_id: Int!, $revision: Int!, $enabled: Boolean!) {
mutation UpdateConstraintPlanSpecification($arguments: jsonb, $constraintInvocationId: Int!, $revision: Int!, $enabled: Boolean!) {
updateConstraintPlanSpecification: ${Queries.UPDATE_CONSTRAINT_SPECIFICATION}(
pk_columns: { constraint_invocation_id: $constraint_invocation_id },
pk_columns: { invocation_id: $constraintInvocationId },
_set: {
arguments: $arguments,
constraint_revision: $revision,
Expand Down

0 comments on commit ef5c351

Please sign in to comment.