Skip to content

Restore tags-dropdown link to open tag pages - #2659

Merged
fregante merged 10 commits into
refined-github:masterfrom
hardikmodha:fix_tags_dropdown
Jan 12, 2020
Merged

fregante merged 10 commits into
refined-github:masterfrom
hardikmodha:fix_tags_dropdown

Conversation

@hardikmodha

@hardikmodha hardikmodha commented Dec 29, 2019 •

Copy link
Copy Markdown
Contributor

Closes #2658

Test

  1. Open any repo's releases page. (e.g. https://github.com/sindresorhus/refined-github/releases)
  2. Open the "Select tag" dropdown and click on any tag. (e.g. Selecting 19.12.22)
  3. Observer the behavior, it should redirect to the tag page. (https://github.com/sindresorhus/refined-github/releases/tag/19.12.22)

@hardikmodha hardikmodha changed the title Fix tags dropdown on releases page. Closes #2658 Fix tags dropdown on releases page. Dec 29, 2019
Comment thread source/features/tags-dropdown.tsx Resolved
@hardikmodha hardikmodha changed the title Fix tags dropdown on releases page. WIP: Fix tags dropdown on releases page. Jan 1, 2020
This reverts commit 496dec8.
@hardikmodha hardikmodha changed the title WIP: Fix tags dropdown on releases page. Fix tags dropdown on releases page. Jan 1, 2020
@hardikmodha
hardikmodha requested a review from fregante January 2, 2020 17:20
@fregante

fregante commented Jan 5, 2020

Copy link
Copy Markdown
Member

This feature used to be handled by onFragmentLoaded. If that doesn't work, it needs to be removed; perhaps you can listen to the event before the fragment loads, so you don't have to listen to load

@fregante fregante added the bug label Jan 5, 2020
@refined-github refined-github deleted a comment Jan 5, 2020
@hardikmodha

Copy link
Copy Markdown
Contributor Author

This feature used to be handled by onFragmentLoaded. If that doesn't work, it needs to be removed; perhaps you can listen to the event before the fragment loads, so you don't have to listen to load

Sorry, but I didn't get this. It is being handled by onFragmentLoaded right now and it is working.

@fregante

fregante commented Jan 5, 2020

Copy link
Copy Markdown
Member

I mean the load event handler was used to detect the updated list. Now the list update is handled by remote-input-success, so load is no longer necessary: they're there for the same purpose.

@hardikmodha

Copy link
Copy Markdown
Contributor Author

I believe, we still need this load event handler because the remote-input, tags list is only available after when this load event handler is fired.

@fregante

fregante commented Jan 5, 2020 •

Copy link
Copy Markdown
Member

If the event bubbles, we don't have to listen to it specifically on remote-input.

I think with useCapture: true you can catch events even if they don't bubble.

@hardikmodha

Copy link
Copy Markdown
Contributor Author

Got that. The remote-input-success event being bubbled https://github.com/github/remote-input-element/blob/master/src/index.ts#L122 but still, we'll need load event to change the tab from "Branch" to "Tags". https://github.com/sindresorhus/refined-github/blob/master/source/features/tags-dropdown.tsx#L38.

A relevant question, Is there any disadvantage of listening it specifically on remote-input element?

@fregante

fregante commented Jan 6, 2020

Copy link
Copy Markdown
Member

Is there any disadvantage of listening it specifically on remote-input element?

That's irrelevant, my suggestion was to drop code that was no longer necessary (i.e. listening to the load event)

we'll need load event to change the tab from "Branch" to "Tags".

If that's the case, onFragmentLoaded can stay, but I'd still like the handlers to be separated and storing the remote-input-success handler function on the top level.

Something like:

function init(): void {
	if (select.exists('.blankslate')) {
		return false;
	}

	select('.subnav')!.append(
		// ...
	);

	// https://github.com/github/remote-input-element#events
	// Wait until the network request is finished and HTML body is updated
	select('.rgh-tags-dropdown')!.addEventListener('remote-input-success', onRemoteInput);
}

function onFragmentLoaded(): void {
	// Change the tab to "Tags"
	select('.rgh-tags-dropdown .select-menu-tab:last-child button')!.click();
}

function onRemoteInput(): void {
	// Change links, which point to the content of each tag, to open the tag page instead
	for (const anchorElement of select.all<HTMLAnchorElement>('.rgh-tags-dropdown .select-menu-list:last-child [href*="/tree/"]')) {
		const pathnameParts = anchorElement.pathname.split('/');
		pathnameParts[3] = 'releases/tag'; // Replace `tree`
		anchorElement.pathname = pathnameParts.join('/');
	}
}

@fregante

fregante commented Jan 6, 2020

Copy link
Copy Markdown
Member

The two handlers could also be renamed to what they actually do since they don't actually handle the event; e.g. useTagsTab and updateLinksToTags respectively

@fregante fregante changed the title Fix tags dropdown on releases page. Restore tags-dropdown link to open tag pages Jan 12, 2020
@fregante
fregante merged commit 5ee6b16 into refined-github:master Jan 12, 2020
@fregante

Copy link
Copy Markdown
Member

Thanks Hardik 🌶

// https://github.com/github/remote-input-element#events
// Wait until the network request is finished and HTML body is updated
// "remote-input-success" event is bubbled
select('.rgh-tags-dropdown')!.addEventListener('remote-input-success', updateLinksToTag);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Support for on-remote-input-success JSX attributes has been added, in case you want to move this.

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

Labels

Development

Successfully merging this pull request may close these issues.

Tags dropdown is broken on releases page

2 participants