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:
@@ -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);
|
||||
|
||||
@@ -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" });
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user