Skip to content

Commit

Permalink
fix(ui-fix-edit-test): ui-fix-edit-test (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
manorlh authored Nov 9, 2020
1 parent 6cf0b6d commit 92aa3d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
41 changes: 15 additions & 26 deletions ui/src/features/components/TestForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class TestForm extends React.Component {
csvFileId: undefined
}
}
this.state.urls = {
this.state.validationErrors = {
[URL_FIELDS.BASE]: {
value: EMPTY_STRING,
error: null
Expand All @@ -63,36 +63,24 @@ export class TestForm extends React.Component {
}

hasValidationErrors = () => {
let urlTypes = Object.values(this.state.urls);
return !urlTypes.some((url) => isUrlValid(url.value));
return !(this.state.baseUrl ? isUrlValid(this.state.baseUrl) : true);
};

isButtonDisabled = () => {
return !this.state.name || this.hasValidationErrors();
}

updatevalidationError = ({ error }) => {
updateValidationError = ({ error }) => {
const newState = Object.assign({}, this.state);
newState.urls[URL_FIELDS.STEP].error = error;
newState.validationErrors[URL_FIELDS.BASE].error = error;
this.setState(newState);
};

setValidationError = ({ error }) => {
this.updatevalidationError({ error });
};

resetValidationError = () => {
this.updatevalidationError({ error: null });
};

validateUrl = ({ name, value }) => {
const newState = Object.assign({}, this.state);
newState.urls[name].value = value;
this.setState(newState);
validateUrl = () => {
if (this.hasValidationErrors()) {
this.setValidationError({ error: INVALID_URL_MESSAGE });
this.updateValidationError({ error: INVALID_URL_MESSAGE });
} else {
this.resetValidationError();
this.updateValidationError({ error: null });
}
};

Expand Down Expand Up @@ -187,11 +175,12 @@ export class TestForm extends React.Component {
</div>
<div className={style['input-container']}>
<TitleInput style={{ flex: '1', marginTop: '2px' }} title={'Base url'}>
<ErrorWrapper errorText={this.state.urls[URL_FIELDS.BASE].error}>
<TextArea maxRows={5} value={this.state.urls[URL_FIELDS.BASE].value} placeholder={'http://my.api.com/'}
<ErrorWrapper errorText={validationErrors[URL_FIELDS.BASE].error}>
<TextArea maxRows={5} value={this.state.baseUrl} placeholder={'http://my.api.com/'}
onChange={(evt, value) => {
this.validateUrl({ name: URL_FIELDS.BASE, value: evt.target.value });
this.setState({ baseUrl: evt.target.value })
this.setState({ baseUrl: evt.target.value }, () => {
this.validateUrl()
})
}} />
</ErrorWrapper>
</TitleInput>
Expand Down Expand Up @@ -498,8 +487,8 @@ export class TestForm extends React.Component {
onDeleteStep={this.onDeleteStep}
onDuplicateStep={this.onDuplicateStep}
updateStepOrder={this.updateStepOrder}
validationError={this.state.urls[URL_FIELDS.STEP].error}
validateUrl={this.validateUrl}
// validationError={validationErrors[URL_FIELDS.STEP].error} //todo
validateUrl={() => {}} // todo temp
/>
</div>

Expand Down Expand Up @@ -555,7 +544,7 @@ export const DragAndDrop = ({ csvFile, onDropFile, csvMetadata }) => {
>

{
csvFile && csvFile.name ||
(csvFile && csvFile.name) ||
<span>Drop csv file here</span>
}

Expand Down
2 changes: 1 addition & 1 deletion ui/src/validators/validate-urls.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { URL_WITH_PROTOCOL_REGEX } from '../constants';

const URL_FIELDS = {
BASE: 'base',
BASE: 'baseUrl',
STEP: 'step'
};

Expand Down

0 comments on commit 92aa3d4

Please sign in to comment.