From e6f8f44f58331303c9d8d1bbe0580edcaf5f6435 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Thu, 3 Nov 2016 14:09:27 -0400 Subject: Fixing store access design issues (#4436) --- .../integrations/components/add_command.jsx | 2 +- .../integrations/components/commands_container.jsx | 74 ++++++++++++++++++++++ .../components/confirm_integration.jsx | 8 ++- .../integrations/components/installed_commands.jsx | 54 ++-------------- webapp/routes/route_integrations.jsx | 19 ++++-- 5 files changed, 104 insertions(+), 53 deletions(-) create mode 100644 webapp/components/integrations/components/commands_container.jsx diff --git a/webapp/components/integrations/components/add_command.jsx b/webapp/components/integrations/components/add_command.jsx index e01358aa7..6ca1cf100 100644 --- a/webapp/components/integrations/components/add_command.jsx +++ b/webapp/components/integrations/components/add_command.jsx @@ -166,7 +166,7 @@ export default class AddCommand extends React.Component { AsyncClient.addCommand( command, (data) => { - browserHistory.push('/' + this.props.team.name + '/integrations/confirm?type=commands&id=' + data.id); + browserHistory.push('/' + this.props.team.name + '/integrations/commands/confirm?type=commands&id=' + data.id); }, (err) => { this.setState({ diff --git a/webapp/components/integrations/components/commands_container.jsx b/webapp/components/integrations/components/commands_container.jsx new file mode 100644 index 000000000..1c2b7af3e --- /dev/null +++ b/webapp/components/integrations/components/commands_container.jsx @@ -0,0 +1,74 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import IntegrationStore from 'stores/integration_store.jsx'; +import TeamStore from 'stores/team_store.jsx'; +import UserStore from 'stores/user_store.jsx'; + +import {loadTeamCommands} from 'actions/integration_actions.jsx'; + +import React from 'react'; + +export default class CommandsContainer extends React.Component { + static get propTypes() { + return { + team: React.propTypes.object.isRequired, + children: React.propTypes.node.isRequired + }; + } + + constructor(props) { + super(props); + + this.handleIntegrationChange = this.handleIntegrationChange.bind(this); + this.handleUserChange = this.handleUserChange.bind(this); + + const teamId = TeamStore.getCurrentId(); + + this.state = { + commands: IntegrationStore.getCommands(teamId), + loading: !IntegrationStore.hasReceivedCommands(teamId), + users: UserStore.getProfiles() + }; + } + + componentDidMount() { + IntegrationStore.addChangeListener(this.handleIntegrationChange); + UserStore.addChangeListener(this.handleUserChange); + + if (window.mm_config.EnableCommands === 'true') { + loadTeamCommands(); + } + } + + componentWillUnmount() { + IntegrationStore.removeChangeListener(this.handleIntegrationChange); + UserStore.removeChangeListener(this.handleUserChange); + } + + handleIntegrationChange() { + const teamId = TeamStore.getCurrentId(); + + this.setState({ + commands: IntegrationStore.getCommands(teamId), + loading: !IntegrationStore.hasReceivedCommands(teamId) + }); + } + + handleUserChange() { + this.setState({users: UserStore.getProfiles()}); + } + + render() { + return ( +
+ {React.cloneElement(this.props.children, { + commands: this.state.commands, + users: this.state.users, + loading: this.state.loading, + team: this.props.team + })} +
+ ); + } +} diff --git a/webapp/components/integrations/components/confirm_integration.jsx b/webapp/components/integrations/components/confirm_integration.jsx index de419341e..1f043ca83 100644 --- a/webapp/components/integrations/components/confirm_integration.jsx +++ b/webapp/components/integrations/components/confirm_integration.jsx @@ -16,7 +16,8 @@ export default class ConfirmIntegration extends React.Component { static get propTypes() { return { team: React.propTypes.object.isRequired, - location: React.PropTypes.object + location: React.PropTypes.object, + loading: React.PropTypes.bool }; } @@ -56,6 +57,11 @@ export default class ConfirmIntegration extends React.Component { let headerText = null; let helpText = null; let tokenText = null; + + if (this.props.loading === true) { + return (
); + } + if (this.state.type === Constants.Integrations.COMMAND) { headerText = ( { + const commands = this.props.commands.map((command) => { return ( ); }); @@ -130,7 +90,7 @@ export default class InstalledCommands extends React.Component { /> } searchPlaceholder={Utils.localizeMessage('installed_commands.search', 'Search Slash Commands')} - loading={this.state.loading} + loading={this.props.loading} > {commands} diff --git a/webapp/routes/route_integrations.jsx b/webapp/routes/route_integrations.jsx index afaf284e9..0feb13bb7 100644 --- a/webapp/routes/route_integrations.jsx +++ b/webapp/routes/route_integrations.jsx @@ -48,17 +48,28 @@ export default { }, { path: 'commands', - indexRoute: { - getComponents: (location, callback) => { - System.import('components/integrations/components/installed_commands.jsx').then(RouteUtils.importComponentSuccess(callback)); - } + getComponents: (location, callback) => { + System.import('components/integrations/components/commands_container.jsx').then(RouteUtils.importComponentSuccess(callback)); }, + indexRoute: {onEnter: (nextState, replace) => replace(nextState.location.pathname + '/installed')}, childRoutes: [ + { + path: 'installed', + getComponents: (location, callback) => { + System.import('components/integrations/components/installed_commands.jsx').then(RouteUtils.importComponentSuccess(callback)); + } + }, { path: 'add', getComponents: (location, callback) => { System.import('components/integrations/components/add_command.jsx').then(RouteUtils.importComponentSuccess(callback)); } + }, + { + path: 'confirm', + getComponents: (location, callback) => { + System.import('components/integrations/components/confirm_integration.jsx').then(RouteUtils.importComponentSuccess(callback)); + } } ] }, -- cgit v1.2.3-1-g7c22