Skip to content

Commit

Permalink
Merge pull request #6978 from TheThingsNetwork/feature/6950-collabora…
Browse files Browse the repository at this point in the history
…tor-complement

Complement collaborators
  • Loading branch information
PavelJankoski authored Mar 11, 2024
2 parents 56e4c3b + af8e074 commit ed1a5f8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ For details about compatibility between different releases, see the **Commitment

### Changed

- Searching for collaborators displays only accounts that are not already attached to the entity's collaborator list.

### Deprecated

### Removed
Expand Down
21 changes: 16 additions & 5 deletions pkg/webui/console/containers/account-select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SingleValue.propTypes = {
}).isRequired,
}

const Suggest = ({ entity, ...rest }) => {
const Suggest = ({ entity, entityId, ...rest }) => {
const dispatch = useDispatch()
const searchResults = useSelector(selectSearchResultAccountIds)
const searchResultsRef = useRef()
Expand All @@ -55,12 +55,16 @@ const Suggest = ({ entity, ...rest }) => {
() => formatMessage(sharedMessages.noMatchingUserFound),
[formatMessage],
)
const collaboratorOf = {
path: `${entity}_ids.${entity}_id`,
id: entityId,
}
const onlyUsers = entity === 'organization'

const handleLoadingOptions = useCallback(
async value => {
if (value.length >= 1) {
await dispatch(attachPromise(searchAccounts(value, onlyUsers)))
await dispatch(attachPromise(searchAccounts(value, onlyUsers, collaboratorOf)))
const newOptions = searchResultsRef.current.map(account => ({
value:
'user_ids' in account
Expand All @@ -85,7 +89,7 @@ const Suggest = ({ entity, ...rest }) => {
return translatedOptions
}
},
[dispatch, searchResultsRef, formatMessage, onlyUsers],
[dispatch, onlyUsers, collaboratorOf, formatMessage],
)

return (
Expand All @@ -106,14 +110,21 @@ const Suggest = ({ entity, ...rest }) => {

Suggest.propTypes = {
entity: PropTypes.string.isRequired,
entityId: PropTypes.string.isRequired,
}

const AccountSelect = ({ entity, ...rest }) => (
<Suggest {...rest} className={styles.userSelect} entity={entity.toLowerCase()} />
const AccountSelect = ({ entity, entityId, ...rest }) => (
<Suggest
{...rest}
className={styles.userSelect}
entity={entity.toLowerCase()}
entityId={entityId}
/>
)

AccountSelect.propTypes = {
entity: PropTypes.string.isRequired,
entityId: PropTypes.string.isRequired,
}

export default AccountSelect
1 change: 1 addition & 0 deletions pkg/webui/containers/collaborator-form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ const CollaboratorForm = props => {
autoFocus={!update}
disabled={update}
entity={entity}
entityId={entityId}
encode={encodeCollaborator}
decode={decodeCollaborator}
/>
Expand Down
9 changes: 3 additions & 6 deletions pkg/webui/containers/collaborator-select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,14 @@ const Suggest = ({
() => formatMessage(sharedMessages.noMatchingUserFound),
[formatMessage],
)
const collaboratorOf = {
path: `${entity}_ids.${entity}_id`,
id: entityId,
}

const onlyUsers = entity === 'organization'

const handleLoadingOptions = useCallback(
async value => {
if (Boolean(value)) {
try {
await dispatch(attachPromise(searchAccounts(value, onlyUsers, collaboratorOf)))
await dispatch(attachPromise(searchAccounts(value, onlyUsers)))
setShowSuggestions(searchResultsRef?.current?.length !== 0)
const newOptions = searchResultsRef?.current?.map(account => ({
value:
Expand Down Expand Up @@ -137,7 +134,7 @@ const Suggest = ({
}
}
},
[dispatch, onlyUsers, searchResultsRef, collaboratorOf, formatMessage],
[dispatch, onlyUsers, searchResultsRef, formatMessage],
)

const handleSetYourself = useCallback(
Expand Down
1 change: 1 addition & 0 deletions pkg/webui/lib/store/middleware/search-accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default tts => {
}
if (Boolean(collaboratorOf)) {
request[collaboratorOf.path] = collaboratorOf.id
request.complement_collaborators = true
}

return await tts.SearchAccounts.searchAccounts(request)
Expand Down

0 comments on commit ed1a5f8

Please sign in to comment.