From 4a1c714405096c0e8a95ed20e25aa8a205f781ab Mon Sep 17 00:00:00 2001 From: Nut He <18328704+hetao92@users.noreply.github.com> Date: Mon, 7 Mar 2022 17:22:25 +0800 Subject: [PATCH] fix: fix chinese and special characters (#136) --- .github/workflows/release.yml | 2 +- app/config/explore.ts | 3 +- app/config/rules.ts | 6 +- app/modules/Schema/Edge/Create.tsx | 22 ++---- app/modules/Schema/Edge/Edit.tsx | 96 ++++++++++-------------- app/modules/Schema/Edge/index.tsx | 27 +++---- app/modules/Schema/Index/Create.tsx | 33 ++++---- app/modules/Schema/Index/index.tsx | 23 +++--- app/modules/Schema/SpaceConfig/index.tsx | 36 +++------ app/modules/Schema/Tag/Create.tsx | 23 +++--- app/modules/Schema/Tag/Edit.tsx | 96 ++++++++++-------------- app/modules/Schema/Tag/index.tsx | 27 +++---- app/modules/Schema/index.tsx | 2 +- app/store/models/import.ts | 9 ++- app/store/models/nebula.ts | 6 +- app/utils/constant.ts | 1 - app/utils/fetch.ts | 4 +- app/utils/function.ts | 7 +- app/utils/gql.ts | 20 +++-- app/utils/import.ts | 20 ++--- deployment/helm/README.md | 2 +- deployment/helm/values.yaml | 2 +- package-lock.json | 4 +- package.json | 2 +- 24 files changed, 209 insertions(+), 264 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cec3c420..89e962f3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,4 +41,4 @@ jobs: context: . file: ./Dockerfile push: true - tags: vesoft/nebula-graph-studio:v3.2.1 \ No newline at end of file + tags: vesoft/nebula-graph-studio:v3.2.2 \ No newline at end of file diff --git a/app/config/explore.ts b/app/config/explore.ts index b6f4e09c..cae94253 100644 --- a/app/config/explore.ts +++ b/app/config/explore.ts @@ -171,7 +171,8 @@ export const downloadCSVFiles = ({ headers, tables, title }) => { // Non-Internet Explorer // Use the download property of the A tag to implement the download function const link = document.createElement('a'); - link.href = 'data:text/csv;charset=utf-8,\uFEFF' + encodeURIComponent(result); + link.href = + 'data:text/csv;charset=utf-8,\uFEFF' + encodeURIComponent(result); link.download = `${title}.csv`; document.body.appendChild(link); link.click(); diff --git a/app/config/rules.ts b/app/config/rules.ts index 5fe31f41..30411c01 100644 --- a/app/config/rules.ts +++ b/app/config/rules.ts @@ -1,4 +1,4 @@ -import { NAME_REGEX, POSITIVE_INTEGER_REGEX } from '#app/utils/constant'; +import { POSITIVE_INTEGER_REGEX } from '#app/utils/constant'; export const hostRulesFn = intl => [ { @@ -37,10 +37,6 @@ export const nameRulesFn = intl => [ required: true, message: intl.get('formRules.nameRequired'), }, - { - pattern: NAME_REGEX, - message: intl.get('formRules.nameValidate'), - }, ]; export const numberRulesFn = intl => [ diff --git a/app/modules/Schema/Edge/Create.tsx b/app/modules/Schema/Edge/Create.tsx index 48645d8b..0cfe1377 100644 --- a/app/modules/Schema/Edge/Create.tsx +++ b/app/modules/Schema/Edge/Create.tsx @@ -17,7 +17,7 @@ import _ from 'lodash'; import React from 'react'; import intl from 'react-intl-universal'; import { connect } from 'react-redux'; -import { match, RouteComponentProps, withRouter } from 'react-router-dom'; +import { RouteComponentProps, withRouter } from 'react-router-dom'; import GQLCodeMirror from '#app/components/GQLCodeMirror'; import { nameRulesFn, numberRulesFn } from '#app/config/rules'; @@ -46,9 +46,7 @@ interface IProps extends ReturnType, ReturnType, FormComponentProps, - RouteComponentProps { - match: match<{ space: string }>; -} + RouteComponentProps {} interface IState { fieldRequired: boolean; @@ -327,10 +325,6 @@ class CreateEdge extends React.Component { handleCreate = () => { const { getFieldsValue } = this.props.form; - const { match } = this.props; - const { - params: { space }, - } = match; this.props.form.validateFields(err => { const form = getFieldsValue(); if (!err) { @@ -349,7 +343,10 @@ class CreateEdge extends React.Component { .then(res => { if (res.code === 0) { message.success(intl.get('schema.createSuccess')); - this.props.history.push(`/space/${space}/edge/edit/${name}`); + this.props.history.push({ + pathname: '/space/edge/edit', + state: { edge: name }, + }); } else { message.warning(res.message); } @@ -361,17 +358,14 @@ class CreateEdge extends React.Component { goBack = e => { e.preventDefault(); - const { match, history } = this.props; - const { - params: { space }, - } = match; + const { history } = this.props; confirm({ title: intl.get('schema.leavePage'), content: intl.get('schema.leavePagePrompt'), okText: intl.get('common.confirm'), cancelText: intl.get('common.cancel'), onOk() { - history.push(`/space/${space}/edge/list`); + history.push(`/space/edge/list`); trackEvent('navigation', 'view_edge_list', 'from_edge_create'); }, }); diff --git a/app/modules/Schema/Edge/Edit.tsx b/app/modules/Schema/Edge/Edit.tsx index 7a6222a8..1335876b 100644 --- a/app/modules/Schema/Edge/Edit.tsx +++ b/app/modules/Schema/Edge/Edit.tsx @@ -18,14 +18,13 @@ import _ from 'lodash'; import React from 'react'; import intl from 'react-intl-universal'; import { connect } from 'react-redux'; -import { match, RouteComponentProps, withRouter } from 'react-router-dom'; +import { RouteComponentProps, withRouter } from 'react-router-dom'; import GQLCodeMirror from '#app/components/GQLCodeMirror'; import { IDispatch, IRootState } from '#app/store'; import { DATA_TYPE, EXPLAIN_DATA_TYPE, - NAME_REGEX, POSITIVE_INTEGER_REGEX, } from '#app/utils/constant'; import { convertBigNumberToString } from '#app/utils/function'; @@ -41,6 +40,7 @@ const confirm = Modal.confirm; const mapState = (state: IRootState) => ({ loading: state.loading.effects.nebula.asyncGetEdgeDetail, editLoading: state.loading.effects.nebula.asyncAlterField, + currentSpace: state.nebula.currentSpace, }); const mapDispatch = (dispatch: IDispatch) => ({ @@ -54,10 +54,6 @@ interface IProps extends ReturnType, ReturnType, RouteComponentProps { - match: match<{ - space: string; - edge: string; - }>; asyncUpdateEditStatus: (status: boolean) => void; } @@ -88,6 +84,7 @@ interface IState extends IRequired { editTtlConfig: ITtl | null; comment: string; temporaryComment: string; + edge: string; } type AlterType = 'ADD' | 'DROP' | 'CHANGE' | 'TTL'; @@ -120,6 +117,7 @@ class EditEdge extends React.Component { editTtlConfig: null, comment: '', temporaryComment: '', + edge: '', }; } @@ -128,11 +126,26 @@ class EditEdge extends React.Component { this.getDetails(); } + componentDidUpdate(prevProps) { + if ( + prevProps.currentSpace && + prevProps.currentSpace !== this.props.currentSpace + ) { + this.props.history.push('/space/edge/list'); + } + } + getDetails = async () => { - const { match } = this.props; const { - params: { edge }, - } = match; + location: { state }, + history, + } = this.props; + if (!(state as any).edge) { + history.push('/space/edge/list'); + return; + } + const edge = (state as any).edge; + this.setState({ edge }); const { code, data } = await this.props.asyncGetEdgeDetail(edge); const { code: propCode, @@ -146,7 +159,7 @@ class EditEdge extends React.Component { }; handleData = (data: string, fieldInfo: IEdgeFeild[]) => { - const reg = /CREATE EDGE\s`\w+`\s\((.*)\)\s+(ttl_duration = \d+),\s+(ttl_col = "\w*")(, comment = ".*")?/gm; + const reg = /CREATE EDGE\s`.+`\s\((.*)\)\s+(ttl_duration = \d+),\s+(ttl_col = ".*?")(, comment = ".*")?$/gm; const str = data.replace(/[\r\n]/g, ' '); const infoList = reg.exec(str) || []; const fieldList: IField[] = fieldInfo.map(i => ({ @@ -204,10 +217,7 @@ class EditEdge extends React.Component { }; handleDeleteField = async (fields: IField[]) => { - const { match } = this.props; - const { - params: { edge }, - } = match; + const { edge } = this.state; const res = await this.props.asyncAlterField({ type: 'EDGE', name: edge, @@ -296,19 +306,12 @@ class EditEdge extends React.Component { }; handleUpdateField = async () => { - const { match } = this.props; - const { - params: { edge }, - } = match; - const { editField } = this.state; + const { editField, edge } = this.state; if (editField) { const { name, type, alterType, fixedLength } = editField; if (name === '' || type === '') { return message.warning(intl.get('schema.fieldRequired')); } - if (name !== '' && !NAME_REGEX.test(name)) { - return message.warning(intl.get('formRules.nameValidate')); - } if ( type === 'fixed_string' && !fixedLength?.match(POSITIVE_INTEGER_REGEX) @@ -338,11 +341,7 @@ class EditEdge extends React.Component { }; handleUpdateTtl = async () => { - const { match } = this.props; - const { - params: { edge }, - } = match; - const { editTtlConfig } = this.state; + const { editTtlConfig, edge } = this.state; if (editTtlConfig) { const { col, duration } = editTtlConfig; if (col === '' || duration === '') { @@ -375,10 +374,7 @@ class EditEdge extends React.Component { }; handleTogglePanels = async (e: string | string[], type: string) => { - const { match } = this.props; - const { - params: { edge }, - } = match; + const { edge } = this.state; if (e.length > 0) { if (type === 'field') { this.handleAddField(); @@ -423,10 +419,7 @@ class EditEdge extends React.Component { }; handleDeleteTtl = async () => { - const { match } = this.props; - const { - params: { edge }, - } = match; + const { edge } = this.state; const res = await this.props.asyncAlterField({ type: 'EDGE', name: edge, @@ -463,7 +456,7 @@ class EditEdge extends React.Component { /> ); } else { - return {record}; + return {record.toString()}; } }, }, @@ -737,12 +730,9 @@ class EditEdge extends React.Component { editTtlConfig, editComment, temporaryComment, + edge, } = this.state; if (editField || editTtlConfig || editComment) { - const { match } = this.props; - const { - params: { edge }, - } = match; let action; let config = {}; if (editField) { @@ -775,11 +765,8 @@ class EditEdge extends React.Component { goBack = e => { e.preventDefault(); - const { match, history } = this.props; + const { history } = this.props; const { editRow, editTtl } = this.state; - const { - params: { space }, - } = match; if (editRow !== null || editTtl) { confirm({ title: intl.get('schema.leavePage'), @@ -787,12 +774,12 @@ class EditEdge extends React.Component { okText: intl.get('common.confirm'), cancelText: intl.get('common.cancel'), onOk() { - history.push(`/space/${space}/edge/list`); + history.push(`/space/edge/list`); trackEvent('navigation', 'view_edge_list', 'from_edge_edit'); }, }); } else { - history.push(`/space/${space}/edge/list`); + history.push(`/space/edge/list`); trackEvent('navigation', 'view_edge_list', 'from_edge_edit'); } }; @@ -806,11 +793,7 @@ class EditEdge extends React.Component { }; handleCommentUpdate = async () => { - const { match } = this.props; - const { - params: { edge }, - } = match; - const { temporaryComment } = this.state; + const { temporaryComment, edge } = this.state; const res = await this.props.asyncAlterField({ type: 'EDGE', name: edge, @@ -847,11 +830,14 @@ class EditEdge extends React.Component { }; render() { - const { match, editLoading } = this.props; - const { fieldRequired, ttlRequired, comment, editComment } = this.state; + const { editLoading } = this.props; const { - params: { edge }, - } = match; + fieldRequired, + ttlRequired, + comment, + editComment, + edge, + } = this.state; const outItemLayout = { labelCol: { span: 2, diff --git a/app/modules/Schema/Edge/index.tsx b/app/modules/Schema/Edge/index.tsx index 752df770..c4db39dc 100644 --- a/app/modules/Schema/Edge/index.tsx +++ b/app/modules/Schema/Edge/index.tsx @@ -2,7 +2,7 @@ import { Breadcrumb, Button, Icon, message, Popconfirm, Table } from 'antd'; import React from 'react'; import intl from 'react-intl-universal'; import { connect } from 'react-redux'; -import { Link, match, RouteComponentProps, withRouter } from 'react-router-dom'; +import { Link, RouteComponentProps, withRouter } from 'react-router-dom'; import { IDispatch, IRootState } from '#app/store'; import { sortByFieldAndFilter } from '#app/utils/function'; @@ -14,6 +14,7 @@ import './index.less'; const mapState = (state: IRootState) => ({ loading: state.loading.effects.nebula.asyncGetEdgeList, edgeList: state.nebula.edgeList, + currentSpace: state.nebula.currentSpace, }); const mapDispatch = (dispatch: IDispatch) => ({ @@ -24,9 +25,7 @@ const mapDispatch = (dispatch: IDispatch) => ({ interface IProps extends ReturnType, ReturnType, - RouteComponentProps { - match: match<{ space: string }>; -} + RouteComponentProps {} interface IEdgeInfo { name: string; @@ -85,7 +84,10 @@ class EdgeList extends React.Component { } componentDidUpdate(prevProps) { - if (prevProps.match.params.space !== this.props.match.params.space) { + if ( + prevProps.currentSpace && + prevProps.currentSpace !== this.props.currentSpace + ) { this.props.asyncGetEdgeList(); } } @@ -116,10 +118,6 @@ class EdgeList extends React.Component { renderEdgeList = () => { const { loading, edgeList } = this.props; - const { match } = this.props; - const { - params: { space }, - } = match; const { expandedRowKeys, searchVal } = this.state; const data = sortByFieldAndFilter({ field: 'name', @@ -143,7 +141,10 @@ class EdgeList extends React.Component {