This commit is contained in:
asp_ly 2024-12-26 22:29:01 +08:00
parent a30b5101ec
commit b7d77c8033

View File

@ -125,40 +125,41 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
if (!selectedTemplate?.buildVariablesSchema) return null; if (!selectedTemplate?.buildVariablesSchema) return null;
const { properties } = selectedTemplate.buildVariablesSchema; const { properties } = selectedTemplate.buildVariablesSchema;
const scriptProperty = properties.script;
return ( return (
<> <>
{/* 脚本编辑器 */} {/* 遍历所有字段,对有 editorConfig 的字段使用富文本编辑器 */}
{scriptProperty?.format === 'monaco-editor' && ( {Object.entries(properties).map(([key, property]) => (
property.editorConfig ? (
<Form.Item <Form.Item
label={scriptProperty.title || 'Pipeline script'} key={key}
required={selectedTemplate.buildVariablesSchema.required?.includes('script')} label={property.title || key}
tooltip={scriptProperty.description} required={selectedTemplate.buildVariablesSchema.required?.includes(key)}
tooltip={property.description}
> >
<Editor <Editor
height="300px" height="300px"
defaultLanguage={scriptProperty.editorConfig?.language || 'shell'} defaultLanguage={property.editorConfig.language || 'shell'}
theme={scriptProperty.editorConfig?.theme || 'vs-dark'} theme={property.editorConfig.theme || 'vs-dark'}
value={buildVariables.script || scriptProperty.default || '#!/bin/bash\n'} value={buildVariables[key] || property.default || ''}
onChange={(value) => setBuildVariables({ onChange={(value) => setBuildVariables({
...buildVariables, ...buildVariables,
script: value || '' [key]: value || ''
})} })}
options={{ options={{
minimap: { enabled: scriptProperty.editorConfig?.minimap ?? false }, minimap: { enabled: property.editorConfig.minimap ?? false },
fontSize: scriptProperty.editorConfig?.fontSize || 14, fontSize: property.editorConfig.fontSize || 14,
lineNumbers: scriptProperty.editorConfig?.lineNumbers ? 'on' : 'off', lineNumbers: property.editorConfig.lineNumbers ? 'on' : 'off',
wordWrap: scriptProperty.editorConfig?.wordWrap ? 'on' : 'off', wordWrap: property.editorConfig.wordWrap ? 'on' : 'off',
tabSize: scriptProperty.editorConfig?.tabSize || 2, tabSize: property.editorConfig.tabSize || 2,
scrollBeyondLastLine: false, scrollBeyondLastLine: false,
automaticLayout: true, automaticLayout: true,
folding: scriptProperty.editorConfig?.folding ?? true, folding: property.editorConfig.folding ?? true,
autoClosingBrackets: 'always', autoClosingBrackets: 'always',
autoClosingQuotes: 'always', autoClosingQuotes: 'always',
formatOnPaste: true, formatOnPaste: true,
formatOnType: true, formatOnType: true,
suggestOnTriggerCharacters: scriptProperty.editorConfig?.autoComplete ?? true, suggestOnTriggerCharacters: property.editorConfig.autoComplete ?? true,
renderWhitespace: 'boundary', renderWhitespace: 'boundary',
}} }}
loading={ loading={
@ -176,7 +177,8 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
} }
/> />
</Form.Item> </Form.Item>
)} ) : null
))}
{/* 其他配置项 */} {/* 其他配置项 */}
<BetaSchemaForm <BetaSchemaForm
@ -184,7 +186,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
columns={convertJsonSchemaToColumns({ columns={convertJsonSchemaToColumns({
type: 'object', type: 'object',
properties: Object.fromEntries( properties: Object.fromEntries(
Object.entries(properties).filter(([key]) => key !== 'script') Object.entries(properties).filter(([_, prop]) => !prop.editorConfig)
), ),
required: selectedTemplate.buildVariablesSchema.required || [] required: selectedTemplate.buildVariablesSchema.required || []
})} })}