Skip to content

Commit

Permalink
fix: nebula connect use sessionStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
xigongdaEricyang committed Sep 21, 2022
1 parent 91b25ed commit 672c8b6
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Button, Form, Input, Select } from 'antd';
import React from 'react';
import intl from 'react-intl-universal';
import { connect } from 'react-redux';
import cookies from 'js-cookie';
import { RouteComponentProps } from 'react-router-dom';
import {
passwordRulesFn,
Expand All @@ -16,6 +15,7 @@ import './index.less';
import nebulaLogo from '@/static/images/nebula_logo.png';
import { IDispatch, IRootState } from '@/store';
import { LanguageContext } from '@/context';
import { SessionStorageUtil } from '@/utils';

const FormItem = Form.Item;

Expand Down Expand Up @@ -58,7 +58,7 @@ class ConfigServerForm extends React.Component<IProps> {
...values,
});
if (ok) {
cookies.set('version', values.version);
SessionStorageUtil.setItem('version', values.version)
this.props.updateVersion(values.version);
this.props.history.push('/machine/overview');
}
Expand Down
9 changes: 4 additions & 5 deletions src/pages/ServiceManage/LeaderDistribution/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const mapDispatch: any = (dispatch: IDispatch) => ({

const mapState = (state: IRootState) => ({
loading: state.loading.effects.nebula.asyncGetHostsInfo,
address: (state.nebula as any).address,
port: (state.nebula as any).port,
nebulaConnect: (state.nebula as any).nebulaConnect,
});

interface IProps
Expand All @@ -44,14 +43,14 @@ const LeaderDistribution: React.FC<IProps> = (props: IProps) => {
const [data, setData] = useState<IChaerData[]>([]);
const [chartInstance, setChartInstance] = useState<Chart>();

const { address, cluster = {}, port, loading, isOverview, baseRouter = '/management' } = props;
const { nebulaConnect, cluster = {}, loading, isOverview, baseRouter = '/management' } = props;

useEffect(() => {
if (isCommunityVersion() || (address && port)) {
if (isCommunityVersion() || nebulaConnect) {
getStorageInfo();
}
return () => setData([]);
}, [address, port]);
}, [nebulaConnect]);

useEffect(() => {
if (chartInstance) {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ServiceManage/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const Overview: React.FC<IProps> = (props: IProps) => {
}
};

const balanceDataa = async () => {
const balanceData = async () => {
const code = await props.asyncExecNGQL('submit job balance data');
if (code === 0) {
message.success(intl.get('common.succeed'));
Expand All @@ -84,7 +84,7 @@ const Overview: React.FC<IProps> = (props: IProps) => {
content: intl.get('common.confirmAction'),
okText: intl.get('common.confirm'),
cancelText: intl.get('common.cancel'),
onOk: () => balanceDataa(),
onOk: () => balanceData(),
});
};

Expand Down
13 changes: 6 additions & 7 deletions src/pages/ServiceManage/PartitionDistribution/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const mapState = (state: IRootState) => ({
spaces: state.nebula.spaces,
loading: state.loading.models.nebula,
currentSpace: state.nebula.currentSpace,
address: state.nebula.address,
port: state.nebula.port,
nebulaConnect: state.nebula.nebulaConnect,
});

interface IProps
Expand All @@ -51,8 +50,8 @@ class PartitionDistribution extends React.Component<IProps, IState> {
}

async componentDidMount() {
const { address, port } = this.props;
if (isCommunityVersion() || (address && port)) {
const { nebulaConnect } = this.props;
if (isCommunityVersion() || (nebulaConnect)) {
await this.props.asyncGetSpaces();
const { currentSpace } = this.props;
if (currentSpace) {
Expand All @@ -62,9 +61,9 @@ class PartitionDistribution extends React.Component<IProps, IState> {
}

async componentDidUpdate(prevProps) {
const { address, port, currentSpace } = this.props;
if (address !== prevProps.address && port !== prevProps.port) {
if (isCommunityVersion() || (address && port)) {
const { nebulaConnect, currentSpace } = this.props;
if (nebulaConnect !== prevProps.nebulaConnect) {
if (isCommunityVersion() || nebulaConnect) {
await this.props.asyncGetSpaces();
const { currentSpace } = this.props;
if (currentSpace) {
Expand Down
9 changes: 4 additions & 5 deletions src/pages/ServiceManage/PartitionInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const mapState = (state: IRootState) => ({
spaces: state.nebula.spaces,
parts: state.nebula.parts,
currentSpace: state.nebula.currentSpace,
address: state.nebula.address,
port: state.nebula.port,
nebulaConnect: state.nebula.nebulaConnect,
});

const mapDispatch: any = (dispatch: IDispatch) => ({
Expand All @@ -32,14 +31,14 @@ interface IProps
}

const PartitionInfo: React.FC<IProps> = (props: IProps) => {
const { address, port, currentSpace, loading, parts, spaces, isOverview } =
const { nebulaConnect, currentSpace, loading, parts, spaces, isOverview } =
props;

useEffect(() => {
if (address && port) {
if (nebulaConnect) {
props.asyncGetSpaces();
}
}, [address, port]);
}, [nebulaConnect]);

useEffect(() => {
if (currentSpace) {
Expand Down
11 changes: 5 additions & 6 deletions src/pages/ServiceManage/ServiceInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { isCommunityVersion } from '@/utils';
const mapState = (state: IRootState) => ({
loading: state.loading.effects.nebula.asyncGetServices,
services: state.nebula.services,
address: (state.nebula as any).address,
port: (state.nebula as any).port,
nebulaConnect: (state.nebula as any).nebulaConnect,
});

const mapDispatch: any = (dispatch: IDispatch) => ({
Expand All @@ -30,15 +29,15 @@ class ServiceInfo extends React.Component<IProps> {
modalHandler;

componentDidMount() {
const { address, port } = this.props;
if (isCommunityVersion() || (address && port)) {
const { nebulaConnect } = this.props;
if (isCommunityVersion() || nebulaConnect) {
this.props.asyncGetServices();
}
}

componentDidUpdate(prevProps) {
const { address, port } = this.props;
if (address !== prevProps.address && port !== prevProps.port) {
const { nebulaConnect } = this.props;
if (nebulaConnect !== prevProps.nebulaConnect) {
this.props.asyncGetServices();
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/pages/ServiceManage/VersionStatistic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const mapDispatch: any = (dispatch: IDispatch) => ({
});

const mapState = (state: IRootState) => ({
address: (state.nebula as any).address,
port: (state.nebula as any).port,
nebulaConnect: (state.nebula as any).nebulaConnect,
});

interface IProps
Expand All @@ -37,15 +36,15 @@ class VersionStatistic extends React.Component<IProps, IState> {
}

componentDidMount() {
const { address, port } = this.props;
if (isCommunityVersion() || (address && port)) {
const { nebulaConnect } = this.props;
if (isCommunityVersion() || nebulaConnect) {
this.getVersion();
}
}

componentDidUpdate(prevProps) {
const { address, port } = this.props;
if (address !== prevProps.address && port !== prevProps.port) {
const { nebulaConnect } = this.props;
if (nebulaConnect !== prevProps.nebulaConnect) {
this.getVersion();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/store/models/nebula.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createModel } from '@rematch/core';
import _ from 'lodash';
import cookies from 'js-cookie';
import service from '@/config/service';
import { getConfigData } from "@/utils/dashboard";
import { NebulaVersionType } from '@/utils/interface';
import { SessionStorageUtil } from '@/utils';

interface IState {
configs: any[];
Expand All @@ -25,8 +25,8 @@ export function NebulaModelWrapper(serviceApi, state, _effects) {
spaces: [] as any,
parts: [],
services: [],
currentSpace: cookies.get('dashboard_space'),
version: cookies.get('version') || '',
currentSpace: SessionStorageUtil.getItem('currentSpace'),
version: SessionStorageUtil.getItem('version') || '',
...state,
},
reducers: {
Expand Down Expand Up @@ -77,7 +77,7 @@ export function NebulaModelWrapper(serviceApi, state, _effects) {
(this as any).update({
currentSpace: space,
});
cookies.set('dashboard_space', space);
SessionStorageUtil.setItem('currentSpace', space);
}
return { code, data };
},
Expand Down
17 changes: 17 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,20 @@ export const updateFn = (service: {
}) => {
getNebulaVersionName = service.getNebulaVersionName;
}

export class SessionStorageUtil {
static setItem<T>(key: string, value: T) {
sessionStorage.setItem(key, JSON.stringify(value));
}

static getItem<T>(key: string): T | undefined {
const item = sessionStorage.getItem(key);
if (item) {
return JSON.parse(item);
}
}

static removeItem(key: string) {
sessionStorage.removeItem(key);
}
}
6 changes: 6 additions & 0 deletions src/utils/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,10 @@ export interface VersionFeatureInfo {
version: string;
type: NebulaVersionType;
feature: VersionFeatureItem;
}

export interface NebulaConnectInfo {
address: string;
port: number;
currentSpace?: string;
}

0 comments on commit 672c8b6

Please sign in to comment.