Skip to content

Commit 487867d

Browse files
committed
fix(seer): Decouple create-pr setting from stopping point
1 parent b62f69f commit 487867d

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

static/app/views/settings/seer/overview/utils/seerStoppingPoint.ts

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ export function getProjectStoppingPointMutationOptions({
134134
project.slug
135135
);
136136

137+
function resolveStoppingPointValue(stoppingPoint: SelectValue) {
138+
return stoppingPoint === 'root_cause'
139+
? ('root_cause' as const)
140+
: organization.autoOpenPrs
141+
? ('open_pr' as const)
142+
: ('code_changes' as const);
143+
}
144+
137145
return mutationOptions({
138146
mutationFn: async ({stoppingPoint}: {stoppingPoint: SelectValue}) => {
139147
const tuning = stoppingPoint === 'off' ? ('off' as const) : ('medium' as const);
@@ -150,22 +158,10 @@ export function getProjectStoppingPointMutationOptions({
150158
const repositories = preference?.repositories ?? [];
151159
const automationHandoff = preference?.automation_handoff;
152160

153-
const stoppingPointValue =
154-
stoppingPoint === 'root_cause'
155-
? ('root_cause' as const)
156-
: organization.autoOpenPrs
157-
? ('open_pr' as const)
158-
: ('code_changes' as const);
159-
160161
const preferencePayload = {
161162
repositories,
162-
automated_run_stopping_point: stoppingPointValue,
163-
automation_handoff: automationHandoff
164-
? {
165-
...automationHandoff,
166-
auto_create_pr: stoppingPointValue === 'open_pr',
167-
}
168-
: automationHandoff,
163+
automated_run_stopping_point: resolveStoppingPointValue(stoppingPoint),
164+
automation_handoff: automationHandoff,
169165
};
170166

171167
preferencePromise = fetchMutation<SeerPreferencesResponse>({
@@ -177,6 +173,28 @@ export function getProjectStoppingPointMutationOptions({
177173

178174
return await Promise.all([projectPromise, preferencePromise]);
179175
},
176+
onMutate: ({stoppingPoint}: {stoppingPoint: SelectValue}) => {
177+
const previousProject = ProjectsStore.getById(project.id);
178+
const previousPreference = getApiQueryData<SeerPreferencesResponse>(
179+
queryClient,
180+
seerPrefsQueryKey
181+
);
182+
183+
const tuning = stoppingPoint === 'off' ? ('off' as const) : ('medium' as const);
184+
ProjectsStore.onUpdateSuccess({...project, autofixAutomationTuning: tuning});
185+
186+
if (stoppingPoint !== 'off' && previousPreference?.preference) {
187+
setApiQueryData<SeerPreferencesResponse>(queryClient, seerPrefsQueryKey, {
188+
...previousPreference,
189+
preference: {
190+
...previousPreference.preference,
191+
automated_run_stopping_point: resolveStoppingPointValue(stoppingPoint),
192+
},
193+
});
194+
}
195+
196+
return {previousProject, previousPreference};
197+
},
180198
onSuccess: ([updatedProject, preferencePayload]) => {
181199
ProjectsStore.onUpdateSuccess(updatedProject);
182200

@@ -197,6 +215,24 @@ export function getProjectStoppingPointMutationOptions({
197215
}
198216
}
199217
},
218+
onError: (_error: unknown, _variables: unknown, context: unknown) => {
219+
const ctx = context as
220+
| {
221+
previousPreference: SeerPreferencesResponse | undefined;
222+
previousProject: Project | undefined;
223+
}
224+
| undefined;
225+
if (ctx?.previousProject) {
226+
ProjectsStore.onUpdateSuccess(ctx.previousProject);
227+
}
228+
if (ctx?.previousPreference) {
229+
setApiQueryData<SeerPreferencesResponse>(
230+
queryClient,
231+
seerPrefsQueryKey,
232+
ctx.previousPreference
233+
);
234+
}
235+
},
200236
onSettled: () => {
201237
queryClient.invalidateQueries({queryKey: seerPrefsQueryKey});
202238

static/gsApp/views/seerAutomation/components/projectDetails/autofixAgent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ function StoppingPointField({
179179
stoppingPointMutationOpts.onSuccess?.(data, variables, onMutateResult, context);
180180
addSuccessMessage(t('Stopping point updated'));
181181
},
182-
onError: () => {
182+
onError: (error, variables, onMutateResult, context) => {
183+
stoppingPointMutationOpts.onError?.(error, variables, onMutateResult, context);
183184
addErrorMessage(t('Failed to update stopping point'));
184185
},
185186
});

0 commit comments

Comments
 (0)