From 0f59bd15e6c3b6ca9def667f40037a2867751e7f 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] Add functionName and actionApiIdentifier when sending stubbed action event --- packages/api-client-core/src/GadgetFunctions.ts | 1 + packages/react/spec/useAction.spec.tsx | 6 ++++-- packages/react/spec/useGlobalAction.spec.ts | 6 ++++-- packages/react/src/useAction.ts | 5 +++-- packages/react/src/useBulkAction.ts | 5 +++-- packages/react/src/useGlobalAction.ts | 3 ++- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/api-client-core/src/GadgetFunctions.ts b/packages/api-client-core/src/GadgetFunctions.ts index 147d51837..4789edb59 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/spec/useAction.spec.tsx b/packages/react/spec/useAction.spec.tsx index 081dedd26..26f8b59a2 100644 --- a/packages/react/spec/useAction.spec.tsx +++ b/packages/react/spec/useAction.spec.tsx @@ -820,7 +820,8 @@ describe("useAction", () => { type: "stubbedAction", reason: "MissingApiTrigger", dataPath: "fakePath", - functionName: "fakeFunction", + functionName: "fakeAction", + actionApiIdentifier: "fakeAction", modelApiIdentifier: "fakeModel", variables: {}, }), @@ -833,7 +834,8 @@ describe("useAction", () => { expect(eventDispatched!.detail).toEqual({ reason: "MissingApiTrigger", action: { - actionApiIdentifier: "fakeFunction", + functionName: "fakeAction", + actionApiIdentifier: "fakeAction", dataPath: "fakePath", modelApiIdentifier: "fakeModel", }, diff --git a/packages/react/spec/useGlobalAction.spec.ts b/packages/react/spec/useGlobalAction.spec.ts index 6b2371241..961164acd 100644 --- a/packages/react/spec/useGlobalAction.spec.ts +++ b/packages/react/spec/useGlobalAction.spec.ts @@ -270,7 +270,8 @@ describe("useGlobalAction", () => { type: "stubbedAction", reason: "MissingApiTrigger", dataPath: "fakePath", - functionName: "fakeFunction", + functionName: "fakeAction", + actionApiIdentifier: "fakeAction", variables: {}, }), { @@ -282,7 +283,8 @@ describe("useGlobalAction", () => { expect(eventDispatched!.detail).toEqual({ reason: "MissingApiTrigger", action: { - actionApiIdentifier: "fakeFunction", + functionName: "fakeAction", + actionApiIdentifier: "fakeAction", dataPath: "fakePath", }, }); diff --git a/packages/react/src/useAction.ts b/packages/react/src/useAction.ts index 944d943e8..eea7f6256 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 5ed80bb70..ca9ce38e9 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, }, diff --git a/packages/react/src/useGlobalAction.ts b/packages/react/src/useGlobalAction.ts index 2b16a31fd..49f537e45 100644 --- a/packages/react/src/useGlobalAction.ts +++ b/packages/react/src/useGlobalAction.ts @@ -42,7 +42,8 @@ export const useGlobalAction = >( detail: { reason: stubbedAction.reason, action: { - actionApiIdentifier: stubbedAction.functionName, + functionName: stubbedAction.functionName, + actionApiIdentifier: stubbedAction.actionApiIdentifier, dataPath: stubbedAction.dataPath, }, },