Skip to content

Commit

Permalink
Add functionName and actionApiIdentifier when sending stubbed action …
Browse files Browse the repository at this point in the history
…event
  • Loading branch information
alanko0511 committed Sep 13, 2024
1 parent 43326e3 commit 0f59bd1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/api-client-core/src/GadgetFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export interface StubbedActionFunctionMetadata {
functionName: string;
operationName?: string;
errorMessage: string;
actionApiIdentifier: string;
modelApiIdentifier?: string;
variables: VariablesOptions;
reason: StubbedActionReason;
Expand Down
6 changes: 4 additions & 2 deletions packages/react/spec/useAction.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,8 @@ describe("useAction", () => {
type: "stubbedAction",
reason: "MissingApiTrigger",
dataPath: "fakePath",
functionName: "fakeFunction",
functionName: "fakeAction",
actionApiIdentifier: "fakeAction",
modelApiIdentifier: "fakeModel",
variables: {},
}),
Expand All @@ -833,7 +834,8 @@ describe("useAction", () => {
expect(eventDispatched!.detail).toEqual({
reason: "MissingApiTrigger",
action: {
actionApiIdentifier: "fakeFunction",
functionName: "fakeAction",
actionApiIdentifier: "fakeAction",
dataPath: "fakePath",
modelApiIdentifier: "fakeModel",
},
Expand Down
6 changes: 4 additions & 2 deletions packages/react/spec/useGlobalAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ describe("useGlobalAction", () => {
type: "stubbedAction",
reason: "MissingApiTrigger",
dataPath: "fakePath",
functionName: "fakeFunction",
functionName: "fakeAction",
actionApiIdentifier: "fakeAction",
variables: {},
}),
{
Expand All @@ -282,7 +283,8 @@ describe("useGlobalAction", () => {
expect(eventDispatched!.detail).toEqual({
reason: "MissingApiTrigger",
action: {
actionApiIdentifier: "fakeFunction",
functionName: "fakeAction",
actionApiIdentifier: "fakeAction",
dataPath: "fakePath",
},
});
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/useAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const useAction = <
useEffect(() => {
if (action.type === ("stubbedAction" as string)) {
const stubbedAction = action as unknown as StubbedActionFunction<GivenOptions>;
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;
}
Expand All @@ -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,
},
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/useBulkAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const useBulkAction = <
useEffect(() => {
if (action.type === ("stubbedAction" as string)) {
const stubbedAction = action as unknown as StubbedActionFunction<GivenOptions>;
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;
}
Expand All @@ -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,
},
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/useGlobalAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const useGlobalAction = <F extends GlobalActionFunction<any>>(
detail: {
reason: stubbedAction.reason,
action: {
actionApiIdentifier: stubbedAction.functionName,
functionName: stubbedAction.functionName,
actionApiIdentifier: stubbedAction.actionApiIdentifier,
dataPath: stubbedAction.dataPath,
},
},
Expand Down

0 comments on commit 0f59bd1

Please sign in to comment.