Skip to content

[BUG] due date not selectable as "Event" in subscription settings #1196

@iva-5-middleware

Description

@iva-5-middleware

Hey,

we found out that we're not able to select "due date" (in German: "Fälligkeitsdatum") as an "Event" for a new subscription.

Steps to reproduce

  • Add new subscription
  • Open "Events" dropdown and select suitable events
  • Try to select or find "due date" (or "Fälligkeitsdatum" in German)

Current behaviour

  • "due date" or "Fälligkeitsdatum" are not selectable

Expected behaviour

  • "due date" or "Fälligkeitsdatum" are selectable

Troubleshooting Developer Console (Google Chrome)

First user action

  • /jira subscribe edit, add new subscription, project "MM" is auto-selected

First request

REQUEST (TRIGGERED BY MM): GET https://<MM URL>/plugins/jira/api/v2/get-jira-project-metadata?instance_id=https://<JIRA URL>

RESPONSE:
{
    "projects": [
	{
            "label": "Mattermost",
            "value": "MM"
        },
        (...)
    ],
}

Second user action

  • None, because project "MM" is auto-selected

Second request

REQUEST (TRIGGERED BY MM): GET https://<MM URL>/plugins/jira/api/v2/get-create-issue-metadata-for-project?project-keys=MM&instance_id=https://<JIRA URL>

RESPONSE:
{
  "projects": [
    {
      "expand": "description,lead,url,projectKeys",
      "self": "https://<JIRA URL>/rest/api/2/project/105702",
      "id": "105702",
      "key": "MM",
      "name": "Mattermost",
      "issuetypes": [
        {
          "self": "https://<JIRA URL>/rest/api/2/issuetype/10100",
          "id": "10100",
          "iconurl": "https://<JIRA URL>/secure/viewavatar?size=xsmall&avatarId=10311&avatarType=issuetype",
          "name": "Aufgabe",
          "fields": {

### => this custom field is selectable in the "Events" dropdown as "Issue Updated: Custom - Wiedervorlage"
            "customfield_11642": {
              "fieldId": "customfield_11642",
              "hasDefaultValue": false,
              "name": "Wiedervorlage",
              "operations": [
                "set"
              ],
              "required": false,
              "schema": {
                "custom": "com.atlassian.jira.plugin.system.customfieldtypes:datepicker",
                "customId": 11642,
                "type": "date"
              }
            },

### => this non-custom field is *not* selectable
            "duedate": {
              "fieldId": "duedate",
              "hasDefaultValue": false,
              "name": "Fälligkeitsdatum",
              "operations": [
                "set"
              ],
              "required": false,
              "schema": {
                "system": "duedate",
                "type": "date"
              }
            },
            (...)
          }},
          (...)
      ]
    }
  ]
}

Searching in the source code

I also tried to find any information in the source code, but these are too many references to different functions and files for me. That's what I got so far:

export function getCustomFieldValuesForEvents(metadata: IssueMetadata | null, projectKeys: string[]): ReactSelectOption[] {
    return getCustomFieldsForProjects(metadata, projectKeys).filter(isValidFieldForEvents).map((field) => ({
        label: `Issue Updated: Custom - ${field.name}`,
        value: `event_updated_${field.changeLogID}`,
    }));
}
=> https://github.com/mattermost/mattermost-plugin-jira/blob/master/webapp/src/utils/jira_issue_metadata.tsx#L341C1-L346C2


function isValidFieldForEvents(field: JiraField): boolean {
    const {custom} = field.schema;
    if (!custom) {
        return false;
    }

    return !avoidedCustomTypesForEvents.includes(custom);
}
=> https://github.com/mattermost/mattermost-plugin-jira/blob/d2e656b5d14ccf5b19d97ccee14db53f577849aa/webapp/src/utils/jira_issue_metadata.tsx#L332-L339


const avoidedCustomTypesForEvents: string[] = [
    JiraFieldCustomTypeEnums.SPRINT,
    JiraFieldCustomTypeEnums.RANK,
];
=> https://github.com/mattermost/mattermost-plugin-jira/blob/d2e656b5d14ccf5b19d97ccee14db53f577849aa/webapp/src/utils/jira_issue_metadata.tsx#L327C1-L330C3


export function getCustomFieldsForProjects(metadata: IssueMetadata | null, projectKeys: string[]): FieldWithInfo[] {
    const issueTypes = flatten(projectKeys.map((key) => getIssueTypes(metadata, key, {includeSubtasks: true}))) as IssueType[];

    const customFieldHash: {[key: string]: FieldWithInfo} = {};
    const fields = flatten(issueTypes.map((issueType) =>
        Object.keys(issueType.fields).map((key) => ({
            ...issueType.fields[key],
            topLevelKey: key,
            issueTypeMeta: {
                id: issueType.id,
                name: issueType.name,
            },
        })),
    )).filter(Boolean) as FieldWithInfo[];

    for (const field of fields) {
        // Jira server webhook fields don't have keys
        // name is the most unique property available in that case
        const changeLogID = field.key || field.name;
        let current = customFieldHash[field.topLevelKey];
        if (!current) {
            current = {...field, changeLogID, key: field.key || field.topLevelKey, validIssueTypes: []};
        }
        current.validIssueTypes.push(field.issueTypeMeta);

        customFieldHash[field.topLevelKey] = current;
    }

    return sortByName(Object.values(customFieldHash));
}
=> https://github.com/mattermost/mattermost-plugin-jira/blob/master/webapp/src/utils/jira_issue_metadata.tsx#L134-L167

Conclusion

In the "Events" dropdown one can select a lot of our "custom fields" and the typical default events such as "Issue Created", "Issue Resolved", ...
The custom field "Wiedervorlage" is selectable - described as "Issue Updated: Custom - Wiedervorlage".
The system field (non-custom) "due date" or "Fälligkeitsdatum" is not selectable for any reason.

Is there any reason for this behaviour?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions