Add autocomplete to add members to a group by name#40
Add autocomplete to add members to a group by name#40mgorkove wants to merge 4 commits intokernel-community:mainfrom
Conversation
simonkernel
left a comment
There was a problem hiding this comment.
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.
nit: just destructure in args -
export default function AutocompleteInput({ items, selectedItems, setSelectedItems }) {
| {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.
nit: break up line so it's more readable
| /> | ||
| {selectedItems.length > 0 && ( | ||
| <div className='flex mt-1'> | ||
| {selectedItems.map((item) => ( |
There was a problem hiding this comment.
nit: destructure item
...map(({ id, name }=> (
| 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.
nit: no need to create a temporary array and can just map directly
... => Object.values(profiles).map(({ data: { memberId, name }}) => ({ id: memberId, name }))
| 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.
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
| const filteredItems = | ||
| query === '' | ||
| ? items | ||
| : items.filter((item) => { |
There was a problem hiding this comment.
nit: shorten to
items.filter(({ name }) => name.toLowerCase().includes(query.toLowerCase()))
|
|
||
| return ( | ||
| <Combobox value={selectedItems} onChange={setSelectedItems} multiple> | ||
| <Combobox.Input |
There was a problem hiding this comment.
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.
Needs to support the case when a member is added by id instead of name.
| const { group, groups, groupMembers, name, taskService } = state | ||
| const groupId = group.id | ||
| const memberIds = textToArray(memberIdsText) | ||
| const memberIds = getMemberIds(groupMembers) |
package.json
Outdated
| "license": "MIT" | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "@heroicons/react": "^1.0.6" |
There was a problem hiding this comment.
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.
@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