-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathdialog.tsx
More file actions
194 lines (179 loc) · 4.58 KB
/
dialog.tsx
File metadata and controls
194 lines (179 loc) · 4.58 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import { Dialog, showDialog } from "@jupyterlab/apputils";
import * as React from "react";
export interface INewCluster {
/**
* The cluster id
*/
cluster_id?: string;
/**
* The profile
*/
profile?: string;
/**
* The number of engines
*/
n?: number;
}
/**
* A namespace for ClusterDialog statics.
*/
namespace NewCluster {
/**
* The props for the NewClusterDialog component.
*/
export interface IProps {
/**
* The initial cluster model shown in the Dialog.
*/
initialModel: INewCluster;
/**
* A callback that allows the component to write state to an
* external object.
*/
stateEscapeHatch: (model: INewCluster) => void;
}
/**
* The state for the ClusterDialog component.
*/
export interface IState {
/**
* The proposed cluster model shown in the Dialog.
*/
model: INewCluster;
}
}
/**
* A component for an HTML form that allows the user
* to select Dialog parameters.
*/
export class NewCluster extends React.Component<
NewCluster.IProps,
NewCluster.IState
> {
/**
* Construct a new NewCluster component.
*/
constructor(props: NewCluster.IProps) {
super(props);
const model: INewCluster = props.initialModel;
this.state = { model };
}
/**
* When the component updates we take the opportunity to write
* the state of the cluster to an external object so this can
* be sent as the result of the dialog.
*/
componentDidUpdate(): void {
const model: INewCluster = { ...this.state.model };
this.props.stateEscapeHatch(model);
}
/**
* React to the number of workers changing.
*/
onScaleChanged(event: React.ChangeEvent): void {
this.setState({
model: {
...this.state.model,
n: parseInt((event.target as HTMLInputElement).value || null, null),
},
});
}
/**
* React to the number of workers changing.
*/
onProfileChanged(event: React.ChangeEvent): void {
this.setState({
model: {
...this.state.model,
profile: (event.target as HTMLInputElement).value,
},
});
}
/**
* React to the number of workers changing.
*/
onClusterIdChanged(event: React.ChangeEvent): void {
this.setState({
model: {
...this.state.model,
cluster_id: (event.target as HTMLInputElement).value,
},
});
}
/**
* Render the component..
*/
render() {
const model = this.state.model;
// const disabledClass = "ipp-mod-disabled";
return (
<div>
<div className="ipp-DialogSection">
<div className="ipp-DialogSection-item">
<span className={`ipp-DialogSection-label`}>Profile</span>
<input
className="ipp-DialogInput"
value={model.profile}
type="string"
placeholder="default"
onChange={(evt) => {
this.onProfileChanged(evt);
}}
/>
</div>
<div className="ipp-DialogSection-item">
<span className={`ipp-DialogSection-label`}>Cluster ID</span>
<input
className="ipp-DialogInput"
value={model.cluster_id}
type="string"
placeholder="auto"
onChange={(evt) => {
this.onClusterIdChanged(evt);
}}
/>
</div>
<div className="ipp-DialogSection-item">
<span className={`ipp-DialogSection-label`}>Engines</span>
<input
className="ipp-DialogInput"
value={model.n}
type="number"
step="1"
placeholder="auto"
onChange={(evt) => {
this.onScaleChanged(evt);
}}
/>
</div>
</div>
</div>
);
}
}
/**
* Show a dialog for Dialog a cluster model.
*
* @param model: the initial model.
*
* @returns a promise that resolves with the user-selected Dialogs for the
* cluster model. If they pressed the cancel button, it resolves with
* the original model.
*/
export function newClusterDialog(model: INewCluster): Promise<INewCluster> {
let updatedModel = { ...model };
const escapeHatch = (update: INewCluster) => {
updatedModel = update;
};
return showDialog({
title: `New Cluster`,
body: <NewCluster initialModel={model} stateEscapeHatch={escapeHatch} />,
buttons: [Dialog.cancelButton(), Dialog.okButton({ label: "CREATE" })],
}).then((result) => {
if (result.button.accept) {
return updatedModel;
} else {
return null;
}
});
}