feat:1、Set language 2、Remove junk code

This commit is contained in:
yanzhiyong
2024-08-16 00:19:21 +08:00
parent fa5e425427
commit c5ba26461e
5 changed files with 35 additions and 33 deletions

View File

@@ -2,6 +2,9 @@ import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
const en = {
UploadData: 'Upload Data',
CodeEditor: 'Code Editor:',
openCodeEditor:'Open Code Editor',
Knowledge_Space: 'Knowledge',
space: 'space',
Vector: 'Vector',
@@ -234,6 +237,9 @@ export interface Resources {
}
const zh: Resources['translation'] = {
UploadData: '上传数据',
CodeEditor: '代码编辑:',
openCodeEditor: '打开代码编辑器',
Knowledge_Space: '知识库',
space: '知识库',
Vector: '向量',

View File

@@ -18,9 +18,6 @@ import {
RenderUpload,
RenderCodeEditor,
} from './node-renderer';
import MonacoEditor from '@/components/chat/monaco-editor'
// C:\Users\Administrator\Desktop\ai\DB-GPT\web\components\chat\monaco-editor.tsx
import { convertKeysToCamelCase } from '@/utils/flow';
interface NodeParamHandlerProps {
node: IFlowNode;

View File

@@ -2,6 +2,8 @@ import React, { useState, useMemo } from 'react';
import { Button, Modal } from 'antd';
import Editor from '@monaco-editor/react';
import { IFlowNodeParameter } from '@/types/flow';
import { convertKeysToCamelCase } from '@/utils/flow';
import { useTranslation } from 'react-i18next';
type Props = {
data: IFlowNodeParameter;
@@ -10,6 +12,8 @@ type Props = {
};
export const RenderCodeEditor = (params: Props) => {
const { t } = useTranslation();
const { data, defaultValue, onChange } = params;
const attr = convertKeysToCamelCase(data.ui?.attr || {});
@@ -35,14 +39,12 @@ export const RenderCodeEditor = (params: Props) => {
return '80%';
}, [data?.ui?.editor?.width]);
return (
<div style={{ textAlign: 'center' }} className="p-2 text-sm">
<Button type="primary" onClick={showModal}>
{t('openCodeEditor')}
</Button>
<Modal title="代码编辑:" width={modalWidth} open={isModalOpen} onOk={handleOk} onCancel={handleCancel}>
<Modal title={t('openCodeEditor')} width={modalWidth} open={isModalOpen} onOk={handleOk} onCancel={handleCancel}>
<Editor
{...data?.ui?.attr}
width={data?.ui?.editor?.width || '100%'}
@@ -51,7 +53,7 @@ export const RenderCodeEditor = (params: Props) => {
height={data?.ui?.editor?.height || 200}
defaultLanguage={data?.ui?.language}
onChange={onChange}
theme='vs-dark' // 编辑器主题颜色
theme='vs-dark'
options={{
minimap: {
enabled: false,

View File

@@ -3,6 +3,8 @@ import { UploadOutlined } from '@ant-design/icons';
import type { UploadProps } from 'antd';
import { Button, message, Upload } from 'antd';
import { convertKeysToCamelCase } from '@/utils/flow';
import { IFlowNodeParameter } from '@/types/flow';
import { useTranslation } from 'react-i18next';
const props: UploadProps = {
name: 'file',
@@ -10,31 +12,29 @@ const props: UploadProps = {
headers: {
authorization: 'authorization-text',
},
onChange(info) {
if (info.file.status !== 'uploading') {
console.log(info.file, info.fileList);
}
if (info.file.status === 'done') {
message.success(`${info.file.name} file uploaded successfully`);
} else if (info.file.status === 'error') {
message.error(`${info.file.name} file upload failed.`);
}
},
};
export const RenderUpload: React.FC = (params) => (
const { data, defaultValue, onChange } = params;
type Props = {
data: IFlowNodeParameter;
defaultValue: any;
onChange: (value: any) => void;
};
const attr = convertKeysToCamelCase(data.ui?.attr || {});
export const RenderUpload = (params: Props) => {
const { t } = useTranslation();
return (
<div style={{ textAlign: 'center' }} className="p-2 text-sm">
<Upload {...attr} {...props}>
<Button icon={<UploadOutlined />}></Button>
</Upload>
</div>
)
const { data, defaultValue, onChange } = params;
);
const attr = convertKeysToCamelCase(data.ui?.attr || {});
return (
<div style={{ textAlign: 'center' }} className="p-2 text-sm">
<Upload {...attr} {...props}>
<Button icon={<UploadOutlined />}>{t('UploadData')}</Button>
</Upload>
</div>
)
}

View File

@@ -1,9 +1,6 @@
import { message } from 'antd';
import axios from './ctx-axios';
import { isPlainObject } from 'lodash';
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css'; // 引入你喜欢的主题
import 'codemirror/mode/javascript/javascript'; // 引入JavaScript语言模式
const DEFAULT_HEADERS = {
'content-type': 'application/json',
};