Skip to content

Commit

Permalink
refactor(web, api, worker, dal): Rename inputs to controls (#5833)
Browse files Browse the repository at this point in the history
* refactor(client): rename input to control throughout code

* test: Add test for provider execution with step outputs

* fix(errors): correct error code enums in execution errors

* refactor(api): rename "inputs" to "controls"

* refactor(email): rename isSavingInputs to isSavingControls

* refactor(components): Rename InputVariables to ControlVariables

* feat(api): Add echo sync and diff routes

* refactor(variables): Rename inputVariables to controlVariables

* chore: update submodule commit

* test: Add missing controls field in test-email e2e test

* fix(sync): correct backend URL in test

* fix

* chore: update subproject commit reference

---------

Co-authored-by: Dima Grossman <[email protected]>
  • Loading branch information
rifont and scopsy authored Jun 26, 2024
1 parent 79605c8 commit d1ee964
Show file tree
Hide file tree
Showing 54 changed files with 269 additions and 225 deletions.
2 changes: 1 addition & 1 deletion .source
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ client.workflow('comment-on-post', async ({step, subscriber}) => {
body: renderReactEmail(<ReactEmailComponent events={digestedEvents} />);
}
}, {
// Step-level inputs defined in code and controlled in the novu Cloud UI by a Non-Technical Team member
// Step-level controls defined in code and controlled in the novu Cloud UI by a Non-Technical Team member
controlSchema: {
// ...JSON Schema
},
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/app/events/dtos/test-email-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ export class TestSendEmailRequestDto {

@IsOptional()
inputs: any;
@IsOptional()
controls: any;
}
4 changes: 2 additions & 2 deletions apps/api/src/app/events/e2e/bridge-trigger.e2e-ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ async function syncWorkflow(
workflowIdentifier: string,
echoServer: EchoServer
) {
await session.testAgent.post(`/v1/echo/sync`).send({
await session.testAgent.post(`/v1/bridge/sync`).send({
bridgeUrl: echoServer.serverPath + '/echo',
});

Expand Down Expand Up @@ -671,7 +671,7 @@ async function discoverAndSyncEcho(
workflowIdentifier?: string,
echoServer?: EchoServer
) {
const discoverResponse = await session.testAgent.post(`/v1/echo/sync`).send({
const discoverResponse = await session.testAgent.post(`/v1/bridge/sync`).send({
bridgeUrl: echoServer?.serverPath + '/echo',
});

Expand Down
1 change: 1 addition & 0 deletions apps/api/src/app/events/e2e/test-email.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Events - Test email - /v1/events/test/email (POST)', function () {
contentType: 'customHtml',
payload: {},
inputs: {},
controls: {},
subject: 'subject',
preheader: 'preheader',
content: '<html><head></head><body>Hello world!</body></html>',
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/app/events/events.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ export class EventsController {
workflowId: body.workflowId,
stepId: body.stepId,
bridge: body.bridge,
inputs: body.inputs,
inputs: body.controls || body.inputs,
controls: body.controls || body.inputs,
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class SendTestEmailCommand extends EnvironmentWithUserCommand {

@IsOptional()
inputs: any;
@IsOptional()
controls: any;

@IsOptional()
@IsString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export class SendTestEmail {
const data = await service.execute({
workflowId: command.workflowId,
stepId: command.stepId,
inputs: command.inputs,
inputs: command.controls || command.inputs,
controls: command.controls || command.inputs,
data: command.payload,
environmentId: command.environmentId,
organizationId: command.organizationId,
Expand Down
12 changes: 6 additions & 6 deletions apps/api/src/app/testing/echo/echo-sync.e2e-ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Echo Sync - /echo/sync (POST)', async () => {
it('should update echo url', async () => {
await echoServer.start({ workflows: [] });

const result = await session.testAgent.post(`/v1/echo/sync`).send({
const result = await session.testAgent.post(`/v1/bridge/sync`).send({
bridgeUrl: echoServer.serverPath,
});

Expand Down Expand Up @@ -92,7 +92,7 @@ describe('Echo Sync - /echo/sync (POST)', async () => {
);
await echoServer.start({ workflows: [newWorkflow] });

const result = await session.testAgent.post(`/v1/echo/sync`).send({
const result = await session.testAgent.post(`/v1/bridge/sync`).send({
bridgeUrl: echoServer.serverPath,
});
expect(result.body.data?.length).to.equal(1);
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('Echo Sync - /echo/sync (POST)', async () => {
);
await echoServer.start({ workflows: [newWorkflow] });

const result = await session.testAgent.post(`/v1/echo/sync`).send({
const result = await session.testAgent.post(`/v1/bridge/sync`).send({
bridgeUrl: echoServer.serverPath,
});
expect(result.body.data?.length).to.equal(1);
Expand All @@ -170,7 +170,7 @@ describe('Echo Sync - /echo/sync (POST)', async () => {
expect(messageTemplates.length).to.equal(1);
const messageTemplatesToTest = messageTemplates[0];

expect(messageTemplatesToTest.inputs).to.deep.equal(inputPostPayload);
expect(messageTemplatesToTest.controls).to.deep.equal(inputPostPayload);
});

it('should update a workflow', async () => {
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('Echo Sync - /echo/sync (POST)', async () => {
);
await echoServer.start({ workflows: [newWorkflow] });

await session.testAgent.post(`/v1/echo/sync`).send({
await session.testAgent.post(`/v1/bridge/sync`).send({
bridgeUrl: echoServer.serverPath,
});

Expand Down Expand Up @@ -257,7 +257,7 @@ describe('Echo Sync - /echo/sync (POST)', async () => {
);
await echoServer.start({ workflows: [newWorkflow2] });

await session.testAgent.post(`/v1/echo/sync`).send({
await session.testAgent.post(`/v1/bridge/sync`).send({
bridgeUrl: echoServer.serverPath,
});

Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const extendedBodySizeRoutes = [
'/v1/layouts',
'/v1/echo/sync',
'/v1/echo/diff',
'/v1/bridge/sync',
'/v1/bridge/diff',
];

if (process.env.SENTRY_DSN) {
Expand Down
5 changes: 3 additions & 2 deletions apps/web/src/api/bridge/bridge.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ export const bridgeApi = {
workflowId: string,
stepId: string,
payload: Record<string, unknown>,
inputs: Record<string, unknown>
controls: Record<string, unknown>
): Promise<any> {
return bridgeHttp.post('?action=preview&workflowId=' + workflowId + '&stepId=' + stepId, {
inputs: inputs || {},
inputs: controls || {},
controls: controls || {},
data: payload || {},
});
},
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/layout/components/EchoStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export function EchoStatus() {
version: string;
discovered: { workflows: number };
}>(
['/v1/echo/status'],
['/v1/bridge/status'],
() => {
return api.get('/v1/echo/status');
return api.get('/v1/bridge/status');
},
{
enabled: echoEnabled,
Expand Down
25 changes: 17 additions & 8 deletions apps/web/src/components/workflow/preview/chat/ChatPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import { useMutation } from '@tanstack/react-query';
import { useTemplateEditorForm } from '../../../../pages/templates/components/TemplateEditorFormProvider';
import { ChatBasePreview } from './ChatBasePreview';

export function ChatPreview({ showLoading = false, inputVariables }: { showLoading?: boolean; inputVariables?: any }) {
export function ChatPreview({
showLoading = false,
controlVariables,
}: {
showLoading?: boolean;
controlVariables?: any;
}) {
const { watch, formState } = useFormContext<IForm>();
const { template } = useTemplateEditorForm();
const { bridge } = useEnvironment({}, template?.bridge);
Expand All @@ -27,18 +33,21 @@ export function ChatPreview({ showLoading = false, inputVariables }: { showLoadi
mutateAsync,
isLoading: isBridgeLoading,
error: previewError,
} = useMutation((data) => api.post('/v1/echo/preview/' + formState?.defaultValues?.identifier + '/' + stepId, data), {
onSuccess(data) {
setBridgeContent(data.outputs.body);
},
});
} = useMutation(
(data) => api.post('/v1/bridge/preview/' + formState?.defaultValues?.identifier + '/' + stepId, data),
{
onSuccess(data) {
setBridgeContent(data.outputs.body);
},
}
);

useEffect(() => {
if (bridge) {
mutateAsync(inputVariables);
mutateAsync(controlVariables);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [bridge, inputVariables]);
}, [bridge, controlVariables]);

const { selectedLocale, locales, areLocalesLoading, onLocaleChange } = useTemplateLocales({
content: content as string,
Expand Down
23 changes: 13 additions & 10 deletions apps/web/src/components/workflow/preview/email/EmailPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { usePreviewEmailTemplate } from '../../../../pages/templates/hooks/usePr
import { useMutation } from '@tanstack/react-query';
import { useEnvironment } from '../../../../hooks/useEnvironment';
import { useTemplateEditorForm } from '../../../../pages/templates/components/TemplateEditorFormProvider';
import { InputVariablesForm } from '../../../../pages/templates/components/InputVariablesForm';
import { ControlVariablesForm } from '../../../../pages/templates/components/ControlVariablesForm';
import { ErrorPrettyRender } from '../ErrorPrettyRender';

const PreviewContainer = styled.div`
Expand Down Expand Up @@ -59,20 +59,23 @@ export const EmailPreview = ({ showVariables = true, view }: { view: string; sho
content,
});

const { mutateAsync: saveInputs, isLoading: isSavingInputs } = useMutation((data) =>
api.put('/v1/echo/inputs/' + formState?.defaultValues?.identifier + '/' + stepId, { variables: data })
const { mutateAsync: saveControls, isLoading: isSavingControls } = useMutation((data) =>
api.put('/v1/bridge/controls/' + formState?.defaultValues?.identifier + '/' + stepId, { variables: data })
);

const {
mutateAsync,
isLoading: isBridgeLoading,
error: previewError,
} = useMutation((data) => api.post('/v1/echo/preview/' + formState?.defaultValues?.identifier + '/' + stepId, data), {
onSuccess(data) {
setBridgeContent(data.outputs.body);
setBridgeSubject(data.outputs.subject);
},
});
} = useMutation(
(data) => api.post('/v1/bridge/preview/' + formState?.defaultValues?.identifier + '/' + stepId, data),
{
onSuccess(data) {
setBridgeContent(data.outputs.body);
setBridgeSubject(data.outputs.subject);
},
}
);

const { getEmailPreview, previewContent, subject, isPreviewContentLoading } = usePreviewEmailTemplate({
locale: selectedLocale,
Expand Down Expand Up @@ -158,7 +161,7 @@ export const EmailPreview = ({ showVariables = true, view }: { view: string; sho
</When>
<When truthy={bridge}>
<div style={{ minWidth: 300, maxWidth: 300, marginLeft: 'auto' }}>
<InputVariablesForm
<ControlVariablesForm
onChange={(values) => {
mutateAsync(values);
}}
Expand Down
23 changes: 13 additions & 10 deletions apps/web/src/components/workflow/preview/in-app/InAppPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { api } from '../../../../api';
import { useEnvironment } from '../../../../hooks/useEnvironment';
import { useMutation } from '@tanstack/react-query';
import { useTemplateEditorForm } from '../../../../pages/templates/components/TemplateEditorFormProvider';
import { InputVariablesForm } from '../../../../pages/templates/components/InputVariablesForm';
import { ControlVariablesForm } from '../../../../pages/templates/components/ControlVariablesForm';
import { InAppBasePreview } from './InAppBasePreview';

export function InAppPreview({ showVariables = true }: { showVariables?: boolean }) {
Expand All @@ -34,14 +34,17 @@ export function InAppPreview({ showVariables = true }: { showVariables?: boolean
mutateAsync,
isLoading: isBridgeLoading,
error: previewError,
} = useMutation((data) => api.post('/v1/echo/preview/' + formState?.defaultValues?.identifier + '/' + stepId, data), {
onSuccess(data) {
setBridgeContent({
content: data.outputs.body,
ctaButtons: [],
});
},
});
} = useMutation(
(data) => api.post('/v1/bridge/preview/' + formState?.defaultValues?.identifier + '/' + stepId, data),
{
onSuccess(data) {
setBridgeContent({
content: data.outputs.body,
ctaButtons: [],
});
},
}
);

useEffect(() => {
if (bridge) {
Expand Down Expand Up @@ -114,7 +117,7 @@ export function InAppPreview({ showVariables = true }: { showVariables?: boolean
</Button>
</When>
<When truthy={bridge}>
<InputVariablesForm
<ControlVariablesForm
onChange={(values) => {
mutateAsync(values);
}}
Expand Down
23 changes: 13 additions & 10 deletions apps/web/src/components/workflow/preview/push/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { PushBasePreview } from './PushBasePreview';
export default function Content({
showLoading = false,
showOverlay = true,
inputVariables,
controlVariables,
}: {
showLoading?: boolean;
showOverlay?: boolean;
inputVariables?: any;
controlVariables?: any;
}) {
const { template } = useTemplateEditorForm();
const { bridge } = useEnvironment({}, template?.bridge);
Expand All @@ -35,12 +35,15 @@ export default function Content({
mutateAsync,
isLoading: isBridgeLoading,
error: previewError,
} = useMutation((data) => api.post('/v1/echo/preview/' + formState?.defaultValues?.identifier + '/' + stepId, data), {
onSuccess(data) {
setBridgeContent(data.outputs.body);
setBridgeSubject(data.outputs.subject);
},
});
} = useMutation(
(data) => api.post('/v1/bridge/preview/' + formState?.defaultValues?.identifier + '/' + stepId, data),
{
onSuccess(data) {
setBridgeContent(data.outputs.body);
setBridgeSubject(data.outputs.subject);
},
}
);

const { selectedLocale, locales, areLocalesLoading, onLocaleChange } = useTemplateLocales({
content: content as string,
Expand All @@ -55,10 +58,10 @@ export default function Content({

useEffect(() => {
if (bridge) {
mutateAsync(inputVariables);
mutateAsync(controlVariables);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [bridge, inputVariables]);
}, [bridge, controlVariables]);

return (
<PushBasePreview
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/workflow/preview/push/PushPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import Content from './Content';
export function PushPreview({
showLoading = false,
showOverlay = true,
inputVariables,
controlVariables: controlVariables,
}: {
showLoading?: boolean;
showOverlay?: boolean;
inputVariables?: any;
controlVariables?: any;
}) {
return (
<div>
<MobileSimulator withBackground>
<Content inputVariables={inputVariables} showLoading={showLoading} showOverlay={showOverlay} />
<Content controlVariables={controlVariables} showLoading={showLoading} showOverlay={showOverlay} />
</MobileSimulator>
</div>
);
Expand Down
Loading

0 comments on commit d1ee964

Please sign in to comment.