Skip to content
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
17 changes: 17 additions & 0 deletions packages/approval-controller/src/ApprovalController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,23 @@ describe('approval controller', () => {
).toStrictEqual(expectedFlow);
},
);

it('does not call showApprovalRequest if show is false', () => {
const result = approvalController.startFlow({ show: false });

const expectedFlow = {
id: expect.any(String),
loadingText: null,
};
expect(result).toStrictEqual(expectedFlow);
expect(showApprovalRequest).toHaveBeenCalledTimes(0);
expect(approvalController.state[APPROVAL_FLOWS_STORE_KEY]).toHaveLength(
1,
);
expect(
approvalController.state[APPROVAL_FLOWS_STORE_KEY][0],
).toStrictEqual(expectedFlow);
});
});

describe('endFlow', () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/approval-controller/src/ApprovalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export type AcceptOptions = {
export type StartFlowOptions = OptionalField<
ApprovalFlow,
'id' | 'loadingText'
>;
> & { show?: boolean };

export type EndFlowOptions = Pick<ApprovalFlow, 'id'>;

Expand Down Expand Up @@ -758,6 +758,7 @@ export class ApprovalController extends BaseControllerV2<
* @param opts - Options bag.
* @param opts.id - The id of the approval flow.
* @param opts.loadingText - The loading text that will be associated to the approval flow.
* @param opts.show - A flag to determine whether the approval should show to the user.
* @returns The object containing the approval flow id.
*/
startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {
Expand All @@ -768,7 +769,10 @@ export class ApprovalController extends BaseControllerV2<
draftState.approvalFlows.push({ id, loadingText });
});

this.#showApprovalRequest();
// By default, if nothing else is specified, we always show the approval.
if (opts.show !== false) {
this.#showApprovalRequest();
}

return { id, loadingText };
}
Expand Down