add changeClusterById
This commit is contained in:
parent
1ba374a048
commit
dfdcb8234c
|
@ -2,6 +2,7 @@ import { Button, Dropdown, List, Spin, message, Icon } from 'antd';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import InfiniteScroll from 'react-infinite-scroller';
|
import InfiniteScroll from 'react-infinite-scroller';
|
||||||
import styles from './DropdownSelect.less';
|
import styles from './DropdownSelect.less';
|
||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
class DropdownSelect extends React.Component{
|
class DropdownSelect extends React.Component{
|
||||||
state={
|
state={
|
||||||
|
@ -11,7 +12,7 @@ class DropdownSelect extends React.Component{
|
||||||
}
|
}
|
||||||
|
|
||||||
handleItemClick = (item)=>{
|
handleItemClick = (item)=>{
|
||||||
let preValue = this.state.value;
|
let preValue = this.props.value || this.state.value;
|
||||||
this.setState({
|
this.setState({
|
||||||
value: item,
|
value: item,
|
||||||
},()=>{
|
},()=>{
|
||||||
|
@ -63,6 +64,8 @@ class DropdownSelect extends React.Component{
|
||||||
render(){
|
render(){
|
||||||
let me = this;
|
let me = this;
|
||||||
const {labelField} = this.props;
|
const {labelField} = this.props;
|
||||||
|
let value = this.props.value || this.state.value;
|
||||||
|
|
||||||
const menu = (<div className={styles.dropmenu} style={{width: this.props.width}}>
|
const menu = (<div className={styles.dropmenu} style={{width: this.props.width}}>
|
||||||
<div className={styles.infiniteContainer} style={{height: this.props.height}}>
|
<div className={styles.infiniteContainer} style={{height: this.props.height}}>
|
||||||
<InfiniteScroll
|
<InfiniteScroll
|
||||||
|
@ -78,11 +81,16 @@ class DropdownSelect extends React.Component{
|
||||||
xs: 3
|
xs: 3
|
||||||
}}
|
}}
|
||||||
dataSource={this.props.data}
|
dataSource={this.props.data}
|
||||||
renderItem={item => (
|
renderItem={item => {
|
||||||
<List.Item key={item[labelField]}>
|
return (
|
||||||
<Button onClick={()=>{this.handleItemClick(item)}} className={styles.btnitem}>{item[labelField]}</Button>
|
<List.Item key={item[labelField]}>
|
||||||
</List.Item>
|
<Button onClick={() => {
|
||||||
)}
|
this.handleItemClick(item)
|
||||||
|
}}
|
||||||
|
className={_.isEqual(item, value) ? styles.btnitem + " " + styles.selected : styles.btnitem}>{item[labelField]}</Button>
|
||||||
|
</List.Item>
|
||||||
|
)
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{this.state.loading && this.state.hasMore && (
|
{this.state.loading && this.state.hasMore && (
|
||||||
<div className={styles.loadingContainer}>
|
<div className={styles.loadingContainer}>
|
||||||
|
@ -101,7 +109,7 @@ class DropdownSelect extends React.Component{
|
||||||
return(
|
return(
|
||||||
this.props.visible ?
|
this.props.visible ?
|
||||||
(<Dropdown overlay={menu} placement="bottomLeft">
|
(<Dropdown overlay={menu} placement="bottomLeft">
|
||||||
<Button className={styles['btn-ds']}>{this.props.value[labelField] || this.state.value[labelField]} <Icon style={{float: 'right', marginTop: 3}}
|
<Button className={styles['btn-ds']}>{value[labelField]} <Icon style={{float: 'right', marginTop: 3}}
|
||||||
type="caret-down"/></Button>
|
type="caret-down"/></Button>
|
||||||
</Dropdown>) : ""
|
</Dropdown>) : ""
|
||||||
)
|
)
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
width: 100px;
|
width: 100px;
|
||||||
}
|
}
|
||||||
|
.selected{
|
||||||
|
color: #1890FF;
|
||||||
|
border-color: #1890FF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.infiniteContainer {
|
.infiniteContainer {
|
||||||
|
|
|
@ -67,7 +67,7 @@ export default {
|
||||||
yield put({
|
yield put({
|
||||||
type: 'saveData',
|
type: 'saveData',
|
||||||
payload: {
|
payload: {
|
||||||
clusterList: clusterList.concat(data)
|
clusterList: clusterList.concat(data),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return data;
|
return data;
|
||||||
|
@ -111,6 +111,7 @@ export default {
|
||||||
...payload,
|
...payload,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
removeCluster(state, {payload}){
|
removeCluster(state, {payload}){
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
@ -125,6 +126,16 @@ export default {
|
||||||
let idx = state.clusterList.findIndex(item => item.id === payload.id);
|
let idx = state.clusterList.findIndex(item => item.id === payload.id);
|
||||||
idx > -1 && (state.clusterList[idx].name = payload.name);
|
idx > -1 && (state.clusterList[idx].name = payload.name);
|
||||||
return state;
|
return state;
|
||||||
|
},
|
||||||
|
changeClusterById(state,{payload}){
|
||||||
|
let idx = state.clusterList.findIndex(item => item.id === payload.id);
|
||||||
|
if(idx > -1){
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
selectedCluster: state.clusterList[idx],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, {Fragment} from 'react';
|
import React, {Fragment} from 'react';
|
||||||
import {Card, List, Divider, Popconfirm, Row, Col, Table, Descriptions} from "antd";
|
import {Card, List, Divider, Popconfirm, Row, Col, Table, Descriptions, Button} from "antd";
|
||||||
import {Link} from "umi"
|
import {Link} from "umi"
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import styles from "./Overview.less";
|
import styles from "./Overview.less";
|
||||||
|
@ -130,10 +130,21 @@ class Overview extends React.Component {
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleChangeClusterById = () =>{
|
||||||
|
const {dispatch} = this.props;
|
||||||
|
dispatch({
|
||||||
|
type: 'global/changeClusterById',
|
||||||
|
payload: {
|
||||||
|
id: "c0oc4kkgq9s8qss2uk51"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
<Button type="primary" onClick={this.handleChangeClusterById}>change cluster</Button>
|
||||||
<Card title={this.props.selectedCluster?this.props.selectedCluster.name:''}>
|
<Card title={this.props.selectedCluster?this.props.selectedCluster.name:''}>
|
||||||
<Row gutter={[16,16]}>
|
<Row gutter={[16,16]}>
|
||||||
<Col xs={24} sm={12} md={12} lg={8} >
|
<Col xs={24} sm={12} md={12} lg={8} >
|
||||||
|
|
Loading…
Reference in New Issue