Skip to content

Commit 0b470c3

Browse files
Migrate sidebar_header component to TypeScript (#617)
* Migrate sidebar_header component to TypeScript - Convert sidebar_header.jsx to sidebar_header.tsx with proper TypeScript interfaces - Migrate index.js to index.ts with GlobalState typing - Add missing 'connected' prop that was added to master after original PR - Use getConnected selector for better type safety - Fix interface formatting (proper spacing and semicolons) Addresses feedback from PR #450 and resolves issue #431. * Fix Theme import path to match codebase convention Use 'mattermost-redux/selectors/entities/preferences' instead of 'mattermost-redux/types/preferences' to be consistent with all other TypeScript files in the codebase. --------- Co-authored-by: Mattermost Build <build@mattermost.com>
1 parent a1bac9f commit 0b470c3

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

webapp/src/components/sidebar_header/index.js renamed to webapp/src/components/sidebar_header/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33

44
import {connect} from 'react-redux';
55

6-
import manifest from '../../manifest';
6+
import {getConnected} from 'src/selectors';
7+
import {GlobalState} from 'src/types/store';
78

8-
import SidebarHeader from './sidebar_header.jsx';
9+
import SidebarHeader from './sidebar_header';
910

10-
function mapStateToProps(state) {
11+
function mapStateToProps(state: GlobalState) {
1112
const members = state.entities.teams.myMembers || {};
1213
return {
1314
show: Object.keys(members).length <= 1,
14-
connected: state[`plugins-${manifest.id}`].connected,
15+
connected: getConnected(state),
1516
};
1617
}
1718

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
22
// See LICENSE.txt for license information.
33

4-
import React from 'react';
5-
import PropTypes from 'prop-types';
4+
import React, {PureComponent, ReactElement} from 'react';
5+
6+
import {Theme} from 'mattermost-redux/selectors/entities/preferences';
67

78
import SidebarButtons from '../sidebar_buttons';
89

9-
export default class SidebarHeader extends React.PureComponent {
10-
static propTypes = {
11-
show: PropTypes.bool.isRequired,
12-
connected: PropTypes.bool.isRequired,
13-
theme: PropTypes.object.isRequired,
14-
};
10+
interface SidebarHeaderProps {
11+
show: boolean;
12+
connected: boolean;
13+
theme: Theme;
14+
}
1515

16-
render() {
16+
export default class SidebarHeader extends PureComponent<SidebarHeaderProps> {
17+
render(): ReactElement | null {
1718
if (!this.props.show || !this.props.connected) {
1819
return null;
1920
}

0 commit comments

Comments
 (0)