Repository navigation
Ask before every destructive action in the dashboard #429
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f7465a3
Ask before every destructive action in the dashboard
artyomsv 8c53728
Document proxy manager settings from the first install
artyomsv 757d8a1
Move the legacy entry from ScmConnections to its extracted form
artyomsv b9b92f5
Move the confirmation tests into their own files
artyomsv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import { render, screen, waitFor, fireEvent, within } from '@testing-library/react'; | ||
| import { OperatorLinksTable } from './OperatorLinksTable'; | ||
| import * as api from '../api'; | ||
|
|
||
| /** | ||
| * Unlinking stops an operator seeing their own numbers for that account, so the trash icon only | ||
| * asks; nothing is unlinked until the dialog's Unlink is pressed. | ||
| */ | ||
|
|
||
| const LINKS: api.OperatorIdentityLink[] = [ | ||
| { oidcSubject: 'TEST-SUBJECT-1', providerType: 'github', authorId: '3218389', authorHandle: 'TEST-handle' }, | ||
| ]; | ||
| const OPERATORS: api.SeenOperator[] = [ | ||
| { subject: 'TEST-SUBJECT-1', username: 'test-user-one', displayName: 'TEST Operator One' }, | ||
| ]; | ||
|
|
||
| function renderTable(onUnlinked = vi.fn()) { | ||
| render(<OperatorLinksTable links={LINKS} operators={OPERATORS} candidates={[]} onUnlinked={onUnlinked} />); | ||
| fireEvent.click(screen.getByRole('button', { name: 'Unlink TEST-SUBJECT-1 on github' })); | ||
| return screen.getByRole('dialog'); | ||
| } | ||
|
|
||
| describe('OperatorLinksTable unlinking', () => { | ||
| it('asks first, naming the operator and the account', () => { | ||
| const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); | ||
|
|
||
| expect(renderTable()).toHaveTextContent('Unlink TEST Operator One · test-user-one from github · TEST-handle?'); | ||
| expect(unlink).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('unlinks once the dialog is confirmed', async () => { | ||
| const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); | ||
| const onUnlinked = vi.fn(); | ||
|
|
||
| fireEvent.click(within(renderTable(onUnlinked)).getByRole('button', { name: 'Unlink' })); | ||
|
|
||
| await waitFor(() => expect(unlink).toHaveBeenCalledWith('TEST-SUBJECT-1', 'github')); | ||
| await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); | ||
| expect(onUnlinked).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('keeps the link when the dialog is cancelled', () => { | ||
| const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); | ||
|
|
||
| fireEvent.click(within(renderTable()).getByRole('button', { name: 'Cancel' })); | ||
|
|
||
| expect(screen.queryByRole('dialog')).toBeNull(); | ||
| expect(unlink).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { useState } from 'react'; | ||
| import { Trash2 } from 'lucide-react'; | ||
| import { ObservedAuthor, OperatorIdentityLink, SeenOperator, unlinkOperatorIdentity } from '../api'; | ||
| import ConfirmDialog from './ConfirmDialog'; | ||
| import { NameWithId } from './NameWithId'; | ||
|
|
||
| interface Props { | ||
| links: OperatorIdentityLink[]; | ||
| operators: SeenOperator[]; | ||
| candidates: ObservedAuthor[]; | ||
| onUnlinked: () => void; | ||
| } | ||
|
|
||
| /** | ||
| * The operator-to-account links, each with an Unlink that waits for a yes: an unlinked operator stops seeing their own | ||
| * numbers for that account until somebody links it again. | ||
| */ | ||
| export function OperatorLinksTable({ links, operators, candidates, onUnlinked }: Props) { | ||
| const [unlinking, setUnlinking] = useState<OperatorIdentityLink | null>(null); | ||
|
|
||
| // A failed unlink stays in the dialog, so it can be tried again or cancelled. | ||
| const unlink = async (link: OperatorIdentityLink) => { | ||
| await unlinkOperatorIdentity(link.oidcSubject, link.providerType); | ||
| onUnlinked(); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <table className="prov-table"> | ||
| <thead> | ||
| <tr> | ||
| <th>Operator</th> | ||
| <th>Platform</th> | ||
| <th>SCM account</th> | ||
| <th className="cell-r" /> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {links.map((link) => ( | ||
| <tr key={`${link.oidcSubject}-${link.providerType}`}> | ||
| <td> | ||
| <NameWithId name={operatorName(operators, link.oidcSubject)} id={link.oidcSubject} /> | ||
| </td> | ||
| <td>{link.providerType}</td> | ||
| <td> | ||
| <NameWithId name={nameFor(candidates, link)} id={link.authorId} /> | ||
| </td> | ||
| <td className="cell-r"> | ||
| <button | ||
| className="iconbtn" | ||
| aria-label={`Unlink ${link.oidcSubject} on ${link.providerType}`} | ||
| onClick={() => setUnlinking(link)} | ||
| > | ||
| <Trash2 size={15} /> | ||
| </button> | ||
| </td> | ||
| </tr> | ||
| ))} | ||
| </tbody> | ||
| </table> | ||
|
|
||
| {unlinking && ( | ||
| <ConfirmDialog | ||
| title="Unlink operator account" | ||
| message={`Unlink ${operatorName(operators, unlinking.oidcSubject)} from ${unlinking.providerType} · ${nameFor(candidates, unlinking)}? They no longer see their own activity for that account until it is linked again.`} | ||
| confirmLabel="Unlink" | ||
| busyLabel="Unlinking…" | ||
| danger | ||
| onConfirm={() => unlink(unlinking)} | ||
| onClose={() => setUnlinking(null)} | ||
| /> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Name first, username second, and the opaque subject only when there is nothing else to show. | ||
| * | ||
| * The username is empty when the identity provider's login is an email address (it is never stored), | ||
| * so the name stands alone then. | ||
| */ | ||
| export function labelFor(operator: SeenOperator): string { | ||
| if (operator.displayName && operator.username && operator.displayName !== operator.username) { | ||
| return `${operator.displayName} · ${operator.username}`; | ||
| } | ||
| return operator.displayName || operator.username || operator.subject; | ||
| } | ||
|
|
||
| function operatorName(operators: SeenOperator[], subject: string): string { | ||
| const match = operators.find((o) => o.subject === subject); | ||
| return match ? labelFor(match) : subject; | ||
| } | ||
|
|
||
| /** | ||
| * The login the operator proved by signing in, else the name the reviews recorded, else the id | ||
| * (a link made by hand for an author no review has seen). | ||
| */ | ||
| function nameFor(candidates: ObservedAuthor[], link: OperatorIdentityLink): string { | ||
| if (link.authorHandle) return link.authorHandle; | ||
| const match = candidates.find( | ||
| (c) => c.providerType === link.providerType && c.authorId === link.authorId, | ||
| ); | ||
| return match ? match.displayName : link.authorId; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import { fireEvent, screen, waitFor, within } from '@testing-library/react'; | ||
| import { MemoryRouter, Route, Routes } from 'react-router'; | ||
| import PromptDetail from './PromptDetail'; | ||
| import * as api from '../api'; | ||
| import { renderWithQuery } from '../test/queryWrapper'; | ||
|
|
||
| /** | ||
| * Reset to default deletes the custom text saved for the scope, and nothing keeps a copy, so the | ||
| * button only asks; the prompt is reset when the dialog's Reset is pressed. | ||
| */ | ||
|
|
||
| function customizedView(): api.PromptView { | ||
| return { | ||
| kind: 'review', | ||
| scope: '*', | ||
| inheritedFrom: 'global', | ||
| customized: true, | ||
| system: 'TEST persona', | ||
| body: 'Diff:\n{{diff}}', | ||
| updatedAt: '2026-08-20T10:00:00Z', | ||
| palette: [], | ||
| lockedSuffixPreview: 'TEST suffix', | ||
| baseKnown: true, | ||
| defaultDrifted: false, | ||
| currentDefaultSystem: 'TEST default persona', | ||
| currentDefaultBody: 'Diff:\n{{diff}}', | ||
| baseSystem: 'TEST default persona', | ||
| baseBody: 'Diff:\n{{diff}}', | ||
| }; | ||
| } | ||
|
|
||
| function renderPrompt() { | ||
| vi.spyOn(api, 'fetchPrompt').mockResolvedValue(customizedView()); | ||
| renderWithQuery( | ||
| <MemoryRouter initialEntries={['/settings/prompts/review']}> | ||
| <Routes> | ||
| <Route path="/settings/prompts/:kind" element={<PromptDetail />} /> | ||
| </Routes> | ||
| </MemoryRouter>, | ||
| ); | ||
| } | ||
|
|
||
| describe('reset to default', () => { | ||
| it('asks first, naming the prompt and what is lost', async () => { | ||
| const reset = vi.spyOn(api, 'resetPrompt').mockResolvedValue(); | ||
| renderPrompt(); | ||
|
|
||
| fireEvent.click(await screen.findByRole('button', { name: /reset to default/i })); | ||
|
|
||
| expect(screen.getByRole('dialog')).toHaveTextContent( | ||
| 'Reset Review to its default? The custom text saved for this scope is deleted and cannot be restored.', | ||
| ); | ||
| expect(reset).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('resets once the dialog is confirmed', async () => { | ||
| const reset = vi.spyOn(api, 'resetPrompt').mockResolvedValue(); | ||
| renderPrompt(); | ||
|
|
||
| fireEvent.click(await screen.findByRole('button', { name: /reset to default/i })); | ||
| fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Reset' })); | ||
|
|
||
| await waitFor(() => expect(reset).toHaveBeenCalledWith('review', '*')); | ||
| await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); | ||
| }); | ||
|
|
||
| it('keeps the custom text when the dialog is cancelled', async () => { | ||
| const reset = vi.spyOn(api, 'resetPrompt').mockResolvedValue(); | ||
| renderPrompt(); | ||
|
|
||
| fireEvent.click(await screen.findByRole('button', { name: /reset to default/i })); | ||
| fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' })); | ||
|
|
||
| expect(screen.queryByRole('dialog')).toBeNull(); | ||
| expect(reset).not.toHaveBeenCalled(); | ||
| expect(screen.getByDisplayValue('TEST persona')).toBeInTheDocument(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.