Skip to content

Commit

Permalink
feat(web): add controls to the preview (#5884)
Browse files Browse the repository at this point in the history
* feat: add controls to the preview

* fix: sync to latest enterprise

* fix: steps

* fix: test

* fix: page colorr

* feat: add debounce

* fix: schema

* fix: pr comments

* fix: pointer
  • Loading branch information
scopsy authored Jul 1, 2024
1 parent d3cd760 commit 752b3a2
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 208 deletions.
14 changes: 11 additions & 3 deletions apps/api/src/app/events/e2e/bridge-trigger.e2e-ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,8 @@ contexts.forEach((context: Context) => {
await saveControlVariables(session, workflowId, stepId, { variables: { name: 'stored_control_name' } });
}

const controls = { controls: { step: { [stepId]: { name: 'stored_control_name' } } } };
await triggerEvent(session, workflowId, subscriber, controls, bridge);
const controls = { steps: { [stepId]: { name: 'stored_control_name' } } };
await triggerEvent(session, workflowId, subscriber, undefined, bridge, controls);
await session.awaitRunningJobs();

const sentMessage = await messageRepository.find({
Expand Down Expand Up @@ -699,7 +699,14 @@ async function syncWorkflow(
if (!foundWorkflow) throw new Error('Workflow not found');
}

async function triggerEvent(session, workflowId: string, subscriber, payload?: any, bridge?: { url: string }) {
async function triggerEvent(
session,
workflowId: string,
subscriber,
payload?: any,
bridge?: { url: string },
controls?: Record<string, unknown>
) {
const defaultPayload = {
name: 'test_name',
};
Expand All @@ -713,6 +720,7 @@ async function triggerEvent(session, workflowId: string, subscriber, payload?: a
email: '[email protected]',
},
payload: payload ?? defaultPayload,
controls: controls ?? undefined,
bridgeUrl: bridge?.url ?? undefined,
},
{
Expand Down
12 changes: 7 additions & 5 deletions apps/web/src/bridgeApi/bridgeApi.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export type TriggerParams = {
bridgeUrl?: string;
to: { subscriberId: string; email: string };
payload: Record<string, unknown>;
controls?: {
steps?: Record<string, unknown>;
};
};

export type BridgeStatus = {
Expand Down Expand Up @@ -85,24 +88,23 @@ export function buildBridgeHTTPClient(baseURL: string) {
*/
async getStepPreview({ workflowId, stepId, controls, payload }: StepPreviewParams): Promise<any> {
return post(`${baseURL}?action=preview&workflowId=${workflowId}&stepId=${stepId}`, {
// TODO: Rename to controls
inputs: controls || {},
// TODO: Rename to payload
data: payload || {},
controls: controls || {},
payload: payload || {},
});
},

/**
* TODO: Use framework shared types
*/
async trigger({ workflowId, bridgeUrl, to, payload }: TriggerParams): Promise<any> {
async trigger({ workflowId, bridgeUrl, to, payload, controls }: TriggerParams): Promise<any> {
payload = payload || {};
payload.__source = 'studio-test-workflow';

return post(`${baseURL}?action=trigger&workflowId=${workflowId}`, {
bridgeUrl,
to,
payload,
controls,
});
},
};
Expand Down
Loading

0 comments on commit 752b3a2

Please sign in to comment.