From 06e0919bca7ee4280c6eed58838ca2be10e7b4fb Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 1 Dec 2015 15:24:53 -0500 Subject: Moved autocomplete components into web/react/components/suggestion --- .../components/suggestion/command_provider.jsx | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 web/react/components/suggestion/command_provider.jsx (limited to 'web/react/components/suggestion/command_provider.jsx') diff --git a/web/react/components/suggestion/command_provider.jsx b/web/react/components/suggestion/command_provider.jsx new file mode 100644 index 000000000..34de3bfd1 --- /dev/null +++ b/web/react/components/suggestion/command_provider.jsx @@ -0,0 +1,68 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import AppDispatcher from '../../dispatcher/app_dispatcher.jsx'; +import * as Client from '../../utils/client.jsx'; +import Constants from '../../utils/constants.jsx'; +import SuggestionStore from '../../stores/suggestion_store.jsx'; + +class CommandSuggestion extends React.Component { + render() { + const {item, isSelection, onClick} = this.props; + + let className = 'command-name'; + if (isSelection) { + className += ' suggestion--selected'; + } + + return ( +
+
+ {item.suggestion} +
+
+ {item.description} +
+
+ ); + } +} + +CommandSuggestion.propTypes = { + item: React.PropTypes.object.isRequired, + isSelection: React.PropTypes.bool, + onClick: React.PropTypes.func +}; + +export default class CommandProvider { + handlePretextChanged(suggestionId, pretext) { + if (pretext.startsWith('/')) { + SuggestionStore.setMatchedPretext(suggestionId, pretext); + + Client.executeCommand( + '', + pretext, + true, + (data) => { + this.handleCommandsReceived(suggestionId, pretext, data.suggestions); + } + ); + } + } + + handleCommandsReceived(suggestionId, matchedPretext, commandSuggestions) { + const terms = commandSuggestions.map(({suggestion}) => suggestion); + + AppDispatcher.handleServerAction({ + type: Constants.ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, + id: suggestionId, + matchedPretext, + terms, + items: commandSuggestions, + component: CommandSuggestion + }); + } +} -- cgit v1.2.3-1-g7c22 From 07f0df6af428a56a4abedde841a0813e2802cd2b Mon Sep 17 00:00:00 2001 From: hmhealey Date: Wed, 2 Dec 2015 09:21:58 -0500 Subject: Moved action creation for suggestions --- .../components/suggestion/command_provider.jsx | 25 ++-------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'web/react/components/suggestion/command_provider.jsx') diff --git a/web/react/components/suggestion/command_provider.jsx b/web/react/components/suggestion/command_provider.jsx index 34de3bfd1..a1f7901ef 100644 --- a/web/react/components/suggestion/command_provider.jsx +++ b/web/react/components/suggestion/command_provider.jsx @@ -1,8 +1,7 @@ // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import AppDispatcher from '../../dispatcher/app_dispatcher.jsx'; -import * as Client from '../../utils/client.jsx'; +import * as AsyncClient from '../../utils/async_client.jsx'; import Constants from '../../utils/constants.jsx'; import SuggestionStore from '../../stores/suggestion_store.jsx'; @@ -42,27 +41,7 @@ export default class CommandProvider { if (pretext.startsWith('/')) { SuggestionStore.setMatchedPretext(suggestionId, pretext); - Client.executeCommand( - '', - pretext, - true, - (data) => { - this.handleCommandsReceived(suggestionId, pretext, data.suggestions); - } - ); + AsyncClient.getSuggestedCommands(pretext, suggestionId, CommandSuggestion); } } - - handleCommandsReceived(suggestionId, matchedPretext, commandSuggestions) { - const terms = commandSuggestions.map(({suggestion}) => suggestion); - - AppDispatcher.handleServerAction({ - type: Constants.ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, - id: suggestionId, - matchedPretext, - terms, - items: commandSuggestions, - component: CommandSuggestion - }); - } } -- cgit v1.2.3-1-g7c22 From 101c74d8b82efb43ade6d67f669d586efc9b943c Mon Sep 17 00:00:00 2001 From: hmhealey Date: Wed, 2 Dec 2015 09:31:12 -0500 Subject: Changed Command autocomplete to pick a suggestion when space is pressed --- web/react/components/suggestion/command_provider.jsx | 1 + 1 file changed, 1 insertion(+) (limited to 'web/react/components/suggestion/command_provider.jsx') diff --git a/web/react/components/suggestion/command_provider.jsx b/web/react/components/suggestion/command_provider.jsx index a1f7901ef..6a7c1ce43 100644 --- a/web/react/components/suggestion/command_provider.jsx +++ b/web/react/components/suggestion/command_provider.jsx @@ -40,6 +40,7 @@ export default class CommandProvider { handlePretextChanged(suggestionId, pretext) { if (pretext.startsWith('/')) { SuggestionStore.setMatchedPretext(suggestionId, pretext); + SuggestionStore.setCompleteOnSpace(suggestionId, false); AsyncClient.getSuggestedCommands(pretext, suggestionId, CommandSuggestion); } -- cgit v1.2.3-1-g7c22 From 482e3fc9a494a54df53d99b060a7cfa13b3d95c0 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Wed, 2 Dec 2015 11:24:25 -0500 Subject: Fixed unused imports --- web/react/components/suggestion/command_provider.jsx | 1 - 1 file changed, 1 deletion(-) (limited to 'web/react/components/suggestion/command_provider.jsx') diff --git a/web/react/components/suggestion/command_provider.jsx b/web/react/components/suggestion/command_provider.jsx index 6a7c1ce43..a2a446de2 100644 --- a/web/react/components/suggestion/command_provider.jsx +++ b/web/react/components/suggestion/command_provider.jsx @@ -2,7 +2,6 @@ // See License.txt for license information. import * as AsyncClient from '../../utils/async_client.jsx'; -import Constants from '../../utils/constants.jsx'; import SuggestionStore from '../../stores/suggestion_store.jsx'; class CommandSuggestion extends React.Component { -- cgit v1.2.3-1-g7c22