This commit is contained in:
dengqichen 2025-01-20 16:22:46 +08:00
parent 0313c02198
commit b967af0f2a
2 changed files with 36 additions and 7 deletions

View File

@ -35,10 +35,12 @@ import {getExternalSystemList, getJenkinsViewList, getJenkinsJobList, createDepl
import {getPublishedDefinitions} from '@/pages/Workflow/Definition/service';
import type {ExternalSystem} from '@/pages/Deploy/External/types';
import { Editor } from "@/components/Editor";
import { message } from 'antd';
interface Application {
id: number;
appName: string;
language: string;
}
interface JenkinsView {
@ -90,10 +92,12 @@ type FormValues = z.infer<typeof formSchema>;
interface DeploymentConfigModalProps {
open: boolean;
onCancel: () => void;
onSuccess: () => void;
onSuccess?: () => void;
environmentId: number;
buildType: string;
}
const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCancel, onSuccess}) => {
const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCancel, onSuccess, environmentId, buildType}) => {
const [applications, setApplications] = useState<Application[]>([]);
const [externalSystems, setExternalSystems] = useState<ExternalSystem[]>([]);
const [jenkinsViews, setJenkinsViews] = useState<JenkinsView[]>([]);
@ -101,6 +105,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCa
const [workflows, setWorkflows] = useState<any[]>([]);
const [fullscreenEditor, setFullscreenEditor] = useState(false);
const [isFullscreen, setIsFullscreen] = useState(false);
const [currentApp, setCurrentApp] = useState<Application | null>(null);
const form = useForm<FormValues>({
resolver: zodResolver(formSchema),
@ -176,11 +181,22 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCa
}
};
// 当选择应用时获取应用信息
const handleApplicationChange = (applicationId: number) => {
const app = applications.find(app => app.id === applicationId);
setCurrentApp(app || null);
form.setValue('applicationId', applicationId);
};
const handleSubmit = async (values: FormValues) => {
try {
if (!environmentId) {
message.error('请选择环境');
return;
}
// 将环境变量数组转换为Map格式
const envMap = values.envs.reduce((acc, {key, value}) => {
// 只有当key和value都不为空时才添加到map中
if (key && value) {
acc[key] = value;
}
@ -188,14 +204,26 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCa
}, {} as Record<string, string>);
const params = {
...values,
envs: envMap
environmentId,
applicationId: values.applicationId,
languageType: currentApp?.language,
workflowDefinitionId: values.workflowId,
buildType,
buildVariables: {
externalSystemId: values.externalSystemId,
viewId: values.jenkinsViewId,
jobId: values.jenkinsJobId,
envs: envMap,
script: values.script
}
};
await createDeploymentConfig(params);
message.success('保存成功');
onSuccess?.();
} catch (error) {
console.error('Failed to create deployment config:', error);
message.error('保存失败');
}
};
@ -218,7 +246,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({open, onCa
<FormItem>
<FormLabel></FormLabel>
<Select
onValueChange={(value) => field.onChange(Number(value))}
onValueChange={(value) => handleApplicationChange(Number(value))}
value={field.value?.toString()}
>
<FormControl>

View File

@ -411,7 +411,8 @@ const DeploymentConfigList: React.FC = () => {
onCancel={handleModalClose}
onSuccess={handleSuccess}
initialValues={currentConfig}
envId={selectedEnvId}
environmentId={selectedEnvId!}
buildType={environments.find(env => env.id === selectedEnvId)?.buildType || ''}
/>
)}