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

Jira integration issues #49

Closed
DePalmo opened this issue Nov 20, 2019 · 3 comments
Closed

Jira integration issues #49

DePalmo opened this issue Nov 20, 2019 · 3 comments

Comments

@DePalmo
Copy link

DePalmo commented Nov 20, 2019

A few months ago Jira updated and the button was gone. I did check other issues here and they all claim it has been resolved but not in my case. I was using Clockify 1.7.9 and in Jira a view where I have a list of issues on the left side with details on the right.

Yesterday I decided that I need Clockify again so looked into updating it myself so it would work for my case and have managed to do that, but the problem now is that the second time I view an issue, the "Start timer" button shows for a second and is then removed. Note that on first issue view, button is added and stays there.

Do you have any ideas why the button would be shown briefly and then removed when I view an issue the second time?

The code update I did in atlassian.js:

clockifyButton.render(
    'div[id="issue-content"]:not(.clockify)',
    { observe: true },
    (elem) => {
        if (document.getElementById('clockifyButton')) {
            console.log('clockify: button removed');
            document.getElementById('clockifyButton').remove();
        }

        const page = elem.closest('div[id="page"]');
        const container =
            $('div[class="aui-page-header-main"]', elem);
        const issueNumber = $('a[class="issue-link"]', container).textContent;
        const desc = $('h1[id="summary-val"]', elem).textContent;

        // Try to find the project
        let project = $('a[id="project-name-val"]', page);
        if (project) {
            project = project.textContent;
        } else {
            project = '';
        }

        const link = clockifyButton.createButton(issueNumber + ' ' + desc, project);
        link.style.position = "relative";
        link.style.padding = "2px 0 0 20px";

        container.appendChild(link);
        console.log('clockify: button added', container);
    }
);

Do note that I also removed all other integration options for Atlassian, but that didn't solve the problem with disappearing button.

@DePalmo
Copy link
Author

DePalmo commented Nov 20, 2019

After a few more tests, it looks like Jira itself removes the button, not sure why. But when I moved the button outside of div[class="issue-container"], the button wasn't removed and it was properly updated by Clockify code with new issue details.

Can you please integrate this code into atlassian.js for next version release:

// AUI layout
clockifyButton.render(
    'div[id="issue-content"]:not(.clockify)',
    { observe: true },
    (elem) => {
        if (document.getElementById('clockifyButton')) {
            document.getElementById('clockifyButton').remove();
        }

        const page = elem.closest('div[id="page"]');
        const container = $('div[class="aui-page-header-main"]', elem);
        const targetEl = $('.search-container');
        const issueNumber = $('a[class="issue-link"]', container).textContent;
        const desc = $('h1[id="summary-val"]', elem).textContent;

        // Try to find the project
        let project = $('a[id="project-name-val"]', page);
        if (project) {
            project = project.textContent;
        } else {
            project = '';
        }

        const link = clockifyButton.createButton(issueNumber + ' ' + desc, project);
        link.style.position = "relative";
        link.style.padding = "6px 10px 7px 20px";
        link.style.marginLeft = "10px";
        link.style.verticalAlign = "top";
        link.style.lineHeight = "30px";

        targetEl.appendChild(link);
    }
);

if (document.getElementById('issue-content')) {
    document.getElementById('issue-content').classList.remove('clockify');

    if (document.getElementById('clockifyButton')) {
        document.getElementById('clockifyButton').remove();
    }
}

I presume that we're using a custom made layout and that one is not supported by your extension. I did try to see what layout we're on, but Jira is too complex to determine that.

@aleksandar-olic
Copy link
Contributor

Thanks for this! Could you push your changes and send us a pull request? There's some other code that targets the same selector, so we're not sure what's the interaction between these.

@DePalmo
Copy link
Author

DePalmo commented Nov 22, 2019

I noticed that too, but in my tests there was no issues. I can add a few IF statements in there, just to be sure that it will only catch proper elements and not throw errors if those are not found.

Will try to do a pull request, never did that before on GitHub since I am using BitBucket primarily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants