fix: yaml editor do not update when upload same file

This commit is contained in:
jialin
2025-11-13 16:53:11 +08:00
parent b61c0d6dee
commit aee9566bbb
13 changed files with 42 additions and 98 deletions
+1 -9
View File
@@ -5,7 +5,7 @@ import SegmentLine from '@/components/segment-line';
import { PageAction } from '@/config';
import { PageActionType } from '@/config/types';
import { useIntl } from '@umijs/max';
import { Segmented, Tabs } from 'antd';
import { Tabs } from 'antd';
import _ from 'lodash';
import React, { useEffect, useId, useRef, useState } from 'react';
import styled from 'styled-components';
@@ -25,14 +25,6 @@ const ModalFooterStyle = {
justifyContent: 'flex-end'
};
const SegmentedInner = styled(Segmented)`
width: 100%;
border-radius: 0;
.ant-segmented-item {
flex: 1;
}
`;
const SegmentedHeader = styled.div`
margin: 16px 24px;
border-bottom: 1px solid var(--ant-color-split);
@@ -67,6 +67,10 @@ const ImportYAML: React.FC<ImportYAMLProps> = forwardRef(
);
const [error, setError] = useState<string>('');
const setContent = (val: string) => {
editorRef.current?.setValue?.(val);
};
const beforeUpload = (file: RcFile) => {
const isYaml =
file.type === 'application/x-yaml' ||
@@ -81,6 +85,7 @@ const ImportYAML: React.FC<ImportYAMLProps> = forwardRef(
const content = e.target?.result;
if (typeof content === 'string') {
setFileContent(content);
setContent(content);
} else {
message.error('Failed to read file content!');
}
@@ -150,9 +155,7 @@ const ImportYAML: React.FC<ImportYAMLProps> = forwardRef(
getContent: () => {
return getContent();
},
setContent: (val: string) => {
editorRef.current?.setValue?.(val);
},
setContent: setContent,
validate() {
return validate();
}
@@ -73,7 +73,6 @@ const ViewerEditor: React.FC<ViewerProps> = forwardRef((props, ref) => {
const handleEditorDidMount = (editor: any, monaco: any) => {
editorRef.current = editor;
monacoRef.current = monaco;
const uri = monaco.Uri.parse(path);
};
const formatCode = () => {
+1 -1
View File
@@ -3,7 +3,7 @@
"properties": {
"backend_name": {
"type": "string",
"pattern": "^-custom$",
"pattern": "^.+-custom$",
"description": "backend name",
"severity": "error"
},