-
Notifications
You must be signed in to change notification settings - Fork 6
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
x-follow-button #59
Merged
Merged
x-follow-button #59
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
41eaed9
Original development of x-follow-button using x-interaction (largely …
9709478
Set main entry in bower.json to enable imports via Bower to resolve. …
ef56c8a
Tidy up after rebase.
92b229f
Update knobs for Storybook 4 (+1 squashed commit)
d9adab3
Dispatch custom event on click of button. Expose more meaningful acti…
93873f4
Remove data-myft-ui to prevent n-myft-ui generic button handling. (+1…
bfe622c
Refactor to not use x-interaction. Also simplify the button as it now…
dan-searle 3bf8403
Use classnames package to apply component classes. Ensure specified v…
dan-searle 48b3081
Remove x-interaction dependency.
dan-searle 1175d5a
Remove focus outline.
dan-searle bb517bc
Only run bower install on prepare
dan-searle 1c52108
don't display concept name in button text as a default
fenglish 6d7de7c
update snapshot tests
fenglish dbbb615
update node-sass
fenglish b1ab83e
useConceptNameAsButtonText => conceptNameAsButtonText
fenglish acc728c
modify explanation of conceptNameAsButtonText
fenglish 8427d7c
conceptNameAsButtonText as a knob not a separated story
fenglish 165f04c
update snapshot tests
fenglish fcdf405
eslintignore tools/x-docs/static/**
fenglish 493414b
MyFT => myFT
fenglish 35fe36c
update snapshots
fenglish 651eb75
add subjectName in event.detail
fenglish 7cfb279
revert the commit to add subjectName in event.detail
fenglish 86ac883
Modify the followed button text
fenglish 240650f
Remove CSS comments
dan-searle b6e7832
More useful readme
dan-searle bfdbe7c
Not enough knobs to make it worth splitting them into groups.
dan-searle 8eec75d
Added onClick prop to X-Follow-Button
537f1f1
renamed onClick prop to onSubmit
53c1f5a
Add x-follow-button to the new story format
kateloschinina e9338da
Update snapshot
kateloschinina 21a1cc0
Refactor x-follow-button storybook demo
kateloschinina 4b5843b
Add tests
kateloschinina 4ae4119
Use sass-loader in storybook webpack
edds 04d7890
Merge remote-tracking branch 'origin/master' into follow-button
edds f7474c7
Update x-follow-button for origami major change
edds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ | |
**/public/** | ||
**/public-prod/** | ||
**/blueprints/** | ||
web/static/** | ||
web/static/** |
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 @@ | ||
module.exports = {}; |
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,8 @@ | ||
{ | ||
"registry": { | ||
"search": [ | ||
"https://origami-bower-registry.ft.com", | ||
"https://registry.bower.io" | ||
] | ||
} | ||
} |
174 changes: 174 additions & 0 deletions
174
components/x-follow-button/__tests__/x-follow-button.test.jsx
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,174 @@ | ||
const { h } = require('@financial-times/x-engine'); | ||
const { mount } = require('@financial-times/x-test-utils/enzyme'); | ||
|
||
import { FollowButton } from '../src/FollowButton'; | ||
|
||
describe('x-follow-button', () => { | ||
describe('concept name', () => { | ||
it('when conceptNameAsButtonText prop is true, and the topic name is provided, the button is named by this name', () => { | ||
const subject = mount( | ||
<FollowButton conceptNameAsButtonText={true} conceptName={'dummy concept name'} /> | ||
); | ||
expect(subject.find('button').text()).toEqual('dummy concept name'); | ||
}); | ||
|
||
it('when conceptNameAsButtonText prop is false, the button has a default name', () => { | ||
const subject = mount( | ||
<FollowButton conceptNameAsButtonText={false} conceptName={'dummy concept name'} /> | ||
); | ||
expect(subject.find('button').text()).toEqual('Add to myFT'); | ||
}); | ||
|
||
it('when conceptNameAsButtonText prop is true, and the topic name is not provided, the button has a default name', () => { | ||
const subject = mount(<FollowButton conceptNameAsButtonText={true} />); | ||
expect(subject.find('button').text()).toEqual('Add to myFT'); | ||
}); | ||
|
||
it('when conceptNameAsButtonText prop is not provided, the button has a default name', () => { | ||
const subject = mount(<FollowButton />); | ||
expect(subject.find('button').text()).toEqual('Add to myFT'); | ||
}); | ||
}); | ||
describe('conceptId prop', () => { | ||
it('assigns conceptId prop to data-concept-id attribute of the button', async () => { | ||
const subject = mount(<FollowButton conceptId={'dummy-id'} />); | ||
expect(subject.find('button').prop('data-concept-id')).toEqual('dummy-id'); | ||
}); | ||
|
||
it('assigns conceptId prop to data-concept-id attribute of the form', async () => { | ||
const subject = mount(<FollowButton conceptId={'dummy-id'} />); | ||
expect(subject.find('form').prop('data-concept-id')).toEqual('dummy-id'); | ||
}); | ||
}); | ||
|
||
describe('form action', () => { | ||
it('assigns follow-plus-digest-email put action if followPlusDigestEmail is true', async () => { | ||
const subject = mount(<FollowButton followPlusDigestEmail={true} conceptId={'dummy-id'} />); | ||
expect(subject.find('form').prop('action')).toEqual( | ||
'/__myft/api/core/follow-plus-digest-email/dummy-id?method=put' | ||
); | ||
}); | ||
|
||
it('assigns followed/concept delete action if isFollowed is true', async () => { | ||
const subject = mount(<FollowButton isFollowed={true} conceptId={'dummy-id'} />); | ||
expect(subject.find('form').prop('action')).toEqual( | ||
'/__myft/api/core/followed/concept/dummy-id?method=delete' | ||
); | ||
}); | ||
|
||
it('assigns followed/concept put action if isFollowed and followPlusDigestEmail are not passed', async () => { | ||
const subject = mount(<FollowButton conceptId={'dummy-id'} />); | ||
expect(subject.find('form').prop('action')).toEqual( | ||
'/__myft/api/core/followed/concept/dummy-id?method=put' | ||
); | ||
}); | ||
}); | ||
|
||
describe('isFollowed', () => { | ||
describe('when true', () => { | ||
it('button text is "Added"', () => { | ||
const subject = mount(<FollowButton isFollowed={true} />); | ||
expect(subject.find('button').text()).toEqual('Added'); | ||
}); | ||
|
||
it('button aria-pressed is "true"', () => { | ||
const subject = mount(<FollowButton isFollowed={true} />); | ||
expect(subject.find('button').prop('aria-pressed')).toEqual('true'); | ||
}); | ||
|
||
it('button title is "Remove ConceptName from myFT"', () => { | ||
const subject = mount(<FollowButton isFollowed={true} conceptName={'ConceptName'} />); | ||
expect(subject.find('button').prop('title')).toEqual('Remove ConceptName from myFT'); | ||
}); | ||
|
||
it('button aria-label is "Remove conceptName from myFT"', () => { | ||
const subject = mount(<FollowButton isFollowed={true} conceptName={'ConceptName'} />); | ||
expect(subject.find('button').prop('aria-label')).toEqual('Remove ConceptName from myFT'); | ||
}); | ||
}); | ||
|
||
describe('when false', () => { | ||
it('button text is "Add to myFT"', () => { | ||
const subject = mount(<FollowButton isFollowed={false} />); | ||
expect(subject.find('button').text()).toEqual('Add to myFT'); | ||
}); | ||
|
||
it('button aria-pressed is "false"', () => { | ||
const subject = mount(<FollowButton isFollowed={false} />); | ||
expect(subject.find('button').prop('aria-pressed')).toEqual('false'); | ||
}); | ||
|
||
it('button title is "Add ConceptName to myFT"', () => { | ||
const subject = mount(<FollowButton isFollowed={false} conceptName={'ConceptName'} />); | ||
expect(subject.find('button').prop('title')).toEqual('Add ConceptName to myFT'); | ||
}); | ||
|
||
it('button aria-label is "Add ConceptName to myFT"', () => { | ||
const subject = mount(<FollowButton isFollowed={false} conceptName={'ConceptName'} />); | ||
expect(subject.find('button').prop('aria-label')).toEqual('Add ConceptName to myFT'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('followPlusDigestEmail', () => { | ||
describe('when true', () => { | ||
it('form has data-myft-ui-variant property which is true', () => { | ||
const subject = mount(<FollowButton followPlusDigestEmail={true} />); | ||
expect(subject.find('form').prop('data-myft-ui-variant')).toEqual(true); | ||
}); | ||
|
||
it('button has data-trackable-context-messaging property which is add-to-myft-plus-digest-button', () => { | ||
const subject = mount(<FollowButton followPlusDigestEmail={true} />); | ||
expect(subject.find('button').prop('data-trackable-context-messaging')).toEqual( | ||
'add-to-myft-plus-digest-button' | ||
); | ||
}); | ||
}); | ||
|
||
describe('when false', () => { | ||
it('form has data-myft-ui-variant property which is true', () => { | ||
const subject = mount(<FollowButton followPlusDigestEmail={false} />); | ||
expect(subject.find('form').prop('data-myft-ui-variant')).toEqual(undefined); | ||
}); | ||
|
||
it('button has data-trackable-context-messaging property which is add-to-myft-plus-digest-button', () => { | ||
const subject = mount(<FollowButton followPlusDigestEmail={false} />); | ||
expect(subject.find('button').prop('data-trackable-context-messaging')).toEqual(null); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('form properties', () => { | ||
it('method = GET', () => { | ||
const subject = mount(<FollowButton />); | ||
expect(subject.find('form').prop('method')).toEqual('GET'); | ||
}); | ||
}); | ||
|
||
describe('button properties', () => { | ||
it('data-trackable="follow"', () => { | ||
const subject = mount(<FollowButton />); | ||
expect(subject.find('button').prop('data-trackable')).toEqual('follow'); | ||
}); | ||
|
||
it('type="submit"', () => { | ||
const subject = mount(<FollowButton />); | ||
expect(subject.find('button').prop('type')).toEqual('submit'); | ||
}); | ||
}); | ||
|
||
describe('csrf token', () => { | ||
it('if passed creates an invisible input field', () => { | ||
const subject = mount(<FollowButton csrfToken={'dummyToken'} />); | ||
expect(subject.find('input').prop('value')).toEqual('dummyToken'); | ||
expect(subject.find('input').prop('type')).toEqual('hidden'); | ||
expect(subject.find('input').prop('name')).toEqual('token'); | ||
expect(subject.find('input').prop('data-myft-csrf-token')).toEqual(true); | ||
}); | ||
|
||
it('if not passed an invisible input field is not created', () => { | ||
const subject = mount(<FollowButton csrf={'dummyToken'} />); | ||
expect(subject.find('input')).toEqual({}); | ||
}); | ||
}); | ||
}); |
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,10 @@ | ||
{ | ||
"name": "x-follow-button", | ||
"private": true, | ||
"main": "dist/FollowButton.es5.js", | ||
"dependencies": { | ||
"o-colors": "^5.0.3", | ||
"o-icons": "^6.0.0", | ||
"o-typography": "^6.1.0" | ||
} | ||
} | ||
dan-searle marked this conversation as resolved.
Show resolved
Hide resolved
|
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,31 @@ | ||
{ | ||
"name": "@financial-times/x-follow-button", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "dist/FollowButton.cjs.js", | ||
"style": "dist/FollowButton.css", | ||
"browser": "dist/FollowButton.es5.js", | ||
"module": "dist/FollowButton.esm.js", | ||
"scripts": { | ||
"prepare": "bower install && npm run build", | ||
"build": "node rollup.js", | ||
"start": "node rollup.js --watch" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@financial-times/x-rollup": "file:../../packages/x-rollup", | ||
"@financial-times/x-test-utils": "file:../../packages/x-test-utils", | ||
"rollup": "^0.57.1", | ||
"bower": "^1.7.9", | ||
"node-sass": "^4.9.2" | ||
}, | ||
"peerDependencies": { | ||
"@financial-times/x-engine": "file:../../packages/x-engine" | ||
}, | ||
"dependencies": { | ||
"@financial-times/x-engine": "file:../../packages/x-engine", | ||
"classnames": "^2.2.6" | ||
} | ||
} |
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,43 @@ | ||
# x-follow-button | ||
|
||
This module provides a template for myFT follow topic button, and is intended to replace the legacy handlebars component in [n-myft-ui](https://github.com/Financial-Times/n-myft-ui/tree/master/components/follow-button). | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install --save @financial-times/x-follow-button | ||
``` | ||
|
||
## Props | ||
|
||
(Some of the properties don't influence the way button looks or acts, but can be used for e.g. client-side Javascript in the apps). | ||
|
||
Feature | Type | Required | Default value | Description | ||
----------------------------|---------|----------|----------------|--------------- | ||
`conceptId` | String | yes | none | UUID of the concept | ||
`conceptName` | String | yes | none | Name of the concept | ||
`conceptNameAsButtonText` | Boolean | no | `false` | If true will use the concept name as the button text, otherwise will default to "Add to MyFT" or "Remove from MyFT" (depending on isFollowed prop). | ||
`isFollowed` | Boolean | no | `false` | Whether the concept is followed or not. | ||
`csrfToken` | String | no | none | CSRF token (will be included in a hidden form field). | ||
`variant` | String | no | `standard` | One of `standard`, `inverse`, `opinion` or `monochrome`. Other values will be ignored. | ||
`followPlusDigestEmail` | Boolean | no | `false` | Whether following the topic should also subscribe to the digest. | ||
|
||
## Client side behaviour | ||
|
||
For users with JavaScript enabled, the default form submit action is prevented, and a custom event (named 'x-follow-button') will be dispatched on the form element. | ||
|
||
This custom event will contain the following in its `detail` object: | ||
|
||
Property | Value | ||
-------------------|----------------- | ||
`action` | `add` or `remove` | ||
`actorType` | `user` | ||
`relationshipName` | `followed` | ||
`subjectType` | `concept` | ||
`subjectId` | the value of the `conceptId` prop | ||
`token` | the value of the `csrfToken` prop | ||
|
||
It is up to the consumer of this component to listen for the `x-follow-button` event, and use this data, along with the user's ID, and carry out the appropriate action. | ||
|
||
For example, if using `next-myft-client` to carry out the follow/unfollow action, n-myft-ui provides a x-button-interaction component for this: | ||
https://github.com/Financial-Times/n-myft-ui/blob/master/components/x-button-integration/index.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,4 @@ | ||
const xRollup = require('@financial-times/x-rollup'); | ||
const pkg = require('./package.json'); | ||
|
||
xRollup({ input: './src/FollowButton.jsx', pkg }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit of a hack because if two different components depend on different versions of bower things then it could get sticky. but it gets this moving and we can iterate that later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#183 should fix that in the future