Skip to content

feat: field to assign a member to a task #756

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

Merged
merged 3 commits into from
Aug 19, 2020

Conversation

maxceem
Copy link
Contributor

@maxceem maxceem commented Aug 18, 2020

image

  • Autocomplete implemented as an independent and reusable component based on react-select.
  • Action loadMemberDetails can be used to load details about any user by userId. It stores data in Redux Store members path. So this functionality could be reused to show handle for any other user by userId.
    • Potentially, this functionality could be converted to a single reusable hook so we don't have to pass members from the store everywhere where we need user details, but I guess we would have to update React 16.7 to 16.8.3+ together with react-redux from 6 till 7.1+ for this.

# Conflicts:
#	src/components/ChallengeEditor/ChallengeView/index.js
#	src/components/ChallengeEditor/index.js
When switching from "view" to "edit".
@vikasrohit
Copy link

Looks good to me. Will merge it to develop to test out feature in dev.

single reusable hook

What exact React construct you are referring here @maxceem? Could you please point me the docs, if it is something new feature that has recently enabled in latest react as you suggested.

@vikasrohit vikasrohit self-requested a review August 19, 2020 05:48
Copy link

@vikasrohit vikasrohit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxceem can you please share a quick pros and cons list for making the SelectUserAutocomplete self sufficient instead of using the redux actions.

@vikasrohit vikasrohit merged commit 1119aeb into topcoder-platform:develop Aug 19, 2020
@maxceem
Copy link
Contributor Author

maxceem commented Aug 19, 2020

@vikasrohit

What exact React construct you are referring here @maxceem?

In the recent version of react-redux there is a new hook useSelector which let us connect to the store from inside the functional component from anywhere.

At the moment, to get member details, we have to pass members from the redux store down to every component where we want to display details. If we could use useSelector we could create a hook which would return user details from Redux Store without any additional code like this:

function SomeComponentDeepInside() {
  // we create custom hook `useMemberDetails` that will take details about the user with id `123456` 
  // from ReduxStore and put it into `memberDetails`
  // so we can just use them inside this component
  // if member details are not loaded yet, `useMemberDetails` would trigger loading of user details, 
  // and would update `memberDetails` as soon as details are loaded
  const memberDetails = useMemberDetails(123456) 
}

Could you please point me the docs, if it is something new feature that has recently enabled in latest react as you suggested.

The new version of react-redux which has useSelector hook requires React 16.8.3+, not sure what exactly it uses from the recent React.

@maxceem
Copy link
Contributor Author

maxceem commented Aug 19, 2020

@vikasrohit

@maxceem can you please share a quick pros and cons list for making the SelectUserAutocomplete self sufficient instead of using the redux actions.

Pros (not using Redux)

  • The biggest pros, is that using local component state we can have multiple instances of this component at the same time. If we use Redux Store, we would only support one instance on the page, as we would have only one place in Store to keep the state of this component.
    store: {
       suggestions: [...]
    }
    Theoretically, we could fix it, and generate unique id for each instance of this component and save states for multiple components, but it would make the code more complex:
    store: {
       suggestionInstances: {
         uid123: [...]
         uid456: [...]
       }
    }
  • Another thing, we would have to "spread" the code of so small component across the multiple files: actions, reducers, views, containers. So small and clear code would become big and harder to understand.

Cons (not using Redux)

  • The biggest cons of not using redux/actions: If everyone decides how to implement things, eventually code would become too diverse. If we use Redux for everything we keep consistency and structure.

TLDR for small local states it makes sense not to use Redux Store and keep data in Redux only for main global things like pages.

@maxceem maxceem mentioned this pull request Aug 19, 2020
@vikasrohit
Copy link

In the recent version of react-redux there is a new hook useSelector which let us connect to the store from inside the functional component from anywhere.

Interesting. Thanks for sharing, didn't know it.

for small local states it makes sense not to use Redux Store and keep data in Redux only for main global things like pages.

Thanks for sharing it as well. I was having the same concept in my mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants