-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Sharing: Implement Redux-based Publicize reducers and actions #338
Conversation
Testing this: the sharing accordion flashes on the page and then disappears. I only had a few online minutes (while travelling) to test, so I haven't yet debugged to find the cause. I did confirm that the The problem didn't happen on a different (WP.com) site. |
@@ -70,7 +70,10 @@ | |||
"raf": "2.0.4", | |||
"react": "0.13.3", | |||
"react-day-picker": "1.1.0", | |||
"react-redux": "3.1.0", |
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.
I'm guessing you didn't go with 4.0.0
because we're still on react 0.13.x
?
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.
I'm guessing you didn't go with
4.0.0
because we're still on react0.13.x
?
Yep, react-redux
4.x requires React 0.14. The biggest change between react-redux
3.x and 4.x that we'll need to account for is that the latter does not require the <Provider>
child to be a callback function.
Confirmed this problem doesn't exist in |
Testing some more, I found that the Sharing accordion would eventually appear, and then I quickly tracked it down to not appearing until a post was initialized (in the case of a brand new post, it didn't initialize until I made a change) |
Other than the post initialization bug I found, this is working pretty well for me. Nice work 👍 I'd suggest more 👀 on here, especially since this is my first exposure to redux, personally. |
const currentUser = user.get(); | ||
const connections = currentUser ? this.props.connections.filter( ( connection ) => { | ||
const { service, keyring_connection_user_ID, shared } = connection; | ||
return service === serviceName && ( shared || keyring_connection_user_ID === currentUser.ID ); |
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.
While I am not sure that a scenario exists where a publicize connection could have a user_ID
different from keyring_connection_user_ID
, and not be a shared
connection, I think that connection.user_ID === currentUser.ID
would also be a valid condition here.
I observed and fixed a few bugs related to changing routes after having visited the editor. I'm not able to reproduce the original issue. Can you take another look and let me know if you're still having trouble? |
( state ) => { | ||
return { state }; | ||
} | ||
)( EditorSharingContainer ); |
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.
Is the state mapping function always going to be the same? If not, why not (for my own education)? If so, it looks like this will be a common pattern going forward, so I think it makes sense to move this logic into a helper method like reduxify
or similar.
I'm also finding it pretty confusing that state
is used to refer to the state of the Redux store - this.props.state
is a strange thing to see in the code. Perhaps calling it store
or reduxState
or something else would help?
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.
Is the state mapping function always going to be the same?
This raises a good point, as it should depend on the data needs of the component. The react-redux
docs examples may help to shed some light here. In this case, rather than injecting the entire state tree, I should probably leverage the existing selectors, specifying connections
and hasFetchedConnections
as the props passed by the connect
mapping function.
I'm also finding it pretty confusing that state is used to refer to the state of the Redux store - this.props.state is a strange thing to see in the code.
"State" is the terminology used by Redux, though I do agree that it becomes a bit confusing in this example where I'm injecting a state
prop into the the component. In consideration of the above, this will likely not be as big a concern if I choose to not pass the entire state tree in to the component, and instead pass only the subset of data needed by the component.
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.
Ah, now I remember why it wasn't simple to pass the subset of data -- since the selected site is not yet made available in the state tree, it's not possible to call hasFetchedConnections
and getConnectionsBySiteId
from the connect
mapping function.
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.
Agreed, state
maybe should be a reserved keyword
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 appears that there is an alternate function signature for the connect
mapping function, where the second parameter passes the props of the component, which should include site
. Will see if I can use this to select based on the passed site prop.
This works well according to my testing. In particular, I was not able to reproduce the issue Joey noticed. This is my first exposure to Redux as well, but from reading the code and documentation this makes sense at a high level. It'll be nice to have this cleaner implementation of our other data stores too - |
I rewrote the |
I am still observing the bug I initially described with some sites only. |
Resolves the case where if the site were to change while the component is still mounted, a connection fetch would not be triggered if those connections had not already been fetched.
Can occur when navigating from a site-specific page to a non-site-specific page, during which time the selected site is unset while the component is still mounted.
57b7d3c
to
c97533c
Compare
Re-tested and tried my best to break things. All is good. |
Sharing: Implement Redux-based Publicize reducers and actions
Closes #350
Partially implements #129
This pull request seeks to implement a new set of Redux-based actions, reducers, selectors, and components related to displaying active Publicize connections in the post editor Sharing accordion. This will serve to eliminate an unnecessary request to the REST API for retrieving Keyring connections, as this data is not currently in use by the post editor.
Implementation notes:
This is a large pull request, but it is mostly comprised of new modules, of which include significant non-front-facing changes (i.e. documentation, testing).
As this pull request introduces Redux, it also includes the necessary changes to wire a new instance of a global Redux store to the routing context. See
shared/lib/redux-store
. The intention is that as reducers are added, they should be included in thecombineReducers
call inshared/lib/redux-store/reducers.js
.Similarly, as new actions are introduced, they would be added to(See #338 (diff))shared/lib/redux-store/action-types.js
. The proposed advantage here is that, by having a single set of action type keys, there's a reduced chance for key conflicts and that this list will serve as a single reference for all action types in use in the application.react-redux is used here for passing the store context through the hierarchy of post editor components. This is used by a new
<EditorSharingContainer />
component for managing and fetching site connections.A nested subdirectory was created for Publicize-related files, as it's intended that we'll soon introduce new reducers and actions for managing Keyring connections.
Testing instructions:
The changes herein replace the current post editor Sharing accordion connections listing. Verify that existing behavior remains unaffected.