-
Notifications
You must be signed in to change notification settings - Fork 16
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
base: main
Are you sure you want to change the base?
Conversation
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.
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) { |
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.
nit: just destructure in args -
export default function AutocompleteInput({ items, selectedItems, setSelectedItems }) {
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.
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> |
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.
nit: break up line so it's more readable
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.
done
/> | ||
{selectedItems.length > 0 && ( | ||
<div className='flex mt-1'> | ||
{selectedItems.map((item) => ( |
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.
nit: destructure item
...map(({ id, name }=> (
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.
done
const getMemberIds = (groupMembers) => groupMembers.map(groupMember => groupMember.id) | ||
const transformProfiles = (profiles) => { | ||
const out = [] | ||
for (const [, v] of Object.entries(profiles)) { |
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.
nit: no need to create a temporary array and can just map directly
... => Object.values(profiles).map(({ data: { memberId, name }}) => ({ id: memberId, name }))
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.
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() |
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.
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
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.
done
const filteredItems = | ||
query === '' | ||
? items | ||
: items.filter((item) => { |
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.
nit: shorten to
items.filter(({ name }) => name.toLowerCase().includes(query.toLowerCase()))
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.
done
|
||
return ( | ||
<Combobox value={selectedItems} onChange={setSelectedItems} multiple> | ||
<Combobox.Input |
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.
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) |
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.
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) |
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.
ditto
package.json
Outdated
"license": "MIT" | ||
"license": "MIT", | ||
"dependencies": { | ||
"@heroicons/react": "^1.0.6" |
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.
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.
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.
removed
@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? |
849eab9
to
df6c3d4
Compare
e19dc1c
to
1e6b10e
Compare
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 Thanks, |
Screen.Recording.2022-06-14.at.5.44.46.PM.mov