-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathNameSourceStep.tsx
280 lines (264 loc) · 11.8 KB
/
NameSourceStep.tsx
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
import { Button, Checkbox, Collapse, Form, Input, Tooltip, Typography } from 'antd';
import React from 'react';
import styled from 'styled-components';
import { SourceBuilderState, StepProps, StringMapEntryInput } from './types';
import { RequiredFieldForm } from '../../../shared/form/RequiredFieldForm';
const ControlsContainer = styled.div`
display: flex;
justify-content: space-between;
margin-top: 8px;
`;
const SaveButton = styled(Button)`
margin-right: 15px;
`;
const ExtraEnvKey = 'extra_env_vars';
const ExtraReqKey = 'extra_pip_requirements';
const ExtraPluginKey = 'extra_pip_plugins';
export const NameSourceStep = ({ state, updateState, prev, submit }: StepProps) => {
const setName = (stagedName: string) => {
const newState: SourceBuilderState = {
...state,
name: stagedName,
};
updateState(newState);
};
const setExecutorId = (execId: string) => {
const newState: SourceBuilderState = {
...state,
config: {
...state.config,
executorId: execId,
},
};
updateState(newState);
};
const setVersion = (version: string) => {
const newState: SourceBuilderState = {
...state,
config: {
...state.config,
version,
},
};
updateState(newState);
};
const setDebugMode = (debugMode: boolean) => {
const newState: SourceBuilderState = {
...state,
config: {
...state.config,
debugMode,
},
};
updateState(newState);
};
const retrieveExtraEnvs = () => {
const extraArgs: StringMapEntryInput[] = state.config?.extraArgs ? state.config?.extraArgs : [];
const index: number = extraArgs.findIndex((entry) => entry.key === ExtraEnvKey) as number;
if (index > -1) {
return extraArgs[index].value;
}
return '';
};
const setExtraEnvs = (envs: string) => {
let extraArgs: StringMapEntryInput[] = state.config?.extraArgs ? state.config?.extraArgs : [];
const indxOfEnvVars: number = extraArgs.findIndex((entry) => entry.key === ExtraEnvKey) as number;
const value = { key: ExtraEnvKey, value: envs };
if (indxOfEnvVars > -1) {
extraArgs[indxOfEnvVars] = value;
} else {
extraArgs = [...extraArgs, value];
}
const newState: SourceBuilderState = {
...state,
config: {
...state.config,
extraArgs,
},
};
updateState(newState);
};
const retrieveExtraDataHubPlugins = () => {
const extraArgs: StringMapEntryInput[] = state.config?.extraArgs ? state.config?.extraArgs : [];
const index: number = extraArgs.findIndex((entry) => entry.key === ExtraPluginKey) as number;
if (index > -1) {
return extraArgs[index].value;
}
return '';
};
const setExtraDataHubPlugins = (plugins: string) => {
let extraArgs: StringMapEntryInput[] = state.config?.extraArgs ? state.config?.extraArgs : [];
const indxOfPlugins: number = extraArgs.findIndex((entry) => entry.key === ExtraPluginKey) as number;
const value = { key: ExtraPluginKey, value: plugins };
if (indxOfPlugins > -1) {
extraArgs[indxOfPlugins] = value;
} else {
extraArgs = [...extraArgs, value];
}
const newState: SourceBuilderState = {
...state,
config: {
...state.config,
extraArgs,
},
};
updateState(newState);
};
const retrieveExtraReqs = () => {
const extraArgs: StringMapEntryInput[] = state.config?.extraArgs ? state.config?.extraArgs : [];
const index: number = extraArgs.findIndex((entry) => entry.key === ExtraReqKey) as number;
if (index > -1) {
return extraArgs[index].value;
}
return '';
};
const setExtraReqs = (reqs: string) => {
let extraArgs: StringMapEntryInput[] = state.config?.extraArgs ? state.config?.extraArgs : [];
const indxOfReqs: number = extraArgs.findIndex((entry) => entry.key === ExtraReqKey) as number;
const value = { key: ExtraReqKey, value: reqs };
if (indxOfReqs > -1) {
extraArgs[indxOfReqs] = value;
} else {
extraArgs = [...extraArgs, value];
}
const newState: SourceBuilderState = {
...state,
config: {
...state.config,
extraArgs,
},
};
updateState(newState);
};
const onClickCreate = (shouldRun?: boolean) => {
if (state.name !== undefined && state.name.length > 0) {
submit(shouldRun);
}
};
const handleBlur = (event: React.FocusEvent<HTMLInputElement>, setterFunction: (value: string) => void) => {
const trimmedValue = event.target.value.trim();
setterFunction(trimmedValue);
};
return (
<>
<RequiredFieldForm layout="vertical">
<Form.Item
required
label={
<Typography.Text strong style={{ marginBottom: 0 }}>
Name
</Typography.Text>
}
style={{ marginBottom: 8 }}
>
<Typography.Paragraph>Give this data source a name</Typography.Paragraph>
<Input
data-testid="source-name-input"
className="source-name-input"
placeholder="My Redshift Source #2"
value={state.name}
onChange={(event) => setName(event.target.value)}
onBlur={(event) => handleBlur(event, setName)}
/>
</Form.Item>
<Collapse ghost>
<Collapse.Panel header={<Typography.Text type="secondary">Advanced</Typography.Text>} key="1">
<Form.Item label={<Typography.Text strong>Executor ID</Typography.Text>}>
<Typography.Paragraph>
Provide the ID of the executor that should execute this ingestion recipe. This ID is
used to route execution requests of the recipe to the executor of the same ID. The
built-in DataHub executor ID is 'default'. Do not change this unless you have
configured a remote or custom executor.
</Typography.Paragraph>
<Input
placeholder="default"
value={state.config?.executorId || ''}
onChange={(event) => setExecutorId(event.target.value)}
onBlur={(event) => handleBlur(event, setExecutorId)}
/>
</Form.Item>
<Form.Item label={<Typography.Text strong>CLI Version</Typography.Text>}>
<Typography.Paragraph>
Advanced: Provide a custom CLI version to use for ingestion.
</Typography.Paragraph>
<Input
data-testid="cli-version-input"
className="cli-version-input"
placeholder="(e.g. 0.15.0)"
value={state.config?.version || ''}
onChange={(event) => setVersion(event.target.value)}
onBlur={(event) => handleBlur(event, setVersion)}
/>
</Form.Item>
<Form.Item label={<Typography.Text strong>Debug Mode</Typography.Text>}>
<Typography.Paragraph>
Advanced: Turn on debug mode in order to get more verbose logs.
</Typography.Paragraph>
<Checkbox
checked={state.config?.debugMode || false}
onChange={(event) => setDebugMode(event.target.checked)}
/>
</Form.Item>
<Form.Item label={<Typography.Text strong>Extra Enviroment Variables</Typography.Text>}>
<Typography.Paragraph>
Advanced: Set extra environment variables to an ingestion execution
</Typography.Paragraph>
<Input
data-testid="extra-args-input"
placeholder='{"MY_CUSTOM_ENV": "my_custom_value2"}'
value={retrieveExtraEnvs()}
onChange={(event) => setExtraEnvs(event.target.value)}
onBlur={(event) => handleBlur(event, setExtraEnvs)}
/>
</Form.Item>
<Form.Item label={<Typography.Text strong>Extra DataHub plugins</Typography.Text>}>
<Typography.Paragraph>
Advanced: Set extra DataHub plugins for an ingestion execution
</Typography.Paragraph>
<Input
data-testid="extra-pip-plugin-input"
placeholder='["debug"]'
value={retrieveExtraDataHubPlugins()}
onChange={(event) => setExtraDataHubPlugins(event.target.value)}
onBlur={(event) => handleBlur(event, setExtraDataHubPlugins)}
/>
</Form.Item>
<Form.Item label={<Typography.Text strong>Extra Pip Libraries</Typography.Text>}>
<Typography.Paragraph>
Advanced: Add extra pip libraries for an ingestion execution
</Typography.Paragraph>
<Input
data-testid="extra-pip-reqs-input"
placeholder='["sqlparse==0.4.3"]'
value={retrieveExtraReqs()}
onChange={(event) => setExtraReqs(event.target.value)}
onBlur={(event) => handleBlur(event, setExtraReqs)}
/>
</Form.Item>
</Collapse.Panel>
</Collapse>
</RequiredFieldForm>
<ControlsContainer>
<Button onClick={prev}>Previous</Button>
<div>
<SaveButton
data-testid="ingestion-source-save-button"
disabled={!(state.name !== undefined && state.name.length > 0)}
onClick={() => onClickCreate(false)}
>
Save
</SaveButton>
<Tooltip showArrow={false} title="Save and starting syncing data source">
<Button
disabled={!(state.name !== undefined && state.name.length > 0)}
onClick={() => onClickCreate(true)}
type="primary"
>
Save & Run
</Button>
</Tooltip>
</div>
</ControlsContainer>
</>
);
};