Skip to content

Commit b09bf35

Browse files
[MM-944]: Typescript migration and converting github_label_selector to TS
1 parent b11ee1e commit b09bf35

File tree

9 files changed

+257
-78
lines changed

9 files changed

+257
-78
lines changed

webapp/.eslintrc.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
{
22
"extends": [
3-
"eslint:recommended",
4-
"plugin:react-hooks/recommended"
3+
"eslint:recommended",
4+
"plugin:react-hooks/recommended"
55
],
6+
"parser": "@typescript-eslint/parser",
67
"parserOptions": {
7-
"ecmaVersion": 8,
8-
"sourceType": "module",
9-
"ecmaFeatures": {
10-
"jsx": true,
11-
"impliedStrict": true,
12-
"modules": true,
13-
"experimentalObjectRestSpread": true
14-
}
8+
"project": "./tsconfig.json",
9+
"tsconfigRootDir": "./"
1510
},
16-
"parser": "babel-eslint",
1711
"plugins": [
1812
"react",
13+
"@typescript-eslint",
1914
"import"
2015
],
2116
"env": {
@@ -35,7 +30,12 @@
3530
"beforeEach": true
3631
},
3732
"settings": {
38-
"import/resolver": "webpack"
33+
"import/resolver": {
34+
"typescript": {}
35+
},
36+
"import/parsers": {
37+
"@typescript-eslint/parser": [".ts", ".tsx"]
38+
}
3939
},
4040
"rules": {
4141
"array-bracket-spacing": [
@@ -639,7 +639,7 @@
639639
],
640640
"rules": {
641641
"@typescript-eslint/ban-ts-ignore": 0,
642-
"@typescript-eslint/ban-types": 1,
642+
"@typescript-eslint/ban-types": 0,
643643
"@typescript-eslint/ban-ts-comment": 0,
644644
"@typescript-eslint/no-var-requires": 0,
645645
"@typescript-eslint/prefer-interface": 0,

webapp/package-lock.json

Lines changed: 140 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webapp/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@types/react-intl": "3.0.0",
3535
"@types/react-redux": "7.1.9",
3636
"@types/react-router-dom": "5.1.5",
37+
"@types/react-select": "3.1.0",
3738
"@types/react-transition-group": "4.4.0",
3839
"@typescript-eslint/eslint-plugin": "4.1.1",
3940
"@typescript-eslint/parser": "4.1.1",
@@ -46,6 +47,7 @@
4647
"enzyme-adapter-react-16": "1.15.4",
4748
"enzyme-to-json": "3.5.0",
4849
"eslint": "7.9.0",
50+
"eslint-import-resolver-typescript": "3.6.1",
4951
"eslint-import-resolver-webpack": "0.12.2",
5052
"eslint-plugin-import": "2.22.0",
5153
"eslint-plugin-react": "7.20.6",

webapp/src/components/github_label_selector/github_label_selector.jsx renamed to webapp/src/components/github_label_selector/github_label_selector.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
// See LICENSE.txt for license information.
33

44
import React, {PureComponent} from 'react';
5-
import PropTypes from 'prop-types';
6-
7-
import IssueAttributeSelector from 'components/issue_attribute_selector';
8-
9-
export default class GithubLabelSelector extends PureComponent {
10-
static propTypes = {
11-
repoName: PropTypes.string.isRequired,
12-
theme: PropTypes.object.isRequired,
13-
selectedLabels: PropTypes.array.isRequired,
14-
onChange: PropTypes.func.isRequired,
15-
actions: PropTypes.shape({
16-
getLabelOptions: PropTypes.func.isRequired,
17-
}).isRequired,
18-
};
5+
6+
import {Theme} from 'mattermost-redux/types/preferences';
7+
8+
import IssueAttributeSelector, {IssueAttributeSelectorSelection} from '../issue_attribute_selector';
9+
10+
import {GitHubLabelSelectorDispatchProps} from '.';
11+
12+
type Props = GitHubLabelSelectorDispatchProps & {
13+
repoName: string;
14+
theme: Theme;
15+
selectedLabels: string[];
16+
onChange: (selection: string[]) => void;
17+
};
18+
19+
export default class GithubLabelSelector extends PureComponent<Props> {
1920

2021
loadLabels = async () => {
2122
if (this.props.repoName === '') {
@@ -32,13 +33,19 @@ export default class GithubLabelSelector extends PureComponent {
3233
return [];
3334
}
3435

35-
return options.data.map((option) => ({
36+
return options.data.map((option: any) => ({
3637
value: option.name,
3738
label: option.name,
3839
}));
3940
};
4041

41-
onChange = (selection) => this.props.onChange(selection.map((s) => s.value));
42+
onChange = (selection: IssueAttributeSelectorSelection) => {
43+
if (!selection || !Array.isArray(selection)) {
44+
return;
45+
}
46+
47+
this.props.onChange(selection.map((s) => s.value));
48+
}
4249

4350
render() {
4451
return (

webapp/src/components/github_label_selector/index.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
2+
// See LICENSE.txt for license information.
3+
4+
import {connect} from 'react-redux';
5+
import {Dispatch, bindActionCreators} from 'redux';
6+
7+
import {getLabelOptions} from '../../actions';
8+
9+
import GithubLabelSelector from './github_label_selector';
10+
11+
const mapDispatchToProps = (dispatch: Dispatch) => ({
12+
actions: bindActionCreators({getLabelOptions}, dispatch),
13+
}) as unknown as Actions;
14+
15+
type Actions = {
16+
getLabelOptions: (repoName: string) => ReturnType<ReturnType<typeof getLabelOptions>>;
17+
};
18+
19+
export type GitHubLabelSelectorDispatchProps = {
20+
actions: Actions;
21+
};
22+
23+
export default connect(
24+
null,
25+
mapDispatchToProps,
26+
)(GithubLabelSelector);

0 commit comments

Comments
 (0)