From 5a7f978feaf2c0a45670a28564e3ba88325c66e4 Mon Sep 17 00:00:00 2001 From: silenceqi Date: Wed, 1 Sep 2021 20:25:42 +0800 Subject: [PATCH] modify global cluster selector and view style --- main.go | 2 + web/src/components/Exception/typeConfig.js | 5 + .../components/GlobalHeader/DropdownItem.tsx | 39 ++++ .../components/GlobalHeader/DropdownSelect.js | 95 +++++----- .../GlobalHeader/DropdownSelect.less | 27 ++- web/src/components/GlobalHeader/index.js | 5 +- .../infini/health_status_circle.tsx | 20 +++ .../index_patterns/index_patterns.ts | 4 - .../public/query/timefilter/timefilter.ts | 4 +- .../create_index_pattern_wizard.tsx | 10 +- .../empty_index_pattern_prompt.tsx | 72 ++------ .../empty_state/empty_state.tsx | 169 ++---------------- .../index_pattern_table.tsx | 99 +++++----- web/src/layouts/Header.js | 24 ++- web/src/models/global.js | 42 ++++- .../pages/DataManagement/IndexPatterns.jsx | 59 ++++-- web/src/pages/System/Cluster/Index.js | 37 ++-- web/src/pages/System/Cluster/health_status.js | 3 - .../pages/System/Cluster/models/cluster.js | 16 +- .../pages/System/Cluster/steps/extra_step.js | 2 +- web/src/services/cluster.js | 4 +- 21 files changed, 344 insertions(+), 394 deletions(-) create mode 100644 web/src/components/GlobalHeader/DropdownItem.tsx create mode 100644 web/src/components/infini/health_status_circle.tsx delete mode 100644 web/src/pages/System/Cluster/health_status.js diff --git a/main.go b/main.go index 8e27d515..59d28f94 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "errors" _ "expvar" "infini.sh/framework" + "infini.sh/framework/core/elastic" "infini.sh/framework/core/env" "infini.sh/framework/core/module" "infini.sh/framework/core/orm" @@ -70,6 +71,7 @@ func main() { }, func() { orm.RegisterSchemaWithIndexName(model.Dict{}, "dict") orm.RegisterSchemaWithIndexName(model.Reindex{}, "reindex") + orm.RegisterSchemaWithIndexName(elastic.IndexPattern{}, "view") }) } diff --git a/web/src/components/Exception/typeConfig.js b/web/src/components/Exception/typeConfig.js index b6e1ee5a..122a07c6 100644 --- a/web/src/components/Exception/typeConfig.js +++ b/web/src/components/Exception/typeConfig.js @@ -14,6 +14,11 @@ const config = { title: '500', desc: '抱歉,服务器出错了', }, + empty: { + img: 'https://gw.alipayobjects.com/zos/rmsportal/KpnpchXsobRgLElEozzI.svg', + title: '找不到数据', + desc: '当前集群找到相关数据', + } }; export default config; diff --git a/web/src/components/GlobalHeader/DropdownItem.tsx b/web/src/components/GlobalHeader/DropdownItem.tsx new file mode 100644 index 00000000..77765975 --- /dev/null +++ b/web/src/components/GlobalHeader/DropdownItem.tsx @@ -0,0 +1,39 @@ +import {Icon} from 'antd'; +import styles from './DropdownSelect.less'; +import {HealthStatusCircle, ClusterHealthStatus} from '@/components/infini/health_status_circle' + +export interface ClusterItem { + id: string + name: string + version: string + endpoint: string +} + +export interface ClusterStatus { + cluster_available: boolean + health_status: ClusterHealthStatus + nodes_count: number +} + +interface props { + clusterItem?: ClusterItem + clusterStatus?: ClusterStatus + onClick: React.MouseEventHandler | undefined + isSelected: boolean +} + +export const DropdownItem = ({ + clusterItem, + clusterStatus, + onClick, + isSelected +}:props)=>{ + return
+
+ {clusterStatus?.cluster_available ? : } + {clusterItem?.name} +
{clusterItem?.version}
+
+ +
+} \ No newline at end of file diff --git a/web/src/components/GlobalHeader/DropdownSelect.js b/web/src/components/GlobalHeader/DropdownSelect.js index 1e126e97..0649d0b5 100644 --- a/web/src/components/GlobalHeader/DropdownSelect.js +++ b/web/src/components/GlobalHeader/DropdownSelect.js @@ -1,20 +1,24 @@ -import { Button, Dropdown, List, Spin, message, Icon } from 'antd'; +import { Button, Dropdown, List, Spin, message, Icon, Input } from 'antd'; import React from 'react'; import InfiniteScroll from 'react-infinite-scroller'; import styles from './DropdownSelect.less'; import _ from "lodash"; +import {DropdownItem} from './DropdownItem'; +import {HealthStatusCircle} from '@/components/infini/health_status_circle' class DropdownSelect extends React.Component{ state={ value: this.props.defaultValue, loading: false, hasMore: true, + overlayVisible: false, } handleItemClick = (item)=>{ let preValue = this.props.value || this.state.value; this.setState({ value: item, + overlayVisible: false, },()=>{ let onChange = this.props.onChange; if(preValue != item && onChange && typeof onChange == 'function'){ @@ -35,75 +39,74 @@ class DropdownSelect extends React.Component{ }) }) } - fetchData = ()=>{ + fetchData = (name)=>{ let me = this; const {fetchData, size} = this.props; let data = this.props.data || []; - let from = data.length; - return fetchData(from, size); + return fetchData(name || '', size); } - handleInfiniteOnLoad = (page) => { + handleInfiniteOnLoad = (name) => { let { data } = this.props; this.setState({ loading: true, }) - this.fetchData().then((newdata)=>{ + this.fetchData(name).then((newdata)=>{ let newState = { loading: false, }; if(newdata.length < this.props.size){ - message.info("no more data"); + //message.info("no more data"); newState.hasMore = false; } this.setState(newState); }); } + handleInputChange = (e) =>{ + const name = e.target.value; + this.setState({ + displayValue: name, + }) + this.handleInfiniteOnLoad(name); + } + render(){ let me = this; - const {labelField} = this.props; + const {labelField, clusterStatus} = this.props; let value = this.props.value || this.state.value; - + let displayVaue = value[labelField]; const menu = (
+
+ +
- {/* { - return ( - - - - ) - }} - > - {this.state.loading && this.state.hasMore && ( -
- -
- )} -
*/}
+ {(!this.props.data || !this.props.data.length)&&
匹配不到集群(匹配规则为前缀匹配)
} {(this.props.data || []).map((item)=>{ - return
+ // return
+ // + //
+ const cstatus = clusterStatus ? clusterStatus[item.id] : null; + return { + this.handleItemClick(item) + }} + /> })}
@@ -114,11 +117,23 @@ class DropdownSelect extends React.Component{
)}
); + const cstatus = clusterStatus ? clusterStatus[value?.id] : null; return( this.props.visible ? - ( - + ({ + this.setState({ overlayVisible: flag }); + }}> + {/* */} + + + {cstatus?.cluster_available ? : } + + + + + ) : "" ) } diff --git a/web/src/components/GlobalHeader/DropdownSelect.less b/web/src/components/GlobalHeader/DropdownSelect.less index bdc79899..6c08e662 100644 --- a/web/src/components/GlobalHeader/DropdownSelect.less +++ b/web/src/components/GlobalHeader/DropdownSelect.less @@ -9,6 +9,7 @@ margin-left: 15px; position: relative; bottom: 8px; + height: 32px; span{ color: #333; } @@ -16,7 +17,7 @@ .dropmenu{ box-shadow: 0 0 15px 0 rgba(0, 0, 0, .15); - padding: 20px; + padding: 0px; padding-bottom: 4px; width: 500px; background: #fff; @@ -56,4 +57,28 @@ .dslist{ display: inline-block; width: 100%; +} + +.dropdown-item{ + box-shadow: 0 0 1px 0 rgba(196, 191, 191, 0.15); + .wrapper{ + display: flex; + align-items: center; + padding: 10px; + padding-left: 15px; + .name{ + margin-left: 5px; + } + .version{ + margin-left: auto; + } + } + :hover{ + background-color: #939ea0; + color: #fff; + cursor: pointer; + } + &.selected { + background-color: #eee; + } } \ No newline at end of file diff --git a/web/src/components/GlobalHeader/index.js b/web/src/components/GlobalHeader/index.js index 03aff724..cb856f74 100644 --- a/web/src/components/GlobalHeader/index.js +++ b/web/src/components/GlobalHeader/index.js @@ -1,5 +1,5 @@ import React, { PureComponent } from 'react'; -import { Icon } from 'antd'; +import { Icon, Select } from 'antd'; import Link from 'umi/link'; import Debounce from 'lodash-decorators/debounce'; import styles from './index.less'; @@ -13,7 +13,7 @@ const path=require('path'); export default class GlobalHeader extends PureComponent { constructor(props) { - super(props); + super(props); } componentDidMount() { @@ -53,6 +53,7 @@ export default class GlobalHeader extends PureComponent { onClick={this.toggle} /> = { + 'green': '#39b362', + 'yellow': 'yellow', + 'red': 'red', +} + +export function convertStatusToColor(status: ClusterHealthStatus){ + return statusColorMap[status]; +} + +interface props { + status: ClusterHealthStatus +} + +export const HealthStatusCircle = ({status}: props)=>{ + const color = convertStatusToColor(status); + return
+} \ No newline at end of file diff --git a/web/src/components/kibana/data/common/index_patterns/index_patterns/index_patterns.ts b/web/src/components/kibana/data/common/index_patterns/index_patterns/index_patterns.ts index 35441a6f..4882d55a 100644 --- a/web/src/components/kibana/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/web/src/components/kibana/data/common/index_patterns/index_patterns/index_patterns.ts @@ -626,10 +626,6 @@ export class IndexPatternsService { }); } - /** - * Deletes an index pattern from .kibana index - * @param indexPatternId: Id of kibana Index Pattern to delete - */ async delete(indexPatternId: string) { indexPatternCache.clear(indexPatternId); return this.savedObjectsClient.delete(savedObjectType, indexPatternId); diff --git a/web/src/components/kibana/data/public/query/timefilter/timefilter.ts b/web/src/components/kibana/data/public/query/timefilter/timefilter.ts index e850c706..c3977d3a 100644 --- a/web/src/components/kibana/data/public/query/timefilter/timefilter.ts +++ b/web/src/components/kibana/data/public/query/timefilter/timefilter.ts @@ -23,8 +23,8 @@ import moment from 'moment'; import { areRefreshIntervalsDifferent, areTimeRangesDifferent } from './lib/diff_time_picker_vals'; import { getForceNow } from './lib/get_force_now'; import { TimefilterConfig, InputTimeRange, TimeRangeBounds } from './types'; -import { getTime, RefreshInterval, TimeRange } from '../../../common'; -import { calculateBounds } from '../../../common/query/timefilter/get_time'; +import { RefreshInterval, TimeRange } from '../../../common'; +import {getTime, calculateBounds } from '../../../common/query/timefilter/get_time'; import { TimeHistoryContract } from './time_history'; import { IndexPattern } from '../../index_patterns'; diff --git a/web/src/components/kibana/index_pattern_management/public/components/create_index_pattern_wizard/create_index_pattern_wizard.tsx b/web/src/components/kibana/index_pattern_management/public/components/create_index_pattern_wizard/create_index_pattern_wizard.tsx index cca81025..5251fcef 100644 --- a/web/src/components/kibana/index_pattern_management/public/components/create_index_pattern_wizard/create_index_pattern_wizard.tsx +++ b/web/src/components/kibana/index_pattern_management/public/components/create_index_pattern_wizard/create_index_pattern_wizard.tsx @@ -218,7 +218,7 @@ export class CreateIndexPatternWizard extends Component< return ; } - const header = this.renderHeader(); + // const header = this.renderHeader(); if (step === 1) { const { location } = this.props; @@ -226,8 +226,8 @@ export class CreateIndexPatternWizard extends Component< return ( - {header} - + {/* {header} + */} - {header} - + {/* {header} + */} { - setBreadcrumbs(getListBreadcrumbs()); + const actions = (
+ +
) return ( - - - {/* - - */} - - -

- Elasticsearch 里面有数据。 -
- 去试试创建一个数据视图吧。 -

-

- 极限搜索中心通过创建数据视图来标识您想要浏览的索引,一个数据视图可以对应一个索引或多个索引。比如数据视图 server_log 匹配索引 - server_log, server_log* 匹配所有以 server_log 开头的索引。 -

- {canSave && ( - - 创建数据视图 - - )} -
-
-
- - - - 了解更多? - - - - 阅读文档 - - - -
+ ); }; diff --git a/web/src/components/kibana/index_pattern_management/public/components/index_pattern_table/empty_state/empty_state.tsx b/web/src/components/kibana/index_pattern_management/public/components/index_pattern_table/empty_state/empty_state.tsx index d905ef39..be397d34 100644 --- a/web/src/components/kibana/index_pattern_management/public/components/index_pattern_table/empty_state/empty_state.tsx +++ b/web/src/components/kibana/index_pattern_management/public/components/index_pattern_table/empty_state/empty_state.tsx @@ -17,165 +17,28 @@ * under the License. */ -import './empty_state.scss'; -import React from 'react'; -import { DocLinksStart, ApplicationStart } from 'kibana/public'; -import { - EuiPageContentHeader, - EuiPageContentHeaderSection, - EuiTitle, - EuiPageContentBody, - EuiPageContent, - EuiIcon, - EuiSpacer, - EuiFlexItem, - EuiDescriptionList, - EuiFlexGrid, - EuiCard, - EuiLink, - EuiText, -} from '@elastic/eui'; -import { useHistory } from 'react-router-dom'; -// import { reactRouterNavigate } from '../../../../../../plugins/kibana_react/public'; -import { MlCardState } from '../../../types'; +import Exception from '@/components/Exception'; +import {Button} from 'antd'; +import Link from 'umi/link'; +import {router} from 'umi'; export const EmptyState = ({ - onRefresh, - navigateToApp, - docLinks, - getMlCardState, - canSave, }: { - onRefresh: () => void; - navigateToApp: ApplicationStart['navigateToApp']; - docLinks: DocLinksStart; - getMlCardState: () => MlCardState; - canSave: boolean; }) => { - const mlCard = ( - - navigateToApp('ml', { path: '#/filedatavisualizer' })} - className="inpEmptyState__card" - betaBadgeLabel={ - getMlCardState() === MlCardState.ENABLED - ? undefined - : 'Basic' - } - betaBadgeTooltipContent={ 'This feature requires a Basic license.'} - isDisabled={getMlCardState() === MlCardState.DISABLED} - icon={} - title={ - "Upload a file" - } - description={ - "Import a CSV, NDJSON, or log file." - } - /> - - ); - const createAnyway = ( - - Some indices may be hidden. Try to - - create an index pattern - anyway. - - ); + const actions = (
+ +
) return ( - <> - - - - -

- 当前集群没有数据,使用数据视图之前要创建数据索引。 -

-
-
-
- - - {/* - - navigateToApp('home', { path: '#/tutorial_directory' })} - icon={} - title={ - "Add integration" - } - description={ - "Add data from a variety of sources." - } - /> - - {getMlCardState() !== MlCardState.HIDDEN ? mlCard : <>} - - navigateToApp('home', { path: '#/tutorial_directory/sampleData' })} - icon={} - title={ - "Add sample data" - } - description={ - "Load a data set and a Kibana dashboard." - } - /> - - */} - -
- - {/* - - Read documentation - - ), - }, - ]} - /> - */} - {/* - - 点击查看是否有新数据{' '} - - - ), - }, - ]} - /> - */} - -
-
-
- - {/* {canSave && createAnyway} */} - + ); }; diff --git a/web/src/components/kibana/index_pattern_management/public/components/index_pattern_table/index_pattern_table.tsx b/web/src/components/kibana/index_pattern_management/public/components/index_pattern_table/index_pattern_table.tsx index 7713dcfa..fea137d3 100644 --- a/web/src/components/kibana/index_pattern_management/public/components/index_pattern_table/index_pattern_table.tsx +++ b/web/src/components/kibana/index_pattern_management/public/components/index_pattern_table/index_pattern_table.tsx @@ -32,17 +32,18 @@ import { } from '@elastic/eui'; import { withRouter, RouteComponentProps } from 'react-router-dom'; import React, { useState, useEffect } from 'react'; -import { reactRouterNavigate, useKibana } from '../../../../kibana_react/public'; -import { IndexPatternManagmentContext } from '../../types'; -import { CreateButton } from '../create_button'; +import { reactRouterNavigate } from '../../../../kibana_react/public'; import { IndexPatternTableItem, IndexPatternCreationOption } from '../types'; import { getIndexPatterns } from '../utils'; -import { getListBreadcrumbs } from '../breadcrumbs'; import { EmptyState } from './empty_state'; import { MatchedItem, ResolveIndexResponseItemAlias } from '../create_index_pattern_wizard/types'; import { EmptyIndexPatternPrompt } from './empty_index_pattern_prompt'; import { getIndices } from '../create_index_pattern_wizard/lib'; import { useGlobalContext } from '../../context'; +import {Button} from 'antd'; +import PageHeaderWrapper from '@/components/PageHeaderWrapper'; +import styles from '@/pages/System/Cluster/step.less'; +import clusterBg from '@/assets/cluster_bg.png'; const pagination = { initialPageSize: 10, @@ -65,10 +66,28 @@ const search = { }, }; -const ariaRegion = 'Index patterns'; + +const ariaRegion = '数据视图'; const title = '数据视图'; +const content = ( +
+

+ 创建和管理数据视图可以帮助您更好地从 Elasticsearch 获取数据。 +

+
+); + +const extraContent = ( +
+ 数据视图 +
+); + interface Props extends RouteComponentProps { canSave: boolean; } @@ -79,9 +98,7 @@ export const IndexPatternTable = ({ canSave, history, selectedCluster }: Props) savedObjects, uiSettings, indexPatternManagementStart, - chrome, docLinks, - application, http, getMlCardState, data, @@ -165,38 +182,17 @@ export const IndexPatternTable = ({ canSave, history, selectedCluster }: Props) { field: 'title', name: '匹配规则', - // render: ( - // name: string, - // index: { - // id: string; - // tags?: Array<{ - // key: string; - // name: string; - // }>; - // } - // ) => ( - // <> - // - // {name} - // - //   - // - // {index.tags && - // index.tags.map(({ key: tagKey, name: tagName }) => ( - // {tagName} - // ))} - // - // - // ), dataType: 'string' as const, sortable: ({ sort }: { sort: string }) => sort, }, ]; const createButton = canSave ? ( - + ) : ( <> ); @@ -210,43 +206,26 @@ export const IndexPatternTable = ({ canSave, history, selectedCluster }: Props) if (!indexPatterns.length) { if (!hasDataIndices && !remoteClustersExist) { return ( - + ); } else { return ( ); } } + const renderToolsRight = () => { + return [ + createButton + ]; + }; + return ( + - - - -

{title}

-
- - -

- 创建和管理{title}可以帮助您更好地从 Elasticsearch 获取数据。 -

-
-
- {createButton} -
-
+
); }; diff --git a/web/src/layouts/Header.js b/web/src/layouts/Header.js index 51a7613c..797bca62 100644 --- a/web/src/layouts/Header.js +++ b/web/src/layouts/Header.js @@ -27,10 +27,14 @@ class HeaderView extends PureComponent { componentDidMount() { document.addEventListener('scroll', this.handScroll, { passive: true }); + this.fetchClusterStatus() } componentWillUnmount() { document.removeEventListener('scroll', this.handScroll); + if(this.fetchClusterStatusTimer){ + clearTimeout(this.fetchClusterStatusTimer); + } } getHeadWidth = () => { @@ -114,14 +118,13 @@ class HeaderView extends PureComponent { this.ticking = false; }; - handleFetchClusterList = (from, size) => { + handleFetchClusterList = (name, size) => { const { dispatch } = this.props; return dispatch({ type: 'global/fetchClusterList', payload: { - from, size, - enabled: true, + name } }); }; @@ -134,6 +137,20 @@ class HeaderView extends PureComponent { }); } + fetchClusterStatus = async ()=>{ + const {dispatch} = this.props; + const res = await dispatch({ + type: 'global/fetchClusterStatus', + }); + if(this.fetchClusterStatusTimer){ + clearTimeout(this.fetchClusterStatusTimer); + } + if(!res){ + return + } + this.fetchClusterStatusTimer = setTimeout(this.fetchClusterStatus, 10000); + } + render() { const { isMobile, handleMenuCollapse, setting } = this.props; const { navTheme, layout, fixedHeader } = setting; @@ -183,4 +200,5 @@ export default connect(({ user, global, setting, loading }) => ({ clusterVisible: global.clusterVisible, clusterList: global.clusterList, selectedCluster: global.selectedCluster, + clusterStatus: global.clusterStatus, }))(HeaderView); diff --git a/web/src/models/global.js b/web/src/models/global.js index 3d827f08..a3e8f8af 100644 --- a/web/src/models/global.js +++ b/web/src/models/global.js @@ -1,6 +1,6 @@ import { queryNotices } from '@/services/api'; import {message} from "antd"; -import {searchClusterConfig} from "@/services/cluster"; +import {searchClusterConfig, getClusterStatus} from "@/services/cluster"; import {formatESSearchResult, extractClusterIDFromURL} from '@/lib/elasticsearch/util'; import {Modal} from 'antd'; import router from "umi/router"; @@ -16,6 +16,10 @@ export default { clusterList: [], selectedCluster: {name:"Select cluster", id: ""}, selectedClusterID: "", + search:{ + cluster: { + } + } }, effects: { @@ -48,7 +52,7 @@ export default { return false; } res = formatESSearchResult(res) - let clusterList = yield select(state => state.global.clusterList); + let {clusterList, search} = yield select(state => state.global); let data = res.data.filter(item=>item.enabled).map((item)=>{ return { name: item.name, @@ -58,7 +62,7 @@ export default { }; }) - if(clusterList.length === 0){ + if(clusterList.length === 0 && !payload.name){ if(data.length === 0 ){ Modal.info({ title: '系统提示', @@ -83,11 +87,20 @@ export default { }); } } - + let newClusterList = []; + if(search.name != payload.name){ + newClusterList = data; + }else{ + newClusterList = clusterList.concat(data); + } yield put({ type: 'saveData', payload: { - clusterList: clusterList.concat(data), + clusterList: newClusterList, + search: { + ...search, + cluster: payload, + } } }) return data; @@ -124,7 +137,24 @@ export default { history.replace(newPath) } } - } + }, + *fetchClusterStatus({payload}, {call, put}){ + let res = yield call(getClusterStatus, payload); + if(!res){ + return false + } + if(res.error){ + console.log(res.error) + return false; + } + yield put({ + type: 'saveData', + payload: { + clusterStatus: res + } + }); + return res; + }, }, reducers: { diff --git a/web/src/pages/DataManagement/IndexPatterns.jsx b/web/src/pages/DataManagement/IndexPatterns.jsx index d240debe..3e99661a 100644 --- a/web/src/pages/DataManagement/IndexPatterns.jsx +++ b/web/src/pages/DataManagement/IndexPatterns.jsx @@ -9,10 +9,31 @@ import { CreateIndexPatternWizardWithRouter, } from '../../components/kibana/index_pattern_management/public/components'; // import '@elastic/eui/dist/eui_theme_amsterdam_light.css'; -import {useGlobalContext} from '../../components/kibana/index_pattern_management/public/context' +import {useGlobalContext} from '../../components/kibana/index_pattern_management/public/context'; +import PageHeaderWrapper from '@/components/PageHeaderWrapper'; +import styles from '../System/Cluster/step.less'; +import clusterBg from '@/assets/cluster_bg.png'; import { connect } from 'dva'; + +const createContent = ( +
+

+ 一个数据视图可以匹配单个索引, 比如, server-log-1, 或者 多个 索引, server-log-*. +

+
+); + +const createExtraContent = ( +
+ 创建视图 +
+); + const IndexPatterns = (props)=> { const history = useMemo(()=>{ return new ScopedHistory(props.history, '/data/views'); @@ -35,23 +56,27 @@ const IndexPatterns = (props)=> { initFetch(); }, [props.selectedCluster]); + + return ( - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + ) } diff --git a/web/src/pages/System/Cluster/Index.js b/web/src/pages/System/Cluster/Index.js index 24572475..c9b8e618 100644 --- a/web/src/pages/System/Cluster/Index.js +++ b/web/src/pages/System/Cluster/Index.js @@ -2,7 +2,7 @@ import React from 'react'; import {Button, Card, Col, Divider, Form, Input, Row, Table, Switch, Icon, Popconfirm, message} from "antd"; import Link from "umi/link"; import {connect} from "dva"; -import {HealthStatusCircle} from './health_status'; +import {HealthStatusCircle} from '@/components/infini/health_status_circle'; import PageHeaderWrapper from '@/components/PageHeaderWrapper'; import styles from './step.less'; import clusterBg from '@/assets/cluster_bg.png'; @@ -25,8 +25,9 @@ const extraContent = ( ); @Form.create() -@connect(({clusterConfig}) =>({ - clusterConfig +@connect(({clusterConfig, global}) =>({ + clusterConfig, + clusterStatus: global.clusterStatus, })) class Index extends React.Component { columns = [{ @@ -38,12 +39,17 @@ class Index extends React.Component { dataIndex: 'id', key: 'health_status', render: (val)=>{ - const {clusterStatus} = this.props.clusterConfig; + const {clusterStatus} = this.props; if(!clusterStatus || !clusterStatus[val]){ return } + const isAvailable = clusterStatus[val].cluster_available; + if(!isAvailable){ + return + } const status = clusterStatus[val].health_status; return + } },{ title: '所属业务', @@ -79,7 +85,7 @@ class Index extends React.Component { dataIndex: 'id', key: 'mode_count', render: (val)=>{ - const {clusterStatus} = this.props.clusterConfig; + const {clusterStatus} = this.props; if(!clusterStatus || !clusterStatus[val]){ return } @@ -141,25 +147,6 @@ class Index extends React.Component { } componentDidMount() { this.fetchData({}) - this.fetchClusterStatus(); - } - componentWillUnmount(){ - if(this.fetchClusterStatusTimer){ - clearTimeout(this.fetchClusterStatusTimer); - } - } - fetchClusterStatus = async ()=>{ - const {dispatch} = this.props; - const res = await dispatch({ - type: 'clusterConfig/fetchClusterStatus', - }); - if(this.fetchClusterStatusTimer){ - clearTimeout(this.fetchClusterStatusTimer); - } - if(!res){ - return - } - this.fetchClusterStatusTimer = setTimeout(this.fetchClusterStatus, 10000); } handleSearchClick = ()=>{ @@ -224,7 +211,7 @@ class Index extends React.Component { return ( -
+
diff --git a/web/src/pages/System/Cluster/health_status.js b/web/src/pages/System/Cluster/health_status.js deleted file mode 100644 index 613c6234..00000000 --- a/web/src/pages/System/Cluster/health_status.js +++ /dev/null @@ -1,3 +0,0 @@ -export const HealthStatusCircle = ({status})=>{ - return
-} \ No newline at end of file diff --git a/web/src/pages/System/Cluster/models/cluster.js b/web/src/pages/System/Cluster/models/cluster.js index c2117e6d..f5b170f1 100644 --- a/web/src/pages/System/Cluster/models/cluster.js +++ b/web/src/pages/System/Cluster/models/cluster.js @@ -1,5 +1,5 @@ import {createClusterConfig, searchClusterConfig, updateClusterConfig,deleteClusterConfig, - getClusterStatus, tryConnect} from "@/services/cluster"; + tryConnect} from "@/services/cluster"; import {message} from "antd"; import {formatESSearchResult} from '@/lib/elasticsearch/util'; @@ -10,20 +10,6 @@ export default { editValue: {}, }, effects:{ - *fetchClusterStatus({payload}, {call, put}){ - let res = yield call(getClusterStatus, payload); - if(res.error){ - message.error(res.error) - return false; - } - yield put({ - type: 'saveData', - payload: { - clusterStatus: res - } - }); - return res; - }, *fetchClusterList({payload}, {call, put, select}){ let res = yield call(searchClusterConfig, payload); if(res.error){ diff --git a/web/src/pages/System/Cluster/steps/extra_step.js b/web/src/pages/System/Cluster/steps/extra_step.js index 5ed9f976..1e9095e3 100644 --- a/web/src/pages/System/Cluster/steps/extra_step.js +++ b/web/src/pages/System/Cluster/steps/extra_step.js @@ -1,5 +1,5 @@ import {Form, Input, Switch, Icon, InputNumber, Divider, Descriptions} from 'antd'; -import {HealthStatusCircle} from '../health_status'; +import {HealthStatusCircle} from '@/components/infini/health_status_circle'; @Form.create() export class ExtraStep extends React.Component { diff --git a/web/src/services/cluster.js b/web/src/services/cluster.js index 711b6401..5c13c0b5 100644 --- a/web/src/services/cluster.js +++ b/web/src/services/cluster.js @@ -42,7 +42,9 @@ export async function searchClusterConfig(params) { let url = `/elasticsearch/_search`; let args = buildQueryArgs({ name: params.name, - enabled: params.enabled + enabled: params.enabled, + from: params.from, + size: params.size, }); if(args.length > 0){ url += args;