Skip to content

Commit

Permalink
Merge branch 'polls' into 'master'
Browse files Browse the repository at this point in the history
Polls

See merge request kchat/webapp!451
  • Loading branch information
antonbuks committed Aug 26, 2024
2 parents df44f57 + 7c6f6d1 commit 608a978
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 22 deletions.
34 changes: 34 additions & 0 deletions webapp/channels/src/actions/views/create_comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,40 @@ export function submitCommand(channelId: string, rootId: string, draft: PostDraf
return {};
};
}
export function submitImmediateCommand(channelId: string, command: string, rootId: string): ActionFuncAsync<unknown, GlobalState> {
return async (dispatch, getState) => {
const state = getState();

const teamId = getCurrentTeamId(state);

let args = {
channel_id: channelId,
team_id: teamId,
root_id: rootId,
};

let message = command;

const hookResult = await dispatch(runSlashCommandWillBePostedHooks(message, args));
if (hookResult.error) {
return {error: hookResult.error};
} else if (!hookResult.data!.message && !hookResult.data!.args) {
// do nothing with an empty return from a hook
return {};
}

message = hookResult.data!.message;
args = hookResult.data!.args;

const {error} = await dispatch(executeCommand(message, args));

if (error) {
throw (error);
}

return {};
};
}

export function makeOnSubmit(channelId: string, rootId: string, latestPostId: string): (draft: PostDraft, options?: {ignoreSlash?: boolean}) => ActionFuncAsync<boolean, GlobalState> {
return (draft, options = {}) => async (dispatch, getState) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ exports[`components/AdvancedCreateComment should match snapshot when cannot post
type={1}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
rootId=""
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={false}
Expand Down Expand Up @@ -143,7 +150,14 @@ exports[`components/AdvancedCreateComment should match snapshot, comment with me
type={1}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
rootId=""
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down Expand Up @@ -229,7 +243,14 @@ exports[`components/AdvancedCreateComment should match snapshot, emoji picker di
type={1}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
rootId=""
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down Expand Up @@ -363,7 +384,14 @@ exports[`components/AdvancedCreateComment should match snapshot, empty comment 1
type={1}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
rootId=""
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down Expand Up @@ -449,7 +477,14 @@ exports[`components/AdvancedCreateComment should match snapshot, non-empty messa
type={1}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
rootId=""
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {ServerError} from '@mattermost/types/errors';
import type {FileInfo} from '@mattermost/types/files';
import {GroupSource} from '@mattermost/types/groups';
import type {Group} from '@mattermost/types/groups';
import type {Post} from '@mattermost/types/posts';
import type {PreferenceType} from '@mattermost/types/preferences';

import {Posts} from 'mattermost-redux/constants';
Expand All @@ -26,6 +27,7 @@ import type {FilePreviewInfo} from 'components/file_preview/file_preview';
import type {FileUpload as FileUploadClass} from 'components/file_upload/file_upload';
import NotifyConfirmModal from 'components/notify_confirm_modal';
import PostDeletedModal from 'components/post_deleted_modal';
import Poll from 'components/post_poll/';
import ScheduledIndicator, {ScheduledIndicatorType} from 'components/schedule_post/scheduled_indicator';
import type {TextboxClass, TextboxElement} from 'components/textbox';

Expand Down Expand Up @@ -1172,7 +1174,14 @@ class AdvancedCreateComment extends React.PureComponent<Props, State> {
setDraftAsPostType={this.setDraftAsPostType}
isSchedulable={true}
handleSchedulePost={this.handleSchedulePost}
additionalControls={pluginItems.filter(Boolean)}
additionalControls={[
<Poll
rootId={this.props.rootId}
key='poll'
disabled={this.props.shouldShowPreview}
/>,
...(pluginItems || []),
].filter(Boolean)}
codeBlockOnCtrlEnter={this.props.codeBlockOnCtrlEnter}
ctrlSend={this.props.ctrlSend}
loadNextMessage={this.loadNextMessage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ exports[`components/advanced_create_post Show tutorial 1`] = `
type={0}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down Expand Up @@ -123,7 +129,13 @@ exports[`components/advanced_create_post should match snapshot for center textbo
type={0}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down Expand Up @@ -234,7 +246,13 @@ exports[`components/advanced_create_post should match snapshot when cannot post
type={0}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={false}
Expand Down Expand Up @@ -345,7 +363,13 @@ exports[`components/advanced_create_post should match snapshot when file upload
type={0}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down Expand Up @@ -456,7 +480,13 @@ exports[`components/advanced_create_post should match snapshot, can post; previe
type={0}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down Expand Up @@ -567,7 +597,13 @@ exports[`components/advanced_create_post should match snapshot, can post; previe
type={0}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down Expand Up @@ -678,7 +714,13 @@ exports[`components/advanced_create_post should match snapshot, cannot post; pre
type={0}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={false}
Expand Down Expand Up @@ -789,7 +831,13 @@ exports[`components/advanced_create_post should match snapshot, cannot post; pre
type={0}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={false}
Expand Down Expand Up @@ -900,7 +948,13 @@ exports[`components/advanced_create_post should match snapshot, init 1`] = `
type={0}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down Expand Up @@ -1011,7 +1065,13 @@ exports[`components/advanced_create_post should match snapshot, post priority di
type={0}
/>
<AdvanceTextEditor
additionalControls={Array []}
additionalControls={
Array [
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
badConnection={false}
canPost={true}
Expand Down Expand Up @@ -1134,6 +1194,9 @@ exports[`components/advanced_create_post should match snapshot, post priority en
onApply={[Function]}
onClose={[Function]}
/>,
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
Expand Down Expand Up @@ -1258,6 +1321,9 @@ exports[`components/advanced_create_post should match snapshot, post priority en
}
}
/>,
<Memo(Connect(Component))
disabled={false}
/>,
]
}
applyMarkdown={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type {FilePreviewInfo} from 'components/file_preview/file_preview';
import type {FileUpload as FileUploadClass} from 'components/file_upload/file_upload';
import NotifyConfirmModal from 'components/notify_confirm_modal';
import PersistNotificationConfirmModal from 'components/persist_notification_confirm_modal';
import Poll from 'components/post_poll';
import PostPriorityPickerOverlay from 'components/post_priority/post_priority_picker_overlay';
import ResetStatusModal from 'components/reset_status_modal';
import ScheduledIndicator, {ScheduledIndicatorType} from 'components/schedule_post/scheduled_indicator';
Expand Down Expand Up @@ -1563,6 +1564,10 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
disabled={this.props.shouldShowPreview}
/>
),
<Poll
key='poll'
disabled={this.props.shouldShowPreview}
/>,
...(pluginItems || []),
].filter(Boolean)}
codeBlockOnCtrlEnter={this.props.codeBlockOnCtrlEnter}
Expand Down
29 changes: 29 additions & 0 deletions webapp/channels/src/components/post_poll/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {connect} from 'react-redux';
import type {Dispatch} from 'redux';
import {bindActionCreators} from 'redux';

import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels';

import {submitImmediateCommand} from 'actions/views/create_comment';

import type {GlobalState} from 'types/store';

import Poll from './poll';

function mapStateToProps(state: GlobalState) {
const currentChannelId = getCurrentChannelId(state);

return {
currentChannelId,
};
}

function mapDispatchToProps(dispatch: Dispatch) {
return {
actions: bindActionCreators({
submitImmediateCommand,
}, dispatch),
};
}

export default connect(mapStateToProps, mapDispatchToProps)(Poll);
Loading

0 comments on commit 608a978

Please sign in to comment.