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

[GH-394] Migration to TypeScript: Sidebar_button migrated to Typescript #438

Merged
merged 11 commits into from
Jan 23, 2024
23 changes: 2 additions & 21 deletions webapp/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,7 @@
"no-lone-blocks": 2,
"no-lonely-if": 2,
"no-loop-func": 2,
"no-magic-numbers": [
1,
{
"ignore": [
-1,
0,
1,
2
],
"enforceConst": true,
"detectObjects": true
}
],
"no-magic-numbers": "off",
"no-mixed-operators": [
2,
{
Expand Down Expand Up @@ -377,14 +365,7 @@
"args": "after-used"
}
],
"no-use-before-define": [
2,
{
"classes": false,
"functions": false,
"variables": false
}
],
"no-use-before-define": "off",
"no-useless-computed-key": 2,
"no-useless-concat": 2,
"no-useless-constructor": 2,
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/sidebar_buttons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {id} from '../../manifest';

import {getPluginServerRoute} from '../../selectors';

import SidebarButtons from './sidebar_buttons.jsx';
import SidebarButtons from './sidebar_buttons';

function mapStateToProps(state) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
import React from 'react';
import React, {PureComponent, ReactElement} from 'react';
import {Tooltip, OverlayTrigger} from 'react-bootstrap';
import PropTypes from 'prop-types';

import {makeStyleFromTheme, changeOpacity} from 'mattermost-redux/utils/theme_utils';

import {RHSStates, connectUsingBrowserMessage} from 'src/constants';
import {isDesktopApp} from 'src/utils/user_agent';
import {Placement} from 'react-bootstrap/esm/Overlay';

import {Theme} from 'mattermost-redux/types/preferences';

import {RHSStates, connectUsingBrowserMessage} from '../../constants';
import {isDesktopApp} from '../../utils/user_agent';

import {GitLabIssuesIcon, GitLabMergeRequestIcon, GitLabReviewsIcon, GitLabTodosIcon} from './button_icons';

export default class SidebarButtons extends React.PureComponent {
static propTypes = {
theme: PropTypes.object.isRequired,
connected: PropTypes.bool,
username: PropTypes.string,
org: PropTypes.string,
clientId: PropTypes.string,
gitlabURL: PropTypes.string,
reviews: PropTypes.arrayOf(PropTypes.object),
todos: PropTypes.arrayOf(PropTypes.object),
yourAssignedPrs: PropTypes.arrayOf(PropTypes.object),
yourAssignedIssues: PropTypes.arrayOf(PropTypes.object),
isTeamSidebar: PropTypes.bool,
pluginServerRoute: PropTypes.string.isRequired,
showRHSPlugin: PropTypes.func.isRequired,
actions: PropTypes.shape({
updateRHSState: PropTypes.func.isRequired,
sendEphemeralPost: PropTypes.func.isRequired,
getLHSData: PropTypes.func.isRequired,
}).isRequired,
interface SidebarButtonsProps {
theme: Theme;
connected: boolean;
username: string;
org: string;
clientId: string;
gitlabURL: string;
reviews: unknown[];
todos: unknown[];
yourAssignedPrs: unknown[];
yourAssignedIssues: unknown[];
isTeamSidebar: boolean;
pluginServerRoute: string;
showRHSPlugin: () => void;
actions: {
updateRHSState: (rhsState: string) => void;
sendEphemeralPost: (message: string) => void;
getLHSData: () => Promise<void>;
};
}

interface SidebarButtonsState {
refreshing: boolean;
}

constructor(props) {
export default class SidebarButtons extends PureComponent<SidebarButtonsProps, SidebarButtonsState> {
constructor(props: SidebarButtonsProps) {
super(props);

this.state = {
Expand All @@ -44,13 +52,13 @@ export default class SidebarButtons extends React.PureComponent {
}
}

componentDidUpdate(prevProps) {
componentDidUpdate(prevProps: SidebarButtonsProps) {
if (this.props.connected && !prevProps.connected) {
this.getData();
}
}

getData = async (e) => {
getData = async (e?: React.MouseEvent<HTMLAnchorElement, MouseEvent>): Promise<void> => {
if (this.state.refreshing) {
return;
}
Expand All @@ -64,7 +72,7 @@ export default class SidebarButtons extends React.PureComponent {
this.setState({refreshing: false});
};

openConnectWindow = (e) => {
openConnectWindow = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>): void => {
e.preventDefault();
if (isDesktopApp()) {
this.props.actions.sendEphemeralPost(connectUsingBrowserMessage);
Expand All @@ -73,18 +81,18 @@ export default class SidebarButtons extends React.PureComponent {
window.open(`${this.props.pluginServerRoute}/oauth/connect`, 'Connect Mattermost to GitLab', 'height=570,width=520');
};

openRHS = (rhsState) => {
openRHS = (rhsState: string): void => {
this.props.actions.updateRHSState(rhsState);
this.props.showRHSPlugin();
};

render() {
render(): ReactElement {
const style = getStyle(this.props.theme);
const isTeamSidebar = this.props.isTeamSidebar;

let container = style.containerHeader;
let button = style.buttonHeader;
let placement = 'bottom';
let placement: Placement = 'bottom';
if (isTeamSidebar) {
placement = 'right';
button = style.buttonTeam;
Expand All @@ -109,7 +117,6 @@ export default class SidebarButtons extends React.PureComponent {
</OverlayTrigger>
);
}
return null;
}

const baseURL = this.props.gitlabURL || 'https://gitlab.com';
Expand Down
Loading