Skip to content

Commit

Permalink
Fix goal plan specification deletion (#1552)
Browse files Browse the repository at this point in the history
  • Loading branch information
duranb authored Nov 12, 2024
1 parent 0f606b6 commit f3af153
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/components/modals/ManagePlanSchedulingGoalsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
}
}
async function onUpdateGoal(selectedGoals: Record<number, boolean>) {
async function onUpdateGoals(selectedGoals: Record<number, boolean>) {
if ($plan && $schedulingPlanSpecification) {
const goalPlanSpecUpdates: {
goalPlanSpecIdsToDelete: number[];
Expand All @@ -220,10 +220,12 @@
// if we find at least one goal invocation with the selected goal_id, we don't want to insert this goal_id into the plan spec
// i.e. this goal was already selected when we entered the modal, so we don't want to kick off an update, which would cause a duplicate invocation to appear
const goalAlreadyExistsInPlanSpec = $allowedSchedulingGoalSpecs.find(e => e.goal_id === goalId) !== undefined;
const goalsInPlanSpecification = $allowedSchedulingGoalSpecs.filter(
schedulingGoalPlanSpecification => schedulingGoalPlanSpecification.goal_id === goalId,
);
if (isSelected && $schedulingPlanSpecification !== null) {
if (!goalAlreadyExistsInPlanSpec) {
if (!goalsInPlanSpecification.length) {
return {
...prevGoalPlanSpecUpdates,
goalPlanSpecsToAdd: [
Expand All @@ -241,7 +243,10 @@
} else {
return {
...prevGoalPlanSpecUpdates,
goalPlanSpecIdsToDelete: [...prevGoalPlanSpecUpdates.goalPlanSpecIdsToDelete, goalId],
goalPlanSpecIdsToDelete: [
...prevGoalPlanSpecUpdates.goalPlanSpecIdsToDelete,
...goalsInPlanSpecification.map(({ goal_invocation_id }) => goal_invocation_id),
],
};
}
},
Expand Down Expand Up @@ -296,7 +301,7 @@
<button class="st-button secondary" on:click={() => dispatch('close')}> Cancel </button>
<button
class="st-button"
on:click={() => onUpdateGoal(selectedGoals)}
on:click={() => onUpdateGoals(selectedGoals)}
use:permissionHandler={{
hasPermission: hasEditSpecPermission && !$planReadOnly,
permissionError: $planReadOnly
Expand Down
2 changes: 1 addition & 1 deletion src/types/scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export type SchedulingGoalPlanSpecification = {
enabled: boolean;
goal_definition?: Pick<SchedulingGoalDefinition, 'analyses'> | null;
goal_id: number;
goal_invocation_id?: number;
goal_invocation_id: number;
goal_metadata:
| (Pick<SchedulingGoalMetadata, 'name' | 'owner' | 'public'> & {
versions: Pick<SchedulingGoalDefinition, 'revision' | 'analyses' | 'type' | 'parameter_schema'>[];
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3815,7 +3815,7 @@ const gql = {
}
deleteSchedulingGoalModelSpecifications: ${Queries.DELETE_SCHEDULING_GOAL_MODEL_SPECIFICATIONS}(
where: {
goal_id: { _in: $goalIdsToDelete },
goal_invocation_id: { _in: $goalIdsToDelete },
_and: {
model_id: { _eq: $modelId }
}
Expand Down Expand Up @@ -3855,7 +3855,7 @@ const gql = {
}
}
deleteSchedulingGoalPlanSpecifications: ${Queries.DELETE_SCHEDULING_SPECIFICATION_GOALS}(
where: { goal_id: { _in: $goalSpecIdsToDelete } }
where: { goal_invocation_id: { _in: $goalSpecIdsToDelete } }
) {
affected_rows
}
Expand Down

0 comments on commit f3af153

Please sign in to comment.