-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
restore-file - Add support for new PR view
#8870
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
Conversation
Fixes: refined-github#8714 - Added support for the new React-based PR files view - Keep legacy view handling unchanged - Use GitHubFileURL for URL parsing - Track focused file container via global variable for removal after discard - Use octicon library (GitCompareIcon) for the menu item icon - Handle renamed files by checking React props for RENAMED status 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The menu is created fresh on each click, so items can't already exist. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
source/features/restore-file.tsx
Outdated
| // New React view: get filenames from the View File link and React props | ||
| const fileAnchor = menuItem | ||
| .closest('ul')! | ||
| .querySelector<HTMLAnchorElement>('li:has(svg.octicon-eye) a')!; | ||
|
|
||
| const fileUrl = new GitHubFileURL(fileAnchor.href); | ||
| const newFileName = fileUrl.filePath; | ||
|
|
||
| // Check if the file was renamed by looking at the React props | ||
| const reactPropsElement = $('[data-target="react-app.embeddedData"]'); | ||
| const reactProps = JSON.parse(reactPropsElement.textContent); | ||
|
|
||
| const diffContents = reactProps.payload.diffContents.find( | ||
| (dc: {path: string}) => dc.path === newFileName, | ||
| ); | ||
|
|
||
| const originalFileName = diffContents?.status === 'RENAMED' | ||
| ? diffContents.oldTreeEntry.path | ||
| : newFileName; | ||
|
|
||
| return {original: originalFileName, new: newFileName}; |
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.
You can do:
const [originalFileName, newFileName = originalFileName] = $('.Link--primary span:not(.sr-only)', focusedFileContainer).textContent.split(' ')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.
done
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 variant I previously suggested works only for renamed files and doesn't account for invisible LRM chars.
Here is a better one:
const fileNameElement = $('[class^="DiffFileHeader-module__file-name"]', focusedFileContainer);
const span = $optional('span:not(.sr-only)', fileNameElement);
const [originalFileName, newFileName = originalFileName] = (span ?? fileNameElement)
// eslint-disable-next-line unicorn/prefer-string-replace-all -- Invisible char
.textContent.split(' ').map(text => text.replaceAll(/\u200E/g, ''));Use focusedFileContainer to get filenames directly from the file header, matching the pattern used in the legacy view. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
source/features/restore-file.tsx
Outdated
|
|
||
| function getFilenames(menuItem: HTMLElement): {original: string; new: string} { | ||
| // Legacy view: get filenames from the data-path and Link--primary elements | ||
| // TODO: Drop in June 2026 |
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 is probably premature. The policy is to keep support for removed UI for 6 months. The React-based view is still in preview and could remain there for a couple more months. The same applies to lines 133, 145, and 181.
source/features/restore-file.tsx
Outdated
| focusedFileContainer = delegateTarget.closest('[class*="DiffFileHeader-module__diff-file-header"]')! | ||
| .parentElement!; |
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.
You are selecting only a header
| focusedFileContainer = delegateTarget.closest('[class*="DiffFileHeader-module__diff-file-header"]')! | |
| .parentElement!; | |
| focusedFileContainer = delegateTarget.closest('div[id^="diff-"]')!; |
The React-based view is still in preview, so we shouldn't mark legacy code for removal yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use DiffFileHeader-module__file-name selector - Use $optional for span to handle both renamed and non-renamed files - Strip invisible LRM characters from filenames 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Select the whole diff container (div[id^="diff-"]) instead of just the header, so the entire file diff is removed after discard. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@SunsetTechuila I was also able to follow the good instructions in https://github.com/refined-github/refined-github/wiki/Contributing to help me actually test this by the end. And I can confirm it's working! Thanks so much! |
|
@SunsetTechuila @fregante do I need to do anything to make it mergeable? 😆 I want this so badly it's my favorite feature of RG |
Only wait a bit |
restore-file - Add support for new React viewrestore-file - Add support for new PR view
|
Thanks @maschwenk! |
Fixes
restore-filebroken in new GitHub PR File List view #8714Reimplementation of
restore-file- Add support for new PR Files #8749addressing the maintainer's feedback, trying to sidestep drama. In honesty I don't totally know how to test this.
Changes
GitHubFileURLhelper for URL parsing instead of manual regexfocusedFileContainer) for removal after discard operationGitCompareIcon) for the menu item iconRENAMEDstatus with the suggested conditional expressionhandleMenuOpeningpattern frommore-file-links.tsxfor adding menu itemsKey differences from previous PR
addLegacyMenuItem,observe) remains exactly as it wasGitHubFileURLinstead of manual string manipulationrestore-file.tsxwhere it belongs, returns{original, new}as suggestedTest URLs