Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-891]: Added reporter and assignee fields in subscription filters #1112

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
priorityField = "priority"
descriptionField = "description"
resolutionField = "resolution"
assigneeField = "assignee"
securityLevelField = "security"

QueryParamInstanceID = "instance_id"
Expand Down Expand Up @@ -794,6 +795,10 @@ func getIssueFieldValue(issue *jira.Issue, key string) StringSet {
if issue.Fields.Priority != nil {
return NewStringSet(issue.Fields.Priority.ID)
}
case reporterField:
return NewStringSet(issue.Fields.Reporter.AccountID)
case assigneeField:
return NewStringSet(issue.Fields.Assignee.AccountID)
case "fixversions":
result := NewStringSet()
for _, v := range issue.Fields.FixVersions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ exports[`components/ChannelSubscriptionFilter should match snapshot 1`] = `
"label": "Affects versions",
"value": "versions",
},
Object {
"label": "Assignee",
"value": "assignee",
},
Object {
"label": "Epic Link",
"value": "customfield_10014",
Expand Down Expand Up @@ -82,6 +86,10 @@ exports[`components/ChannelSubscriptionFilter should match snapshot 1`] = `
"label": "MJK - Select List 3",
"value": "customfield_10076",
},
Object {
"label": "MJK - User Picker",
"value": "customfield_10080",
},
Object {
"label": "Priority",
"value": "priority",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,36 @@ exports[`components/EditChannelSubscription should match snapshot after fetching
},
],
},
Object {
"issueTypes": Array [
Object {
"id": "10002",
"name": "Task",
},
Object {
"id": "10003",
"name": "Sub-task",
},
Object {
"id": "10001",
"name": "Story",
},
Object {
"id": "10004",
"name": "Bug",
},
Object {
"id": "10000",
"name": "Epic",
},
],
"key": "assignee",
"name": "Assignee",
"schema": Object {
"system": "assignee",
"type": "user",
},
},
Object {
"issueTypes": Array [
Object {
Expand Down Expand Up @@ -820,6 +850,37 @@ exports[`components/EditChannelSubscription should match snapshot after fetching
},
],
},
Object {
"issueTypes": Array [
Object {
"id": "10002",
"name": "Task",
},
Object {
"id": "10003",
"name": "Sub-task",
},
Object {
"id": "10001",
"name": "Story",
},
Object {
"id": "10004",
"name": "Bug",
},
Object {
"id": "10000",
"name": "Epic",
},
],
"key": "customfield_10080",
"name": "MJK - User Picker",
"schema": Object {
"custom": "com.atlassian.jira.plugin.system.customfieldtypes:userpicker",
"customId": 10080,
"type": "user",
},
},
Object {
"issueTypes": Array [
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isLabelField,
isMultiSelectField,
isSecurityLevelField,
isUserField,
} from 'utils/jira_issue_metadata';
import {
FilterField,
Expand Down Expand Up @@ -307,6 +308,15 @@ export default class ChannelSubscriptionFilter extends React.PureComponent<Props
onChange={this.handleEpicLinkChange}
/>
);
} else if (isUserField(field)) {
valueSelector = (
<JiraAutoCompleteSelector
{...selectProps}
fieldName={field.name}
value={value.values}
onChange={this.handleEpicLinkChange}
/>
);
} else {
valueSelector = (
<ReactSelectSetting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ exports[`components/CreateIssue should match snapshot with error 1`] = `
Array [
"project",
"issuetype",
"reporter",
"priority",
"description",
"summary",
Expand Down Expand Up @@ -3212,6 +3213,7 @@ exports[`components/CreateIssue should match snapshot with form filled 1`] = `
Array [
"project",
"issuetype",
"reporter",
"priority",
"description",
"summary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import JiraInstanceAndProjectSelector from 'components/jira_instance_and_project
const allowedFields: string[] = [
JiraFieldTypeEnums.PROJECT,
JiraFieldTypeEnums.ISSUE_TYPE,
JiraFieldTypeEnums.REPORTER,
JiraFieldTypeEnums.PRIORITY,
JiraFieldTypeEnums.DESCRIPTION,
JiraFieldTypeEnums.SUMMARY,
Expand Down
1 change: 1 addition & 0 deletions webapp/src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export type SavedFieldValues = {
export enum JiraFieldTypeEnums {
PROJECT = 'project',
ISSUE_TYPE = 'issuetype',
REPORTER = 'reporter',
PRIORITY = 'priority',
DESCRIPTION = 'description',
SUMMARY = 'summary',
Expand Down
30 changes: 27 additions & 3 deletions webapp/src/utils/jira_issue_metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,16 @@ const allowedArrayTypes = [
'option', // multiselect
'string', // labels
'version', // fix and affects versions
'user',
];

const allowedFieldTypes = [
'user',
'option',
];

const jiraSystemCustomFieldTypesKey = 'com.atlassian.jira.plugin.system.customfieldtypes';

const avoidedCustomTypesForFilters: string[] = [
JiraFieldCustomTypeEnums.SPRINT,
];
Expand All @@ -194,7 +202,7 @@ function isValidFieldForFilter(field: JiraField): boolean {
}

return allowedTypes.includes(type) || (custom && acceptedCustomTypesForFilters.includes(custom)) ||
type === 'option' || // single select
allowedFieldTypes.includes(type) ||
(type === 'array' && typeof items !== 'undefined' && allowedArrayTypes.includes(items));
}

Expand Down Expand Up @@ -255,6 +263,18 @@ export function getCustomFieldFiltersForProjects(metadata: IssueMetadata | null,
} as FilterField;
});

const userFields = fields.filter((field) => field.schema.type === 'user' && !field.allowedValues) as (StringArrayField & FieldWithInfo)[];
const populatedUserFields = userFields.map((field) => {
return {
key: field.key,
name: field.name,
schema: field.schema,
issueTypes: field.validIssueTypes,
} as FilterField;
});

const userResult = populatedFields.concat(populatedUserFields);

const stringArrayFields = fields.filter((field) => field.schema.type === 'array' && field.schema.items === 'string' && !field.allowedValues) as (StringArrayField & FieldWithInfo)[];
const userDefinedFields = stringArrayFields.map((field) => {
return {
Expand All @@ -266,7 +286,7 @@ export function getCustomFieldFiltersForProjects(metadata: IssueMetadata | null,
} as FilterField;
});

const result = populatedFields.concat(userDefinedFields);
const result = userResult.concat(userDefinedFields);
const epicLinkField = fields.find(isEpicLinkField);
if (epicLinkField) {
result.unshift({
Expand Down Expand Up @@ -322,7 +342,11 @@ export function isEpicLinkField(field: JiraField | FilterField): boolean {
}

export function isLabelField(field: JiraField | FilterField): boolean {
return field.schema.system === 'labels' || field.schema.custom === 'com.atlassian.jira.plugin.system.customfieldtypes:labels';
return field.schema.system === 'labels' || field.schema.custom === `${jiraSystemCustomFieldTypesKey}:labels`;
}

export function isUserField(field: JiraField | FilterField): boolean {
return field.schema.type === 'user' || field.schema.custom === `${jiraSystemCustomFieldTypesKey}:userpicker`;
}

export function isEpicIssueType(issueType: IssueType): boolean {
Expand Down
Loading