/
LocalVolumesComponent.jsx
149 lines (127 loc) · 4.12 KB
/
LocalVolumesComponent.jsx
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import classNames from "classnames";
import React from "react/addons";
import DuplicableRowControls from "../components/DuplicableRowControls";
import DuplicableRowsMixin from "../mixins/DuplicableRowsMixin";
import FormGroupComponent from "../components/FormGroupComponent";
import TooltipComponent from "../components/TooltipComponent";
import ExternalLinks from "../constants/ExternalLinks";
var LocalVolumesComponent = React.createClass({
displayName: "LocalVolumesComponent",
propTypes: {
errorIndices: React.PropTypes.object.isRequired,
fields: React.PropTypes.object.isRequired,
getErrorMessage: React.PropTypes.func.isRequired
},
mixins: [DuplicableRowsMixin],
duplicableRowsScheme: {
localVolumes: {
persistentSize: "",
containerPath: ""
}
},
handleAddRow: function (position, event) {
event.target.blur();
event.preventDefault();
this.addRow("localVolumes", position);
},
handleRemoveRow: function (position, event) {
event.target.blur();
event.preventDefault();
this.removeRow("localVolumes", position);
},
handleChange: function (position) {
this.updateRow("localVolumes", position);
},
getVolumeRow: function (row, i, disableRemoveButton = false) {
var error = this.getError("localVolumes", row.consecutiveKey);
var rowClassSet = classNames({
"has-error": !!error,
"duplicable-row": true
});
var containerPathTooltipMessage = (
<span>
The path to the directory where your application will
read and write data. The path must be non-nested,
e.g. `/var/lib/mysql`.
<a href={ExternalLinks.CONTAINER_PATH} target="_blank">Read more</a>.
</span>
);
var containerPathLabel = (
<span>
Container Path
<TooltipComponent message={containerPathTooltipMessage}>
<i className="icon icon-xs help" />
</TooltipComponent>
</span>
);
return (
<div key={row.consecutiveKey} className={rowClassSet}>
<fieldset className="row duplicable-row"
onChange={this.handleChange.bind(null, i)}>
<div className="col-sm-4">
<FormGroupComponent
fieldId={`localVolumes.persistent.size.${i}`}
label="Size (MiB)"
value={row.persistentSize}>
<input ref={`persistentSize${i}`}
type="number"/>
</FormGroupComponent>
</div>
<div className="col-sm-8">
<FormGroupComponent
fieldId={`localVolumes.containerPath.${i}`}
label={containerPathLabel}
value={row.containerPath}>
<input ref={`containerPath${i}`} />
</FormGroupComponent>
<DuplicableRowControls
disableRemoveButton={disableRemoveButton}
handleAddRow={this.handleAddRow.bind(null, i + 1)}
handleRemoveRow={this.handleRemoveRow.bind(null, i)} />
</div>
</fieldset>
{error}
</div>
);
},
getVolumesRows: function () {
var rows = this.state.rows.localVolumes;
if (rows == null) {
return (
<button type="button">
Add a persistent local volume
</button>
);
}
let disableRemoveButton = this.hasOnlyOneSingleEmptyRow(
"localVolumes"
);
return rows.map((row, i) => {
return this.getVolumeRow(row, i, disableRemoveButton);
});
},
render: function () {
var localVolumesTooltipMessage = (
<span>
Local volumes retain data if an
application terminates.
<a href={ExternalLinks.LOCAL_VOLUMES} target="_blank">Read more</a>.
</span>
);
return (
<div>
<h4 className="subtitle">
Persistent Local Volumes
<TooltipComponent message={localVolumesTooltipMessage}>
<i className="icon icon-xs help" />
</TooltipComponent>
</h4>
<div className="duplicable-list">
{this.getVolumesRows()}
</div>
{this.getGeneralErrorBlock("localVolumes")}
</div>
);
}
});
export default LocalVolumesComponent;