Skip to content

Commit

Permalink
[GH-12442] Convert profile_picture and related test to typescript (ma…
Browse files Browse the repository at this point in the history
…ttermost#3876)

* Convert profile_picture and related test to typescript
* Add ImageSize enum to `types/images.d.ts
* Use createRef instead of deprecated refs access in profile_picture component
Fixes mattermost/mattermost#12442

* Update package-lock.json

* Remove ImageSize enum because change is greater in scope and opinionated

* Revert size prop to string to avoid a lot of casting

* Update snapshot

* Fix snapshot

* Revert unrelated changes to package-lock.json
  • Loading branch information
steevsachs authored and devinbinnie committed Oct 10, 2019
1 parent 97401e0 commit 08b5a4d
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ exports[`components/ProfilePicture should match snapshot, profile and src, defau
>
<button
className="status-wrapper style--none "
tabIndex="-1"
tabIndex={-1}
>
<span
className="profile-icon "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import {Client4} from 'mattermost-redux/client';

import ProfilePicture from 'components/profile_picture.jsx';
import ProfilePicture from 'components/profile_picture';
import * as Utils from 'utils/utils.jsx';

import './admin_user_card.scss';
Expand Down
2 changes: 1 addition & 1 deletion components/channel_invite_modal/channel_invite_modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Client4} from 'mattermost-redux/client';
import {filterProfilesMatchingTerm} from 'mattermost-redux/utils/user_utils';

import {displayEntireNameForUser, localizeMessage, isGuest} from 'utils/utils.jsx';
import ProfilePicture from 'components/profile_picture.jsx';
import ProfilePicture from 'components/profile_picture';
import MultiSelect from 'components/multiselect/multiselect.jsx';
import AddIcon from 'components/widgets/icons/fa_add_icon';
import GuestBadge from 'components/widgets/badges/guest_badge';
Expand Down
2 changes: 1 addition & 1 deletion components/more_direct_channels/more_direct_channels.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {browserHistory} from 'utils/browser_history';
import Constants from 'utils/constants.jsx';
import {displayEntireNameForUser, localizeMessage, isGuest} from 'utils/utils.jsx';
import MultiSelect from 'components/multiselect/multiselect.jsx';
import ProfilePicture from 'components/profile_picture.jsx';
import ProfilePicture from 'components/profile_picture';
import AddIcon from 'components/widgets/icons/fa_add_icon';
import GuestBadge from 'components/widgets/badges/guest_badge';
import BotBadge from 'components/widgets/badges/bot_badge';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Permissions} from 'mattermost-redux/constants';
import {Constants, ModalIdentifiers} from 'utils/constants';
import ChannelInviteModal from 'components/channel_invite_modal';
import EditChannelHeaderModal from 'components/edit_channel_header_modal';
import ProfilePicture from 'components/profile_picture.jsx';
import ProfilePicture from 'components/profile_picture';
import ToggleModalButtonRedux from 'components/toggle_modal_button_redux';
import ToggleModalButton from 'components/toggle_modal_button.jsx';
import UserProfile from 'components/user_profile';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react';
import {shallow} from 'enzyme';

import ProfilePicture from 'components/profile_picture.jsx';
import ProfilePicture from 'components/profile_picture';

describe('components/ProfilePicture', () => {
const baseProps = {
Expand Down
51 changes: 29 additions & 22 deletions components/profile_picture.jsx → components/profile_picture.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import PropTypes from 'prop-types';
import React from 'react';
import {OverlayTrigger} from 'react-bootstrap';

import ProfilePopover from 'components/profile_popover';
import StatusIcon from 'components/status_icon';
import Avatar from 'components/widgets/users/avatar';

export default class ProfilePicture extends React.PureComponent {
static defaultProps = {
interface MMOverlayTrigger extends OverlayTrigger {
hide: () => void;
}

type Props = {
hasMention?: boolean;
isBusy?: boolean;
isEmoji?: boolean;
isRHS?: boolean;
profileSrc?: string;
size: string;
src: string;
status?: string;
userId?: string;
username?: string;
wrapperClass?: string;
}

export default class ProfilePicture extends React.PureComponent<Props> {
public overlay = React.createRef<MMOverlayTrigger>();

public static defaultProps = {
size: 'md',
isRHS: false,
isEmoji: false,
hasMention: false,
wrapperClass: '',
};

static propTypes = {
src: PropTypes.string.isRequired,
profileSrc: PropTypes.string,
status: PropTypes.string,
size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', 'xxl']),
userId: PropTypes.string,
username: PropTypes.string,
isBusy: PropTypes.bool,
isRHS: PropTypes.bool,
hasMention: PropTypes.bool,
isEmoji: PropTypes.bool,
wrapperClass: PropTypes.string,
};

hideProfilePopover = () => {
this.refs.overlay.hide();
public hideProfilePopover = () => {
if (this.overlay.current && typeof this.overlay.current.hide === 'function') {
this.overlay.current.hide();
}
}

render() {
public render() {
// profileSrc will, if possible, be the original user profile picture even if the icon
// for the post is overriden, so that the popup shows the user identity
const profileSrc = (typeof this.props.profileSrc === 'string' && this.props.profileSrc !== '') ?
Expand All @@ -48,7 +55,7 @@ export default class ProfilePicture extends React.PureComponent {
if (this.props.userId) {
return (
<OverlayTrigger
ref='overlay'
ref={this.overlay}
trigger='click'
placement='right'
rootClose={true}
Expand All @@ -65,7 +72,7 @@ export default class ProfilePicture extends React.PureComponent {
>
<button
className={`status-wrapper style--none ${this.props.wrapperClass}`}
tabIndex='-1'
tabIndex={-1}
>
<span className={profileIconClass}>
<Avatar
Expand Down
2 changes: 1 addition & 1 deletion components/user_list_row/user_list_row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react';
import {Client4} from 'mattermost-redux/client';

import * as Utils from 'utils/utils.jsx';
import ProfilePicture from 'components/profile_picture.jsx';
import ProfilePicture from 'components/profile_picture';
import GuestBadge from 'components/widgets/badges/guest_badge';
import BotBadge from 'components/widgets/badges/bot_badge';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Link} from 'react-router-dom';
import {Client4} from 'mattermost-redux/client';

import * as Utils from 'utils/utils.jsx';
import ProfilePicture from 'components/profile_picture.jsx';
import ProfilePicture from 'components/profile_picture';
import BotBadge from 'components/widgets/badges/bot_badge';

import FormattedMarkdownMessage from 'components/formatted_markdown_message.jsx';
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"@storybook/addons": "5.2.1",
"@storybook/react": "5.2.1",
"@types/chart.js": "2.8.5",
"@types/react-bootstrap": "^0.32.20",
"@types/react-color": "3.0.1",
"@types/react-intl": "2.3.18",
"@typescript-eslint/eslint-plugin": "1.13.0",
Expand Down
2 changes: 1 addition & 1 deletion types/images.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// See LICENSE.txt for license information.

declare module '*.jpg';
declare module '*.png';
declare module '*.png';

0 comments on commit 08b5a4d

Please sign in to comment.