modify global cluster select

This commit is contained in:
silenceqi 2021-02-27 23:37:38 +08:00
parent d05c039b48
commit 7f028986b4
7 changed files with 38 additions and 9 deletions

View File

@ -73,8 +73,9 @@ class DropdownSelect extends React.Component{
> >
<List <List
grid={{ grid={{
gutter: 8, gutter: 16,
column: 4, sm: 4,
xs: 3
}} }}
dataSource={this.props.data} dataSource={this.props.data}
renderItem={item => ( renderItem={item => (
@ -100,7 +101,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.state.value[labelField]} <Icon style={{float: 'right', marginTop: 3}} <Button className={styles['btn-ds']}>{this.props.value[labelField] || this.state.value[labelField]} <Icon style={{float: 'right', marginTop: 3}}
type="caret-down"/></Button> type="caret-down"/></Button>
</Dropdown>) : "" </Dropdown>) : ""
) )

View File

@ -17,6 +17,7 @@
.dropmenu{ .dropmenu{
box-shadow: 0 0 15px 0 rgba(0, 0, 0, .15); box-shadow: 0 0 15px 0 rgba(0, 0, 0, .15);
padding: 20px; padding: 20px;
padding-bottom: 4px;
width: 500px; width: 500px;
background: #fff; background: #fff;
.item{ .item{
@ -39,4 +40,10 @@
bottom: 40px; bottom: 40px;
width: 100%; width: 100%;
text-align: center; text-align: center;
}
@media screen and (max-width: 500px) {
.dropmenu{
width: 100%;
}
} }

View File

@ -24,7 +24,7 @@ export default class GlobalHeader extends PureComponent {
this.triggerResizeEvent(); this.triggerResizeEvent();
}; };
render() { render() {
const { collapsed, isMobile, logo, clusterVisible, clusterList } = this.props; const { collapsed, isMobile, logo, clusterVisible, clusterList, selectedCluster } = this.props;
return ( return (
<div className={styles.header}> <div className={styles.header}>
{isMobile && ( {isMobile && (
@ -37,7 +37,8 @@ export default class GlobalHeader extends PureComponent {
type={collapsed ? 'menu-unfold' : 'menu-fold'} type={collapsed ? 'menu-unfold' : 'menu-fold'}
onClick={this.toggle} onClick={this.toggle}
/> />
<DropdownSelect defaultValue={{name:"Select cluster"}} <DropdownSelect defaultValue={selectedCluster}
value={selectedCluster}
labelField="name" labelField="name"
visible={clusterVisible} visible={clusterVisible}
onChange={(item)=>{ onChange={(item)=>{

View File

@ -182,4 +182,5 @@ export default connect(({ user, global, setting, loading }) => ({
setting, setting,
clusterVisible: global.clusterVisible, clusterVisible: global.clusterVisible,
clusterList: global.clusterList, clusterList: global.clusterList,
selectedCluster: global.selectedCluster,
}))(HeaderView); }))(HeaderView);

View File

@ -12,7 +12,7 @@ export default {
notices: [], notices: [],
clusterVisible: true, clusterVisible: true,
clusterList: [], clusterList: [],
selectedCluster: '', selectedCluster: {name:"Select cluster", id: ""},
}, },
effects: { effects: {
@ -46,6 +46,17 @@ export default {
} }
res = formatESSearchResult(res) res = formatESSearchResult(res)
let clusterList = yield select(state => state.global.clusterList); let clusterList = yield select(state => state.global.clusterList);
if(clusterList.length === 0 && res.data.length > 0){
yield put({
type: 'saveData',
payload: {
selectedCluster: {
name: res.data[0].name,
id: res.data[0].id,
}
}
})
}
let data = res.data.map((item)=>{ let data = res.data.map((item)=>{
return { return {
name: item.name, name: item.name,

View File

@ -1,7 +1,10 @@
.clusterItem { .clusterItem {
display: inline-block;
text-align: center;
width: 100%; width: 100%;
height: 400px; height: 400px;
} }
.clusterItemWrapper {
display: inline-block;
margin: 0 auto;
}

View File

@ -52,6 +52,9 @@ class ClusterList extends React.Component{
} }
class ClusterItem extends Component { class ClusterItem extends Component {
state={
wrapperWidth: 235
}
componentDidMount(){ componentDidMount(){
this.root.addEventListener("click", function({offsetX, offsetY}){ this.root.addEventListener("click", function({offsetX, offsetY}){
@ -117,7 +120,9 @@ class ClusterItem extends Component {
} }
render(){ render(){
return ( return (
<div className={styles.clusterItem} ref={ref=>this.root=ref}></div> <div className={styles.clusterItemWrapper} style={{width: this.state.wrapperWidth}}>
<div className={styles.clusterItem} ref={ref=>this.root=ref}></div>
</div>
) )
} }
} }