Skip to content

Commit

Permalink
feat(Tracking): add checkbox to post comment also as issue comment (#99)
Browse files Browse the repository at this point in the history
* feat(Tracking): add checkbox to post worklog comment also as issue comment

ISSUES CLOSED: #90

* fix: fix comment field cancel behavior
  • Loading branch information
shafua authored and VladimirPal committed Mar 23, 2018
1 parent 0ce226d commit 6f6c23a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
EditButtonContainer,
} from './styled';

import WorklogCommentOptions from './WorklogCommentOptions';

type Props = {
issue: Issue,
Expand All @@ -47,15 +48,18 @@ class WorklogCommentDialog extends PureComponent<Props, State> {
this.state = {
dialogOpen: false,
isEditing: true,
comment: this.props.comment,
};
}

onConfirm = () => {
this.exitEditingMode();
this.props.onSetComment(this.state.comment);
};

onCancel = () => {
this.exitEditingMode();
this.setState({ comment: this.props.comment });
};

toggleDialog = () => {
Expand Down Expand Up @@ -89,8 +93,8 @@ class WorklogCommentDialog extends PureComponent<Props, State> {
autoFocus
isEditing
isInitiallySelected
value={this.props.comment}
onChange={e => this.props.onSetComment(e.target.value)}
value={this.state.comment}
onChange={e => this.setState({ comment: e.target.value })}
/>
}
readView={(
Expand All @@ -106,6 +110,7 @@ class WorklogCommentDialog extends PureComponent<Props, State> {
onConfirm={this.onConfirm}
onCancel={this.onCancel}
/>
<WorklogCommentOptions />
<RemainingEstimatePicker
issue={this.props.issue}
value={this.props.remainingEstimateValue}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// @flow
import React from 'react';
import { connect } from 'react-redux';
import { compose, withHandlers } from 'recompose';

import {
CheckboxStateless as Checkbox,
CheckboxGroup,
} from '@atlaskit/checkbox';

import {
uiActions,
} from 'actions';
import {
getUiState,
} from 'selectors';

import type {
StatelessFunctionalComponent,
Node,
} from 'react';

import type {
Dispatch,
} from 'types';

import {
IssueCommentCheckboxWrapper,
} from './styled';

type Props = {
postAlsoAsIssueComment: boolean,
changePostOption: () => void,
};

const WorklogCommentOptions: StatelessFunctionalComponent<Props> = ({
postAlsoAsIssueComment,
changePostOption,
}: Props): Node =>
<IssueCommentCheckboxWrapper>
<CheckboxGroup>
<Checkbox
isChecked={postAlsoAsIssueComment}
value={postAlsoAsIssueComment}
name="postAlsoAsIssueComment"
label="Post also as comment to issue"
onChange={changePostOption}
/>
</CheckboxGroup>
</IssueCommentCheckboxWrapper>;

export default compose(
connect(
state => ({
postAlsoAsIssueComment: getUiState('postAlsoAsIssueComment')(state),
}),
dispatch => ({ dispatch }),
),
withHandlers({
changePostOption: ({
dispatch,
postAlsoAsIssueComment,
}: {
postAlsoAsIssueComment: boolean,
dispatch: Dispatch,
}) => () => dispatch(uiActions.setUiState('postAlsoAsIssueComment', !postAlsoAsIssueComment))
})
)(WorklogCommentOptions);
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export const EditButton = styled(EditFilledIcon)`
export const EditButtonContainer = styled.div`
cursor: pointer;
`;

export const IssueCommentCheckboxWrapper = styled.div`
margin-left: -10px;
`;
1 change: 1 addition & 0 deletions app/reducers/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const initialState: UiState = {
editWorklogId: null,
worklogFormIssueId: null,
worklogComment: '',
postAlsoAsIssueComment: false,
remainingEstimateValue: 'auto',
remainingEstimateNewValue: '',
remainingEstimateReduceByValue: '',
Expand Down
7 changes: 7 additions & 0 deletions app/sagas/worklogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import {
types,
uiActions,
issuesActions,
} from 'actions';
import {
getResourceIds,
Expand Down Expand Up @@ -266,9 +267,15 @@ export function* uploadWorklog(options: any): Generator<*, *, *> {
},
});

const postAlsoAsIssueComment = yield select(getUiState('postAlsoAsIssueComment'));
if (postAlsoAsIssueComment && options.comment) {
yield put(issuesActions.commentRequest(options.comment, options.issueId));
}

// reset ui state
yield put(uiActions.resetUiState([
'worklogComment',
'postAlsoAsIssueComment',
'remainingEstimateValue',
'remainingEstimateNewValue',
'remainingEstimateReduceByValue',
Expand Down
1 change: 1 addition & 0 deletions app/types/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export type UiState = {|
editWorklogId: Id | null,
worklogFormIssueId: Id | null,
worklogComment: string,
postAlsoAsIssueComment: boolean,
remainingEstimateValue: RemainingEstimate,
remainingEstimateNewValue: string,
remainingEstimateReduceByValue: string,
Expand Down

0 comments on commit 6f6c23a

Please sign in to comment.