Guard store updater and handle reorder errors

Check that the move mutation payload contains the pattern
before removing it from the uncategorised connection. Add
onCompleted error handling to reorder mutations so GraphQL
errors are surfaced to the user.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-05-05 11:08:55 +04:00
parent 3b4aa7f971
commit 39db90168c
2 changed files with 15 additions and 0 deletions

View File

@@ -195,6 +195,11 @@ export function DetectionPatternRow({ patternKey, connectionId }: DetectionPatte
},
},
updater(store) {
const payload = store.getRootField("moveCookiePatternToCategory");
if (!payload?.getLinkedRecord("cookiePattern")) {
return;
}
const conn = store.get(connectionId);
if (conn) {
ConnectionHandler.deleteNode(conn, pattern.id);

View File

@@ -562,6 +562,11 @@ export function CategorySection({ categoryKey, connectionId }: CategorySectionPr
const above = allCategories[selfIndex - 1];
reorderCategory({
variables: { input: { cookieCategoryId: category.id, rank: above.rank } },
onCompleted(_, errors) {
if (errors?.length) {
toast({ title: __("Error"), description: errors[0].message, variant: "error" });
}
},
onError(error) {
toast({ title: __("Error"), description: formatError(__("Failed to reorder"), error as GraphQLError), variant: "error" });
},
@@ -573,6 +578,11 @@ export function CategorySection({ categoryKey, connectionId }: CategorySectionPr
const below = allCategories[selfIndex + 1];
reorderCategory({
variables: { input: { cookieCategoryId: category.id, rank: below.rank } },
onCompleted(_, errors) {
if (errors?.length) {
toast({ title: __("Error"), description: errors[0].message, variant: "error" });
}
},
onError(error) {
toast({ title: __("Error"), description: formatError(__("Failed to reorder"), error as GraphQLError), variant: "error" });
},