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

Add "reporter" and "assignee" fields in subscription filters #890

Closed
wants to merge 12 commits into from
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "Atlassian Jira plugin for Mattermost.",
"homepage_url": "https://github.com/mattermost/mattermost-plugin-jira",
"support_url": "https://github.com/mattermost/mattermost-plugin-jira/issues",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-jira/releases/tag/v3.2.0",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-jira/releases/tag/v3.2.1",
"icon_path": "assets/icon.svg",
"version": "3.2.0",
"version": "3.2.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not resolved

"min_server_version": "6.5.0",
"server": {
"executables": {
Expand Down
14 changes: 10 additions & 4 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"
)

func makePost(userID, channelID, message string) *model.Post {
Expand Down Expand Up @@ -811,12 +812,17 @@ func getIssueCustomFieldValue(issue *jira.Issue, key string) StringSet {
func getIssueFieldValue(issue *jira.Issue, key string) StringSet {
key = strings.ToLower(key)
switch key {
case statusField:
case statusField:
return NewStringSet(issue.Fields.Status.ID)
case labelsField:
case labelsField:
return NewStringSet(issue.Fields.Labels...)
case priorityField:
if issue.Fields.Priority != nil {
case priorityField:
return NewStringSet(issue.Fields.Priority.ID)
case reporterField:
return NewStringSet(issue.Fields.Reporter.AccountID)
case assigneeField:
return NewStringSet(issue.Fields.Assignee.AccountID)
if issue.Fields.Priority != nil {
return NewStringSet(issue.Fields.Priority.ID)
}
case "fixversions":
Expand Down
2 changes: 1 addition & 1 deletion server/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ var manifest = struct {
Version string
}{
ID: "jira",
Version: "3.2.0",
Version: "3.2.1",
shigalovalexs marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Theme} from 'mattermost-redux/types/preferences';
import ReactSelectSetting from 'components/react_select_setting';
import JiraEpicSelector from 'components/data_selectors/jira_epic_selector';

import {isEpicLinkField, isMultiSelectField, isLabelField} from 'utils/jira_issue_metadata';
import {isEpicLinkField, isMultiSelectField, isLabelField, isUserField} from 'utils/jira_issue_metadata';
import {FilterField, FilterValue, ReactSelectOption, IssueMetadata, IssueType, FilterFieldInclusion} from 'types/model';
import ConfirmModal from 'components/confirm_modal';
import JiraAutoCompleteSelector from 'components/data_selectors/jira_autocomplete_selector';
Expand Down Expand Up @@ -262,6 +262,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 @@ -23,6 +23,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
2 changes: 1 addition & 1 deletion webapp/src/manifest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is automatically generated. Do not modify it manually.

export const id = 'jira';
export const version = '3.2.0';
export const version = '3.2.1';
2 changes: 2 additions & 0 deletions webapp/src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export type ProjectMetadata = {
export enum JiraFieldTypeEnums {
PROJECT = 'project',
ISSUE_TYPE = 'issuetype',

REPORTER = 'reporter',
PRIORITY = 'priority',
DESCRIPTION = 'description',
SUMMARY = 'summary',
Expand Down
20 changes: 18 additions & 2 deletions webapp/src/utils/jira_issue_metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function isValidFieldForFilter(field: JiraField): boolean {
}

return allowedTypes.includes(type) || (custom && acceptedCustomTypesForFilters.includes(custom)) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this part a bit difficult to follow and understand, but this would be a future refactor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also allowedTypes is a bit confusing, because we have here other types (option, user) but those aren't in the allowedTypes array, but they're called types too 🤷 .

But as I said, this is for the future.

Copy link
Contributor

@mickmister mickmister Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javaguirre Yeah I too think option and user should be added to allowedTypes. I don't see any logic that would break if we did that

type === 'option' || // single select
type === 'option' || type === 'user' ||
(type === 'array' && allowedArrayTypes.includes(items));
}

Expand All @@ -199,6 +199,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 @@ -210,7 +222,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 @@ -264,6 +276,10 @@ export function isLabelField(field: JiraField | FilterField): boolean {
return field.schema.system === 'labels' || field.schema.custom === 'com.atlassian.jira.plugin.system.customfieldtypes:labels';
}

export function isUserField(field: JiraField | FilterField): boolean {
return field.schema.type === 'user' || field.schema.custom === 'com.atlassian.jira.plugin.system.customfieldtypes:userpicker';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the string 'com.atlassian.....' be a constant more to the top of the file? It seems some kind of "magic string".

}

export function isEpicIssueType(issueType: IssueType): boolean {
return issueType.name === 'Epic';
}
Expand Down