Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert rhs_sidebar component to ts #527

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion webapp/src/components/rhs_sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../../actions';
import {getPluginServerRoute} from '../../selectors';

import RHSSidebar from './rhs_sidebar.jsx';
import RHSSidebar from './rhs_sidebar';

const noSubscriptions = [];

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<HTMLAnchorElement, MouseEvent>) => {
e.preventDefault();
if (isDesktopApp()) {
props.sendEphemeralPost(connectUsingBrowserMessage);
Expand Down Expand Up @@ -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) => (
<div className='gitlab-rhs-UserHeaderContainer'>
<img
className='gitlab-rhs-UserProfile Avatar Avatar-lg'
Expand All @@ -62,13 +61,13 @@ const UserHeader = (props) => (
</div>
);

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 (
<div className='gitlab-rhs-SubscriptionContainer'>
<div>
Expand All @@ -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 (
<div className='gitlab-rhs-NoSubscriptionsContainer'>
Expand Down Expand Up @@ -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<Subscription>[],
pluginServerRoute: string,
actions: {
getChannelSubscriptions: (channel: string) => Promise<any>,
sendEphemeralPost: (message: string) => void;
}
}

interface RhsSidebarState {
refreshing: boolean;
}

constructor(props) {
export default class RHSSidebar extends React.PureComponent<RhsSidebarProps, RhsSidebarState> {
constructor(props: RhsSidebarProps) {
super(props);

this.state = {
Expand All @@ -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<HTMLAnchorElement, MouseEvent>): Promise<void> => {
if (this.state.refreshing) {
return;
}
Expand Down