Skip to content

Commit

Permalink
fix: remove v2.x version compatible logic (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao92 authored Nov 11, 2022
1 parent 805a82d commit 44861f9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 35 deletions.
24 changes: 7 additions & 17 deletions app/config/rules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MAX_COMMENT_BYTES, NAME_REGEX, POSITIVE_INTEGER_REGEX } from '@app/utils/constant';
import { MAX_COMMENT_BYTES, POSITIVE_INTEGER_REGEX } from '@app/utils/constant';
import { getByteLength } from '@app/utils/function';
import intl from 'react-intl-universal';

Expand All @@ -23,22 +23,12 @@ export const passwordRulesFn = () => [
},
];

export const nameRulesFn = () => {
const version = sessionStorage.getItem('nebulaVersion');
const nameRequired = [
{
required: true,
message: intl.get('formRules.nameRequired'),
},
];
const nameValidate = [
{
pattern: NAME_REGEX,
message: intl.get('formRules.nameValidate'),
},
];
return version?.startsWith('v2') ? [...nameRequired, ...nameValidate] : nameRequired;
};
export const nameRulesFn = () => [
{
required: true,
message: intl.get('formRules.nameRequired'),
},
];

export const numberRulesFn = () => [
{
Expand Down
5 changes: 2 additions & 3 deletions app/pages/Console/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ interface IProps {
templateRender?: (data?) => JSX.Element
}
const Console = (props: IProps) => {
const { schema, console, global } = useStore();
const { schema, console } = useStore();
const { onExplorer, templateRender } = props;
const { spaces, getSpaces, switchSpace, currentSpace, spaceVidType, updateVidType } = schema;
const { runGQL, currentGQL, results, runGQLLoading, getParams, update, paramsMap, getFavoriteList } = console;
const { nebulaVersion } = global;
const [isUpDown, setUpDown] = useState(false);
const [modalVisible, setModalVisible] = useState(false);
const [modalData, setModalData] = useState<any>(null);
Expand Down Expand Up @@ -156,7 +155,7 @@ const Console = (props: IProps) => {
</div>
</div>
<div className={styles.codeInput}>
{nebulaVersion?.startsWith('v3') && <CypherParameterBox onSelect={addParam} data={paramsMap} />}
<CypherParameterBox onSelect={addParam} data={paramsMap} />
<CodeMirror
value={currentGQL}
onBlur={value => update({ currentGQL: value })}
Expand Down
9 changes: 2 additions & 7 deletions app/stores/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import { Base64 } from 'js-base64';
import intl from 'react-intl-universal';
import service from '@app/config/service';
import { BrowserHistory } from 'history';
import { NebulaVersion } from './types';
import { getRootStore, resetStore } from '.';

export class GlobalStore {
history: BrowserHistory;
_username = cookies.get('nu');
_host = cookies.get('nh');
version = process.env.VERSION;
nebulaVersion?: NebulaVersion = sessionStorage.getItem('nebulaVersion') as NebulaVersion;
constructor() {
makeObservable(this, {
_username: observable,
Expand Down Expand Up @@ -53,7 +51,6 @@ export class GlobalStore {
resetStore();
cookies.remove('nh');
cookies.remove('nu');
sessionStorage.removeItem('nebulaVersion');
this.history.push(`/login${location.search}`);
};

Expand All @@ -66,7 +63,7 @@ export class GlobalStore {
const _host = host.trim().replace(/^https?:\/\//, '');
const [address, port] = _host.split(':');
const authorization = Base64.encode(JSON.stringify([username, password]));
const { code, data } = (await service.connectDB(
const { code } = (await service.connectDB(
{
address,
port: +port,
Expand All @@ -85,15 +82,13 @@ export class GlobalStore {
message.success(intl.get('configServer.success'));
cookies.set('nh', _host);
cookies.set('nu', username);
sessionStorage.setItem('nebulaVersion', data.version);
this.update({ _host, _username: username, nebulaVersion: data.version });
this.update({ _host, _username: username });
return true;
}

this.update({ _host: '', _username: '' });
cookies.remove('nh');
cookies.remove('nu');
sessionStorage.removeItem('nebulaVersion');
return false;
};
}
Expand Down
6 changes: 0 additions & 6 deletions app/stores/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
export enum NebulaVersion {
V2_5 = 'v2.5',
V2_6 = 'v2.6',
V3_0 = 'v3.0',
}

export interface ITransform {
x: number;
y: number;
Expand Down
2 changes: 0 additions & 2 deletions app/utils/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,4 @@ export const EXPLAIN_DATA_TYPE = [

export const MAX_COMMENT_BYTES = 256;

export const NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9_]*$/;

export const POSITIVE_INTEGER_REGEX = /^[1-9]\d*$/g;

0 comments on commit 44861f9

Please sign in to comment.