From 00926261115d83275d8b64825021c3492a5d5cf1 Mon Sep 17 00:00:00 2001 From: Nut He <18328704+hetao92@users.noreply.github.com> Date: Thu, 30 Dec 2021 15:26:21 +0800 Subject: [PATCH] feat: add tips when use space err after creating (#73) mod: update tip --- app/assets/config/locale/en-US.json | 1 + app/assets/config/locale/zh-CN.json | 1 + app/assets/modules/Schema/index.tsx | 42 ++++++++++++++++------------- app/assets/store/models/nebula.ts | 4 ++- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/app/assets/config/locale/en-US.json b/app/assets/config/locale/en-US.json index fa336ed0..7204bd16 100644 --- a/app/assets/config/locale/en-US.json +++ b/app/assets/config/locale/en-US.json @@ -302,6 +302,7 @@ "schema": { "spaceList": "Graph Space List", "backToSpaceList": "Graph Space List", + "useSpaceErrTip": "Space not found. Trying to use a newly created graph space may fail because the creation is implemented asynchronously. To make sure the follow-up operations work as expected, Wait for two heartbeat cycles, i.e., 20 seconds.", "partitionNumDescription": "partition_num specifies the number of partitions in one replica. The default value is 100. It is usually 5 times the number of hard disks in the cluster.", "replicaFactorDescription": "replica_factor specifies the number of replicas in the cluster. The default replica factor is 1. The suggested number is 3 in cluster. It is usually 3 in production. Due to the majority voting principle, it must set to be odd.", "charsetDescription": "charset is short for character set. A character set is a set of symbols and encodings. The default value is utf8.", diff --git a/app/assets/config/locale/zh-CN.json b/app/assets/config/locale/zh-CN.json index fd4f2b20..dd9b0a04 100644 --- a/app/assets/config/locale/zh-CN.json +++ b/app/assets/config/locale/zh-CN.json @@ -298,6 +298,7 @@ "schema": { "spaceList": "图空间列表", "backToSpaceList": "图空间列表", + "useSpaceErrTip": "图空间未找到。立刻尝试使用刚创建的图空间可能会失败,因为创建是异步实现的。为确保数据同步,后续操作能顺利进行,请等待 2 个心跳周期(20 秒)。", "partitionNumDescription": "partition_num 表示数据分片数量。默认值为 100。建议为硬盘数量的 5 倍。", "replicaFactorDescription": "replica_factor 表示副本数量。默认值是 1,生产集群建议为 3。由于采用多数表决原理,因此需为奇数。", "charsetDescription": "charset 表示字符集,定义了字符以及字符的编码,默认为 utf8。", diff --git a/app/assets/modules/Schema/index.tsx b/app/assets/modules/Schema/index.tsx index f3628526..c0ce46c1 100644 --- a/app/assets/modules/Schema/index.tsx +++ b/app/assets/modules/Schema/index.tsx @@ -19,10 +19,8 @@ const mapState = (state: IRootState) => ({ const mapDispatch = (dispatch: IDispatch) => ({ asyncGetSpacesList: dispatch.nebula.asyncGetSpacesList, asyncDeleteSpace: dispatch.nebula.asyncDeleteSpace, - asyncSwitchSpace: async space => { - await dispatch.nebula.asyncSwitchSpace(space); - await dispatch.explore.clear(); - }, + asyncSwitchSpace: dispatch.nebula.asyncSwitchSpace, + asyncClearExplore: dispatch.explore.clear, clearCurrentSpace: () => dispatch.nebula.update({ currentSpace: '', @@ -60,6 +58,16 @@ class Schema extends React.Component { } }; + handleSwitchSpace = async (space: string) => { + const { asyncSwitchSpace, history, asyncClearExplore } = this.props; + const err = await asyncSwitchSpace(space); + if (!err) { + await asyncClearExplore(); + history.push(`/space/${space}/tag/list`); + } else if (err && err.toLowerCase().includes('spacenotfound')) { + message.warning(intl.get('schema.useSpaceErrTip')); + } + }; render() { const { loading, spaceList, asyncSwitchSpace } = this.props; const columns = [ @@ -73,15 +81,15 @@ class Schema extends React.Component { dataIndex: 'Name', align: 'center' as const, render: value => ( - asyncSwitchSpace(value)} + ), }, { @@ -163,16 +171,14 @@ class Schema extends React.Component { return (
- this.handleDeleteSpace(space.Name)} diff --git a/app/assets/store/models/nebula.ts b/app/assets/store/models/nebula.ts index 033bb86b..0be98214 100644 --- a/app/assets/store/models/nebula.ts +++ b/app/assets/store/models/nebula.ts @@ -313,7 +313,7 @@ export const nebula = createModel({ }, async asyncSwitchSpace(space: string) { - const { code } = (await service.execNGQL({ + const { code, message } = (await service.execNGQL({ // HACK: Processing keyword gql: 'use' + '`' + space + '`;', })) as any; @@ -329,6 +329,8 @@ export const nebula = createModel({ spaceVidType, }); sessionStorage.setItem('currentSpace', space); + } else { + return message; } },