import React from 'react'; import PropTypes from 'prop-types'; import {isDesktopApp} from 'src/utils/user_agent'; import {connectUsingBrowserMessage} from 'src/constants'; import MattermostGitLabSVG from './mattermost_gitlab'; import NoSubscriptionsSVG from './no_subscriptions'; import './rhs_sidebar.css'; const NotSignedIn = (props) => { const openConnectWindow = (e) => { e.preventDefault(); if (isDesktopApp()) { props.sendEphemeralPost(connectUsingBrowserMessage); return; } window.open(`${props.pluginServerRoute}/oauth/connect`, 'Connect Mattermost to GitLab', 'height=570,width=520'); }; return (
{'Welcome to the Mattermost GitLab plugin'}

{'Connect your account'}
{'to get started'}
{'Connect account'}
); }; NotSignedIn.propTypes = { pluginServerRoute: PropTypes.string.isRequired, sendEphemeralPost: PropTypes.func.isRequired, }; const UserHeader = (props) => (
user profile image
{'Signed in as'}
{props.username}
{'GitLab'}
); UserHeader.propTypes = { currentUserId: PropTypes.string.isRequired, username: PropTypes.string.isRequired, gitlabURL: PropTypes.string.isRequired, }; const Subscription = (props) => { return (

{'Repository'}

{props.name}

{'Features'}

{props.features.map((feature) => ( {feature} ))}
); }; Subscription.propTypes = { url: PropTypes.string.isRequired, name: PropTypes.string.isRequired, features: PropTypes.arrayOf(PropTypes.string).isRequired, }; const Subscriptions = (props) => { if (props.subscriptions.length === 0) { return (
{'There are no GitLab subscriptions available in this channel.'}
{'Use the /gitlab slash command to create a subscription.'}
); } return (
{'GitLab Subscriptions'}
{props.subscriptions.map((subscription) => ( ))}
); }; Subscriptions.propTypes = { currentChannelId: PropTypes.string, subscriptions: PropTypes.arrayOf(PropTypes.shape({ repository_name: PropTypes.string.isRequired, repository_url: PropTypes.string.isRequired, })).isRequired, }; 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, }; constructor(props) { super(props); this.state = { refreshing: false, }; } componentDidMount() { if (this.props.connected) { this.getData(); } } componentDidUpdate(prevProps) { if ((this.props.connected && !prevProps.connected) || (this.props.currentChannelId !== prevProps.currentChannelId)) { this.getData(); } } getData = async (e) => { if (this.state.refreshing) { return; } if (e) { e.preventDefault(); } this.setState({refreshing: true}); await this.props.actions.getChannelSubscriptions(this.props.currentChannelId); this.setState({refreshing: false}); } render() { if (!this.props.connected) { return ( ); } return (
); } }