-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Hide inactive deployments #1149
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
Hide inactive deployments #1149
Conversation
The classes are removed as soon as the page is reloaded via AJAX (e.g. when a new commit is added). I'll try to fix that. Edit: I added a observer, but it watches too many events which slows down the page. |
if (isInactive && !isLastDeployment) { | ||
discussionItem.classList.add('rgh-inactive-deployment'); | ||
} else { | ||
discussionItem.classList.remove('rgh-inactive-deployment'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have to keep removing the class for these elements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to catch cases in which inactive deployments are reactivated again later. Don't if this happens.
import select from 'select-dom'; | ||
|
||
export default function () { | ||
const deployments = select.all('.discussion-item .deployment-meta'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this be changed to .discussion-item .deployment-meta.is-inactive
and skip checks inside loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the last deployment message is invalid, I don't want to hide it. That's why I have to go through all deployments, and only hide them if they are invalid and not the last deployment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only meant to skip the isInactive
check (by only looping through inactive deployment-item
s)!
Edit: In case removing classes is not needed (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isLastDeployment
check refers to all deployments, inactive and active ones.
For example:
inactive -> hidden
inactive -> hidden
inactive -> hidden
active
inactive -> hidden
inactive
inactive -> hidden
inactive -> hidden
active
active
Not the last inactive should be shown, but the last deployment (even if it is inactive).
However, I could save the amount of deployment items and loop through the inactive ones then. Edit: I can't, as the index would be incorrect then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I understand what you are trying to do. I thought the .is-inactive
class was in .deployment-meta
.
Can you try this:
const deployments = select.all('.discussion-item .deployment-meta');
deployments.pop(); // don't hide the last deployment, even if it is inactive
for (const deployment of deployments) {
const discussionItem = deployment.closest('.discussion-item');
const isInactiveDeployment = select.exists('.is-inactive', deployment);
if (isInactiveDeployment) {
discussionItem.setAttribute('data-rgh-inactive-deployment', 'true');
}
}
@ramlmn Could you please review again? I think I'm done now :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
const deployments = select.all('.discussion-item .deployment-meta'); | ||
|
||
deployments.forEach((deployment, index) => { | ||
const discussionItem = deployment.closest(`.discussion-item`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``
-> ''
deployments.forEach((deployment, index) => { | ||
const discussionItem = deployment.closest(`.discussion-item`); | ||
|
||
const isInactive = select.exists(`.is-inactive`, deployment); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``
-> ''
source/content.js
Outdated
attributes: true, | ||
subtree: true, | ||
attributeFilter: ['class'] | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in the feature file. You should only have enableFeature(hideInactiveDeployments);
here.
const isInactiveDeployment = select.exists('.is-inactive', deployment); | ||
if (isInactiveDeployment) { | ||
const discussionItem = deployment.closest('.discussion-item'); | ||
discussionItem.setAttribute('data-rgh-inactive-deployment', 'true'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use .dataset
instead.
readme.md
Outdated
- [Makes the "Expand diff" button wider](https://user-images.githubusercontent.com/6978877/34470024-eee4f43e-ef20-11e7-9036-65094bd58960.PNG) | ||
- [Automatically closes modals when they’re no longer visible](https://user-images.githubusercontent.com/1402241/37022353-531c676e-2155-11e8-96cc-80d934bb22e0.gif) | ||
- [Highlights permalinked comments](https://user-images.githubusercontent.com/1402241/37349492-226bd37a-2709-11e8-8087-d9686b330240.png) | ||
- [Hide inactive deployments in PR timeline](https://github.com/sindresorhus/refined-github/issues/1144) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this:
Hides inactive deployments in the PR timeline
childList: true, | ||
attributes: true, | ||
subtree: true, | ||
attributeFilter: ['class'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this all necessary? I think others observers on the discussion only listen to childList. Subtree is heavy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if the node list is updated when a deployment changes from active to inactive. That's why I'm watching class names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're still selecting them all, so whether the class is there or not will be found by is-inactive
, right?
Worst case scenario there's an old inactive deployment on the current page... because the user never left the page. I'll take that over watching all nodes on PR pages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested it again at OpenLightingProject/open-fixture-library#449 with only childList
set to true:
- Initial timeline: (only commits and deployments)
- 2 commits
- Active deployment (with
View deployment
button)
- Directly after pushed commit:
- 2 commits
- Active deployment (with
View deployment
button) - 1 commit
- Some seconds later:
- 2 commits
- Active deployment (with
View deployment
button) - 1 commit
- Pending deployment (with
Pending
label)
- About a minute later:
- 2 commits
- 1 commit
- Active deployment (with
View deployment
button)
I thought that at least subtree
had to be turned on, as from 3. to 4., no element is (visually) added or removed from the timeline. However, it seems like that not the last deployment's contents are changed from pending to active, but the complete timeline item is replaced with a new node.
So you're right, childList
is sufficient (as it's the default, I'll remove the whole options object).
const isInactiveDeployment = select.exists('.is-inactive', deployment); | ||
if (isInactiveDeployment) { | ||
const discussionItem = deployment.closest('.discussion-item'); | ||
discussionItem.dataset.rghInactiveDeployment = 'true'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can just be a class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I'm watching class names, setting a class would create an infinite loop.
Edit: I'm not watching them anymore, so I'll use a class instead.
source/content.js
Outdated
enableFeature(openCIDetailsInNewTab); | ||
enableFeature(waitForBuild); | ||
enableFeature(toggleAllThingsWithAlt); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for space here
|
||
for (const deployment of deployments) { | ||
const isInactiveDeployment = select.exists('.is-inactive', deployment); | ||
if (isInactiveDeployment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be if select.exists
without the extra var. Same for discussionItem on the next line
Do you know of a public repo with deployments? I’ve never seen this and can’t test it |
OpenLightingProject/open-fixture-library#425 has a lot of deployment messages. |
import observeEl from '../libs/simplified-element-observer'; | ||
|
||
export default function () { | ||
observeEl('.js-discussion', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deployments only appear in PRs, right? Then before observeEl
I think we need this:
if (!pageDetect.isPR()) {
return;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this is done in content.js
, but I added it anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We’re trying to move away from that, so that the feature is self-contained
Any news here? It seems like all requested changes are implemented. As I am the owner of the repo mentioned above, I'd really like to see this feature merged soon :) |
@bfred-it Merge this fast! |
Dismissing as all comments were addressed.
Everything looks good to me! I'm going to merge tomorrow if there's nothing to give a few hours to @bfred-it if he wants something to add here. |
Can merge, I haven't had time to re-review :) |
Wow am I glad that we now have a PR template to include a URL. Took me almost 10 min to find a URL to test on. @FloEdelmann do you have URL that this feature still works on. The linked URL does not. |
@yakov116 The linked URL works for me in both Firefox and Chromium, even after clicking "Load more…". Note that failed deployments are not hidden, only inactive ones (except for the latest deployment, regardless its status). |
Oh I should have disabled the feature before. No wonder I didn't see anything 😀 |
See description in #1144. Closes #1144.