KEMBAR78
Hide inactive deployments by fxedel · Pull Request #1149 · refined-github/refined-github · GitHub
Skip to content

Conversation

@fxedel
Copy link
Contributor

@fxedel fxedel commented Mar 8, 2018

See description in #1144. Closes #1144.

fxedel added a commit to OpenLightingProject/open-fixture-library that referenced this pull request Mar 8, 2018
@fxedel fxedel changed the title Hide inactive deployments (closes #1144) WIP: Hide inactive deployments (closes #1144) Mar 8, 2018
@fxedel
Copy link
Contributor Author

fxedel commented Mar 8, 2018

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.

@fxedel fxedel changed the title WIP: Hide inactive deployments (closes #1144) Hide inactive deployments (closes #1144) Mar 8, 2018
@fxedel fxedel changed the title Hide inactive deployments (closes #1144) WIP: Hide inactive deployments (closes #1144) Mar 8, 2018
if (isInactive && !isLastDeployment) {
discussionItem.classList.add('rgh-inactive-deployment');
} else {
discussionItem.classList.remove('rgh-inactive-deployment');
Copy link

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?

Copy link
Contributor Author

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');
Copy link

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?

Copy link
Contributor Author

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.

Copy link

@ramlmn ramlmn Mar 8, 2018

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-items)!

Edit: In case removing classes is not needed (comment)

Copy link
Contributor Author

@fxedel fxedel Mar 8, 2018

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.

Copy link

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');
	}
}

@fxedel fxedel changed the title WIP: Hide inactive deployments (closes #1144) Hide inactive deployments (closes #1144) Mar 8, 2018
@fxedel
Copy link
Contributor Author

fxedel commented Mar 8, 2018

@ramlmn Could you please review again? I think I'm done now :)

Copy link

@ProLoser ProLoser left a 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`);
Copy link

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);
Copy link

Choose a reason for hiding this comment

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

`` -> ''

attributes: true,
subtree: true,
attributeFilter: ['class']
});
Copy link
Member

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');
Copy link
Member

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)
Copy link
Member

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

@sindresorhus sindresorhus changed the title Hide inactive deployments (closes #1144) Hide inactive deployments Mar 15, 2018
childList: true,
attributes: true,
subtree: true,
attributeFilter: ['class']
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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:

  1. Initial timeline: (only commits and deployments)
    • 2 commits
    • Active deployment (with View deployment button)
  2. Directly after pushed commit:
    • 2 commits
    • Active deployment (with View deployment button)
    • 1 commit
  3. Some seconds later:
    • 2 commits
    • Active deployment (with View deployment button)
    • 1 commit
    • Pending deployment (with Pending label)
  4. 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';
Copy link
Member

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

Copy link
Contributor Author

@fxedel fxedel Mar 17, 2018

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.

enableFeature(openCIDetailsInNewTab);
enableFeature(waitForBuild);
enableFeature(toggleAllThingsWithAlt);

Copy link
Member

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) {
Copy link
Member

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

@fregante
Copy link
Member

Do you know of a public repo with deployments? I’ve never seen this and can’t test it

@fxedel
Copy link
Contributor Author

fxedel commented Mar 17, 2018

OpenLightingProject/open-fixture-library#425 has a lot of deployment messages.

import observeEl from '../libs/simplified-element-observer';

export default function () {
observeEl('.js-discussion', () => {
Copy link
Member

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;
}

Copy link
Contributor Author

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.

Copy link
Member

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

@FloEdelmann
Copy link
Member

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 :)

@ramlmn
Copy link

ramlmn commented Mar 21, 2018

@bfred-it Merge this fast!

@hkdobrev hkdobrev dismissed fregante’s stale review March 21, 2018 22:12

Dismissing as all comments were addressed.

@hkdobrev
Copy link
Contributor

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.

@fregante
Copy link
Member

Can merge, I haven't had time to re-review :)

@hkdobrev hkdobrev merged commit 7e3670b into refined-github:master Mar 22, 2018
@fxedel fxedel deleted the hide-inactive-deployments branch March 25, 2018 16:55
@yakov116
Copy link
Member

OpenLightingProject/open-fixture-library#425 has a lot of deployment messages.

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.

@FloEdelmann
Copy link
Member

@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).

@yakov116
Copy link
Member

Oh I should have disabled the feature before. No wonder I didn't see anything 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Hide inactive deployments

8 participants