diff --git a/.eslintrc b/.eslintrc index 52ca1829..4ef5c4fd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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, diff --git a/src/client/client/base.js b/src/client/client/base.js index b6e0e3f6..4d427c38 100644 --- a/src/client/client/base.js +++ b/src/client/client/base.js @@ -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 || ''; } diff --git a/src/client/client/constants.js b/src/client/client/constants.js index 14392b27..f641353e 100644 --- a/src/client/client/constants.js +++ b/src/client/client/constants.js @@ -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]; }; diff --git a/src/client/client/request.js b/src/client/client/request.js index e40b1ad6..62c7da08 100644 --- a/src/client/client/request.js +++ b/src/client/client/request.js @@ -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; diff --git a/src/client/skyline/index.js b/src/client/skyline/index.js index 9d4055cb..c7775811 100644 --- a/src/client/skyline/index.js +++ b/src/client/skyline/index.js @@ -59,6 +59,10 @@ class SkylineClient extends Base { { key: 'ports', }, + { + name: 'computeServices', + key: 'compute-services', + }, ], }, { diff --git a/src/containers/Action/ModalAction/index.jsx b/src/containers/Action/ModalAction/index.jsx index a0fa345b..eddee90d 100644 --- a/src/containers/Action/ModalAction/index.jsx +++ b/src/containers/Action/ModalAction/index.jsx @@ -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'; diff --git a/src/containers/List/index.jsx b/src/containers/List/index.jsx index 4efcedb4..da7d8e51 100644 --- a/src/containers/List/index.jsx +++ b/src/containers/List/index.jsx @@ -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 ( - - ); + const props = this.getBaseTableProps(); + return ; } catch (e) { // eslint-disable-next-line no-console console.log(e); diff --git a/src/stores/octavia/loadbalancer.js b/src/stores/octavia/loadbalancer.js index d1ddd0b4..d73e45d3 100644 --- a/src/stores/octavia/loadbalancer.js +++ b/src/stores/octavia/loadbalancer.js @@ -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, }); diff --git a/src/stores/root.js b/src/stores/root.js index 7132de66..d86ba04f 100644 --- a/src/stores/root.js +++ b/src/stores/root.js @@ -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();