diff --git a/package-lock.json b/package-lock.json index a6feeae85e..4aa287078b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16253,9 +16253,9 @@ } }, "superdesk-ui-framework": { - "version": "3.0.53", - "resolved": "https://registry.npmjs.org/superdesk-ui-framework/-/superdesk-ui-framework-3.0.53.tgz", - "integrity": "sha512-A6j/vVP5EzN5tcfHYJCtXsInySiCYGs+L4WmrJplTboLuGPZ3vhHtivzm/LZqx+kk4N/u7JedmGqSMl6z6K5dQ==", + "version": "3.0.54", + "resolved": "https://registry.npmjs.org/superdesk-ui-framework/-/superdesk-ui-framework-3.0.54.tgz", + "integrity": "sha512-wWtx2AEJUEShU7v60KteMcPW+vfP0iI3KDnWxnBxsNm6Y7T/nT2ROrd2U5dM/fjNt41jJEiP+AD7mN3ykX8Q4g==", "requires": { "@material-ui/lab": "^4.0.0-alpha.56", "@popperjs/core": "^2.4.0", diff --git a/package.json b/package.json index 0ac30ed85a..b6e8448e6f 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "sass-loader": "6.0.6", "shortid": "2.2.8", "style-loader": "0.20.2", - "superdesk-ui-framework": "^3.0.53", + "superdesk-ui-framework": "^3.0.54", "ts-loader": "3.5.0", "tslint": "5.11.0", "typescript": "~4.9.5", diff --git a/scripts/apps/dashboard/user-activity/components/UserActivityWidget.tsx b/scripts/apps/dashboard/user-activity/components/UserActivityWidget.tsx index cefbffc3cc..f4d142b8db 100644 --- a/scripts/apps/dashboard/user-activity/components/UserActivityWidget.tsx +++ b/scripts/apps/dashboard/user-activity/components/UserActivityWidget.tsx @@ -346,12 +346,13 @@ export default class UserActivityWidget extends React.Component >
{ this.props.onUserChange(user); }} horizontalSpacing={true} + clearable={false} /> diff --git a/scripts/core/superdesk-api.d.ts b/scripts/core/superdesk-api.d.ts index c70559391a..3c02189f74 100644 --- a/scripts/core/superdesk-api.d.ts +++ b/scripts/core/superdesk-api.d.ts @@ -1176,6 +1176,8 @@ declare module 'superdesk-api' { disabled?: boolean; autoFocus?: boolean; horizontalSpacing?: boolean; + valueTemplate?: React.ComponentType<{option: IUser}>; + clearable: boolean; } export interface IDropdownTreeGroup { diff --git a/scripts/core/ui/components/SelectUser.tsx b/scripts/core/ui/components/SelectUser.tsx index c1bf37e808..c0f5b49572 100644 --- a/scripts/core/ui/components/SelectUser.tsx +++ b/scripts/core/ui/components/SelectUser.tsx @@ -1,8 +1,9 @@ +/* eslint-disable react/no-multi-comp */ import React from 'react'; import {IPropsSelectUser, IUser, IRestApiResponse} from 'superdesk-api'; import {gettext, getUserSearchMongoQuery} from 'core/utils'; import {UserAvatar} from 'apps/users/components/UserAvatar'; -import {SelectWithTemplate} from 'superdesk-ui-framework/react'; +import {SelectWithTemplate, Spacer} from 'superdesk-ui-framework/react'; import {httpRequestJsonLocal} from 'core/helpers/network'; import {SuperdeskReactComponent} from 'core/SuperdeskReactComponent'; @@ -10,6 +11,52 @@ interface IState { selectedUser: IUser | null | 'loading'; } +const itemTemplate = (props: {option: IUser}) => { + const user: IUser | null = props.option; + + return user == null + ? ( +
+ {gettext('Select a user')} +
+ ) + : ( + + +
+ +
+ + +
{user.display_name}
+
@{user.username}
+
+ +
+ +
{user.sign_off}
+
+ ); +}; + +const valueTemplateDefault = (props: {option: IUser}) => { + const user: IUser | null = props.option; + + return user == null + ? ( +
+ {gettext('Select a user')} +
+ ) + : ( + + + + {user.display_name} + + ); +}; + export class SelectUser extends SuperdeskReactComponent { constructor(props: IPropsSelectUser) { super(props); @@ -37,24 +84,26 @@ export class SelectUser extends SuperdeskReactComponent({ - method: 'GET', - path: `/users/${this.props.selectedUserId}`, - }).then((selectedUser) => { + if (prevProps.selectedUserId !== this.props.selectedUserId) { + // state.user needs to be updated if props.selectedUserId changes + if (this.props.selectedUserId == null) { // eslint-disable-next-line react/no-did-update-set-state - this.setState({selectedUser}); - }); + this.setState({selectedUser: null}); + } else if ( + this.state.selectedUser === 'loading' + || this.state.selectedUser?._id !== this.props.selectedUserId + ) { + // eslint-disable-next-line react/no-did-update-set-state + this.setState({selectedUser: 'loading'}); + + this.asyncHelpers.httpRequestJsonLocal({ + method: 'GET', + path: `/users/${this.props.selectedUserId}`, + }).then((selectedUser) => { + // eslint-disable-next-line react/no-did-update-set-state + this.setState({selectedUser}); + }); + } } } @@ -63,6 +112,8 @@ export class SelectUser extends SuperdeskReactComponent option.display_name} - itemTemplate={ - (props) => { - const user = props.option; - - return user == null - ? ( -
- {gettext('Select a user')} -
- ) - : ( -
- -
-
{user.display_name}
-
@{user.username}
-
-
- ); - } - } + itemTemplate={itemTemplate} + valueTemplate={valueTemplate} areEqual={(a, b) => a._id === b._id} autoFocus={this.props.autoFocus} autoOpen={this.state.selectedUser == null} @@ -137,7 +169,7 @@ export class SelectUser extends SuperdeskReactComponent ); } diff --git a/scripts/core/utils.ts b/scripts/core/utils.ts index 7f8a91971a..bc18522b17 100644 --- a/scripts/core/utils.ts +++ b/scripts/core/utils.ts @@ -187,6 +187,7 @@ export function getUserSearchMongoQuery(searchString: string) { {first_name: {$regex: searchString, $options: '-i'}}, {last_name: {$regex: searchString, $options: '-i'}}, {email: {$regex: searchString, $options: '-i'}}, + {sign_off: {$regex: searchString, $options: '-i'}}, ], }; } diff --git a/scripts/extensions/markForUser/src/get-mark-for-user-modal.tsx b/scripts/extensions/markForUser/src/get-mark-for-user-modal.tsx index e7959a29b2..ae9e1adcda 100644 --- a/scripts/extensions/markForUser/src/get-mark-for-user-modal.tsx +++ b/scripts/extensions/markForUser/src/get-mark-for-user-modal.tsx @@ -78,6 +78,7 @@ export function getMarkForUserModal(options: { onSelect={(selectedUser) => this.setState({selectedUserId: selectedUser._id})} selectedUserId={this.state.selectedUserId} autoFocus={true} + clearable={false} />