Skip to content

Commit 7f594fb

Browse files
authored
Rename wizard types for reuse across Campaign and Benchmark (#2185)
Part of OPS-4044.
1 parent 1c85342 commit 7f594fb

22 files changed

Lines changed: 193 additions & 161 deletions

packages/react-ui/src/app/features/benchmark/benchmark-api.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ import {
22
BenchmarkCreationResult,
33
BenchmarkStatusResponse,
44
BenchmarkWebhookPayload,
5-
BenchmarkWizardRequest,
6-
BenchmarkWizardStepResponse,
75
ListBenchmarksResponse,
6+
WizardRequest,
7+
WizardStepResponse,
88
} from '@openops/shared';
99

1010
import { api } from '@/app/lib/api';
1111

1212
const getWizardStep = (
1313
provider: string,
14-
request: BenchmarkWizardRequest,
15-
): Promise<BenchmarkWizardStepResponse> =>
16-
api.post<BenchmarkWizardStepResponse, BenchmarkWizardRequest>(
14+
request: WizardRequest,
15+
): Promise<WizardStepResponse> =>
16+
api.post<WizardStepResponse, WizardRequest>(
1717
`/v1/benchmarks/${provider}/wizard`,
1818
request,
1919
);
2020

2121
const createBenchmark = (
2222
provider: string,
23-
benchmarkConfiguration: Record<string, string[]>,
23+
wizardState: Record<string, string[]>,
2424
): Promise<BenchmarkCreationResult> =>
25-
api.post<
26-
BenchmarkCreationResult,
27-
{ benchmarkConfiguration: Record<string, string[]> }
28-
>(`/v1/benchmarks/${provider}`, { benchmarkConfiguration });
25+
api.post<BenchmarkCreationResult, { wizardState: Record<string, string[]> }>(
26+
`/v1/benchmarks/${provider}`,
27+
{ wizardState: wizardState },
28+
);
2929

3030
const runBenchmark = (
3131
orchestratorFlowId: string,

packages/react-ui/src/app/features/benchmark/components/dynamic-benchmark-step/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { BenchmarkWizardStepResponse } from '@openops/shared';
1+
import { WizardStepResponse } from '@openops/shared';
22

33
export interface DynamicBenchmarkStepProps {
4-
stepResponse: BenchmarkWizardStepResponse;
4+
stepResponse: WizardStepResponse;
55
value: string[];
66
onValueChange: (value: string[]) => void;
77
stepBodyClassName?: string;

packages/react-ui/src/app/features/benchmark/use-benchmark-wizard-navigation.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { INTERNAL_ERROR_TOAST, toast } from '@openops/components/ui';
2-
import { BenchmarkWizardStepResponse } from '@openops/shared';
2+
import { WizardStepResponse } from '@openops/shared';
33
import { useMutation, useQueryClient } from '@tanstack/react-query';
44
import { act, renderHook } from '@testing-library/react';
55

@@ -31,8 +31,8 @@ const mockCreateBenchmark = benchmarkApi.createBenchmark as jest.Mock;
3131
const mockToast = toast as jest.Mock;
3232

3333
const buildStepResponse = (
34-
overrides?: Partial<BenchmarkWizardStepResponse>,
35-
): BenchmarkWizardStepResponse => ({
34+
overrides?: Partial<WizardStepResponse>,
35+
): WizardStepResponse => ({
3636
currentStep: 'region',
3737
title: 'Select Region',
3838
description: 'Choose your cloud region',
@@ -327,7 +327,7 @@ describe('useBenchmarkWizardNavigation', () => {
327327

328328
expect(mockGetWizardStep).toHaveBeenNthCalledWith(2, 'aws', {
329329
currentStep: 'region',
330-
benchmarkConfiguration: { region: ['us-east-1'] },
330+
wizardState: { region: ['us-east-1'] },
331331
});
332332
expect(result.current.currentStepResponse).toEqual(secondStep);
333333
expect(result.current.currentSelections).toEqual([]);
@@ -399,7 +399,7 @@ describe('useBenchmarkWizardNavigation', () => {
399399

400400
expect(mockGetWizardStep).toHaveBeenNthCalledWith(3, 'aws', {
401401
currentStep: 'instance-type',
402-
benchmarkConfiguration: {
402+
wizardState: {
403403
region: ['us-east-1'],
404404
'instance-type': ['t3.medium'],
405405
},
@@ -502,9 +502,7 @@ describe('useBenchmarkWizardNavigation', () => {
502502
});
503503

504504
describe('isNextDisabled in provider-step phase', () => {
505-
const setupAtProviderStep = async (
506-
stepResponse: BenchmarkWizardStepResponse,
507-
) => {
505+
const setupAtProviderStep = async (stepResponse: WizardStepResponse) => {
508506
mockGetWizardStep.mockResolvedValue(stepResponse);
509507
const { result } = renderHook(() =>
510508
useBenchmarkWizardNavigation(connectedProviders),

packages/react-ui/src/app/features/benchmark/use-benchmark-wizard-navigation.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { handleMutationError } from '@/app/interceptors/interceptor-utils';
22
import {
33
BenchmarkCreationResult,
4-
BenchmarkWizardRequest,
5-
BenchmarkWizardStepResponse,
4+
WizardRequest,
5+
WizardStepResponse,
66
} from '@openops/shared';
77
import { useMutation, useQueryClient } from '@tanstack/react-query';
88
import { useState } from 'react';
@@ -13,11 +13,11 @@ import { benchmarkApi } from './benchmark-api';
1313
export type WizardPhase = 'initial' | 'provider-step' | 'benchmark-ready';
1414

1515
type StepHistoryEntry = {
16-
stepResponse: BenchmarkWizardStepResponse;
16+
stepResponse: WizardStepResponse;
1717
selections: string[];
1818
};
1919

20-
const buildBenchmarkConfiguration = (
20+
const buildWizardState = (
2121
history: StepHistoryEntry[],
2222
): Record<string, string[]> =>
2323
history.reduce<Record<string, string[]>>((acc, entry) => {
@@ -29,7 +29,7 @@ type UseBenchmarkWizardNavigationResult = {
2929
selectedProvider: string | undefined;
3030
setSelectedProvider: (provider: string) => void;
3131
wizardPhase: WizardPhase;
32-
currentStepResponse: BenchmarkWizardStepResponse | null;
32+
currentStepResponse: WizardStepResponse | null;
3333
currentSelections: string[];
3434
setCurrentSelections: (selections: string[]) => void;
3535
isLoadingStep: boolean;
@@ -49,7 +49,7 @@ export const useBenchmarkWizardNavigation = (
4949
const [selectedProvider, setSelectedProvider] = useState<string>();
5050
const [wizardPhase, setWizardPhase] = useState<WizardPhase>('initial');
5151
const [currentStepResponse, setCurrentStepResponse] =
52-
useState<BenchmarkWizardStepResponse | null>(null);
52+
useState<WizardStepResponse | null>(null);
5353
const [currentSelections, setCurrentSelections] = useState<string[]>([]);
5454
const [stepHistory, setStepHistory] = useState<StepHistoryEntry[]>([]);
5555
const [benchmarkCreateResult, setBenchmarkCreateResult] =
@@ -62,7 +62,7 @@ export const useBenchmarkWizardNavigation = (
6262
request,
6363
}: {
6464
provider: string;
65-
request: BenchmarkWizardRequest;
65+
request: WizardRequest;
6666
}) => benchmarkApi.getWizardStep(provider, request),
6767
onError: handleMutationError,
6868
});
@@ -73,11 +73,11 @@ export const useBenchmarkWizardNavigation = (
7373
useMutation({
7474
mutationFn: ({
7575
provider,
76-
benchmarkConfiguration,
76+
wizardState,
7777
}: {
7878
provider: string;
79-
benchmarkConfiguration: Record<string, string[]>;
80-
}) => benchmarkApi.createBenchmark(provider, benchmarkConfiguration),
79+
wizardState: Record<string, string[]>;
80+
}) => benchmarkApi.createBenchmark(provider, wizardState),
8181
onSuccess: (result) => {
8282
setBenchmarkCreateResult(result);
8383
setWizardPhase('benchmark-ready');
@@ -115,13 +115,13 @@ export const useBenchmarkWizardNavigation = (
115115
selections: currentSelections,
116116
};
117117
const newHistory = [...stepHistory, committed];
118-
const benchmarkConfiguration = buildBenchmarkConfiguration(newHistory);
118+
const wizardState = buildWizardState(newHistory);
119119

120120
if (currentStepResponse.nextStep === null) {
121121
setStepHistory(newHistory);
122122
await runCreateBenchmark({
123123
provider: selectedProvider,
124-
benchmarkConfiguration,
124+
wizardState: wizardState,
125125
});
126126
return;
127127
}
@@ -130,7 +130,7 @@ export const useBenchmarkWizardNavigation = (
130130
provider: selectedProvider,
131131
request: {
132132
currentStep: currentStepResponse.currentStep,
133-
benchmarkConfiguration,
133+
wizardState: wizardState,
134134
},
135135
});
136136

packages/server/api/src/app/benchmark/attach-benchmark-flows.service.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
BenchmarkProviders,
33
openOpsId,
4-
type BenchmarkConfiguration,
54
type BenchmarkWebhookPayload,
65
type BenchmarkWorkflowBase,
6+
type WizardState,
77
} from '@openops/shared';
88
import { webhookUtils } from 'server-worker';
99
import { transaction } from '../core/db/transaction';
@@ -13,7 +13,7 @@ import { benchmarkRepo } from './benchmark.repo';
1313
import { throwValidationError } from './errors';
1414

1515
export type AttachFlowsToBenchmarkRequest = {
16-
benchmarkConfiguration: BenchmarkConfiguration;
16+
wizardState: WizardState;
1717
workflows: BenchmarkWorkflowBase[];
1818
projectId: string;
1919
provider: BenchmarkProviders;
@@ -28,10 +28,10 @@ export type AttachFlowsToBenchmarkResponse = {
2828

2929
async function buildPayloadForWebhook(params: {
3030
provider: BenchmarkProviders;
31-
benchmarkConfiguration: BenchmarkConfiguration;
31+
wizardState: WizardState;
3232
workflows: BenchmarkWorkflowBase[];
3333
}): Promise<BenchmarkWebhookPayload> {
34-
const { provider, benchmarkConfiguration, workflows } = params;
34+
const { provider, wizardState, workflows } = params;
3535

3636
if (workflows.length < 3) {
3737
throwValidationError(
@@ -51,19 +51,19 @@ async function buildPayloadForWebhook(params: {
5151
webhookBaseUrl,
5252
workflows: subWorkflowFlowIds,
5353
cleanupWorkflows: cleanupFlowIds,
54-
regions: benchmarkConfiguration.regions ?? [],
54+
regions: wizardState.regions ?? [],
5555
};
5656

5757
switch (provider) {
5858
case BenchmarkProviders.AWS:
5959
return {
6060
...webhookPayloadCommon,
61-
accounts: benchmarkConfiguration.accounts ?? [],
61+
accounts: wizardState.accounts ?? [],
6262
};
6363
case BenchmarkProviders.AZURE:
6464
return {
6565
...webhookPayloadCommon,
66-
subscriptions: benchmarkConfiguration.subscriptions ?? [],
66+
subscriptions: wizardState.subscriptions ?? [],
6767
};
6868
default: {
6969
throwValidationError(
@@ -119,7 +119,7 @@ export async function attachFlowsToBenchmark(
119119
params: AttachFlowsToBenchmarkRequest,
120120
): Promise<AttachFlowsToBenchmarkResponse> {
121121
const {
122-
benchmarkConfiguration,
122+
wizardState,
123123
workflows,
124124
projectId,
125125
provider,
@@ -129,7 +129,7 @@ export async function attachFlowsToBenchmark(
129129

130130
const payload = await buildPayloadForWebhook({
131131
provider,
132-
benchmarkConfiguration,
132+
wizardState,
133133
workflows,
134134
});
135135

packages/server/api/src/app/benchmark/benchmark.controller.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ import {
66
BenchmarkCreationResult,
77
BenchmarkProviders,
88
BenchmarkStatusResponse,
9-
BenchmarkWizardRequest,
10-
BenchmarkWizardStepResponse,
119
CreateBenchmarkRequest,
1210
ListBenchmarksResponse,
1311
Permission,
1412
PrincipalType,
13+
WizardRequest,
14+
WizardStepResponse,
1515
} from '@openops/shared';
1616
import { StatusCodes } from 'http-status-codes';
1717
import { getProjectScopedRoutePolicy } from '../core/security/route-policies/route-security-policy-factory';
1818
import { assertBenchmarkFeatureEnabled } from './benchmark-feature-guard';
1919
import { getBenchmarkStatus, listBenchmarks } from './benchmark-status.service';
2020
import { createBenchmark } from './create-benchmark.service';
21+
import { getProvider } from './providers/providers-registry';
2122
import { resolveWizardNavigation } from './wizard.service';
2223

2324
export const benchmarkController: FastifyPluginAsyncTypebox = async (app) => {
@@ -27,11 +28,15 @@ export const benchmarkController: FastifyPluginAsyncTypebox = async (app) => {
2728
'/:provider/wizard',
2829
WizardStepRequestOptions,
2930
async (request, reply) => {
31+
const provider = request.params.provider;
32+
const providerAdapter = getProvider(provider);
33+
3034
const step = await resolveWizardNavigation(
31-
request.params.provider,
35+
provider,
36+
providerAdapter,
3237
{
3338
currentStep: request.body.currentStep,
34-
benchmarkConfiguration: request.body.benchmarkConfiguration,
39+
wizardState: request.body.wizardState,
3540
},
3641
request.principal.projectId,
3742
);
@@ -47,7 +52,7 @@ export const benchmarkController: FastifyPluginAsyncTypebox = async (app) => {
4752
provider: request.params.provider,
4853
projectId: request.principal.projectId,
4954
userId: request.principal.id,
50-
benchmarkConfiguration: request.body.benchmarkConfiguration,
55+
wizardState: request.body.wizardState,
5156
});
5257

5358
return reply.status(StatusCodes.CREATED).send(result);
@@ -116,9 +121,9 @@ const WizardStepRequestOptions = {
116121
params: Type.Object({
117122
provider: Type.Enum(BenchmarkProviders),
118123
}),
119-
body: BenchmarkWizardRequest,
124+
body: WizardRequest,
120125
response: {
121-
[StatusCodes.OK]: BenchmarkWizardStepResponse,
126+
[StatusCodes.OK]: WizardStepResponse,
122127
},
123128
},
124129
};

packages/server/api/src/app/benchmark/common-resolvers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
AppConnectionStatus,
3-
BenchmarkWizardOption,
43
WizardContext,
4+
WizardOption,
55
} from '@openops/shared';
66
import { appConnectionService } from '../app-connection/app-connection-service/app-connection-service';
77
import { getAuthProviderMetadata } from '../app-connection/connection-providers-resolver';
@@ -17,7 +17,7 @@ export async function getAuthProviderLogoUrl(
1717

1818
export async function listConnections(
1919
context: WizardContext,
20-
): Promise<BenchmarkWizardOption[]> {
20+
): Promise<WizardOption[]> {
2121
if (!context.projectId) {
2222
throwValidationError('projectId is required to list connections');
2323
}

0 commit comments

Comments
 (0)