From 6ae26734bbee465a47987c04219f17b3886dd90b Mon Sep 17 00:00:00 2001 From: Alan Ko <34646302+alanko0511@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:37:41 -0400 Subject: [PATCH] Use action API identifier instead --- packages/api-client-core/src/GadgetFunctions.ts | 1 + packages/react/src/useAction.ts | 5 +++-- packages/react/src/useBulkAction.ts | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/api-client-core/src/GadgetFunctions.ts b/packages/api-client-core/src/GadgetFunctions.ts index 147d5183..4789edb5 100644 --- a/packages/api-client-core/src/GadgetFunctions.ts +++ b/packages/api-client-core/src/GadgetFunctions.ts @@ -143,6 +143,7 @@ export interface StubbedActionFunctionMetadata { functionName: string; operationName?: string; errorMessage: string; + actionApiIdentifier: string; modelApiIdentifier?: string; variables: VariablesOptions; reason: StubbedActionReason; diff --git a/packages/react/src/useAction.ts b/packages/react/src/useAction.ts index 944d943e..eea7f625 100644 --- a/packages/react/src/useAction.ts +++ b/packages/react/src/useAction.ts @@ -72,7 +72,7 @@ export const useAction = < useEffect(() => { if (action.type === ("stubbedAction" as string)) { const stubbedAction = action as unknown as StubbedActionFunction; - if (!("reason" in stubbedAction) || !("dataPath" in stubbedAction)) { + if (!("reason" in stubbedAction) || !("dataPath" in stubbedAction) || !("actionApiIdentifier" in stubbedAction)) { // Don't dispatch an event if the generated client has not yet been updated with the updated parameters return; } @@ -81,7 +81,8 @@ export const useAction = < detail: { reason: stubbedAction.reason, action: { - actionApiIdentifier: stubbedAction.functionName, + functionName: stubbedAction.functionName, + actionApiIdentifier: stubbedAction.actionApiIdentifier, modelApiIdentifier: stubbedAction.modelApiIdentifier, dataPath: stubbedAction.dataPath, }, diff --git a/packages/react/src/useBulkAction.ts b/packages/react/src/useBulkAction.ts index 5ed80bb7..ca9ce38e 100644 --- a/packages/react/src/useBulkAction.ts +++ b/packages/react/src/useBulkAction.ts @@ -67,7 +67,7 @@ export const useBulkAction = < useEffect(() => { if (action.type === ("stubbedAction" as string)) { const stubbedAction = action as unknown as StubbedActionFunction; - if (!("reason" in stubbedAction) || !("dataPath" in stubbedAction)) { + if (!("reason" in stubbedAction) || !("dataPath" in stubbedAction) || !("actionApiIdentifier" in stubbedAction)) { // Don't dispatch an event if the generated client has not yet been updated with the updated parameters return; } @@ -76,7 +76,8 @@ export const useBulkAction = < detail: { reason: stubbedAction.reason, action: { - actionApiIdentifier: stubbedAction.functionName, + functionName: stubbedAction.functionName, + actionApiIdentifier: stubbedAction.actionApiIdentifier, modelApiIdentifier: stubbedAction.modelApiIdentifier, dataPath: stubbedAction.dataPath, },