fix: yaml edior height

This commit is contained in:
jialin
2026-03-10 19:06:49 +08:00
parent 73e52fe334
commit 972e147fdf
3 changed files with 21 additions and 7 deletions
+6 -4
View File
@@ -18,9 +18,7 @@ const { Text } = Typography;
loader.config({ monaco }); loader.config({ monaco });
const Container = styled.div<{ $minHeight: string | number }>` const Container = styled.div`
min-height: ${({ $minHeight }) =>
typeof $minHeight === 'number' ? `${$minHeight}px` : $minHeight};
position: relative; position: relative;
border: 1px solid var(--ant-color-border); border: 1px solid var(--ant-color-border);
border-radius: var(--ant-border-radius); border-radius: var(--ant-border-radius);
@@ -153,7 +151,11 @@ const YamlEditor: React.FC<ViewerProps> = forwardRef((props, ref) => {
}, [value]); }, [value]);
return ( return (
<Container $minHeight={height}> <Container
style={{
minHeight: height
}}
>
<EditorInner <EditorInner
ref={editorRef} ref={editorRef}
header={renderHeader()} header={renderHeader()}
+12 -1
View File
@@ -60,6 +60,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
const [activeKey, setActiveKey] = useState<string>('form'); const [activeKey, setActiveKey] = useState<string>('form');
const [yamlContent, setYamlContent] = useState<string>(''); const [yamlContent, setYamlContent] = useState<string>('');
const [formContent, setFormContent] = useState<FormData>({} as FormData); const [formContent, setFormContent] = useState<FormData>({} as FormData);
const alertRef = useRef<HTMLDivElement>(null);
const showVersionCustomSuffix = const showVersionCustomSuffix =
currentData?.backend_source === BackendSourceValueMap.BUILTIN || currentData?.backend_source === BackendSourceValueMap.BUILTIN ||
@@ -193,6 +194,15 @@ const AddModal: React.FC<AddModalProps> = (props) => {
} }
}, [action, currentData, open]); }, [action, currentData, open]);
const yamlHeight = useMemo(() => {
if (action !== PageAction.CREATE) {
return undefined;
}
const baseHeight = 260;
const alertHeight = alertRef.current?.offsetHeight || 0;
return `calc(100vh - ${baseHeight + alertHeight}px)`;
}, [action, activeKey]);
return ( return (
<GSDrawer <GSDrawer
title={title} title={title}
@@ -247,7 +257,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
footer={ footer={
<> <>
{action === PageAction.CREATE && ( {action === PageAction.CREATE && (
<div style={{ marginInline: 24, paddingTop: 8 }}> <div style={{ marginInline: 24, paddingTop: 8 }} ref={alertRef}>
<AlertBlockInfo <AlertBlockInfo
type="warning" type="warning"
contentStyle={{ paddingInline: 0 }} contentStyle={{ paddingInline: 0 }}
@@ -287,6 +297,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
label: intl.formatMessage({ id: 'backend.mode.yaml' }), label: intl.formatMessage({ id: 'backend.mode.yaml' }),
children: ( children: (
<ImportYAML <ImportYAML
height={yamlHeight}
actionStatus={{ actionStatus={{
action: action, action: action,
backendSource: backendSource backendSource: backendSource
@@ -19,12 +19,13 @@ interface ImportYAMLProps {
action: PageActionType; action: PageActionType;
backendSource: string; backendSource: string;
}; };
height?: string | number;
content?: string; content?: string;
onSubmit?: (content: string) => void; onSubmit?: (content: string) => void;
} }
const ImportYAML: React.FC<ImportYAMLProps> = forwardRef( const ImportYAML: React.FC<ImportYAMLProps> = forwardRef(
({ actionStatus, content = '' }, ref) => { ({ actionStatus, content = '', height }, ref) => {
const intl = useIntl(); const intl = useIntl();
const editorRef = useRef<any>(null); const editorRef = useRef<any>(null);
const [fileContent, setFileContent] = useState<string>( const [fileContent, setFileContent] = useState<string>(
@@ -109,7 +110,7 @@ const ImportYAML: React.FC<ImportYAMLProps> = forwardRef(
<YamlEditor <YamlEditor
ref={editorRef} ref={editorRef}
value={fileContent} value={fileContent}
height={'calc(100vh - 260px)'} height={height || 'calc(100vh - 260px)'}
validateMessage={error} validateMessage={error}
onUpload={(content) => { onUpload={(content) => {
setError(''); setError('');