summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
author94117nl <rttededersixtwo@gmail.com>2017-06-28 09:38:57 -0500
committerChristopher Speller <crspeller@gmail.com>2017-06-28 07:38:57 -0700
commit28e0b8dc27e71c4b383f49db3be2a31088924bf1 (patch)
tree440d4cda57b44f2b7e9ce3550601f52544f718e0 /webapp
parent005dd0754ba6dec00d8e4a84a297d0f35fbefb2b (diff)
downloadchat-28e0b8dc27e71c4b383f49db3be2a31088924bf1.tar.gz
chat-28e0b8dc27e71c4b383f49db3be2a31088924bf1.tar.bz2
chat-28e0b8dc27e71c4b383f49db3be2a31088924bf1.zip
PLT-6456 Migrate installed_commands.jsx to be pure and use Redux (#6759)
* Add documentation to props, migrate to pure component * Migrate commands_container and installed_commands to redux * Partially move confirm_integration to redux * Add more props to commands_container * Fix identation issue * Remove unused import * Update command token to reference redux store
Diffstat (limited to 'webapp')
-rw-r--r--webapp/components/integrations/components/commands_container/commands_container.jsx78
-rw-r--r--webapp/components/integrations/components/commands_container/index.js29
-rw-r--r--webapp/components/integrations/components/confirm_integration/confirm_integration.jsx (renamed from webapp/components/integrations/components/confirm_integration.jsx)8
-rw-r--r--webapp/components/integrations/components/confirm_integration/index.js16
-rw-r--r--webapp/components/integrations/components/installed_commands/index.js25
-rw-r--r--webapp/components/integrations/components/installed_commands/installed_commands.jsx (renamed from webapp/components/integrations/components/installed_commands.jsx)73
-rw-r--r--webapp/routes/route_integrations.jsx8
7 files changed, 206 insertions, 31 deletions
diff --git a/webapp/components/integrations/components/commands_container/commands_container.jsx b/webapp/components/integrations/components/commands_container/commands_container.jsx
new file mode 100644
index 000000000..55ce2017b
--- /dev/null
+++ b/webapp/components/integrations/components/commands_container/commands_container.jsx
@@ -0,0 +1,78 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import React from 'react';
+import PropTypes from 'prop-types';
+
+export default class CommandsContainer extends React.PureComponent {
+ static propTypes = {
+
+ /**
+ * The team data needed to pass into child components
+ */
+ team: PropTypes.object,
+
+ /**
+ * The user data needed to pass into child components
+ */
+ user: PropTypes.object,
+
+ /**
+ * The children prop needed to render child component
+ */
+ children: PropTypes.node.isRequired,
+
+ /**
+ * Set if user is admin
+ */
+ isAdmin: PropTypes.bool,
+
+ /**
+ * The users collection
+ */
+ users: PropTypes.object,
+
+ /**
+ * Installed splash commands to display
+ */
+ commands: PropTypes.array,
+
+ actions: PropTypes.shape({
+
+ /**
+ * The function to call to fetch team commands
+ */
+ getCustomTeamCommands: PropTypes.func.isRequired
+ }).isRequired
+ }
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ loading: true
+ };
+ }
+
+ componentDidMount() {
+ if (window.mm_config.EnableCommands === 'true') {
+ this.props.actions.getCustomTeamCommands(this.props.team.id).then(
+ () => this.setState({loading: false})
+ );
+ }
+ }
+
+ render() {
+ return (
+ <div>
+ {React.cloneElement(this.props.children, {
+ loading: this.state.loading,
+ commands: this.props.commands || [],
+ users: this.props.users,
+ team: this.props.team,
+ user: this.props.user,
+ isAdmin: this.props.isAdmin
+ })}
+ </div>
+ );
+ }
+}
diff --git a/webapp/components/integrations/components/commands_container/index.js b/webapp/components/integrations/components/commands_container/index.js
new file mode 100644
index 000000000..ed0a4c138
--- /dev/null
+++ b/webapp/components/integrations/components/commands_container/index.js
@@ -0,0 +1,29 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import {connect} from 'react-redux';
+import {bindActionCreators} from 'redux';
+import {getCustomTeamCommands} from 'mattermost-redux/actions/integrations';
+
+import {getCommands} from 'mattermost-redux/selectors/entities/integrations';
+import {getUsers} from 'mattermost-redux/selectors/entities/users';
+
+import CommandsContainer from './commands_container.jsx';
+
+function mapStateToProps(state, ownProps) {
+ return {
+ ...ownProps,
+ commands: Object.values(getCommands(state)),
+ users: getUsers(state)
+ };
+}
+
+function mapDispatchToProps(dispatch) {
+ return {
+ actions: bindActionCreators({
+ getCustomTeamCommands
+ }, dispatch)
+ };
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(CommandsContainer); \ No newline at end of file
diff --git a/webapp/components/integrations/components/confirm_integration.jsx b/webapp/components/integrations/components/confirm_integration/confirm_integration.jsx
index 30f6034d5..05dd61efb 100644
--- a/webapp/components/integrations/components/confirm_integration.jsx
+++ b/webapp/components/integrations/components/confirm_integration/confirm_integration.jsx
@@ -1,9 +1,8 @@
-import PropTypes from 'prop-types';
-
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
+import PropTypes from 'prop-types';
import BackstageHeader from 'components/backstage/components/backstage_header.jsx';
import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
@@ -19,6 +18,7 @@ export default class ConfirmIntegration extends React.Component {
return {
team: PropTypes.object,
location: PropTypes.object,
+ commands: PropTypes.object,
loading: PropTypes.bool
};
}
@@ -94,7 +94,7 @@ export default class ConfirmIntegration extends React.Component {
id='add_command.token'
defaultMessage='<b>Token</b>: {token}'
values={{
- token: IntegrationStore.getCommand(this.props.team.id, this.state.id).token
+ token: this.props.commands[this.state.id].token
}}
/>
</p>
diff --git a/webapp/components/integrations/components/confirm_integration/index.js b/webapp/components/integrations/components/confirm_integration/index.js
new file mode 100644
index 000000000..fe7984f2b
--- /dev/null
+++ b/webapp/components/integrations/components/confirm_integration/index.js
@@ -0,0 +1,16 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import {connect} from 'react-redux';
+import {getCommands} from 'mattermost-redux/selectors/entities/integrations';
+
+import ConfirmIntegration from './confirm_integration.jsx';
+
+function mapStateToProps(state, ownProps) {
+ return {
+ ...ownProps,
+ commands: getCommands(state)
+ };
+}
+
+export default connect(mapStateToProps)(ConfirmIntegration); \ No newline at end of file
diff --git a/webapp/components/integrations/components/installed_commands/index.js b/webapp/components/integrations/components/installed_commands/index.js
new file mode 100644
index 000000000..b8fb9b8bd
--- /dev/null
+++ b/webapp/components/integrations/components/installed_commands/index.js
@@ -0,0 +1,25 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import {connect} from 'react-redux';
+import {bindActionCreators} from 'redux';
+import {regenCommandToken, deleteCommand} from 'mattermost-redux/actions/integrations';
+
+import InstalledCommands from './installed_commands.jsx';
+
+function mapStateToProps(state, ownProps) {
+ return {
+ ...ownProps
+ };
+}
+
+function mapDispatchToProps(dispatch) {
+ return {
+ actions: bindActionCreators({
+ regenCommandToken,
+ deleteCommand
+ }, dispatch)
+ };
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(InstalledCommands); \ No newline at end of file
diff --git a/webapp/components/integrations/components/installed_commands.jsx b/webapp/components/integrations/components/installed_commands/installed_commands.jsx
index 731b62cd6..c84af77eb 100644
--- a/webapp/components/integrations/components/installed_commands.jsx
+++ b/webapp/components/integrations/components/installed_commands/installed_commands.jsx
@@ -1,10 +1,9 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import BackstageList from 'components/backstage/components/backstage_list.jsx';
-import InstalledCommand from './installed_command.jsx';
+import InstalledCommand from '../installed_command.jsx';
-import {regenCommandToken, deleteCommand} from 'actions/integration_actions.jsx';
import * as Utils from 'utils/utils.jsx';
import PropTypes from 'prop-types';
@@ -12,31 +11,59 @@ import PropTypes from 'prop-types';
import React from 'react';
import {FormattedMessage} from 'react-intl';
-export default class InstalledCommands extends React.Component {
- static get propTypes() {
- return {
- team: PropTypes.object,
- user: PropTypes.object,
- users: PropTypes.object,
- commands: PropTypes.array,
- loading: PropTypes.bool,
- isAdmin: PropTypes.bool
- };
- }
+export default class InstalledCommands extends React.PureComponent {
+ static propTypes = {
+
+ /**
+ * The team object
+ */
+ team: PropTypes.object,
+
+ /**
+ * The user object
+ */
+ user: PropTypes.object,
+
+ /**
+ * The users collection
+ */
+ users: PropTypes.object,
+
+ /**
+ * Installed splash commands to display
+ */
+ commands: PropTypes.array,
+
+ /**
+ * Set whether to show the loading... animation or not
+ */
+ loading: PropTypes.bool,
+
+ /**
+ * Set to allow changes to installed splash commands
+ */
+ isAdmin: PropTypes.bool,
+
+ actions: PropTypes.shape({
- constructor(props) {
- super(props);
+ /**
+ * The function to call when Regenerate Token link is clicked
+ */
+ regenCommandToken: PropTypes.func.isRequired,
- this.regenCommandToken = this.regenCommandToken.bind(this);
- this.deleteCommand = this.deleteCommand.bind(this);
+ /**
+ * The function to call when Delete link is clicked
+ */
+ deleteCommand: PropTypes.func.isRequired
+ }).isRequired
}
- regenCommandToken(command) {
- regenCommandToken(command.id);
+ regenCommandToken = (command) => {
+ this.props.actions.regenCommandToken(command.id);
}
- deleteCommand(command) {
- deleteCommand(command.id);
+ deleteCommand = (command) => {
+ this.props.actions.deleteCommand(command.id);
}
commandCompare(a, b) {
@@ -118,4 +145,4 @@ export default class InstalledCommands extends React.Component {
</BackstageList>
);
}
-}
+} \ No newline at end of file
diff --git a/webapp/routes/route_integrations.jsx b/webapp/routes/route_integrations.jsx
index cf59882dd..c7c7497b8 100644
--- a/webapp/routes/route_integrations.jsx
+++ b/webapp/routes/route_integrations.jsx
@@ -61,14 +61,14 @@ export default {
{
path: 'commands',
getComponents: (location, callback) => {
- System.import('components/integrations/components/commands_container.jsx').then(RouteUtils.importComponentSuccess(callback));
+ System.import('components/integrations/components/commands_container').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));
+ System.import('components/integrations/components/installed_commands').then(RouteUtils.importComponentSuccess(callback));
}
},
{
@@ -86,7 +86,7 @@ export default {
{
path: 'confirm',
getComponents: (location, callback) => {
- System.import('components/integrations/components/confirm_integration.jsx').then(RouteUtils.importComponentSuccess(callback));
+ System.import('components/integrations/components/confirm_integration').then(RouteUtils.importComponentSuccess(callback));
}
}
]
@@ -110,7 +110,7 @@ export default {
{
path: 'confirm',
getComponents: (location, callback) => {
- System.import('components/integrations/components/confirm_integration.jsx').then(RouteUtils.importComponentSuccess(callback));
+ System.import('components/integrations/components/confirm_integration').then(RouteUtils.importComponentSuccess(callback));
}
}
]