Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionName and actionApiIdentifier when sending stubbed action event #642

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading