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

Fix K2 for new GitHub UI #226

Merged
merged 17 commits into from
Jan 17, 2025
Merged

Fix K2 for new GitHub UI #226

merged 17 commits into from
Jan 17, 2025

Conversation

mjasikowski
Copy link
Contributor

@mjasikowski mjasikowski commented Jan 14, 2025

The new javascript selectors are looking nasty, unfortunately the new GitHub UI has a lot of random, unreliable class names that we can't really attach to. This the best I could do in a short timespan.

I hope they won't shift the UI around once again.

Testing

  1. Build the extension for your browser of choice with npm run build:chrome or npm run build:firefox
  2. Package it to a dist.zip file with npm run package
  3. Load it up (for Firefox, you need to go to about:debugging)
  4. Check if the K2 dashboard work correctly at https://github.com/Expensify/Expensify#k2
  5. Go to an issue (you can use this one for testing, but still be wary what you press). Check if the issue owner change buttons (stars) and buttons on the right hand side load correctly and if they work.
  6. Got a PR that has [HOLD] in the title (you can use this one for testing) and see if the merge pull request button is disabled with an appropriate message above it

@mjasikowski mjasikowski changed the title Fix K2 for new GitHub UI [Hold] Fix K2 for new GitHub UI Jan 14, 2025
@mjasikowski mjasikowski marked this pull request as ready for review January 14, 2025 09:24
@mjasikowski mjasikowski requested review from a team and tgolen January 14, 2025 10:46
@melvin-bot melvin-bot bot requested review from MonilBhavsar and removed request for a team January 14, 2025 10:46
@mjasikowski
Copy link
Contributor Author

Made this version 1.4.0 (minor version bump), as it's quite a big change.

@mjasikowski mjasikowski self-assigned this Jan 14, 2025
@mjasikowski mjasikowski changed the title [Hold] Fix K2 for new GitHub UI Fix K2 for new GitHub UI Jan 14, 2025
src/js/lib/pages/github/issue.js Outdated Show resolved Hide resolved
src/js/lib/pages/github/issue.js Outdated Show resolved Hide resolved
$('div[data-testid="mergebox-partial"] > div > div > section:last-of-type h3')
.text('You cannot merge your own PR');
$('div[data-testid="mergebox-partial"] > div > div > section:last-of-type p')
.html('It\'s like giving yourself a high-five in public.');
Copy link
Contributor

Choose a reason for hiding this comment

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

🤩

@tgolen tgolen changed the title Fix K2 for new GitHub UI [HOLD] Fix K2 for new GitHub UI Jan 14, 2025
tgolen
tgolen previously approved these changes Jan 14, 2025
Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

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

I'm gonna install this and test it out today!

@tgolen tgolen changed the title [HOLD] Fix K2 for new GitHub UI Fix K2 for new GitHub UI Jan 14, 2025
@tgolen
Copy link
Contributor

tgolen commented Jan 14, 2025

It looks like the issue owner feature isn't working quite right.

image

Bug 1

Steps taken:

  1. Click the star next to my name
  2. Verify that the Issue Owner data is added to the GH description

Expected outcome:

The star next to my name should now be yellow to indicate that I am the issue owner

Actual outcome:

All the stars remain uncolored

@tgolen
Copy link
Contributor

tgolen commented Jan 14, 2025

Bug 2

Steps Taken:

  1. With one person assigned as the issue owner (as verified by the Issue Owner markdown in the GH description)
  2. Click the star next to a different assignee to change them to be the current owner

Expected Outcome

The old owner should be removed and the new owner should be added.

Actual Outcome

The markdown in the GH description contains duplicate Issue Owner data for both people.

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

Thanks, looks good. Please add test steps and make sure everything changed is working. I see Tim found some bugs.

@mjasikowski
Copy link
Contributor Author

Hm, that's weird, I tested the stars earlier today and they were working fine. I'll take another look and see if I can fix that! Thanks for reporting.

MonilBhavsar
MonilBhavsar previously approved these changes Jan 14, 2025
Copy link
Contributor

@MonilBhavsar MonilBhavsar left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

@@ -47,11 +45,11 @@ export default function () {
Page.setup = function () {};

Page.getRepoOwner = function () {
return $('.author a span').text();
return document.querySelectorAll('.AppHeader-context-item-label.Truncate-text')[0].textContent.trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB, I wonder if we could keep the repeatedly used selectors as constant with meaningful names of what we are selecting - For example - const selectorForRepoLabel = '.AppHeader-context-item-label.Truncate-text'; , so next time github changes UI, we could simply change the constant instead of going all over the code, and hopefully it should be simple to transition and works 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For sure, I agree with that. Once we get this PR of the gate I'll spend some time to reorganize the selectors a little bit.

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be great. Thank you!!

Copy link
Contributor

Choose a reason for hiding this comment

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

NAB ➕ I would also like to see this. Is it easy enough to do in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The repeating selectors are now removed, but I've added a bunch of comments for existing selectors to clarify what exactly they are selecting.

I chose comments over variables to not have to introduce additional null checks to satisfy ESLint for selectors that turn out empty.

@mjasikowski mjasikowski dismissed stale reviews from MonilBhavsar and tgolen via 8e464d5 January 15, 2025 09:57
@mjasikowski
Copy link
Contributor Author

A few new changes:

  • Fixed bugs reported by @tgolen
  • I've modified the owner setting behavior to work based on events with async/await, rather than issue body parsing (for some reason this wasn't working too well)
  • Removed the previously-borked-but-fixed behavior that prevented PR self-merging per this discussion
  • Added some simple spinner animations for changing the issue owner and clicking checklist copy buttons
  • Optimized/simplified the code for setting the owner and rendering checklist copy buttons
  • Removed createpr.js, which was unused and contained references to functions that don't exist
  • Removed some obsolete rules from .eslintrc.js:
{
        '@lwc/lwc/no-async-await': 'off',
        'es/no-nullish-coalescing-operators' : 'off'
}

@mjasikowski mjasikowski changed the title Fix K2 for new GitHub UI [HOLD] Fix K2 for new GitHub UI Jan 15, 2025
@mjasikowski mjasikowski changed the title [HOLD] Fix K2 for new GitHub UI Fix K2 for new GitHub UI Jan 15, 2025
@mjasikowski
Copy link
Contributor Author

Small bug fix, but ready for review now.

src/js/lib/pages/github/_base.js Outdated Show resolved Hide resolved
src/js/lib/pages/github/issue.js Outdated Show resolved Hide resolved
src/js/lib/pages/github/issue.js Outdated Show resolved Hide resolved
@tgolen
Copy link
Contributor

tgolen commented Jan 15, 2025

It looks like the K2 label buttons aren't working quite right.

Here, I've changed the issue from Daily to Monthly (but clicking on the "M" button) and it's left both labels on the issue.
image

Here is a case where the "M" button isn't highlighted (like after refreshing the page).
image

@mjasikowski
Copy link
Contributor Author

@tgolen reverted the previous assignee setting functions and fixed the K2 label selectors, would you mind giving a spin again?

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

One small fix please. Other than that it looks good assuming testing passes. Can you please write test steps even if it's just "load the K2 extension from this branch and test all features"?

Comment on lines 38 to 46
console.error(`Failed to load contents of ${checklistUrl}: ${response.statusText}`);
return;
}

const fileContents = await response.text();

if (!fileContents) {
console.error(`Could not load contents of ${checklistUrl} for some reason`);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

In these error cases we should revert the loader. So instead of logging and returning we could throw an error and have the catch and finally block handle things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the original code moved to a different function, but I changed it to:

        try {
            // Fetch the checklist contents
            const response = await fetch(checklistUrl);
            const fileContents = await response.text();

            // Call the API to add the comment
            await API.addComment(fileContents);
        } catch (error) {
            console.error('Error fetching the checklist:', error);
        } finally {
            // Restore the original button content
            button.innerHTML = originalContent;
        }

this way the loader will always be reverted, and:

  1. If fetch() returns something other than 200, it will throw anyway
  2. If fetched text is empty, then API.addComment() will throw due to incorrect parameters

So all error cases are covered now.

@@ -47,11 +45,11 @@ export default function () {
Page.setup = function () {};

Page.getRepoOwner = function () {
return $('.author a span').text();
return document.querySelectorAll('.AppHeader-context-item-label.Truncate-text')[0].textContent.trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB ➕ I would also like to see this. Is it easy enough to do in this PR?

tgolen
tgolen previously approved these changes Jan 16, 2025
@mjasikowski
Copy link
Contributor Author

@neil-marcellini basic test steps added and all change requests were addressed

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

Good to go! Thanks for your hard work.

@neil-marcellini neil-marcellini merged commit d433312 into main Jan 17, 2025
3 checks passed
@neil-marcellini neil-marcellini deleted the github-new-ui-fix branch January 17, 2025 16:21
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

Successfully merging this pull request may close these issues.

4 participants