Skip to content

Commit

Permalink
feat(dea/task/ticket): add ability to restrict users by assigned & cr…
Browse files Browse the repository at this point in the history
…eated users

close #1428
  • Loading branch information
munkhsaikhan committed Nov 15, 2019
1 parent 7f81056 commit 17fe9f8
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/modules/boards/containers/Stage.tsx
Expand Up @@ -65,6 +65,7 @@ class StageContainer extends React.PureComponent<FinalStageProps> {
query: gql(options.queries.itemsQuery),
variables: {
stageId: stage._id,
pipelineId: stage.pipelineId,
skip: items.length,
...getFilterParams(queryParams, options.getExtraParams)
}
Expand Down Expand Up @@ -140,6 +141,7 @@ const withQuery = ({ options }) => {
options: ({ stage, queryParams, loadingState }) => ({
variables: {
stageId: stage._id,
pipelineId: stage.pipelineId,
...getFilterParams(queryParams, options.getExtraParams)
},
fetchPolicy:
Expand Down
5 changes: 5 additions & 0 deletions src/modules/boards/containers/editForm/EditForm.tsx
Expand Up @@ -5,6 +5,7 @@ import { queries as userQueries } from 'modules/settings/team/graphql';
import { AllUsersQueryResponse } from 'modules/settings/team/types';
import React from 'react';
import { compose, graphql } from 'react-apollo';
import ErrorMsg from '../../../common/components/ErrorMsg';
import { queries } from '../../graphql';
import {
DetailQueryResponse,
Expand Down Expand Up @@ -124,6 +125,10 @@ class EditFormContainer extends React.Component<FinalProps> {
return <Spinner />;
}

if (detailQuery.error) {
return <ErrorMsg>{detailQuery.error.message}</ErrorMsg>;
}

const users = usersQuery.allUsers;
const item = detailQuery[options.queriesName.detailQuery];

Expand Down
1 change: 1 addition & 0 deletions src/modules/boards/graphql/queries.ts
Expand Up @@ -122,6 +122,7 @@ const stages = `
initialDealsTotalCount
stayedDealsTotalCount
inProcessDealsTotalCount
pipelineId
}
}
`;
Expand Down
5 changes: 4 additions & 1 deletion src/modules/boards/types.ts
Expand Up @@ -69,14 +69,15 @@ export interface IPipeline {
memberIds?: string[];
bgColor?: string;
isWatched: boolean;
// growth hack
startDate?: Date;
endDate?: Date;
metric?: string;
hackScoringType?: string;
templateId?: string;
state?: string;
itemsTotalCount?: number;
isCheckUser?: boolean;
excludeCheckUserIds?: string[];
}

interface IStageComparisonInfo {
Expand All @@ -98,6 +99,7 @@ export interface IStage {
stayedDealsTotalCount: number;
compareNextStage: IStageComparisonInfo;
formId: string;
pipelineId: string;
}

export interface IPipelineLabel {
Expand Down Expand Up @@ -228,6 +230,7 @@ export type RelatedItemsQueryResponse = {

export type DetailQueryResponse = {
loading: boolean;
error?: Error;
};

// query response
Expand Down
24 changes: 24 additions & 0 deletions src/modules/common/components/ErrorMsg.tsx
@@ -0,0 +1,24 @@
import React from 'react';
import styled from 'styled-components';
import styledTS from 'styled-components-ts';

const Text = styledTS<{}>(styled.span)`
font-size: 10px;
color: red
`;

type Props = {
children: string;
};

class ErrorMsg extends React.PureComponent<Props> {
render() {
const { children } = this.props;

const content = children.replace('GraphQL error: ', '');

return <Text {...this.props}>{content}</Text>;
}
}

export default ErrorMsg;
3 changes: 2 additions & 1 deletion src/modules/engage/components/EmailForm.tsx
Expand Up @@ -8,6 +8,7 @@ import { __, Alert } from 'modules/common/utils';
import { EMAIL_CONTENT } from 'modules/engage/constants';
import { EditorContainer } from 'modules/engage/styles';
import React from 'react';
import ErrorMsg from '../../common/components/ErrorMsg';
import { IEmailFormProps, IEngageEmail, IEngageScheduleDate } from '../types';
import Scheduler from './Scheduler';

Expand Down Expand Up @@ -99,7 +100,7 @@ class EmailForm extends React.Component<Props, State> {
const { error } = this.props;

if (error) {
return <p style={{ color: 'red' }}>{error}</p>;
return <ErrorMsg>{error}</ErrorMsg>;
}

const onChangeUser = e =>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/engage/containers/EmailForm.tsx
Expand Up @@ -18,7 +18,7 @@ const EmailFormContainer = (props: FinalProps) => {

const updatedProps = {
...props,
error: error && error.message.replace('GraphQL error: ', ''),
error: error && error.message,
verifiedEmails
};

Expand Down
71 changes: 62 additions & 9 deletions src/modules/settings/boards/components/PipelineForm.tsx
Expand Up @@ -38,6 +38,8 @@ type State = {
visibility: string;
selectedMemberIds: string[];
backgroundColor: string;
isCheckUser: boolean;
excludeCheckUserIds: string[];
};

class PipelineForm extends React.Component<Props, State> {
Expand All @@ -50,7 +52,10 @@ class PipelineForm extends React.Component<Props, State> {
stages: (stages || []).map(stage => ({ ...stage })),
visibility: pipeline ? pipeline.visibility || 'public' : 'public',
selectedMemberIds: pipeline ? pipeline.memberIds || [] : [],
backgroundColor: (pipeline && pipeline.bgColor) || colors.colorPrimaryDark
backgroundColor:
(pipeline && pipeline.bgColor) || colors.colorPrimaryDark,
isCheckUser: pipeline ? pipeline.isCheckUser || false : false,
excludeCheckUserIds: pipeline ? pipeline.excludeCheckUserIds || [] : []
};
}

Expand All @@ -68,6 +73,10 @@ class PipelineForm extends React.Component<Props, State> {
this.setState({ selectedMemberIds: items });
};

onChangeDominantUsers = items => {
this.setState({ excludeCheckUserIds: items });
};

collectValues = items => {
return items.map(item => item.value);
};
Expand All @@ -82,7 +91,13 @@ class PipelineForm extends React.Component<Props, State> {
visibility: string;
}) => {
const { pipeline, type, boardId, extraFields } = this.props;
const { selectedMemberIds, stages, backgroundColor } = this.state;
const {
selectedMemberIds,
stages,
backgroundColor,
isCheckUser,
excludeCheckUserIds
} = this.state;
const finalValues = values;

if (pipeline) {
Expand All @@ -96,7 +111,9 @@ class PipelineForm extends React.Component<Props, State> {
boardId: pipeline ? pipeline.boardId : boardId,
stages: stages.filter(el => el.name),
memberIds: selectedMemberIds,
bgColor: backgroundColor
bgColor: backgroundColor,
isCheckUser,
excludeCheckUserIds
};
};

Expand All @@ -106,11 +123,6 @@ class PipelineForm extends React.Component<Props, State> {
if (visibility === 'public') {
return;
}
const self = this;

const onChange = items => {
self.setState({ selectedMemberIds: items });
};

return (
<FormGroup>
Expand All @@ -121,7 +133,35 @@ class PipelineForm extends React.Component<Props, State> {
label="Choose members"
name="selectedMemberIds"
value={selectedMemberIds}
onSelect={onChange}
onSelect={this.onChangeMembers}
/>
</SelectMemberStyled>
</FormGroup>
);
}

onChangeIsCheckUser = e => {
const isChecked = (e.currentTarget as HTMLInputElement).checked;
this.setState({ isCheckUser: isChecked });
};

renderDominantUsers() {
const { isCheckUser, excludeCheckUserIds } = this.state;

if (!isCheckUser) {
return;
}

return (
<FormGroup>
<SelectMemberStyled>
<ControlLabel>Users eligible to see all cards</ControlLabel>

<SelectTeamMembers
label="Choose members"
name="excludeCheckUserIds"
value={excludeCheckUserIds}
onSelect={this.onChangeDominantUsers}
/>
</SelectMemberStyled>
</FormGroup>
Expand Down Expand Up @@ -213,6 +253,19 @@ class PipelineForm extends React.Component<Props, State> {

{this.renderSelectMembers()}

<FormGroup>
<ControlLabel>
Show only the user's assigned(created) cards
</ControlLabel>
<FormControl
componentClass="checkbox"
checked={this.state.isCheckUser}
onChange={this.onChangeIsCheckUser}
/>
</FormGroup>

{this.renderDominantUsers()}

<FormGroup>
<ControlLabel>Stages</ControlLabel>
<Stages
Expand Down
8 changes: 6 additions & 2 deletions src/modules/settings/boards/graphql/mutations.ts
Expand Up @@ -42,7 +42,9 @@ const commonPipelineParamsDef = `
$endDate: Date,
$metric: String,
$hackScoringType: String,
$templateId: String
$templateId: String,
$isCheckUser: Boolean
$excludeCheckUserIds: [String],
`;

const commonPipelineParams = `
Expand All @@ -57,7 +59,9 @@ const commonPipelineParams = `
startDate: $startDate,
endDate: $endDate,
metric: $metric,
templateId: $templateId
templateId: $templateId,
isCheckUser: $isCheckUser,
excludeCheckUserIds: $excludeCheckUserIds,
`;

const pipelineAdd = `
Expand Down
2 changes: 2 additions & 0 deletions src/modules/settings/boards/graphql/queries.ts
Expand Up @@ -30,6 +30,8 @@ const pipelines = `
startDate
endDate
metric
isCheckUser
excludeCheckUserIds
}
}
`;
Expand Down

0 comments on commit 17fe9f8

Please sign in to comment.