Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix goal plan specification deletion #1552

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading