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

Add releases-dropdown feature #6506

Merged
merged 10 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ Thanks for contributing! 🦋🙌

- [](# "release-download-count") [Adds a download count next to release assets.](https://user-images.githubusercontent.com/1402241/197958719-1577bc1b-1f4d-44a8-98c2-2645b7b14d31.png)
- [](# "releases-tab") [Adds a `Releases` tab and a keyboard shortcut: <kbd>g</kbd> <kbd>r</kbd>.](https://cloud.githubusercontent.com/assets/170270/13136797/16d3f0ea-d64f-11e5-8a45-d771c903038f.png)
- [](# "tags-dropdown") [Adds a tags dropdown/search on tag/release pages.](https://user-images.githubusercontent.com/1402241/231678527-f0a96112-9c30-4b49-8205-efa472bd880e.png)
- [](# "create-release-shortcut") Adds a keyboard shortcut to create a new release while on the Releases page: <kbd>c</kbd>.
- [](# "tag-changes-link") 🔥 [Adds a link to changes since last tag/release for each tag/release.](https://user-images.githubusercontent.com/1402241/57081611-ad4a7180-6d27-11e9-9cb6-c54ec1ac18bb.png)
- [](# "latest-tag-button") [Adds a link to the latest version tag on directory listings and files.](https://user-images.githubusercontent.com/44045911/155496122-6267c45d-21d4-45c9-adf7-94c9e41cc652.png)
Expand Down
61 changes: 61 additions & 0 deletions source/features/tags-dropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'dom-chef';
import * as pageDetect from 'github-url-detection';
import delegate, {DelegateEvent} from 'delegate-it';

import * as api from '../github-helpers/api';
import features from '../feature-manager';
import {buildRepoURL} from '../github-helpers';
import observe from '../helpers/selector-observer';

let latestTags: string[] | undefined;

const gql = `
repository() {
refs(refPrefix: "refs/tags/", last: 100) {
nodes {
name
}
}
}
`;

// `datalist` selections don't have an `inputType`
function selectionHandler(event: DelegateEvent<Event, HTMLInputElement>): void {
const field = event.delegateTarget;
const selectedTag = field.value;
if (!('inputType' in event) && latestTags!.includes(selectedTag)) {
location.href = buildRepoURL('releases/tag', selectedTag);
Copy link
Member Author

Choose a reason for hiding this comment

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

As expected, it's broken on unescaped tag names:

https://github.com/refined-github/refined-github/releases

Screenshot 5

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed! Pretty sure we have the same bug in features like tags-on-commits-list too

field.value = '';
}
}

async function addList(searchField: HTMLInputElement): Promise<void> {
const {repository} = await api.v4(gql);
const nodes = repository.refs.nodes as Array<{name: string}>;
if (nodes.length === 0) {
return;
}

// Save globally
latestTags = nodes.map(({name}) => name).reverse();

searchField.after(
<datalist id="rgh-tags-dropdown">
{latestTags.map(tag => <option value={tag}/>)}
</datalist>,
);
searchField.setAttribute('list', 'rgh-tags-dropdown');
Copy link
Member Author

Choose a reason for hiding this comment

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

Unreal… searchField.list is read-only 🤷‍♂️

}

const searchFieldSelector = 'input#release-filter';
async function init(signal: AbortSignal): Promise<void> {
observe(searchFieldSelector, addList, {signal});
delegate(document, searchFieldSelector, 'input', selectionHandler, {signal});
}

void features.add(import.meta.url, {
include: [
pageDetect.isReleasesOrTags,
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@kidonng kidonng Apr 14, 2023

Choose a reason for hiding this comment

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

Then this should use isReleases? Because the search box only exists there

Also previous tags-dropdown works on tags page, should this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Then this should use isReleases? Because the search box only exists there

Done

Also previous tags-dropdown works on tags page, should this one?

The issue is that the native field SEARCHES the releases notes, which means it does nothing on tags. See https://github.com/python/cpython/releases?q=v3&expanded=true which is empty even if there are plenty "v3" tags

So if we were to add this feature there, we'd have to reinvent the feature to not use datalist. Not worth it in this PR (or maybe ever)

],
init,
});
2 changes: 2 additions & 0 deletions source/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ interface GlobalEventHandlersEventMap {
'page:loaded': CustomEvent;
'turbo:visit': CustomEvent;
'session:resume': CustomEvent;
// No input:InputEvent match
// https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1174#issuecomment-933042088
}

declare namespace JSX {
Expand Down
1 change: 1 addition & 0 deletions source/refined-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,4 @@ import './features/file-age-color';
import './features/netiquette';
import './features/rgh-netiquette';
import './features/small-user-avatars';
import './features/tags-dropdown';