Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion ai-services/assets/catalog/openshift/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ui:
image: icr.io/ai-services-cicd/catalog-ui:v0.0.53
image: icr.io/ai-services-cicd/catalog-ui:v0.0.54
resources:
requests:
memory: "512Mi"
Expand Down
2 changes: 1 addition & 1 deletion ai-services/assets/catalog/podman/values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ui:
port: ""
image: icr.io/ai-services-cicd/catalog-ui:v0.0.53
image: icr.io/ai-services-cicd/catalog-ui:v0.0.54

backend:
port: ""
Expand Down
2 changes: 1 addition & 1 deletion ui/catalog/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
REGISTRY ?= icr.io/ai-services-private
IMAGE ?= catalog-ui
TAG ?= v0.0.53
TAG ?= v0.0.54
CREDS_ARG := $(if $(and $(REGISTRY_USER),$(REGISTRY_PASSWORD)),--creds="$(REGISTRY_USER):$(REGISTRY_PASSWORD)")

CONTAINER_BUILDER ?= podman
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useReducer, useEffect, useCallback, useRef, useMemo } from "react";
import { useReducer, useEffect, useRef, useMemo } from "react";
import { Tearsheet } from "@carbon/ibm-products";
import {
ProgressIndicator,
Expand All @@ -10,7 +10,10 @@ import type { DeployFlowState, DeployFlowAction } from "./types.ts";
import type { BaseDeployFlowProps, DeployFormData } from "../Shared/types";
import type { ProviderSchema } from "@/types/api.types";
import { ACTION_TYPES } from "./types.ts";
import { handleUpdateFormData } from "../Shared/utils/formData";
import {
sharedDeployFlowReducer,
useDeployFlowReducer,
} from "../Shared/hooks/useDeployFlowReducer";
import { deployApplication, fetchServices } from "@/api/applications.api";
import { transformToDeploymentPayload } from "./utils/digitalAssistantDeploymentTransform";
import { extractDeployError } from "../Shared/utils/deployError";
Expand All @@ -19,51 +22,26 @@ import { StepTwo } from "./steps/StepTwo";
import { useDeployOptions } from "./hooks/useDeployOptions";
import { useDeployStore } from "@/store/deploy.store";
import { initializeFormData } from "./utils/formDataInitializer";
import { BASE_INITIAL_STATE } from "../Shared/utils/formData";
import { dedupe } from "@/utils/requestManager";
import styles from "./DigitalAssistantDeployFlow.module.scss";

const getInitialState = (formData: DeployFormData): DeployFlowState => ({
currentStep: 0,
...BASE_INITIAL_STATE,
isLoading: false,
isDeploying: false,
isEditing: false,
hasInsufficientResources: false,
error: null,
deployError: null,
deployToastOpen: false,
formData,
showStepOneNameError: false,
});

const deployFlowReducer = (
const daDeployFlowReducer = (
state: DeployFlowState,
action: DeployFlowAction,
): DeployFlowState => {
switch (action.type) {
case ACTION_TYPES.SET_CURRENT_STEP:
return { ...state, currentStep: action.payload };
case ACTION_TYPES.SET_IS_LOADING:
return { ...state, isLoading: action.payload };
case ACTION_TYPES.SET_IS_DEPLOYING:
return { ...state, isDeploying: action.payload };
case ACTION_TYPES.SET_IS_EDITING:
return { ...state, isEditing: action.payload };
case ACTION_TYPES.SET_HAS_INSUFFICIENT_RESOURCES:
return { ...state, hasInsufficientResources: action.payload };
case ACTION_TYPES.SET_ERROR:
return { ...state, error: action.payload };
case ACTION_TYPES.SET_DEPLOY_ERROR:
return { ...state, deployError: action.payload };
case ACTION_TYPES.SHOW_DEPLOY_TOAST:
return { ...state, deployToastOpen: true };
case ACTION_TYPES.HIDE_DEPLOY_TOAST:
return { ...state, deployToastOpen: false };
case ACTION_TYPES.SET_FORM_DATA:
return { ...state, formData: action.payload };
case ACTION_TYPES.UPDATE_FORM_DATA:
return handleUpdateFormData(state, action.payload);
case ACTION_TYPES.SET_SHOW_STEP_ONE_NAME_ERROR:
return { ...state, showStepOneNameError: action.payload };
case ACTION_TYPES.RESET_STATE:
return getInitialState({
name: "Digital assistant (copy)",
Expand All @@ -72,7 +50,7 @@ const deployFlowReducer = (
services: {},
});
default:
return state;
return sharedDeployFlowReducer(state, action);
}
};

Expand Down Expand Up @@ -142,7 +120,7 @@ export const DeployFlow = ({
});
}, [deployOptions]);

const [state, dispatch] = useReducer(deployFlowReducer, initialState);
const [state, dispatch] = useReducer(daDeployFlowReducer, initialState);
const hasInitialized = useRef(false);

useEffect(() => {
Expand Down Expand Up @@ -172,26 +150,12 @@ export const DeployFlow = ({
}
}, [error]);

const handleFormDataChange = useCallback(
(updates: Partial<DeployFormData>) => {
dispatch({ type: ACTION_TYPES.UPDATE_FORM_DATA, payload: updates });
},
[],
);

const handleEditingChange = useCallback((isEditing: boolean) => {
dispatch({ type: ACTION_TYPES.SET_IS_EDITING, payload: isEditing });
}, []);

const handleResourceStatusChange = useCallback(
(hasInsufficientResources: boolean) => {
dispatch({
type: ACTION_TYPES.SET_HAS_INSUFFICIENT_RESOURCES,
payload: hasInsufficientResources,
});
},
[],
);
const {
handleFormDataChange,
handleEditingChange,
handleResourceStatusChange,
handleBack,
} = useDeployFlowReducer(dispatch, state.currentStep);

const handleNext = () => {
if (!state.formData.name.trim()) {
Expand All @@ -214,15 +178,6 @@ export const DeployFlow = ({
}
};

const handleBack = () => {
if (state.currentStep > 0) {
dispatch({
type: ACTION_TYPES.SET_CURRENT_STEP,
payload: state.currentStep - 1,
});
}
};

const handleSubmit = async () => {
if (!deployOptions) {
dispatch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@ export interface ServiceConfig extends BaseServiceConfig {
export interface DeployFlowState extends BaseDeployFlowState {
isLoading: boolean;
error: string | null;
deployToastOpen: boolean;
}

export const ACTION_TYPES = {
...SHARED_ACTION_TYPES,
RESET_STATE: "RESET_STATE",
SET_IS_LOADING: "SET_IS_LOADING",
SET_ERROR: "SET_ERROR",
SHOW_DEPLOY_TOAST: "SHOW_DEPLOY_TOAST",
HIDE_DEPLOY_TOAST: "HIDE_DEPLOY_TOAST",
} as const;

export type DeployFlowAction =
| SharedDeployFlowAction
| { type: typeof ACTION_TYPES.RESET_STATE }
| { type: typeof ACTION_TYPES.SET_IS_LOADING; payload: boolean }
| { type: typeof ACTION_TYPES.SET_ERROR; payload: string | null }
| { type: typeof ACTION_TYPES.SHOW_DEPLOY_TOAST }
| { type: typeof ACTION_TYPES.HIDE_DEPLOY_TOAST };
| { type: typeof ACTION_TYPES.SET_ERROR; payload: string | null };

export interface StepProps extends BaseStepProps {
deployOptions: DeployOptionsResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useReducer, useEffect, useCallback, useRef, useMemo } from "react";
import { useReducer, useEffect, useRef, useMemo } from "react";
import { Tearsheet } from "@carbon/ibm-products";
import {
ProgressIndicator,
Expand All @@ -11,9 +11,12 @@ import type {
DeployFlowState,
DeployFlowAction,
} from "./types.ts";
import type { DeployFormData, ComponentConfig } from "../Shared/types";
import type { ComponentConfig } from "../Shared/types";
import { ACTION_TYPES } from "./types.ts";
import { handleUpdateFormData } from "../Shared/utils/formData";
import {
sharedDeployFlowReducer,
useDeployFlowReducer,
} from "../Shared/hooks/useDeployFlowReducer";
import { deployApplication } from "@/api/applications.api";
import { transformToDeploymentPayload } from "./utils/serviceDeploymentTransform";
import { extractDeployError } from "../Shared/utils/deployError";
Expand All @@ -23,52 +26,32 @@ import { StepZero } from "./steps/StepZero";
import { useServiceDeployOptions } from "./hooks/useServiceDeployOptions";
import { useServiceDeployStore } from "@/store/serviceDeploy.store";
import { initializeFormData } from "./utils/formDataInitializer";
import { BASE_INITIAL_STATE } from "../Shared/utils/formData";
import styles from "./ServicesDeployFlow.module.scss";

// Initial state for the deployment flow
const getInitialState = (): DeployFlowState => ({
currentStep: 0,
isDeploying: false,
isEditing: false,
hasInsufficientResources: false,
deployError: null,
...BASE_INITIAL_STATE,
formData: {
name: "Service deployment (copy)",
version: "",
globalComponents: {},
services: {},
},
selectedServiceId: null,
showStepOneNameError: false,
});

const deployFlowReducer = (
const servicesDeployFlowReducer = (
state: DeployFlowState,
action: DeployFlowAction,
): DeployFlowState => {
switch (action.type) {
case ACTION_TYPES.SET_CURRENT_STEP:
return { ...state, currentStep: action.payload };
case ACTION_TYPES.SET_IS_DEPLOYING:
return { ...state, isDeploying: action.payload };
case ACTION_TYPES.SET_IS_EDITING:
return { ...state, isEditing: action.payload };
case ACTION_TYPES.SET_HAS_INSUFFICIENT_RESOURCES:
return { ...state, hasInsufficientResources: action.payload };
case ACTION_TYPES.SET_DEPLOY_ERROR:
return { ...state, deployError: action.payload };
case ACTION_TYPES.SET_FORM_DATA:
return { ...state, formData: action.payload };
case ACTION_TYPES.UPDATE_FORM_DATA:
return handleUpdateFormData(state, action.payload);
case ACTION_TYPES.SET_SELECTED_SERVICE:
return { ...state, selectedServiceId: action.payload };
case ACTION_TYPES.SET_SHOW_STEP_ONE_NAME_ERROR:
return { ...state, showStepOneNameError: action.payload };
case ACTION_TYPES.RESET_STATE:
return getInitialState();
default:
return state;
return sharedDeployFlowReducer(state, action);
}
};

Expand All @@ -78,7 +61,7 @@ export const ServicesDeployFlow = ({
onSubmit,
preSelectedServiceId,
}: ServicesDeployFlowProps) => {
const [state, dispatch] = useReducer(deployFlowReducer, {
const [state, dispatch] = useReducer(servicesDeployFlowReducer, {
...getInitialState(),
selectedServiceId: preSelectedServiceId || null,
currentStep: preSelectedServiceId ? 1 : 0, // Start at step 1 if service is pre-selected
Expand Down Expand Up @@ -285,31 +268,17 @@ export const ServicesDeployFlow = ({
componentModels,
]);

const handleFormDataChange = useCallback(
(updates: Partial<DeployFormData>) => {
dispatch({ type: ACTION_TYPES.UPDATE_FORM_DATA, payload: updates });
},
[],
);

const handleEditingChange = useCallback((isEditing: boolean) => {
dispatch({ type: ACTION_TYPES.SET_IS_EDITING, payload: isEditing });
}, []);

const handleResourceStatusChange = useCallback(
(hasInsufficientResources: boolean) => {
dispatch({
type: ACTION_TYPES.SET_HAS_INSUFFICIENT_RESOURCES,
payload: hasInsufficientResources,
});
},
[],
);
const {
handleFormDataChange,
handleEditingChange,
handleResourceStatusChange,
handleBack,
} = useDeployFlowReducer(dispatch, state.currentStep);

const handleServiceSelect = useCallback((serviceId: string) => {
const handleServiceSelect = (serviceId: string) => {
// Service selection will trigger useServiceDeployOptions to fetch data
dispatch({ type: ACTION_TYPES.SET_SELECTED_SERVICE, payload: serviceId });
}, []);
};

const handleNext = () => {
// Show validation error if trying to proceed from step 1 with invalid name
Expand All @@ -329,15 +298,6 @@ export const ServicesDeployFlow = ({
}
};

const handleBack = () => {
if (state.currentStep > 0) {
dispatch({
type: ACTION_TYPES.SET_CURRENT_STEP,
payload: state.currentStep - 1,
});
}
};

const handleSubmit = async () => {
if (!deployOptions) {
dispatch({
Expand Down
2 changes: 2 additions & 0 deletions ui/catalog/src/components/DeployFlow/Services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export interface DeployFlowState extends BaseDeployFlowState {

export const ACTION_TYPES = {
...SHARED_ACTION_TYPES,
RESET_STATE: "RESET_STATE",
SET_SELECTED_SERVICE: "SET_SELECTED_SERVICE",
} as const;

export type DeployFlowAction =
| SharedDeployFlowAction
| { type: typeof ACTION_TYPES.RESET_STATE }
| { type: typeof ACTION_TYPES.SET_SELECTED_SERVICE; payload: string | null };

export interface StepProps extends BaseStepProps {
Expand Down
Loading
Loading