Skip to content

Commit

Permalink
fix: page jump when session is invalid (#562)
Browse files Browse the repository at this point in the history
mod: code review
  • Loading branch information
hetao92 authored May 23, 2023
1 parent ccc00f5 commit 6ccddbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
22 changes: 11 additions & 11 deletions app/pages/Schema/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Popconfirm, Table, message, Popover, Form, Input, Dropdown, Menu, Tooltip } from 'antd';
import React, { useEffect, useMemo, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useI18n } from '@vesoft-inc/i18n';
import Icon from '@app/components/Icon';
import { trackPageView } from '@app/utils/stat';
Expand Down Expand Up @@ -102,23 +102,23 @@ const Schema = () => {
}
};

const handleSwitchSpace = async (space: string) => {
await switchSpace(space);
history.push(`/schema/tag/list`);
};
const getSpaces = async () => {
const viewSpaceDetail = useCallback(async (space: string) => {
const ok = await switchSpace(space);
ok && history.push(`/schema/tag/list`);
}, []);
const getSpaces = useCallback(async () => {
setLoading(true);
await getSpacesList();
setLoading(false);
};
}, []);

const handleCloneSpace = async (name: string, oldSpace: string) => {
const handleCloneSpace = useCallback(async (name: string, oldSpace: string) => {
const { code } = await cloneSpace(name, oldSpace);
if(code === 0) {
message.success(intl.get('schema.createSuccess'));
getSpaces();
}
};
}, []);
const columns = [
{
title: intl.get('schema.No'),
Expand All @@ -137,7 +137,7 @@ const Schema = () => {
<a
className={styles.cellBtn}
type="link"
onClick={() => handleSwitchSpace(data)}
onClick={() => viewSpaceDetail(data)}
data-track-category="navigation"
data-track-action="view_space_list"
data-track-label="from_space_list"
Expand Down Expand Up @@ -193,7 +193,7 @@ const Schema = () => {
<div className={styles.operation}>
<Button
className="primaryBtn"
onClick={() => handleSwitchSpace(space.Name)}
onClick={() => viewSpaceDetail(space.Name)}
data-track-category="navigation"
data-track-action="view_space_list"
data-track-label="from_space_list"
Expand Down
8 changes: 5 additions & 3 deletions app/stores/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ export class SchemaStore {
updateVidType = async (space?: string) => {
const spaceVidType = await this.getSpaceVidType(space || this.currentSpace);
this.update({ spaceVidType });
return !!spaceVidType;
};

switchSpace = async (space: string) => {
this.update({ currentSpace: space, ...initialSchemaData });
localStorage.setItem('currentSpace', space);
await this.updateVidType(space);
const ok = await this.updateVidType(space);
return ok;
};

getSchemaInfo = async () => {
Expand All @@ -127,8 +129,8 @@ export class SchemaStore {
};

getSpaceVidType = async (space: string) => {
const { data } = await this.getSpaceInfo(space);
return data?.tables?.[0]?.['Vid Type'];
const { code, data } = await this.getSpaceInfo(space);
return code === 0 ? data?.tables?.[0]?.['Vid Type'] : null;
};

getSpaceCreateGQL = async (space: string) => {
Expand Down

0 comments on commit 6ccddbb

Please sign in to comment.