-
Notifications
You must be signed in to change notification settings - Fork 89
/
scheduleSettingsContent.jsx
326 lines (290 loc) · 11.1 KB
/
scheduleSettingsContent.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// *********************************************************************
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License
// *********************************************************************
import React from 'react';
import PropTypes from 'prop-types';
import * as Models from '../../flowModels';
import { DetailsList, DetailsListLayoutMode, Selection, SelectionMode, CheckboxVisibility, DefaultButton } from 'office-ui-fabric-react';
import { Colors, IconButtonStyles, PanelHeader, PanelHeaderButtons, ScrollableContentPane, StatementBox } from 'datax-common';
import RecurringScheduleSettings from './recurringScheduleSettings';
import OneTimeScheduleSettings from './oneTimeScheduleSettings';
import * as Styles from '../../../../common/styles';
const batchColumns = [
{
key: 'columnBatchName',
name: 'Alias',
fieldName: 'id',
isResizable: true
},
{
key: 'columnBatchType',
name: 'Type',
fieldName: 'typeDisplay',
isResizable: true,
minWidth: 100
},
{
key: 'columnBatchStatus',
name: 'Status',
fieldName: 'status',
isResizable: true,
minWidth: 100
}
];
export default class ScheduleSettingsContent extends React.Component {
constructor(props) {
super(props);
this.batchSelection = new Selection({
selectionMode: SelectionMode.single
});
this.batchTypeToRenderFuncMap = {
[Models.batchTypeEnum.recurring]: batch => this.renderRecurringScheduleSettings(batch),
[Models.batchTypeEnum.oneTime]: batch => this.renderOneTimeScheduleSettings(batch)
};
this.batchTypeToDisplayMap = {};
Models.batchTypes.forEach(batchType => {
this.batchTypeToDisplayMap[batchType.key] = batchType.name;
});
}
render() {
return (
<div style={rootStyle}>
<StatementBox
icon="SignOut"
statement="Schedule recurring and/or one time batch jobs. For the jobs scheduled correctly, the scheduler will create and start jobs. And once a job is created, the schedule associated with it will be disabled and read-only."
/>
{this.renderContent()}
</div>
);
}
renderContent() {
return (
<div style={contentStyle}>
{this.renderLeftPane()}
{this.renderRightPane()}
</div>
);
}
renderLeftPane() {
this.showSelectionInDetailsList();
const batchList = this.props.batchList;
batchList.forEach(item => {
item.typeDisplay = this.batchTypeToDisplayMap[item.type];
item.status = !item.disabled ? 'Active' : 'Disabled';
});
return (
<div style={leftPaneStyle}>
<PanelHeader style={Styles.panelHeaderStyle}>Schedule Batch Jobs</PanelHeader>
<PanelHeaderButtons style={panelHeaderButtonStyle}>{this.renderButtons()}</PanelHeaderButtons>
<div style={leftPaneContentStyle}>
<div style={listContainerStyle}>
<DetailsList
items={batchList}
columns={batchColumns}
onActiveItemChanged={(item, index) => this.onSelectBatchItem(item, index)}
setKey="batchList"
layoutMode={DetailsListLayoutMode.justified}
selectionMode={SelectionMode.single}
selectionPreservedOnEmptyClick={true}
isHeaderVisible={true}
checkboxVisibility={CheckboxVisibility.hidden}
selection={this.batchSelection}
/>
</div>
</div>
</div>
);
}
renderRightPane() {
return (
<div style={rightPaneStyle}>
<PanelHeader style={Styles.panelHeaderStyle}>Settings</PanelHeader>
<ScrollableContentPane backgroundColor={Colors.neutralLighterAlt}>{this.renderBatchSettings()}</ScrollableContentPane>
</div>
);
}
renderButtons() {
return [this.renderAddBatchButton(), this.renderDeleteBatchButton()];
}
renderAddBatchButton() {
let recurringExists = this.props.batchList.filter(b => b.type === Models.batchTypeEnum.recurring);
const menuItems =
!recurringExists || recurringExists.length < 1
? Models.batchTypes.map(batchType => {
return Object.assign({}, batchType, {
onClick: () => this.props.onNewBatch(batchType.key)
});
})
: Models.batchTypes
.filter(batchType => batchType.key !== Models.batchTypeEnum.recurring)
.map(batchType => {
return Object.assign({}, batchType, {
onClick: () => this.props.onNewBatch(batchType.key)
});
});
return (
<DefaultButton
key="newbatch"
className="content-header-button"
disabled={!this.props.addBatchButtonEnabled}
title="Add new batch"
menuProps={{ items: menuItems }}
>
<i
style={this.props.addBatchButtonEnabled ? IconButtonStyles.greenStyle : IconButtonStyles.disabledStyle}
className="ms-Icon ms-Icon--Add"
/>
Add
</DefaultButton>
);
}
renderDeleteBatchButton() {
const batch = this.getBatch();
const enableButton = batch !== undefined && this.props.deleteBatchButtonEnabled;
return (
<DefaultButton
key="deletebatch"
className="content-header-button"
disabled={!enableButton}
title="Delete selected batch"
onClick={() => this.props.onDeleteBatch(this.props.selectedBatchIndex)}
>
<i
style={enableButton ? IconButtonStyles.neutralStyle : IconButtonStyles.disabledStyle}
className="ms-Icon ms-Icon--Delete"
/>
Delete
</DefaultButton>
);
}
renderBatchSettings() {
const batch = this.getBatch();
if (!batch) {
return null;
}
if (batch.type in this.batchTypeToRenderFuncMap) {
return this.batchTypeToRenderFuncMap[batch.type](batch);
} else {
alert('Not supported batch type');
return null;
}
}
renderRecurringScheduleSettings(batch) {
return (
<RecurringScheduleSettings
batch={batch}
batchTypeDisplayName={this.batchTypeToDisplayMap[batch.type]}
onUpdateBatchName={this.props.onUpdateBatchName}
onUpdateBatchStartTime={this.props.onUpdateBatchStartTime}
onUpdateBatchEndTime={this.props.onUpdateBatchEndTime}
onUpdateBatchIntervalValue={this.props.onUpdateBatchIntervalValue}
onUpdateBatchIntervalType={this.props.onUpdateBatchIntervalType}
onUpdateBatchDelayValue={this.props.onUpdateBatchDelayValue}
onUpdateBatchDelayType={this.props.onUpdateBatchDelayType}
onUpdateBatchWindowValue={this.props.onUpdateBatchWindowValue}
onUpdateBatchWindowType={this.props.onUpdateBatchWindowType}
/>
);
}
renderOneTimeScheduleSettings(batch) {
return (
<OneTimeScheduleSettings
batch={batch}
batchTypeDisplayName={this.batchTypeToDisplayMap[batch.type]}
onUpdateBatchName={this.props.onUpdateBatchName}
onUpdateBatchStartTime={this.props.onUpdateBatchStartTime}
onUpdateBatchEndTime={this.props.onUpdateBatchEndTime}
onUpdateBatchIntervalValue={this.props.onUpdateBatchIntervalValue}
onUpdateBatchIntervalType={this.props.onUpdateBatchIntervalType}
onUpdateBatchWindowValue={this.props.onUpdateBatchWindowValue}
onUpdateBatchWindowType={this.props.onUpdateBatchWindowType}
/>
);
}
onSelectBatchItem(item, index) {
if (index !== this.props.selectedBatchIndex) {
this.props.onUpdateSelectedBatchIndex(index);
}
}
getBatch() {
const batchList = this.props.batchList;
if (this.props.selectedBatchIndex !== undefined && this.props.selectedBatchIndex < batchList.length) {
return batchList[this.props.selectedBatchIndex];
} else {
return undefined;
}
}
showSelectionInDetailsList() {
const batchList = this.props.batchList;
if (batchList.length > 0) {
this.batchSelection.setChangeEvents(false, true);
this.batchSelection.setItems(batchList);
this.batchSelection.setIndexSelected(this.props.selectedBatchIndex, true, false);
this.batchSelection.setChangeEvents(true, true);
}
}
}
// Props
ScheduleSettingsContent.propTypes = {
batchList: PropTypes.array.isRequired,
selectedBatchIndex: PropTypes.number,
onNewBatch: PropTypes.func.isRequired,
onDeleteBatch: PropTypes.func.isRequired,
onUpdateSelectedBatchIndex: PropTypes.func.isRequired,
addBatchButtonEnabled: PropTypes.bool.isRequired,
deleteBatchButtonEnabled: PropTypes.bool.isRequired,
// Schedule Settings
onUpdateBatchName: PropTypes.func.isRequired,
onUpdateBatchStartTime: PropTypes.func.isRequired,
onUpdateBatchEndTime: PropTypes.func.isRequired,
onUpdateBatchIntervalValue: PropTypes.func.isRequired,
onUpdateBatchIntervalType: PropTypes.func.isRequired,
onUpdateBatchDelayValue: PropTypes.func.isRequired,
onUpdateBatchDelayType: PropTypes.func.isRequired,
onUpdateBatchWindowValue: PropTypes.func.isRequired,
onUpdateBatchWindowType: PropTypes.func.isRequired
};
// Styles
const rootStyle = {
display: 'flex',
flexDirection: 'column',
overflowY: 'hidden',
flex: 1
};
const contentStyle = {
display: 'flex',
flexDirection: 'row',
overflowY: 'hidden',
flex: 1
};
const panelHeaderButtonStyle = {
backgroundColor: Colors.neutralLighter
};
const leftPaneStyle = {
flex: 1,
display: 'flex',
flexDirection: 'column',
borderRight: `1px solid ${Colors.neutralTertiaryAlt}`
};
const leftPaneContentStyle = {
paddingLeft: 30,
paddingRight: 30,
paddingTop: 30,
paddingBottom: 30,
flex: 1,
display: 'flex',
flexDirection: 'column',
overflowY: 'hidden'
};
const rightPaneStyle = {
flex: 3,
display: 'flex',
flexDirection: 'column'
};
const listContainerStyle = {
backgroundColor: Colors.white,
border: `1px solid ${Colors.neutralTertiaryAlt}`,
flex: 1,
overflowY: 'auto'
};