-
Notifications
You must be signed in to change notification settings - Fork 94
[GH-394] Migration to TypeScript: Sidebar_button migrated to Typescript #438
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
Merged
+42
−54
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ad1013c
sidebar_button converted in Typescript
Willy-Wakam 5bb0e06
updated import
Willy-Wakam acad8c6
Merge branch 'mattermost:master' into master
Willy-Wakam fcad7de
Some changes based on comments
Willy-Wakam 669cbfc
Merge branch 'mattermost:master' into master
Willy-Wakam fd88fe7
Unnecessary imports removed
Willy-Wakam a67be49
Merge branch 'master' of https://github.com/Willy-Wakam/mattermost-pl…
Willy-Wakam 8277efd
Updated imports
Willy-Wakam 232a4f9
Merge branch 'mattermost:master' into master
Willy-Wakam 1f782cc
Reset the node-version to 14.21.1
Willy-Wakam aac3ab2
revert changes to package-lock.json
mickmister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,45 @@ | ||
| import React from 'react'; | ||
| import {Tooltip, OverlayTrigger} from 'react-bootstrap'; | ||
| import React, { PureComponent, ReactElement } from 'react'; | ||
| import { Tooltip, OverlayTrigger } from 'react-bootstrap'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our convention is generally to not have spaces in the imports. Our linter should catch this, though on a closer inspection, the |
||
| 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 { makeStyleFromTheme, changeOpacity } from 'mattermost-redux/utils/theme_utils'; | ||
|
|
||
| import { RHSStates, connectUsingBrowserMessage } from 'src/constants'; | ||
| import { isDesktopApp } from 'src/utils/user_agent'; | ||
|
|
||
| import { GitLabIssuesIcon, GitLabMergeRequestIcon, GitLabReviewsIcon, GitLabTodosIcon } from './button_icons'; | ||
| import { Placement } from 'react-bootstrap/esm/Overlay'; | ||
|
|
||
| interface SidebarButtonsProps { | ||
| theme: any; | ||
|
mickmister marked this conversation as resolved.
Outdated
|
||
| connected: boolean; | ||
| username: string; | ||
| org: string; | ||
| clientId: string; | ||
| gitlabURL: string; | ||
| reviews: any[]; | ||
|
mickmister marked this conversation as resolved.
Outdated
|
||
| todos: any[]; | ||
| yourAssignedPrs: any[]; | ||
| yourAssignedIssues: any[]; | ||
| isTeamSidebar: boolean; | ||
| pluginServerRoute: string; | ||
| showRHSPlugin: () => void; | ||
| actions: { | ||
| updateRHSState: (rhsState: string) => void; | ||
| sendEphemeralPost: (message: string) => void; | ||
| getLHSData: () => Promise<void>; | ||
| }; | ||
| } | ||
|
|
||
| import {GitLabIssuesIcon, GitLabMergeRequestIcon, GitLabReviewsIcon, GitLabTodosIcon} from './button_icons'; | ||
| interface SidebarButtonsState { | ||
| refreshing: boolean; | ||
| } | ||
|
|
||
| export default class SidebarButtons extends React.PureComponent { | ||
| export default class SidebarButtons extends PureComponent<SidebarButtonsProps, SidebarButtonsState> { | ||
| static propTypes = { | ||
|
mickmister marked this conversation as resolved.
Outdated
|
||
| 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, | ||
| // Prop types definition here | ||
| }; | ||
|
|
||
| constructor(props) { | ||
| constructor(props: SidebarButtonsProps) { | ||
| super(props); | ||
|
|
||
| this.state = { | ||
|
|
@@ -44,13 +53,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; | ||
| } | ||
|
|
@@ -59,12 +68,12 @@ export default class SidebarButtons extends React.PureComponent { | |
| e.preventDefault(); | ||
| } | ||
|
|
||
| this.setState({refreshing: true}); | ||
| this.setState({ refreshing: true }); | ||
| await this.props.actions.getLHSData(); | ||
| this.setState({refreshing: false}); | ||
| this.setState({ refreshing: false }); | ||
| }; | ||
|
|
||
| openConnectWindow = (e) => { | ||
| openConnectWindow = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>): void => { | ||
| e.preventDefault(); | ||
| if (isDesktopApp()) { | ||
| this.props.actions.sendEphemeralPost(connectUsingBrowserMessage); | ||
|
|
@@ -73,18 +82,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() { | ||
| const style = getStyle(this.props.theme); | ||
| const isTeamSidebar = this.props.isTeamSidebar; | ||
| render(): ReactElement { | ||
| const style: any = getStyle(this.props.theme); | ||
|
mickmister marked this conversation as resolved.
Outdated
|
||
| const isTeamSidebar: boolean = this.props.isTeamSidebar; | ||
|
mickmister marked this conversation as resolved.
Outdated
|
||
|
|
||
| let container = style.containerHeader; | ||
| let button = style.buttonHeader; | ||
| let placement = 'bottom'; | ||
| let placement: Placement = 'bottom'; | ||
| if (isTeamSidebar) { | ||
| placement = 'right'; | ||
| button = style.buttonTeam; | ||
|
|
@@ -104,12 +113,11 @@ export default class SidebarButtons extends React.PureComponent { | |
| onClick={this.openConnectWindow} | ||
| style={button} | ||
| > | ||
| <i className='fa fa-gitlab fa-2x'/> | ||
| <i className='fa fa-gitlab fa-2x' /> | ||
| </a> | ||
| </OverlayTrigger> | ||
| ); | ||
| } | ||
| return null; | ||
| }; | ||
| } | ||
|
|
||
| const baseURL = this.props.gitlabURL || 'https://gitlab.com'; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.