Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Namespace-related validation in UI #2686

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Namespace-related validation in UI
  • Loading branch information
simster7 committed Apr 14, 2020
commit b9e8d97db3282160407a8a6d51ca5abe42d05cf4
35 changes: 17 additions & 18 deletions ui/src/app/shared/components/resource-submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@ export class ResourceSubmit<T> extends React.Component<ResourceSubmitProps<T>, R
this.state = {invalid: false};
}

private extractAndValidate(formikApi: any, resource: any) {
formikApi.setFieldValue('resource', resource);
if (!this.props.validate) {
const validateResult = this.props.validate(resource);
if (!validateResult.valid) {
this.setState({invalid: true, error: {message: validateResult.message}});
return;
}
}
this.setState({
error: undefined,
invalid: false
});
}

public render() {
return (
<div>
<Formik
initialValues={{resource: this.props.defaultResource, resourceString: jsYaml.dump(this.props.defaultResource)}}
onSubmit={(values, {setSubmitting}) => {
if (!this.props.validate) {
const validateResult = this.props.validate(values.resource);
if (!validateResult.valid) {
this.setState({invalid: true, error: {message: validateResult.message}});
setSubmitting(false);
return;
}
}
this.props
.onSubmit(values.resource)
.then(_ => setSubmitting(false))
Expand Down Expand Up @@ -80,11 +87,7 @@ export class ResourceSubmit<T> extends React.Component<ResourceSubmitProps<T>, R
onChange={e => {
try {
this.readFile(e.target.files, (newResource: string) => {
formikApi.setFieldValue('resource', jsYaml.load(e.currentTarget.value));
this.setState({
error: undefined,
invalid: false
});
this.extractAndValidate(formikApi, jsYaml.load(e.currentTarget.value));
formikApi.setFieldValue('resourceString', newResource);
});
} catch (e) {
Expand All @@ -108,11 +111,7 @@ export class ResourceSubmit<T> extends React.Component<ResourceSubmitProps<T>, R
onBlur={e => {
formikApi.handleBlur(e);
try {
formikApi.setFieldValue('resource', jsYaml.load(e.currentTarget.value));
this.setState({
error: undefined,
invalid: false
});
this.extractAndValidate(formikApi, jsYaml.load(e.currentTarget.value));
} catch (e) {
this.setState({
error: {
Expand Down