Skip to content

Commit a1217a1

Browse files
fix(code/frontend): should not show import error at the first time (#33921)
1 parent 4b2c60f commit a1217a1

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

x-pack/plugins/code/public/components/admin_page/import_project.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,32 @@ class CodeImportProject extends React.PureComponent<
3333
importRepo: (p: string) => void;
3434
importLoading: boolean;
3535
},
36-
{ value: string }
36+
{ value: string; isInvalid: boolean }
3737
> {
3838
public state = {
3939
value: '',
40+
isInvalid: false,
4041
};
4142

4243
public onChange = (e: ChangeEvent<HTMLInputElement>) => {
4344
this.setState({
4445
value: e.target.value,
46+
isInvalid: isImportRepositoryURLInvalid(e.target.value),
4547
});
4648
};
4749

4850
public submitImportProject = () => {
4951
if (!isImportRepositoryURLInvalid(this.state.value)) {
5052
this.props.importRepo(this.state.value);
53+
} else if (!this.state.isInvalid) {
54+
this.setState({ isInvalid: true });
5155
}
5256
};
5357

58+
public updateIsInvalid = () => {
59+
this.setState({ isInvalid: isImportRepositoryURLInvalid(this.state.value) });
60+
};
61+
5462
public render() {
5563
return (
5664
<ImportWrapper>
@@ -61,7 +69,7 @@ class CodeImportProject extends React.PureComponent<
6169
label="Repository URL"
6270
helpText="e.g. https://github.com/elastic/elasticsearch"
6371
fullWidth
64-
isInvalid={isImportRepositoryURLInvalid(this.state.value)}
72+
isInvalid={this.state.isInvalid}
6573
error="This field shouldn't be empty."
6674
>
6775
<EuiFieldText
@@ -71,7 +79,8 @@ class CodeImportProject extends React.PureComponent<
7179
data-test-subj="importRepositoryUrlInputBox"
7280
isLoading={this.props.importLoading}
7381
fullWidth={true}
74-
isInvalid={isImportRepositoryURLInvalid(this.state.value)}
82+
onBlur={this.updateIsInvalid}
83+
isInvalid={this.state.isInvalid}
7584
/>
7685
</EuiFormRow>
7786
</EuiFlexItem>

x-pack/plugins/code/public/components/admin_page/project_tab.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ interface State {
9090
importLoading: boolean;
9191
settingModal: { url?: string; uri?: string; show: boolean };
9292
repoURL: string;
93+
isInvalid: boolean;
9394
sortOption: SortOptionsValue;
9495
}
9596

@@ -109,11 +110,12 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
109110
settingModal: { show: false },
110111
repoURL: '',
111112
sortOption: SortOptionsValue.alphabetical_asc,
113+
isInvalid: false,
112114
};
113115
}
114116

115117
public closeModal = () => {
116-
this.setState({ showImportProjectModal: false, repoURL: '' });
118+
this.setState({ showImportProjectModal: false, repoURL: '', isInvalid: false });
117119
};
118120

119121
public openModal = () => {
@@ -131,15 +133,22 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
131133
public onChange = (e: ChangeEvent<HTMLInputElement>) => {
132134
this.setState({
133135
repoURL: e.target.value,
136+
isInvalid: isImportRepositoryURLInvalid(e.target.value),
134137
});
135138
};
136139

137140
public submitImportProject = () => {
138141
if (!isImportRepositoryURLInvalid(this.state.repoURL)) {
139142
this.props.importRepo(this.state.repoURL);
143+
} else if (!this.state.isInvalid) {
144+
this.setState({ isInvalid: true });
140145
}
141146
};
142147

148+
public updateIsInvalid = () => {
149+
this.setState({ isInvalid: isImportRepositoryURLInvalid(this.state.repoURL) });
150+
};
151+
143152
public renderImportModal = () => {
144153
return (
145154
<EuiOverlayMask>
@@ -152,19 +161,17 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
152161
<h3>Repository URL</h3>
153162
</EuiTitle>
154163
<EuiForm>
155-
<EuiFormRow
156-
isInvalid={isImportRepositoryURLInvalid(this.state.repoURL)}
157-
error="This field shouldn't be empty."
158-
>
164+
<EuiFormRow isInvalid={this.state.isInvalid} error="This field shouldn't be empty.">
159165
<EuiFieldText
160166
value={this.state.repoURL}
161167
onChange={this.onChange}
168+
onBlur={this.updateIsInvalid}
162169
placeholder="https://github.com/elastic/elasticsearch"
163170
aria-label="input project url"
164171
data-test-subj="importRepositoryUrlInputBox"
165172
isLoading={this.props.importLoading}
166173
fullWidth={true}
167-
isInvalid={isImportRepositoryURLInvalid(this.state.repoURL)}
174+
isInvalid={this.state.isInvalid}
168175
/>
169176
</EuiFormRow>
170177
</EuiForm>

0 commit comments

Comments
 (0)