fix: Fix import circle

Fix import circle

Change-Id: I3588254da48ade79c31c99a6f03bd48c82350116
This commit is contained in:
Jingwei.Zhang 2021-09-07 12:15:03 +08:00
parent f21c5a6daa
commit 535badf92e
9 changed files with 95 additions and 84 deletions

View File

@ -56,7 +56,6 @@
"consistent-return": "warn",
"no-underscore-dangle": "warn",
"no-unused-expressions": "warn",
"import/no-cycle": "warn",
"no-empty": [
2,
{
@ -69,7 +68,8 @@
"import/no-extraneous-dependencies": "warn",
"import/prefer-default-export": "off",
"no-nested-ternary": "warn",
"import/no-named-as-default": "warn"
"import/no-named-as-default": "warn",
"global-require": "off"
},
"globals": {
"t": true,

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import globalRootStore from 'stores/root';
import clientRequest from './request';
export default class BaseClient {
@ -64,6 +63,7 @@ export default class BaseClient {
if (!this.projectInUrl) {
return '';
}
const globalRootStore = require('stores/root').default;
const { project: { id } = {} } = globalRootStore.user || {};
return id || '';
}

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import globalRootStore from 'stores/root';
import { toJS } from 'mobx';
export const groupNameVersionMap = {
@ -48,6 +47,7 @@ const endpointsDefault = {
};
export const getOpenstackEndpoint = (key) => {
const globalRootStore = require('stores/root').default;
const { endpoints = {} } = globalRootStore || {};
const version = endpointVersionMap[key];
const endpoint = endpoints[key] || endpointsDefault[key] || '';
@ -55,6 +55,7 @@ export const getOpenstackEndpoint = (key) => {
};
export const getOriginEndpoint = (key) => {
const globalRootStore = require('stores/root').default;
const endpoints = toJS((globalRootStore && globalRootStore.endpoints) || {});
return endpoints[key];
};

View File

@ -16,9 +16,7 @@ import Axios from 'axios';
import { getLocalStorageItem } from 'utils/local-storage';
import { isEqual } from 'lodash';
import qs from 'qs';
import globalRootStore from 'stores/root';
import { v4 as uuidv4 } from 'uuid';
import { getOpenstackApiVersion } from './constants';
const METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'];
/**
@ -31,6 +29,7 @@ export class HttpRequest {
}
gotoLoginPage(path) {
const globalRootStore = require('stores/root').defaullt;
globalRootStore.gotoLoginPage(path);
}
@ -46,6 +45,7 @@ export class HttpRequest {
const uuid = uuidv4();
config.headers['X-Openstack-Request-Id'] = `req-${uuid}`;
const keystoneToken = getLocalStorageItem('keystone_token') || '';
const { getOpenstackApiVersion } = require('./constants');
const apiVersionMap = getOpenstackApiVersion(url);
if (keystoneToken) {
config.headers['X-Auth-Token'] = keystoneToken;

View File

@ -59,6 +59,10 @@ class SkylineClient extends Base {
{
key: 'ports',
},
{
name: 'computeServices',
key: 'compute-services',
},
],
},
{

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { firstUpperCase } from 'utils/index';
import BaseForm from '../../../components/Form';
import BaseForm from 'components/Form';
export default class ModalAction extends BaseForm {
static id = 'modalAction';

View File

@ -436,6 +436,78 @@ export default class BaseList extends React.Component {
};
}
getBaseTableProps() {
const {
keyword,
selectedRowKeys,
total,
page,
limit,
silent,
sortKey,
sortOrder,
timerFilter,
} = this.list;
const pagination = {
total,
current: Number(page),
pageSize: limit || 10,
// eslint-disable-next-line no-shadow
showTotal: (total) => t('Total {total} items', { total }),
showSizeChanger: true,
};
if (this.pageSizeOptions) {
pagination.pageSizeOptions = this.pageSizeOptions;
}
const { autoRefresh, tableHeight } = this.state;
return {
resourceName: this.name,
data: this.getDataSource(),
// data:data,
columns: this.getColumns(),
filters: this.getFilters(),
timerFilter,
searchFilters: this.getSearchFilters(),
keyword,
pagination,
primaryActions: this.primaryActions,
batchActions: this.batchActions,
itemActions: this.itemActions,
getCheckboxProps: this.getCheckboxProps,
isLoading: this.isLoading,
silentLoading: silent,
rowKey: this.rowKey,
selectedRowKeys: toJS(selectedRowKeys),
scrollY: tableHeight,
sortKey,
sortOrder,
defaultSortKey: this.defaultSortKey,
defaultSortOrder: this.defaultSortOrder,
getDownloadData: this.getDownloadData,
containerProps: this.props,
expandable: this.expandable,
showTimeFilter: !!this.filterTimeKey,
filterTimeDefalutValue: this.filterTimeDefalutValue,
isPageByBack: this.isFilterByBackend,
isSortByBack: this.isSortByBackend,
isCourier: this.isCourier,
autoRefresh,
startRefreshAuto: this.startRefreshAuto,
stopRefreshAuto: this.onStopRefreshAuto,
onClickAction: this.onClickAction,
onFinishAction: this.onFinishAction,
onCancelAction: this.onCancelAction,
dataDurationAuto: this.dataDurationAuto,
handleInputFocus: this.handleInputFocus,
hideTotal: this.hideTotal,
hideDownload: this.hideDownload,
primaryActionsExtra: this.primaryActionsExtra,
isAdminPage: this.isAdminPage,
initFilter: this.initFilter,
...this.getEnabledTableProps(),
};
}
onStopRefreshAuto = () => {
this.setState({
autoRefresh: false,
@ -973,78 +1045,8 @@ export default class BaseList extends React.Component {
renderTable() {
try {
const {
keyword,
selectedRowKeys,
total,
page,
limit,
silent,
sortKey,
sortOrder,
timerFilter,
} = this.list;
const pagination = {
total,
current: Number(page),
pageSize: limit || 10,
// eslint-disable-next-line no-shadow
showTotal: (total) => t('Total {total} items', { total }),
showSizeChanger: true,
};
if (this.pageSizeOptions) {
pagination.pageSizeOptions = this.pageSizeOptions;
}
const { autoRefresh, tableHeight } = this.state;
return (
<BaseTable
resourceName={this.name}
data={this.getDataSource()}
// data={data}
columns={this.getColumns()}
filters={this.getFilters()}
timerFilter={timerFilter}
searchFilters={this.getSearchFilters()}
keyword={keyword}
pagination={pagination}
primaryActions={this.primaryActions}
batchActions={this.batchActions}
itemActions={this.itemActions}
getCheckboxProps={this.getCheckboxProps}
isLoading={this.isLoading}
silentLoading={silent}
rowKey={this.rowKey}
selectedRowKeys={toJS(selectedRowKeys)}
scrollY={tableHeight}
sortKey={sortKey}
sortOrder={sortOrder}
defaultSortKey={this.defaultSortKey}
defaultSortOrder={this.defaultSortOrder}
getDownloadData={this.getDownloadData}
containerProps={this.props}
expandable={this.expandable}
showTimeFilter={!!this.filterTimeKey}
filterTimeDefalutValue={this.filterTimeDefalutValue}
isPageByBack={this.isFilterByBackend}
isSortByBack={this.isSortByBackend}
isCourier={this.isCourier}
autoRefresh={autoRefresh}
startRefreshAuto={this.startRefreshAuto}
stopRefreshAuto={this.onStopRefreshAuto}
onClickAction={this.onClickAction}
onFinishAction={this.onFinishAction}
onCancelAction={this.onCancelAction}
dataDurationAuto={this.dataDurationAuto}
handleInputFocus={this.handleInputFocus}
hideTotal={this.hideTotal}
hideDownload={this.hideDownload}
primaryActionsExtra={this.primaryActionsExtra}
isAdminPage={this.isAdminPage}
initFilter={this.initFilter}
{...this.getEnabledTableProps()}
/>
);
const props = this.getBaseTableProps();
return <BaseTable {...props} />;
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);

View File

@ -14,7 +14,6 @@
import { action } from 'mobx';
import { get } from 'lodash';
import globalFloatingIpsStore from 'stores/neutron/floatingIp';
import client from 'client';
import Base from '../base';
@ -59,6 +58,7 @@ export class LbaasStore extends Base {
this.updateMarker(allData, page, result);
const allDataNew = allData.map(this.mapperBeforeFetchProject);
let newData = await this.listDidFetchProject(allDataNew, all_projects);
const globalFloatingIpsStore = require('stores/neutron/floatingIp').default;
const fipDetails = await Promise.all(
newData.map((item) =>
globalFloatingIpsStore.pureFetchList({
@ -118,6 +118,8 @@ export class LbaasStore extends Base {
try {
const newItem = await this.detailDidFetch(item, all_projects);
const detail = this.mapper(newItem);
const globalFloatingIpsStore =
require('stores/neutron/floatingIp').default;
const fipInfo = await globalFloatingIpsStore.fetchList({
fixed_ip_address: item.vip_address,
});

View File

@ -20,11 +20,11 @@ import { getQueryString } from 'utils/index';
import { getLocalTime } from 'utils/time';
import { setLocalStorageItem } from 'utils/local-storage';
import { isEmpty, values } from 'lodash';
import checkItemPolicy, { onlyAdminCanReadPolicy } from 'resources/policy';
// global stores need to be clear data when change auth
import allGlobalStores from './index';
class RootStore {
const checkItemPolicy = require('resources/policy').default;
const { onlyAdminCanReadPolicy } = require('resources/policy');
export class RootStore {
@observable
user = null;
@ -261,6 +261,8 @@ class RootStore {
}
clearData() {
// global stores need to be clear data when change auth
const allGlobalStores = require('./index').default;
const stores = values(allGlobalStores);
stores.forEach((store) => {
store.clearData();