Skip to content

Commit

Permalink
must
Browse files Browse the repository at this point in the history
  • Loading branch information
HSunboy committed Dec 6, 2023
1 parent 4d194f0 commit bdb5448
Show file tree
Hide file tree
Showing 50 changed files with 2,058 additions and 810 deletions.
50 changes: 37 additions & 13 deletions src/component/ErrorBoundary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@
import { formatMessage } from '@/util/intl';
import { Button, Result } from 'antd';
import React from 'react';

export default class ErrorBoundary extends React.Component {
public static getDerivedStateFromError(error: any) {
return { hasError: true };
return {
hasError: true,
};
}
public state = {
hasError: false,
errorComponent: null,
errorStack: null,
};

constructor(props: any) {
super(props);
this.state = { hasError: false, errorComponent: null, errorStack: null };
this.state = {
hasError: false,
errorComponent: null,
errorStack: null,
};
}

public componentDidCatch(error: any, errorInfo) {
// You can also log the error to an error reporting service
console.log('error', error?.stack, errorInfo);
Expand All @@ -42,23 +45,32 @@ export default class ErrorBoundary extends React.Component {
errorStack: error?.stack,
});
}

public render() {
const isChunkError = this.state.errorStack?.toString().includes('ChunkLoadError');
if (isChunkError) {
return (
<Result
status="404"
title="系统正在升级中"
subTitle="当前 ODC 版本已过期,请刷新重试"
title={
formatMessage({
id: 'odc.src.component.ErrorBoundary.TheSystemIsBeingUpgraded',
}) /* 系统正在升级中 */
}
subTitle={
formatMessage({
id: 'odc.src.component.ErrorBoundary.TheCurrentODCVersionHas',
}) /* 当前 ODC 版本已过期,请刷新重试 */
}
extra={
<Button
onClick={() => {
window.location.href = `${location.origin}${location.pathname}`;
}}
type="primary"
>
{formatMessage({ id: 'odc.component.ErrorBoundary.Reload' })}
{formatMessage({
id: 'odc.component.ErrorBoundary.Reload',
})}
</Button>
}
/>
Expand All @@ -85,19 +97,31 @@ export default class ErrorBoundary extends React.Component {
window.location.href = `${location.origin}${location.pathname}`;
}}
>
{formatMessage({ id: 'odc.component.ErrorBoundary.Reload' })}
{formatMessage({
id: 'odc.component.ErrorBoundary.Reload',
})}
</a>
</div>
<pre style={{ padding: 20, color: 'red' }}>
<pre
style={{
padding: 20,
color: 'red',
}}
>
<h3>Stack</h3>
{this.state.errorStack}
<h3 style={{ marginTop: 10 }}>Component</h3>
<h3
style={{
marginTop: 10,
}}
>
Component
</h3>
{this.state.errorComponent}
</pre>
</div>
);
}

return this.props.children;
}
}
78 changes: 36 additions & 42 deletions src/component/GrammerHelpSider/component/SnippetForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ import { formatMessage } from '@/util/intl';
import { Button, Drawer, Form, Input, message, Modal, Select } from 'antd';
import type { FormInstance } from 'antd/lib/form';
import React, { PureComponent } from 'react';

import MonacoEditor, { IEditor } from '@/component/MonacoEditor';
import { getDataSourceModeConfig } from '@/common/datasource';
import { ConnectType } from '@/d.ts';

const MAX_SNIPPRT_SIZE = 10000;

const { Option } = Select;
const { TextArea } = Input;
interface IProps {
Expand All @@ -40,19 +37,15 @@ interface IProps {
snippet: any;
onClose: (isNeedReloadList?: boolean) => void;
}

class SnippetFormDrawer extends PureComponent<IProps> {
public formRef = React.createRef<FormInstance>();

// @ts-ignore
public editor: IEditor;

private modal: any;

public getSession() {
return null;
}

onClose = async () => {
const self = this;
const { action } = this.props;
Expand All @@ -66,14 +59,20 @@ class SnippetFormDrawer extends PureComponent<IProps> {
{
id: 'odc.component.SnippetForm.ExitTheActionnameCodeSnippet',
},
{ actionName },
), // `退出${actionName}代码片段`
{
actionName,
},
),
// `退出${actionName}代码片段`
content: formatMessage(
{
id: 'odc.component.SnippetForm.IfTheContentIsNot',
},
{ actionName },
), // `存在未保存内容, 退出${actionName}代码片段`
{
actionName,
},
),
// `存在未保存内容, 退出${actionName}代码片段`
onOk() {
self.props.onClose();
},
Expand All @@ -82,64 +81,58 @@ class SnippetFormDrawer extends PureComponent<IProps> {
this.props.onClose();
}
};

componentWillUnmount() {
this.modal?.destroy();
}

