Skip to content

Commit

Permalink
PF3->Carbon: Replace async-credentials' validate button and result
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Nov 13, 2020
1 parent 3e31d54 commit a107273
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 95 deletions.
20 changes: 12 additions & 8 deletions app/javascript/components/async-credentials/async-credentials.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useState, useMemo } from 'react';
import PropTypes from 'prop-types';
import { isEqual, flatMap, get, set } from 'lodash';
import { Button, InlineLoading } from 'carbon-components-react';

import { useFormApi, useFieldApi, validatorTypes, FormSpy } from '@@ddf';
import { Button, FormGroup, HelpBlock } from 'patternfly-react';
import ButtonSpinner from '../../forms/button-spinner';
import HelperTextBlock from '../../forms/helper-text-block';

const extractNames = (schema) => {
const childFields = schema.fields ? flatMap(schema.fields, field => extractNames(field)) : [];
Expand Down Expand Up @@ -77,7 +78,7 @@ const AsyncCredentials = ({
...(field.component === 'password-field' ? { parent: name, edit } : undefined),
isDisabled: field.isDisabled,
})), formOptions)}
<FormGroup validationState={meta.error ? 'error' : null}>
<>
<input type="hidden" {...input} />

<FormSpy subscription={{ values: true, dirtyFields: true }}>
Expand All @@ -98,17 +99,20 @@ const AsyncCredentials = ({

return (
<>
<Button bsSize="small" bsStyle="primary" onClick={onClick} disabled={isValid || !depsValid || validating}>
<Button size="small" kind="tertiary" onClick={onClick} disabled={isValid || !depsValid || validating}>
{validating && <InlineLoading /> }
{validating ? validationProgressLabel : validateLabel}
{validating && <ButtonSpinner /> }
</Button>
{ !meta.error && isEqual(currentValues, lastValid) && <HelpBlock>{ validationSuccessLabel }</HelpBlock> }
{ meta.error && !validating && <HelpBlock>{ errorMessage || validateDefaultError }</HelpBlock> }

<HelperTextBlock
helperText={!meta.error && isEqual(currentValues, lastValid) && validationSuccessLabel}
errorText={meta.error && !validating && (errorMessage || validateDefaultError)}
/>
</>
);
}}
</FormSpy>
</FormGroup>
</>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,106 +45,94 @@ exports[`Async credentials component should render correctly 1`] = `
initialValue="bar"
name="foo"
>
<Pf3FormGroup
meta={
Object {
"active": false,
"data": Object {},
"dirty": false,
"dirtySinceLastSubmit": false,
"error": undefined,
"initial": "bar",
"invalid": false,
"length": undefined,
"modified": false,
"modifiedSinceLastSubmit": false,
"pristine": true,
"submitError": undefined,
"submitFailed": false,
"submitSucceeded": false,
"submitting": false,
"touched": false,
"valid": true,
"validating": false,
"visited": false,
}
}
<ForwardRef(TextInput)
disabled={false}
helperText=""
id="foo"
inline={false}
invalid={false}
invalidText=""
key="foo"
light={false}
name="foo"
onBlur={[Function]}
onChange={[Function]}
onClick={[Function]}
onFocus={[Function]}
type="text"
value="bar"
warn={false}
warnText=""
>
<FormGroup
bsClass="form-group"
validationState={null}
<div
className="bx--form-item bx--text-input-wrapper"
>
<div
className="form-group"
className="bx--text-input__field-outer-wrapper"
>
<FormControl
bsClass="form-control"
componentClass="input"
name="foo"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
value="bar"
<div
className="bx--text-input__field-wrapper"
data-invalid={null}
>
<input
className="form-control"
className="bx--text-input bx--text__input"
disabled={false}
id="foo"
name="foo"
onBlur={[Function]}
onChange={[Function]}
onClick={[Function]}
onFocus={[Function]}
type="text"
value="bar"
/>
</FormControl>
</div>
</div>
</FormGroup>
</Pf3FormGroup>
</div>
</ForwardRef(TextInput)>
</TextField>
</FormFieldHideWrapper>
</FormConditionWrapper>
</SingleField>
<FormGroup
bsClass="form-group"
validationState={null}
<input
name="validate_credentials"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
type="hidden"
value={true}
/>
<FormSpy
subscription={
Object {
"dirtyFields": true,
"values": true,
}
}
>
<div
className="form-group"
<Button
disabled={true}
kind="tertiary"
onClick={[Function]}
size="small"
tabIndex={0}
tooltipAlignment="center"
tooltipPosition="top"
type="button"
>
<input
name="validate_credentials"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
type="hidden"
value={true}
/>
<FormSpy
subscription={
Object {
"dirtyFields": true,
"values": true,
}
}
<button
className="bx--btn bx--btn--sm bx--btn--tertiary bx--btn--disabled"
disabled={true}
onClick={[Function]}
tabIndex={0}
type="button"
>
<Button
active={false}
block={false}
bsClass="btn"
bsSize="small"
bsStyle="primary"
disabled={true}
onClick={[Function]}
>
<button
className="btn btn-sm btn-primary"
disabled={true}
onClick={[Function]}
type="button"
>
Validate
</button>
</Button>
</FormSpy>
</div>
</FormGroup>
Validate
</button>
</Button>
<HelperTextBlock
helperText={false}
/>
</FormSpy>
</AsyncCredentials>
`;
12 changes: 6 additions & 6 deletions app/javascript/spec/async-credentials/async-credentials.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Async credentials component', () => {

wrapper.update();

expect(wrapper.find('span.help-block').text()).toEqual('Validation failed');
expect(wrapper.find('div.bx--form-requirement.ddorg__carbon-error-helper-text').text()).toEqual('Validation failed');

done();
});
Expand All @@ -94,10 +94,10 @@ describe('Async credentials component', () => {

wrapper.update();

expect(wrapper.find('span.help-block').text()).toEqual('Validation successful');
expect(wrapper.find('div.bx--form__helper-text').text()).toEqual('Validation successful');
wrapper.find('input[name="foo"]').simulate('change', { target: { value: 'test' } });
wrapper.update();
expect(wrapper.find('span.help-block').text()).toEqual('Validation Required');
expect(wrapper.find('div.bx--form-requirement.ddorg__carbon-error-helper-text').text()).toEqual('Validation Required');

done();
});
Expand All @@ -113,13 +113,13 @@ describe('Async credentials component', () => {

wrapper.update();

expect(wrapper.find('span.help-block').text()).toEqual('Validation successful');
expect(wrapper.find('div.bx--form__helper-text').text()).toEqual('Validation successful');
wrapper.find('input[name="foo"]').simulate('change', { target: { value: 'test' } });
wrapper.update();
expect(wrapper.find('span.help-block').text()).toEqual('Validation Required');
expect(wrapper.find('div.bx--form-requirement.ddorg__carbon-error-helper-text').text()).toEqual('Validation Required');
wrapper.find('input[name="foo"]').simulate('change', { target: { value: 'baz' } });
wrapper.update();
expect(wrapper.find('span.help-block').text()).toEqual('Validation successful');
expect(wrapper.find('div.bx--form__helper-text').text()).toEqual('Validation successful');

done();
});
Expand Down

0 comments on commit a107273

Please sign in to comment.