|
| 1 | +import * as React from 'react' |
| 2 | + |
| 3 | +import { Dispatcher } from '../dispatcher' |
| 4 | +import { Repository } from '../../models/repository' |
| 5 | +import { Branch } from '../../models/branch' |
| 6 | +import { Dialog, DialogContent, DialogFooter } from '../dialog' |
| 7 | +import { Ref } from '../lib/ref' |
| 8 | +import { OkCancelButtonGroup } from '../dialog/ok-cancel-button-group' |
| 9 | + |
| 10 | +interface IDeleteAllLocalBranchesProps { |
| 11 | + readonly dispatcher: Dispatcher |
| 12 | + readonly repository: Repository |
| 13 | + readonly branches: ReadonlyArray<Branch> |
| 14 | + readonly onDismissed: () => void |
| 15 | + readonly onDeleted: (repository: Repository) => void |
| 16 | +} |
| 17 | + |
| 18 | +interface IDeleteAllLocalBranchesState { |
| 19 | + readonly isDeleting: boolean |
| 20 | +} |
| 21 | + |
| 22 | +export class DeleteAllLocalBranches extends React.Component< |
| 23 | + IDeleteAllLocalBranchesProps, |
| 24 | + IDeleteAllLocalBranchesState |
| 25 | +> { |
| 26 | + public constructor(props: IDeleteAllLocalBranchesProps) { |
| 27 | + super(props) |
| 28 | + |
| 29 | + this.state = { |
| 30 | + isDeleting: false, |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + public render() { |
| 35 | + const count = this.props.branches.length |
| 36 | + |
| 37 | + return ( |
| 38 | + <Dialog |
| 39 | + id="delete-all-local-branches" |
| 40 | + title={ |
| 41 | + __DARWIN__ ? 'Delete All Local Branches' : 'Delete all local branches' |
| 42 | + } |
| 43 | + type="warning" |
| 44 | + onSubmit={this.deleteBranches} |
| 45 | + onDismissed={this.props.onDismissed} |
| 46 | + disabled={this.state.isDeleting} |
| 47 | + loading={this.state.isDeleting} |
| 48 | + role="alertdialog" |
| 49 | + ariaDescribedBy="delete-all-local-branches-message" |
| 50 | + > |
| 51 | + <DialogContent> |
| 52 | + <div id="delete-all-local-branches-message"> |
| 53 | + <p> |
| 54 | + Delete the following {count}{' '} |
| 55 | + {count === 1 ? 'local branch' : 'local branches'}? |
| 56 | + </p> |
| 57 | + <ul className="delete-all-local-branches-list"> |
| 58 | + {this.props.branches.map(branch => ( |
| 59 | + <li key={branch.name}> |
| 60 | + <Ref>{branch.name}</Ref> |
| 61 | + </li> |
| 62 | + ))} |
| 63 | + </ul> |
| 64 | + <p>This action cannot be undone.</p> |
| 65 | + </div> |
| 66 | + </DialogContent> |
| 67 | + <DialogFooter> |
| 68 | + <OkCancelButtonGroup destructive={true} okButtonText="Delete" /> |
| 69 | + </DialogFooter> |
| 70 | + </Dialog> |
| 71 | + ) |
| 72 | + } |
| 73 | + |
| 74 | + private deleteBranches = async () => { |
| 75 | + const { dispatcher, repository, branches } = this.props |
| 76 | + |
| 77 | + this.setState({ isDeleting: true }) |
| 78 | + |
| 79 | + await dispatcher.deleteLocalBranches(repository, branches) |
| 80 | + this.props.onDeleted(repository) |
| 81 | + |
| 82 | + this.props.onDismissed() |
| 83 | + } |
| 84 | +} |
0 commit comments