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 470532d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 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
2 changes: 2 additions & 0 deletions packages/react/spec/useGlobalAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ describe("useGlobalAction", () => {
reason: "MissingApiTrigger",
dataPath: "fakePath",
functionName: "fakeFunction",
actionApiIdentifier: "fakeAction",
variables: {},
}),
{
Expand All @@ -282,6 +283,7 @@ describe("useGlobalAction", () => {
expect(eventDispatched!.detail).toEqual({
reason: "MissingApiTrigger",
action: {
functionName: "fakeFunction",
actionApiIdentifier: "fakeFunction",
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
1 change: 1 addition & 0 deletions packages/react/src/useGlobalAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const useGlobalAction = <F extends GlobalActionFunction<any>>(
detail: {
reason: stubbedAction.reason,
action: {
functionName: stubbedAction.functionName,
actionApiIdentifier: stubbedAction.functionName,
dataPath: stubbedAction.dataPath,
},
Expand Down

0 comments on commit 470532d

Please sign in to comment.