X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/38d27e9783f7f760cee84cc225e86144069848c4..c872f6b8420d83f2b378a274c412e3bc1865cd8c:/src/views-components/sharing-dialog/participant-select.tsx diff --git a/src/views-components/sharing-dialog/participant-select.tsx b/src/views-components/sharing-dialog/participant-select.tsx index 402faa7f..02cdeaf2 100644 --- a/src/views-components/sharing-dialog/participant-select.tsx +++ b/src/views-components/sharing-dialog/participant-select.tsx @@ -11,12 +11,13 @@ import { debounce } from 'debounce'; import { ListItemText, Typography } from '@material-ui/core'; import { noop } from 'lodash/fp'; import { GroupClass, GroupResource } from 'models/group'; -import { getUserDisplayName, UserResource } from 'models/user'; +import { getUserDetailsString, getUserDisplayName, UserResource } from 'models/user'; import { Resource, ResourceKind } from 'models/resource'; import { ListResults } from 'services/common-service/common-service'; export interface Participant { name: string; + tooltip: string; uuid: string; } @@ -24,9 +25,12 @@ type ParticipantResource = GroupResource | UserResource; interface ParticipantSelectProps { items: Participant[]; + excludedParticipants?: string[]; label?: string; autofocus?: boolean; onlyPeople?: boolean; + onlyActive?: boolean; + disabled?: boolean; onBlur?: (event: React.FocusEvent) => void; onFocus?: (event: React.FocusEvent) => void; @@ -40,12 +44,23 @@ interface ParticipantSelectState { suggestions: ParticipantResource[]; } -const getDisplayName = (item: GroupResource | UserResource) => { +const getDisplayName = (item: GroupResource | UserResource, detailed: boolean) => { switch (item.kind) { case ResourceKind.USER: - return getUserDisplayName(item, true); + return getUserDisplayName(item, detailed, detailed); case ResourceKind.GROUP: - return item.name; + return item.name + `(${`(${(item as Resource).uuid})`})`; + default: + return (item as Resource).uuid; + } +}; + +const getDisplayTooltip = (item: GroupResource | UserResource) => { + switch (item.kind) { + case ResourceKind.USER: + return getUserDetailsString(item); + case ResourceKind.GROUP: + return item.name + `(${`(${(item as Resource).uuid})`})`; default: return (item as Resource).uuid; } @@ -71,11 +86,13 @@ export const ParticipantSelect = connect()( onChange={this.handleChange} onCreate={this.handleCreate} onSelect={this.handleSelect} - onDelete={this.handleDelete} + onDelete={this.props.onDelete && !this.props.disabled ? this.handleDelete : undefined} onFocus={this.props.onFocus} onBlur={this.props.onBlur} renderChipValue={this.renderChipValue} - renderSuggestion={this.renderSuggestion} /> + renderChipTooltip={this.renderChipTooltip} + renderSuggestion={this.renderSuggestion} + disabled={this.props.disabled}/> ); } @@ -84,10 +101,14 @@ export const ParticipantSelect = connect()( return name || uuid; } + renderChipTooltip(item: Participant) { + return item.tooltip; + } + renderSuggestion(item: ParticipantResource) { return ( - {getDisplayName(item)} + {getDisplayName(item, true)} ); } @@ -103,6 +124,7 @@ export const ParticipantSelect = connect()( this.setState({ value: '', suggestions: [] }); onCreate({ name: '', + tooltip: '', uuid: this.state.value, }); } @@ -113,7 +135,8 @@ export const ParticipantSelect = connect()( const { onSelect = noop } = this.props; this.setState({ value: '', suggestions: [] }); onSelect({ - name: getDisplayName(selection), + name: getDisplayName(selection, false), + tooltip: getDisplayTooltip(selection), uuid, }); } @@ -130,11 +153,14 @@ export const ParticipantSelect = connect()( const filterUsers = new FilterBuilder() .addILike('any', value) + .addEqual('is_active', this.props.onlyActive || undefined) + .addNotIn('uuid', this.props.excludedParticipants) .getFilters(); const userItems: ListResults = await userService.list({ filters: filterUsers, limit, count: "none" }); const filterGroups = new FilterBuilder() .addNotIn('group_class', [GroupClass.PROJECT, GroupClass.FILTER]) + .addNotIn('uuid', this.props.excludedParticipants) .addILike('name', value) .getFilters();