forked from spiffe/tornjak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster-management.js
132 lines (124 loc) · 4.59 KB
/
cluster-management.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import React, { Component } from 'react';
import { Tabs, Tab } from 'carbon-components-react';
import ClusterCreate from './cluster-create';
import ClusterEdit from './cluster-edit';
import { connect } from 'react-redux';
import IsManager from './is_manager';
import TornjakApi from './tornjak-api-helpers';
import './style.css';
import {
clusterTypeInfoFunc,
serverSelectedFunc,
selectorInfoFunc,
agentsListUpdateFunc,
tornjakMessageFunc,
tornjakServerInfoUpdateFunc,
serverInfoUpdateFunc
} from 'redux/actions';
class ClusterManagement extends Component {
constructor(props) {
super(props);
this.TornjakApi = new TornjakApi();
this.prepareClusterTypeList = this.prepareClusterTypeList.bind(this);
this.prepareAgentsList = this.prepareAgentsList.bind(this);
this.state = {
clusterTypeList: [],
agentsList: [],
agentsListDisplay: "Select Agents",
clusterTypeManualEntryOption: "----Select this option and Enter Custom Cluster Type Below----",
}
}
componentDidMount() {
if (IsManager) {
if (this.props.globalServerSelected !== "" && (this.props.globalErrorMessage === "OK" || this.props.globalErrorMessage === "")) {
this.TornjakApi.populateAgentsUpdate(this.props.globalServerSelected, this.props.agentsListUpdateFunc, this.props.tornjakMessageFunc);
this.TornjakApi.populateTornjakServerInfo(this.props.globalServerSelected, this.props.tornjakServerInfoUpdateFunc, this.props.tornjakMessageFunc);
this.setState({ selectedServer: this.props.globalServerSelected });
this.prepareClusterTypeList();
this.prepareAgentsList();
}
} else {
this.TornjakApi.populateLocalAgentsUpdate(this.props.agentsListUpdateFunc, this.props.tornjakMessageFunc);
this.TornjakApi.populateLocalTornjakServerInfo(this.props.tornjakServerInfoUpdateFunc, this.props.tornjakMessageFunc);
this.TornjakApi.populateServerInfo(this.props.globalTornjakServerInfo, this.props.serverInfoUpdateFunc);
this.prepareClusterTypeList();
this.prepareAgentsList();
}
}
componentDidUpdate(prevProps, prevState) {
if (IsManager) {
if (prevProps.globalServerSelected !== this.props.globalServerSelected) {
this.setState({ selectedServer: this.props.globalServerSelected });
}
if (prevProps.globalServerInfo !== this.props.globalServerInfo) {
this.prepareAgentsList();
}
} else {
if (prevProps.globalServerInfo !== this.props.globalServerInfo) {
this.prepareAgentsList();
}
}
}
prepareClusterTypeList() {
let localClusterTypeList = [];
// user prefered option
localClusterTypeList[0] = this.state.clusterTypeManualEntryOption;
// cluster type list
for (let i = 0; i < this.props.globalClusterTypeInfo.length; i++) {
localClusterTypeList[i + 1] = this.props.globalClusterTypeInfo[i];
}
this.setState({
clusterTypeList: localClusterTypeList
});
}
prepareAgentsList() {
var prefix = "spiffe://";
let localAgentsIdList = [];
//agents
for (let i = 0; i < this.props.globalAgentsList.length; i++) {
localAgentsIdList[i] = {}
localAgentsIdList[i]["label"] = prefix + this.props.globalAgentsList[i].id.trust_domain + this.props.globalAgentsList[i].id.path;
}
this.setState({
agentsList: localAgentsIdList,
});
}
render() {
return (
<div className="cluster-management-tabs">
<Tabs scrollIntoView={false} >
<Tab className="cluster-management-tab1"
id="tab-1"
label="Create Cluster"
>
<ClusterCreate
clusterTypeList={this.state.clusterTypeList}
agentsList={this.state.agentsList}
/>
</Tab>
<Tab
id="tab-2"
label="Edit Cluster"
>
<ClusterEdit
clusterTypeList={this.state.clusterTypeList}
agentsList={this.state.agentsList}
/>
</Tab>
</Tabs>
</div>
)
}
}
const mapStateToProps = (state) => ({
globalClusterTypeInfo: state.clusters.globalClusterTypeInfo,
globalServerSelected: state.servers.globalServerSelected,
globalAgentsList: state.agents.globalAgentsList,
globalServerInfo: state.servers.globalServerInfo,
globalTornjakServerInfo: state.servers.globalTornjakServerInfo,
globalErrorMessage: state.tornjak.globalErrorMessage,
})
export default connect(
mapStateToProps,
{ clusterTypeInfoFunc, serverSelectedFunc, selectorInfoFunc, agentsListUpdateFunc, tornjakMessageFunc, tornjakServerInfoUpdateFunc, serverInfoUpdateFunc }
)(ClusterManagement)