-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UIForms) : rendering lib based on json-schema-form-core (#415)
- Loading branch information
1 parent
b14580a
commit e53b9a1
Showing
88 changed files
with
5,171 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Lerna v2.0.0-beta.36 | ||
Scoping to packages that match 'react-talend-forms' | ||
|
||
> react-talend-forms@0.79.0 lint:style /home/travis/build/Talend/ui/packages/forms | ||
> react-talend-forms@0.80.0 lint:style /home/travis/build/Talend/ui/packages/forms | ||
> sass-lint -v -q | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React from 'react'; | ||
import configureMockStore from 'redux-mock-store'; | ||
|
||
export const data = { | ||
jsonSchema: { | ||
type: 'object', | ||
title: 'Comment', | ||
properties: { | ||
lastname: { | ||
type: 'string', | ||
minLength: 10, | ||
}, | ||
firstname: { | ||
type: 'string', | ||
}, | ||
check: {}, | ||
}, | ||
required: [ | ||
'firstname', | ||
], | ||
}, | ||
uiSchema: [ | ||
{ | ||
key: 'lastname', | ||
title: 'Last Name (with description)', | ||
description: 'Hint: this is the last name', | ||
autoFocus: true, | ||
}, | ||
{ | ||
key: 'firstname', | ||
title: 'First Name (with placeholder)', | ||
placeholder: 'Enter your firstname here', | ||
triggers: ['after'], | ||
}, | ||
{ | ||
key: 'check', | ||
type: 'button', | ||
title: 'Check the thing', | ||
triggers: ['after'], | ||
}, | ||
], | ||
properties: {}, | ||
errors: {}, | ||
}; | ||
|
||
export const mergedSchema = [ | ||
{ | ||
autoFocus: true, | ||
description: 'Hint: this is the last name', | ||
key: ['lastname'], | ||
minlength: 10, | ||
ngModelOptions: {}, | ||
schema: { minLength: 10, type: 'string' }, | ||
title: 'Last Name (with description)', | ||
type: 'text', | ||
}, | ||
{ | ||
key: ['firstname'], | ||
ngModelOptions: {}, | ||
placeholder: 'Enter your firstname here', | ||
required: true, | ||
schema: { type: 'string' }, | ||
title: 'First Name (with placeholder)', | ||
triggers: ['after'], | ||
type: 'text', | ||
}, | ||
{ | ||
key: ['check'], | ||
title: 'Check the thing', | ||
triggers: ['after'], | ||
type: 'button', | ||
}, | ||
]; | ||
|
||
export function initProps() { | ||
return { | ||
autoComplete: 'off', | ||
customValidation: jest.fn(), | ||
formName: 'myFormName', | ||
id: 'myFormId', | ||
onChange: jest.fn(), | ||
onSubmit: jest.fn(), | ||
onTrigger: jest.fn(), | ||
widgets: { | ||
custom: () => (<div>Custom</div>), | ||
}, | ||
}; | ||
} | ||
|
||
export function initStore(formName, form) { | ||
const mockStore = configureMockStore(); | ||
const state = { forms: {} }; | ||
|
||
if (formName && form) { | ||
state.forms[formName] = { ...form }; | ||
} | ||
|
||
return mockStore(state); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
export default function Message(props) { | ||
const { | ||
errorMessage, | ||
description, | ||
isValid, | ||
} = props; | ||
|
||
const message = isValid ? description : errorMessage; | ||
return message ? | ||
( | ||
<p | ||
className="help-block" | ||
role="status" | ||
> | ||
{ message } | ||
</p> | ||
) : | ||
null; | ||
} | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
Message.propTypes = { | ||
errorMessage: PropTypes.string, | ||
description: PropTypes.string, | ||
isValid: PropTypes.bool, | ||
}; | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/forms/src/UIForm/Message/Message.component.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import Message from './Message.component'; | ||
|
||
describe('Message component', () => { | ||
it('should render provided description if the field is valid', () => { | ||
// when | ||
const wrapper = shallow( | ||
<Message | ||
errorMessage={'My error message'} | ||
description={'My description'} | ||
isValid | ||
/> | ||
); | ||
|
||
// then | ||
expect(wrapper.node).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render provided error message if the field is invalid', () => { | ||
// when | ||
const wrapper = shallow( | ||
<Message | ||
errorMessage={'My error message'} | ||
description={'My description'} | ||
isValid={false} | ||
/> | ||
); | ||
|
||
// then | ||
expect(wrapper.node).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render nothing when field is valid and no description is provided', () => { | ||
// when | ||
const wrapper = shallow( | ||
<Message | ||
errorMessage={'My error message'} | ||
isValid | ||
/> | ||
); | ||
|
||
// then | ||
expect(wrapper.node).toMatchSnapshot(); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/forms/src/UIForm/Message/__snapshots__/Message.component.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
exports[`Message component should render nothing when field is valid and no description is provided 1`] = `null`; | ||
|
||
exports[`Message component should render provided description if the field is valid 1`] = ` | ||
<p | ||
className="help-block" | ||
role="status"> | ||
My description | ||
</p> | ||
`; | ||
|
||
exports[`Message component should render provided error message if the field is invalid 1`] = ` | ||
<p | ||
className="help-block" | ||
role="status"> | ||
My error message | ||
</p> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Message from './Message.component'; | ||
|
||
export default Message; |
Oops, something went wrong.