Skip to content

Commit

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

ISSUES CLOSED: #90
  • Loading branch information
shafua committed Mar 22, 2018
1 parent ae57962 commit c1503a4
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/actions/actionTypes/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export const ADD_FLAG = 'ui/ADD_FLAG';
export const DELETE_FLAG = 'ui/DELETE_FLAG';
export const ISSUE_WORKLOGS_SCROLL_TO_INDEX_REQUEST = 'ui/ISSUE_WORKLOGS_SCROLL_TO_INDEX_REQUEST';
export const ACKNOWLEDGE_FEATURE = 'ui/ACKNOWLEDGE_FEATURE';
export const SET_POST_ALSO_AS_ISSUE_COMMENT = 'ui/SET_POST_ALSO_AS_ISSUE_COMMENT';
7 changes: 7 additions & 0 deletions app/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ export const acknowlegdeFeature = (payload: {
type: actionTypes.ACKNOWLEDGE_FEATURE,
payload,
});

export const setPostAlsoAsIssueComment = (postAlsoAsIssueComment: boolean): UiAction => ({
type: actionTypes.SET_POST_ALSO_AS_ISSUE_COMMENT,
payload: {
postAlsoAsIssueComment,
},
});
1 change: 1 addition & 0 deletions app/containers/IssueView/TrackingBar/TrackingBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const TrackingBar: StatelessFunctionalComponent<Props> = ({
issue={trackingIssue}
onSetComment={(comment) => {
dispatch(uiActions.setUiState('worklogComment', comment));
if (!comment) dispatch(uiActions.setPostAlsoAsIssueComment(false));
}}
onRemainingEstimateChange={(value) => {
dispatch(uiActions.setUiState('remainingEstimateValue', value));
Expand Down
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 Down Expand Up @@ -106,6 +107,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,66 @@
// @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';

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

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

export default compose(
connect(
state => ({
postAlsoAsIssueComment: getUiState('postAlsoAsIssueComment')(state),
isOptionUnavailable: !getUiState('worklogComment')(state),
}),
dispatch => ({ dispatch }),
),
withHandlers({
changePostOption: ({
dispatch,
postAlsoAsIssueComment,
}: {
postAlsoAsIssueComment: boolean,
dispatch: Dispatch,
}) => () => dispatch(uiActions.setPostAlsoAsIssueComment(!postAlsoAsIssueComment))
})
)(WorklogCommentOptions);
6 changes: 6 additions & 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 Expand Up @@ -119,6 +120,11 @@ export default function ui(
flags: state.flags.filter(f => f.id !== id),
};
}
case actionTypes.SET_POST_ALSO_AS_ISSUE_COMMENT:
return {
...state,
postAlsoAsIssueComment: action.payload.postAlsoAsIssueComment,
};
case actionTypes.__CLEAR_ALL_REDUCERS__:
return initialState;
default:
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
6 changes: 6 additions & 0 deletions app/types/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export type UiAction =
payload: {
featureId: string,
},
|} | {|
type: typeof actionTypes.SET_POST_ALSO_AS_ISSUE_COMMENT,
payload: {
postAlsoAsIssueComment: boolean,
},
|};

export type RemainingEstimate = 'auto' | 'new' | 'manual' | 'leave';
Expand Down Expand Up @@ -89,6 +94,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 c1503a4

Please sign in to comment.