Skip to content

Commit 60171f3

Browse files
committed
fix(FR-2820): handle network failures in activate/deactivate project mutations
1 parent 9d751e2 commit 60171f3

1 file changed

Lines changed: 71 additions & 43 deletions

File tree

packages/backend.ai-ui/src/components/fragments/BAIProjectTable.tsx

Lines changed: 71 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -164,36 +164,51 @@ const BAIProjectTable = ({
164164
okText: t('comp:BAIProjectTable.Deactivate'),
165165
onConfirm: () => {
166166
if (!record.row_id) return;
167-
commitDeleteGroup({
168-
variables: { gid: record.row_id },
169-
onCompleted: (response, errors) => {
170-
if (errors && errors.length > 0) {
171-
errors.forEach((error) => {
167+
return new Promise<void>((resolve) => {
168+
commitDeleteGroup({
169+
variables: { gid: record.row_id },
170+
onCompleted: (response, errors) => {
171+
if (errors && errors.length > 0) {
172+
errors.forEach((error) => {
173+
message.error(
174+
getErrorMessage(
175+
error,
176+
t(
177+
'comp:BAIProjectTable.FailedToDeactivateProject',
178+
),
179+
),
180+
);
181+
});
182+
resolve();
183+
return;
184+
}
185+
if (response.delete_group?.ok) {
186+
message.success(
187+
t(
188+
'comp:BAIProjectTable.ProjectDeactivated',
189+
),
190+
);
191+
updateFetchKey?.();
192+
} else {
172193
message.error(
173-
getErrorMessage(
174-
error,
194+
response.delete_group?.msg ||
175195
t(
176196
'comp:BAIProjectTable.FailedToDeactivateProject',
177197
),
178-
),
179198
);
180-
});
181-
return;
182-
}
183-
if (response.delete_group?.ok) {
184-
message.success(
185-
t('comp:BAIProjectTable.ProjectDeactivated'),
186-
);
187-
updateFetchKey?.();
188-
} else {
199+
}
200+
resolve();
201+
},
202+
onError: (error) => {
189203
message.error(
190-
response.delete_group?.msg ||
204+
error?.message ||
191205
t(
192206
'comp:BAIProjectTable.FailedToDeactivateProject',
193207
),
194208
);
195-
}
196-
},
209+
resolve();
210+
},
211+
});
197212
});
198213
},
199214
},
@@ -211,39 +226,52 @@ const BAIProjectTable = ({
211226
okText: t('comp:BAIProjectTable.Activate'),
212227
onConfirm: () => {
213228
if (!record.row_id) return;
214-
commitModifyGroup({
215-
variables: {
216-
gid: record.row_id,
217-
props: { is_active: true },
218-
},
219-
onCompleted: (response, errors) => {
220-
if (errors && errors.length > 0) {
221-
errors.forEach((error) => {
229+
return new Promise<void>((resolve) => {
230+
commitModifyGroup({
231+
variables: {
232+
gid: record.row_id,
233+
props: { is_active: true },
234+
},
235+
onCompleted: (response, errors) => {
236+
if (errors && errors.length > 0) {
237+
errors.forEach((error) => {
238+
message.error(
239+
getErrorMessage(
240+
error,
241+
t(
242+
'comp:BAIProjectTable.FailedToActivateProject',
243+
),
244+
),
245+
);
246+
});
247+
resolve();
248+
return;
249+
}
250+
if (response.modify_group?.ok) {
251+
message.success(
252+
t('comp:BAIProjectTable.ProjectActivated'),
253+
);
254+
updateFetchKey?.();
255+
} else {
222256
message.error(
223-
getErrorMessage(
224-
error,
257+
response.modify_group?.msg ||
225258
t(
226259
'comp:BAIProjectTable.FailedToActivateProject',
227260
),
228-
),
229261
);
230-
});
231-
return;
232-
}
233-
if (response.modify_group?.ok) {
234-
message.success(
235-
t('comp:BAIProjectTable.ProjectActivated'),
236-
);
237-
updateFetchKey?.();
238-
} else {
262+
}
263+
resolve();
264+
},
265+
onError: (error) => {
239266
message.error(
240-
response.modify_group?.msg ||
267+
error?.message ||
241268
t(
242269
'comp:BAIProjectTable.FailedToActivateProject',
243270
),
244271
);
245-
}
246-
},
272+
resolve();
273+
},
274+
});
247275
});
248276
},
249277
},

0 commit comments

Comments
 (0)