Skip to content
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

Add autocomplete to add members to a group by name #40

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mgorkove
Copy link
Collaborator

Screen.Recording.2022-06-14.at.5.44.46.PM.mov

@mgorkove mgorkove requested a review from rorysaur June 15, 2022 20:34
Copy link
Contributor

@simonkernel simonkernel left a comment

Choose a reason for hiding this comment

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

Hi @mgorkove,

Thanks for working on this!

Just a few smaller nits, the linter had some feedback, and then one main comment is -

The query service can throw for the cases where the user has either no profile or has not consented to sharing their data.

This has the following implications -

  • need to try/catch
  • need to still accommodate adding users by member ids directly

Let me know if the comments aren't sufficient and you have more questions!

import { Combobox } from '@headlessui/react'
import { XIcon } from '@heroicons/react/outline'

export default function AutocompleteInput(props) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: just destructure in args -

export default function AutocompleteInput({ items, selectedItems, setSelectedItems }) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

{selectedItems.length > 0 && (
<div className='flex mt-1'>
{selectedItems.map((item) => (
<div key={item.id} className='flex p-1 border-solid border-2 border-gray-300 rounded-md mr-2'>{item.name} <XIcon className='w-4 ml-3' onClick={() => removeSelectedItem(item.id)}/></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: break up line so it's more readable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

/>
{selectedItems.length > 0 && (
<div className='flex mt-1'>
{selectedItems.map((item) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: destructure item

...map(({ id, name }=> (

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

const getMemberIds = (groupMembers) => groupMembers.map(groupMember => groupMember.id)
const transformProfiles = (profiles) => {
const out = []
for (const [, v] of Object.entries(profiles)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: no need to create a temporary array and can just map directly

... => Object.values(profiles).map(({ data: { memberId, name }}) => ({ id: memberId, name }))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

dispatch({ type: 'taskService', payload: taskService })
const members = await entityFactory({ resource: 'member' })
const member = await members.get(user.iss)
const groups = await entityFactory({ resource: 'group' })
const { profiles } = await queryService.recommend()
Copy link
Contributor

Choose a reason for hiding this comment

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

This can throw an exception when the user making this call either has no profile or did not consent to sharing their data [0]

We should wrap this call in a try/catch to not break the app.

[0] https://github.com/kernel-community/services/blob/main/packages/query/src/services/query.js#L58

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

const filteredItems =
query === ''
? items
: items.filter((item) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: shorten to

items.filter(({ name }) => name.toLowerCase().includes(query.toLowerCase()))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


return (
<Combobox value={selectedItems} onChange={setSelectedItems} multiple>
<Combobox.Input
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to allow for custom values so we can still add members by id only [0]

[0] https://headlessui.dev/react/combobox#allowing-custom-values

const memberIds = textToArray(memberIdsText)
if (!name.length || !memberIdsText.length) {
const { groups, groupMembers, name, taskService } = state
const memberIds = getMemberIds(groupMembers)
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to support the case when a member is added by id instead of name.

const groupId = group.id
const memberIds = textToArray(memberIdsText)
const memberIds = getMemberIds(groupMembers)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

package.json Outdated
"license": "MIT"
"license": "MIT",
"dependencies": {
"@heroicons/react": "^1.0.6"
Copy link
Contributor

Choose a reason for hiding this comment

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

how useful do we think this library is in the future?

we should debate any additional dependency and ensure there is significant value as a whole outweighing the risks of an added dep.

alternatively, if we think we just need this one SVG, we can always just copy it over directly into the repo and later add the dep if we end up using a lot of different icons.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

@mgorkove
Copy link
Collaborator Author

Hi @mgorkove,

Thanks for working on this!

Just a few smaller nits, the linter had some feedback, and then one main comment is -

The query service can throw for the cases where the user has either no profile or has not consented to sharing their data.

This has the following implications -

  • need to try/catch
  • need to still accommodate adding users by member ids directly

Let me know if the comments aren't sufficient and you have more questions!

@simonkernel do we really need to accommodate still adding by member ids directly? Wasn't the whole point of the autocomplete to be able to get rid of that?

@mgorkove mgorkove force-pushed the autocomplete branch 2 times, most recently from 849eab9 to df6c3d4 Compare June 19, 2022 06:58
@mgorkove mgorkove force-pushed the autocomplete branch 2 times, most recently from e19dc1c to 1e6b10e Compare June 20, 2022 02:16
@simonkernel
Copy link
Contributor

Hi @mgorkove,

Yes we do need adding members by id. Also, we actually also need to display the member id so members with the same name can be distinguished. We can just add it in parentheses ex Rory (1234567).

Thanks,
Simon

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