handleSubmit = async () => {
const { action, snippet } = this.props;
this.formRef.current
.validateFields()
.then(async (values) => {
let r;

switch (action) {
case EnumSnippetAction.CREATE:
r = await snippetStore.createCustomerSnippet(values);

if (r) {
message.success(
formatMessage(
{
id: 'odc.component.SnippetForm.SyntaxFragmentValuesprefixIsCreated',
},

{ valuesPrefix: values.prefix },
{
valuesPrefix: values.prefix,
},
),

// `代码片段 ${values.prefix} 创建成功!`
);
}

break;

case EnumSnippetAction.EDIT:
r = await snippetStore.updateCustomerSnippet({
...values,
id: snippet.id,
});

if (r) {
message.success(
formatMessage(
{
id: 'odc.component.SnippetForm.TheSyntaxSnippetSnippetprefixHas',
},

{ snippetPrefix: snippet.prefix },
{
snippetPrefix: snippet.prefix,
},
),

// `代码片段 ${snippet.prefix} 更新成功!`
);
}

break;

default:
break;
}

if (r) {
this.props.onClose(r);
}
Expand All @@ -148,14 +141,11 @@ class SnippetFormDrawer extends PureComponent<IProps> {
console.error(JSON.stringify(error));
});
};

render() {
const { action, snippet, visible } = this.props;

if (!action) {
return null;
}

const config = getDataSourceModeConfig(ConnectType.MYSQL);
const actionItem = SNIPPET_ACTIONS.find((actionItem) => actionItem.key === action);
const initialValues = {
Expand All @@ -164,16 +154,16 @@ class SnippetFormDrawer extends PureComponent<IProps> {
description: snippet?.description,
body: snippet?.body,
};

return (
<Drawer
title={
formatMessage(
{
id: 'odc.component.SnippetForm.ActionitemnameSyntaxFragment',
},

{ actionItemName: actionItem.name },
{
actionItemName: actionItem.name,
},
)

// `${actionItem.name}代码片段`
Expand All @@ -190,9 +180,10 @@ class SnippetFormDrawer extends PureComponent<IProps> {
<Form layout="vertical" hideRequiredMark initialValues={initialValues} ref={this.formRef}>
<Form.Item
name="prefix"
label={formatMessage({ id: 'odc.component.SnippetForm.Syntax' })}
/* 语法名称 */
rules={[
label={formatMessage({
id: 'odc.component.SnippetForm.Syntax',
})}
/* 语法名称 */ rules={[
{
required: true,
message: formatMessage({
Expand Down Expand Up @@ -232,8 +223,7 @@ class SnippetFormDrawer extends PureComponent<IProps> {
label={formatMessage({
id: 'odc.component.SnippetForm.SyntaxType',
})}
/* 语法类型 */
rules={[
/* 语法类型 */ rules={[
{
required: true,
message: formatMessage({
Expand All @@ -247,8 +237,7 @@ class SnippetFormDrawer extends PureComponent<IProps> {
placeholder={formatMessage({
id: 'odc.component.SnippetForm.SelectASyntaxType',
})}
/* 请选择语法类型 */
style={{
/* 请选择语法类型 */ style={{
width: '196px',
}}
>
Expand Down Expand Up @@ -300,7 +289,15 @@ class SnippetFormDrawer extends PureComponent<IProps> {
},
{
max: MAX_SNIPPRT_SIZE,
message: `语法长度不能超过 ${MAX_SNIPPRT_SIZE} 个字符`,
message: formatMessage(
{
id:
'odc.src.component.GrammerHelpSider.component.SnippetForm.TheGrammarLengthCannotExceed',
},
{
MAX_SNIPPRT_SIZE: MAX_SNIPPRT_SIZE,
},
), //`语法长度不能超过 ${MAX_SNIPPRT_SIZE} 个字符`
},
]}
>
Expand All @@ -320,8 +317,7 @@ class SnippetFormDrawer extends PureComponent<IProps> {
label={formatMessage({
id: 'odc.component.SnippetForm.SyntaxDescription',
})}
/* 语法描述 */
rules={[
/* 语法描述 */ rules={[
{
required: false,
message: formatMessage({
Expand All @@ -344,8 +340,7 @@ class SnippetFormDrawer extends PureComponent<IProps> {
placeholder={formatMessage({
id: 'odc.component.SnippetForm.EnterASyntaxDescription',
})}
/* 请输入语法描述 */
style={{
/* 请输入语法描述 */ style={{
height: '120px',
}}
/>
Expand Down Expand Up @@ -390,5 +385,4 @@ class SnippetFormDrawer extends PureComponent<IProps> {
);
}
}

export default SnippetFormDrawer;
16 changes: 10 additions & 6 deletions src/component/SQLLintResult/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ interface IProps {
visible: boolean;
closePage: () => void;
}

const LintDrawer: React.FC<IProps> = function ({ data, visible, closePage }) {
return (
<Drawer
Expand All @@ -34,10 +33,16 @@ const LintDrawer: React.FC<IProps> = function ({ data, visible, closePage }) {
open={visible}
title={formatMessage({
id: 'odc.component.SQLLintResult.Drawer.CheckResult',
})} /*检查结果*/
footer={
<Space style={{ float: 'right' }}>
<Button onClick={closePage}>关闭</Button>
})}
/*检查结果*/ footer={
<Space
style={{
float: 'right',
}}
>
<Button onClick={closePage}>
{formatMessage({ id: 'odc.src.component.SQLLintResult.Closure' }) /* 关闭 */}
</Button>
</Space>
}
onClose={() => {
Expand All @@ -48,5 +53,4 @@ const LintDrawer: React.FC<IProps> = function ({ data, visible, closePage }) {
</Drawer>
);
};

export default LintDrawer;
Loading

0 comments on commit bdb5448

Please sign in to comment.