diff --git a/webapp/src/components/rhs_sidebar/index.js b/webapp/src/components/rhs_sidebar/index.js index 447c8fb5..020d9b0d 100644 --- a/webapp/src/components/rhs_sidebar/index.js +++ b/webapp/src/components/rhs_sidebar/index.js @@ -11,7 +11,7 @@ import { } from '../../actions'; import {getPluginServerRoute} from '../../selectors'; -import RHSSidebar from './rhs_sidebar.jsx'; +import RHSSidebar from './rhs_sidebar'; const noSubscriptions = []; diff --git a/webapp/src/components/rhs_sidebar/rhs_sidebar.jsx b/webapp/src/components/rhs_sidebar/rhs_sidebar.tsx similarity index 73% rename from webapp/src/components/rhs_sidebar/rhs_sidebar.jsx rename to webapp/src/components/rhs_sidebar/rhs_sidebar.tsx index 44166f35..d9eba46c 100644 --- a/webapp/src/components/rhs_sidebar/rhs_sidebar.jsx +++ b/webapp/src/components/rhs_sidebar/rhs_sidebar.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import PropTypes from 'prop-types'; import {isDesktopApp} from 'src/utils/user_agent'; import {connectUsingBrowserMessage} from 'src/constants'; @@ -9,8 +8,8 @@ import NoSubscriptionsSVG from './no_subscriptions'; import './rhs_sidebar.css'; -const NotSignedIn = (props) => { - const openConnectWindow = (e) => { +const NotSignedIn = (props: NotSignedInProps) => { + const openConnectWindow = (e: React.MouseEvent) => { e.preventDefault(); if (isDesktopApp()) { props.sendEphemeralPost(connectUsingBrowserMessage); @@ -38,12 +37,12 @@ const NotSignedIn = (props) => { ); }; -NotSignedIn.propTypes = { - pluginServerRoute: PropTypes.string.isRequired, - sendEphemeralPost: PropTypes.func.isRequired, -}; +interface NotSignedInProps { + pluginServerRoute: string; + sendEphemeralPost: (message: string) => void; +} -const UserHeader = (props) => ( +const UserHeader = (props: UserHeaderProps) => (
(
); -UserHeader.propTypes = { - currentUserId: PropTypes.string.isRequired, - username: PropTypes.string.isRequired, - gitlabURL: PropTypes.string.isRequired, -}; +interface UserHeaderProps { + currentUserId: string; + username?: string; + gitlabURL?: string; +} -const Subscription = (props) => { +const Subscription = (props: SubscriptionProps) => { return (
@@ -91,13 +90,13 @@ const Subscription = (props) => { ); }; -Subscription.propTypes = { - url: PropTypes.string.isRequired, - name: PropTypes.string.isRequired, - features: PropTypes.arrayOf(PropTypes.string).isRequired, -}; +interface SubscriptionProps { + url: string; + name: string; + features: string[]; +} -const Subscriptions = (props) => { +const Subscriptions = (props: SubscriptionsProps) => { if (props.subscriptions.length === 0) { return (
@@ -125,34 +124,37 @@ const Subscriptions = (props) => { ); }; -Subscriptions.propTypes = { - currentChannelId: PropTypes.string, - subscriptions: PropTypes.arrayOf(PropTypes.shape({ - repository_name: PropTypes.string.isRequired, - repository_url: PropTypes.string.isRequired, - })).isRequired, -}; +interface SubscriptionsProps { + currentChannelId?: string; + subscriptions: Subscription[]; +} -export default class RHSSidebar extends React.PureComponent { - static propTypes = { - currentUserId: PropTypes.string.isRequired, - connected: PropTypes.bool.isRequired, - username: PropTypes.string, - gitlabURL: PropTypes.string, - currentChannelId: PropTypes.string, - currentChannelSubscriptions: PropTypes.arrayOf(PropTypes.shape({ - repository_name: PropTypes.string, - repository_url: PropTypes.string, - features: PropTypes.arrayOf(PropTypes.string), - })).isRequired, - pluginServerRoute: PropTypes.string.isRequired, - actions: PropTypes.shape({ - getChannelSubscriptions: PropTypes.func.isRequired, - sendEphemeralPost: PropTypes.func.isRequired, - }).isRequired, - }; +interface Subscription { + repository_name: string; + repository_url: string; + features: string[]; +} + +interface RhsSidebarProps { + currentUserId: string, + connected: boolean, + username?: string, + gitlabURL?: string, + currentChannelId?: string, + currentChannelSubscriptions: Partial[], + pluginServerRoute: string, + actions: { + getChannelSubscriptions: (channel: string) => Promise, + sendEphemeralPost: (message: string) => void; + } +} + +interface RhsSidebarState { + refreshing: boolean; +} - constructor(props) { +export default class RHSSidebar extends React.PureComponent { + constructor(props: RhsSidebarProps) { super(props); this.state = { @@ -166,13 +168,13 @@ export default class RHSSidebar extends React.PureComponent { } } - componentDidUpdate(prevProps) { + componentDidUpdate(prevProps: RhsSidebarProps) { if ((this.props.connected && !prevProps.connected) || (this.props.currentChannelId !== prevProps.currentChannelId)) { this.getData(); } } - getData = async (e) => { + getData = async (e?: React.MouseEvent): Promise => { if (this.state.refreshing) { return; } @@ -182,7 +184,7 @@ export default class RHSSidebar extends React.PureComponent { } this.setState({refreshing: true}); - await this.props.actions.getChannelSubscriptions(this.props.currentChannelId); + await this.props.actions.getChannelSubscriptions(this.props.currentChannelId as string); this.setState({refreshing: false}); } @@ -205,7 +207,7 @@ export default class RHSSidebar extends React.PureComponent { />
);