Skip to content

Commit

Permalink
Merge pull request #981 from NERC-CEH/ED-111-emails-dropdown
Browse files Browse the repository at this point in the history
Hide e-mails in autocomplete of Project Settings ED-111
  • Loading branch information
iwalmsley authored Jun 24, 2024
2 parents f3fbfba + 9276cb0 commit b8d2726
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
29 changes: 18 additions & 11 deletions code/workspaces/web-app/src/components/common/input/UserSelect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import Autocomplete from '@mui/material/Autocomplete';
import CircularProgress from '@mui/material/CircularProgress';
Expand All @@ -14,19 +14,26 @@ const useStyles = makeStyles(theme => ({
},
}));

const UserSelect = ({ selectedUsers, setSelectedUsers, label, placeholder, multiselect = false, userSelectedToolTip = 'User Selected', ...otherProps }) => {
const UserSelect = ({ selectedUsers, setSelectedUsers, label, placeholder, multiselect = false, userSelectedToolTip = 'User Selected', isDropdownHidden = false, ...otherProps }) => {
const { value: users, fetching: loading } = useUsersSortedByName();
const [currentInput, setCurrentInput] = useState('');

return (
<Autocomplete
{...otherProps}
filterOptions={options => options.filter(opt => (isDropdownHidden ? opt.name === currentInput : opt.name.includes(currentInput)))}
multiple={multiselect}
freeSolo={true}
options={users}
getOptionLabel={getOptionLabel}
isOptionEqualToValue={val => (multiselect ? selectedUsers.includes(val) : selectedUsers === val)}
value={selectedUsers}
onInputChange={(event, newValue) => setSelectedUsers({ name: newValue, userId: newValue })}
onInputChange={(event, newValue) => {
setCurrentInput(newValue);
if (isDropdownHidden) {
setSelectedUsers({ name: newValue, userId: newValue });
}
}}
onChange={(event, newValue) => setSelectedUsers(newValue)}
loading={loading}
autoHighlight
Expand Down Expand Up @@ -69,14 +76,14 @@ export const Option = ({ option, selected, userSelectedToolTip }) => {
<>
{getOptionLabel(option)}
{selected
&& <Tooltip title={userSelectedToolTip} placement="right">
<CheckCircleRoundedIcon
className={classes.userSelectedIcon}
titleAccess={userSelectedToolTip}
color="primary"
fontSize="small"
/>
</Tooltip>
&& <Tooltip title={userSelectedToolTip} placement="right">
<CheckCircleRoundedIcon
className={classes.userSelectedIcon}
titleAccess={userSelectedToolTip}
color="primary"
fontSize="small"
/>
</Tooltip>
}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function PureAddUserPermission({
setSelectedUsers={setSelectedUser}
label="Add User"
placeholder="Type user's email..."
isDropdownHidden={true}
/>
<PermissionsSelector
className={classes.permissionsSelector}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ exports[`AddUserPermissions renders pure component with correct props 1`] = `
>
<div>
UserSelect mock
{"className":"AddUserPermission-usersAutofill-5","selectedUsers":null,"label":"Add User","placeholder":"Type user's email..."}
{"className":"AddUserPermission-usersAutofill-5","selectedUsers":null,"label":"Add User","placeholder":"Type user's email...","isDropdownHidden":true}
</div>
<div
class="MuiFormControl-root MuiFormControl-marginDense MuiTextField-root AddUserPermission-permissionsSelector-4 css-4mzek5-MuiFormControl-root-MuiTextField-root"
Expand Down Expand Up @@ -235,7 +235,7 @@ exports[`PureAddUserPermission renders to match snapshot 1`] = `
>
<div>
UserSelect mock
{"className":"usersAutofill","selectedUsers":{"name":"Test User One","userId":"test-user-one"},"label":"Add User","placeholder":"Type user's email..."}
{"className":"usersAutofill","selectedUsers":{"name":"Test User One","userId":"test-user-one"},"label":"Add User","placeholder":"Type user's email...","isDropdownHidden":true}
</div>
<div
class="MuiFormControl-root MuiFormControl-marginDense MuiTextField-root permissionsSelector css-4mzek5-MuiFormControl-root-MuiTextField-root"
Expand Down

0 comments on commit b8d2726

Please sign in to comment.