-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from 3 commits
0d4b6cb
54aa694
f2d6d7f
b88b508
14c71d6
086afba
ec0157f
1ff4abe
76f74b1
9b4ba57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unreal… |
||
} | ||
|
||
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then this should use Also previous There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Done
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 |
||
], | ||
init, | ||
}); |
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 expected, it's broken on unescaped tag names:
https://github.com/refined-github/refined-github/releases
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.
Fixed! Pretty sure we have the same bug in features like
tags-on-commits-list
tooThere 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.
All good:
Also cool UI:
/*\
/*%26apos;)/*<!--></Title/</Style/</Script/</textArea/</iFrame/</noScript>\74k<K/contentEditable/autoFocus/OnFocus=/*${/*/;{/**/(alert)(1)}//><Base/Href=//X55.is\76--> sandbox#40