| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {ReactNode} from 'react'; |
| b69ab31 | | | 9 | import type {ContextMenuItem} from 'shared/ContextMenu'; |
| b69ab31 | | | 10 | import type {UICodeReviewProvider} from './codeReview/UICodeReviewProvider'; |
| b69ab31 | | | 11 | import type {DagCommitInfo} from './dag/dag'; |
| 083fd5f | | | 12 | import type {CommitInfo, Hash, SuccessorInfo} from './types'; |
| b69ab31 | | | 13 | import {succeedableRevset, WarningCheckResult} from './types'; |
| b69ab31 | | | 14 | |
| b69ab31 | | | 15 | import * as stylex from '@stylexjs/stylex'; |
| b69ab31 | | | 16 | import {Button} from 'isl-components/Button'; |
| b69ab31 | | | 17 | import {Icon} from 'isl-components/Icon'; |
| b69ab31 | | | 18 | import {Subtle} from 'isl-components/Subtle'; |
| b69ab31 | | | 19 | import {Tooltip} from 'isl-components/Tooltip'; |
| b69ab31 | | | 20 | import {atom, useAtomValue, useSetAtom} from 'jotai'; |
| b69ab31 | | | 21 | import React, {memo, useEffect} from 'react'; |
| b69ab31 | | | 22 | import {ComparisonType} from 'shared/Comparison'; |
| b69ab31 | | | 23 | import {contextMenuState, useContextMenu} from 'shared/ContextMenu'; |
| b69ab31 | | | 24 | import {MS_PER_DAY} from 'shared/constants'; |
| b69ab31 | | | 25 | import {useAutofocusRef} from 'shared/hooks'; |
| b69ab31 | | | 26 | import {notEmpty, nullthrows} from 'shared/utils'; |
| b69ab31 | | | 27 | import {spacing} from '../../components/theme/tokens.stylex'; |
| b69ab31 | | | 28 | import {AllBookmarksTruncated, Bookmark, Bookmarks, createBookmarkAtCommit} from './Bookmark'; |
| b69ab31 | | | 29 | import {openBrowseUrlForHash, supportsBrowseUrlForHash} from './BrowseRepo'; |
| b69ab31 | | | 30 | import {hasUnsavedEditedCommitMessage} from './CommitInfoView/CommitInfoState'; |
| b69ab31 | | | 31 | import {showComparison} from './ComparisonView/atoms'; |
| b69ab31 | | | 32 | import {Row} from './ComponentUtils'; |
| b69ab31 | | | 33 | import {DragToRebase} from './DragToRebase'; |
| b69ab31 | | | 34 | import {EducationInfoTip} from './Education'; |
| b69ab31 | | | 35 | import {HighlightCommitsWhileHovering} from './HighlightedCommits'; |
| b69ab31 | | | 36 | import {Internal} from './Internal'; |
| b69ab31 | | | 37 | import {SubmitSelectionButton} from './SubmitSelectionButton'; |
| b69ab31 | | | 38 | import {SubmitSingleCommitButton} from './SubmitSingleCommitButton'; |
| b69ab31 | | | 39 | import {getSuggestedRebaseOperation, suggestedRebaseDestinations} from './SuggestedRebase'; |
| b69ab31 | | | 40 | import {UncommitButton} from './UncommitButton'; |
| b69ab31 | | | 41 | import {UncommittedChanges} from './UncommittedChanges'; |
| b69ab31 | | | 42 | import {tracker} from './analytics'; |
| b69ab31 | | | 43 | import {clipboardLinkHtml} from './clipboard'; |
| b69ab31 | | | 44 | import { |
| b69ab31 | | | 45 | allDiffSummaries, |
| b69ab31 | | | 46 | branchingDiffInfos, |
| 083fd5f | | | 47 | canopySignalForCommit, |
| b69ab31 | | | 48 | codeReviewProvider, |
| b69ab31 | | | 49 | diffSummary, |
| e7069e1 | | | 50 | ensureCanopySignalsFetched, |
| b69ab31 | | | 51 | latestCommitMessageTitle, |
| b69ab31 | | | 52 | } from './codeReview/CodeReviewInfo'; |
| 083fd5f | | | 53 | import {DiffBadge, DiffFollower, DiffInfo, SignalSummaryIcon} from './codeReview/DiffBadge'; |
| b69ab31 | | | 54 | import {submitAsDraft} from './codeReview/DraftCheckbox'; |
| b69ab31 | | | 55 | import {SyncStatus, syncStatusAtom} from './codeReview/syncStatus'; |
| b69ab31 | | | 56 | import {useFeatureFlagSync} from './featureFlags'; |
| b69ab31 | | | 57 | import {FoldButton, useRunFoldPreview} from './fold'; |
| b69ab31 | | | 58 | import {findPublicBaseAncestor} from './getCommitTree'; |
| b69ab31 | | | 59 | import {t, T} from './i18n'; |
| b69ab31 | | | 60 | import {IconStack} from './icons/IconStack'; |
| b69ab31 | | | 61 | import {IrrelevantCwdIcon} from './icons/IrrelevantCwdIcon'; |
| b69ab31 | | | 62 | import {atomFamilyWeak, localStorageBackedAtom, readAtom, writeAtom} from './jotaiUtils'; |
| b69ab31 | | | 63 | import {CONFLICT_SIDE_LABELS} from './mergeConflicts/consts'; |
| b69ab31 | | | 64 | import {getAmendToOperation, isAmendToAllowedForCommit} from './operationUtils'; |
| b69ab31 | | | 65 | import {GotoOperation} from './operations/GotoOperation'; |
| b69ab31 | | | 66 | import {HideOperation} from './operations/HideOperation'; |
| b69ab31 | | | 67 | import { |
| b69ab31 | | | 68 | inlineProgressByHash, |
| b69ab31 | | | 69 | operationBeingPreviewed, |
| b69ab31 | | | 70 | useRunOperation, |
| b69ab31 | | | 71 | useRunPreviewedOperation, |
| b69ab31 | | | 72 | } from './operationsState'; |
| b69ab31 | | | 73 | import platform from './platform'; |
| b69ab31 | | | 74 | import {CommitPreview, dagWithPreviews, uncommittedChangesWithPreviews} from './previews'; |
| b69ab31 | | | 75 | import {RelativeDate, relativeDate} from './relativeDate'; |
| b69ab31 | | | 76 | import {repoRelativeCwd, useIsIrrelevantToCwd} from './repositoryData'; |
| b69ab31 | | | 77 | import {isNarrowCommitTree} from './responsive'; |
| b69ab31 | | | 78 | import { |
| b69ab31 | | | 79 | actioningCommit, |
| b69ab31 | | | 80 | selectedCommitInfos, |
| b69ab31 | | | 81 | selectedCommits, |
| b69ab31 | | | 82 | useCommitCallbacks, |
| b69ab31 | | | 83 | } from './selection'; |
| 9e488cc | | | 84 | import {inMergeConflicts, mergeConflicts, repositoryInfo} from './serverAPIState'; |
| b69ab31 | | | 85 | import {SmartActionsDropdown} from './smartActions/SmartActionsDropdown'; |
| b69ab31 | | | 86 | import {SmartActionsMenu} from './smartActions/SmartActionsMenu'; |
| b69ab31 | | | 87 | import {useConfirmUnsavedEditsBeforeSplit} from './stackEdit/ui/ConfirmUnsavedEditsBeforeSplit'; |
| b69ab31 | | | 88 | import {SplitButton} from './stackEdit/ui/SplitButton'; |
| b69ab31 | | | 89 | import {editingStackIntentionHashes} from './stackEdit/ui/stackEditState'; |
| b69ab31 | | | 90 | import {latestSuccessorUnlessExplicitlyObsolete} from './successionUtils'; |
| b69ab31 | | | 91 | import {copyAndShowToast} from './toast'; |
| b69ab31 | | | 92 | import {showModal} from './useModal'; |
| b69ab31 | | | 93 | import {short} from './utils'; |
| b69ab31 | | | 94 | |
| b69ab31 | | | 95 | export const rebaseOffWarmWarningEnabled = localStorageBackedAtom<boolean>( |
| b69ab31 | | | 96 | 'isl.rebase-off-warm-warning-enabled', |
| b69ab31 | | | 97 | true, |
| b69ab31 | | | 98 | ); |
| b69ab31 | | | 99 | |
| b69ab31 | | | 100 | export const distantRebaseWarningEnabled = localStorageBackedAtom<boolean>( |
| b69ab31 | | | 101 | 'isl.distant-rebase-warning-enabled', |
| b69ab31 | | | 102 | true, |
| b69ab31 | | | 103 | ); |
| b69ab31 | | | 104 | |
| b69ab31 | | | 105 | export const rebaseOntoMasterWarningEnabled = localStorageBackedAtom<boolean>( |
| b69ab31 | | | 106 | 'isl.rebase-onto-master-warning-enabled', |
| b69ab31 | | | 107 | true, |
| b69ab31 | | | 108 | ); |
| b69ab31 | | | 109 | |
| b69ab31 | | | 110 | /** |
| b69ab31 | | | 111 | * Some preview types should not allow actions on top of them |
| b69ab31 | | | 112 | * For example, you can't click goto on the preview of dragging a rebase, |
| b69ab31 | | | 113 | * but you can goto on the optimistic form of a running rebase. |
| b69ab31 | | | 114 | */ |
| b69ab31 | | | 115 | function previewPreventsActions(preview?: CommitPreview): boolean { |
| b69ab31 | | | 116 | switch (preview) { |
| b69ab31 | | | 117 | case CommitPreview.REBASE_OLD: |
| b69ab31 | | | 118 | case CommitPreview.REBASE_DESCENDANT: |
| b69ab31 | | | 119 | case CommitPreview.REBASE_ROOT: |
| b69ab31 | | | 120 | case CommitPreview.HIDDEN_ROOT: |
| b69ab31 | | | 121 | case CommitPreview.HIDDEN_DESCENDANT: |
| b69ab31 | | | 122 | case CommitPreview.FOLD: |
| b69ab31 | | | 123 | case CommitPreview.FOLD_PREVIEW: |
| b69ab31 | | | 124 | case CommitPreview.NON_ACTIONABLE_COMMIT: |
| b69ab31 | | | 125 | return true; |
| b69ab31 | | | 126 | } |
| b69ab31 | | | 127 | return false; |
| b69ab31 | | | 128 | } |
| b69ab31 | | | 129 | |
| b69ab31 | | | 130 | const commitLabelForCommit = atomFamilyWeak((hash: string) => |
| b69ab31 | | | 131 | atom(get => { |
| b69ab31 | | | 132 | const conflicts = get(mergeConflicts); |
| b69ab31 | | | 133 | const {localShort, incomingShort} = CONFLICT_SIDE_LABELS; |
| b69ab31 | | | 134 | const hashes = conflicts?.hashes; |
| b69ab31 | | | 135 | if (hash === hashes?.other) { |
| b69ab31 | | | 136 | return incomingShort; |
| b69ab31 | | | 137 | } else if (hash === hashes?.local) { |
| b69ab31 | | | 138 | return localShort; |
| b69ab31 | | | 139 | } |
| b69ab31 | | | 140 | return null; |
| b69ab31 | | | 141 | }), |
| b69ab31 | | | 142 | ); |
| b69ab31 | | | 143 | |
| b69ab31 | | | 144 | export const Commit = memo( |
| b69ab31 | | | 145 | ({ |
| b69ab31 | | | 146 | commit, |
| b69ab31 | | | 147 | previewType, |
| b69ab31 | | | 148 | hasChildren, |
| b69ab31 | | | 149 | }: { |
| b69ab31 | | | 150 | commit: DagCommitInfo | CommitInfo; |
| b69ab31 | | | 151 | previewType?: CommitPreview; |
| b69ab31 | | | 152 | hasChildren: boolean; |
| b69ab31 | | | 153 | }) => { |
| b69ab31 | | | 154 | const isPublic = commit.phase === 'public'; |
| b69ab31 | | | 155 | const isObsoleted = commit.successorInfo != null; |
| b69ab31 | | | 156 | const hasUncommittedChanges = (readAtom(uncommittedChangesWithPreviews).length ?? 0) > 0; |
| b69ab31 | | | 157 | |
| b69ab31 | | | 158 | const isIrrelevantToCwd = useIsIrrelevantToCwd(commit); |
| b69ab31 | | | 159 | |
| b69ab31 | | | 160 | const handlePreviewedOperation = useRunPreviewedOperation(); |
| b69ab31 | | | 161 | const runOperation = useRunOperation(); |
| b69ab31 | | | 162 | const setEditStackIntentionHashes = useSetAtom(editingStackIntentionHashes); |
| b69ab31 | | | 163 | |
| b69ab31 | | | 164 | const inlineProgress = useAtomValue(inlineProgressByHash(commit.hash)); |
| b69ab31 | | | 165 | |
| b69ab31 | | | 166 | const {isSelected, onDoubleClickToShowDrawer} = useCommitCallbacks(commit); |
| b69ab31 | | | 167 | const actionsPrevented = previewPreventsActions(previewType); |
| b69ab31 | | | 168 | |
| b69ab31 | | | 169 | const isActioning = useAtomValue(actioningCommit) === commit.hash; |
| b69ab31 | | | 170 | const isContextMenuOpen = useAtomValue(contextMenuState) != null; |
| b69ab31 | | | 171 | |
| b69ab31 | | | 172 | useEffect(() => { |
| b69ab31 | | | 173 | if (!isContextMenuOpen && isActioning) { |
| b69ab31 | | | 174 | writeAtom(actioningCommit, null); |
| b69ab31 | | | 175 | } |
| b69ab31 | | | 176 | }, [isContextMenuOpen, isActioning]); |
| b69ab31 | | | 177 | |
| b69ab31 | | | 178 | const inConflicts = useAtomValue(inMergeConflicts); |
| b69ab31 | | | 179 | |
| b69ab31 | | | 180 | const isNarrow = useAtomValue(isNarrowCommitTree); |
| b69ab31 | | | 181 | |
| b69ab31 | | | 182 | const title = useAtomValue(latestCommitMessageTitle(commit.hash)); |
| b69ab31 | | | 183 | |
| b69ab31 | | | 184 | const commitLabel = useAtomValue(commitLabelForCommit(commit.hash)); |
| b69ab31 | | | 185 | |
| b69ab31 | | | 186 | const clipboardCopy = (text: string, url?: string) => |
| b69ab31 | | | 187 | copyAndShowToast(text, url == null ? undefined : clipboardLinkHtml(text, url)); |
| b69ab31 | | | 188 | |
| b69ab31 | | | 189 | const confirmUnsavedEditsBeforeSplit = useConfirmUnsavedEditsBeforeSplit(); |
| b69ab31 | | | 190 | async function handleSplit() { |
| b69ab31 | | | 191 | if (!(await confirmUnsavedEditsBeforeSplit([commit], 'split'))) { |
| b69ab31 | | | 192 | return; |
| b69ab31 | | | 193 | } |
| b69ab31 | | | 194 | setEditStackIntentionHashes(['split', new Set([commit.hash])]); |
| b69ab31 | | | 195 | tracker.track('SplitOpenFromCommitContextMenu'); |
| b69ab31 | | | 196 | } |
| b69ab31 | | | 197 | |
| b69ab31 | | | 198 | const makeContextMenuOptions = () => { |
| b69ab31 | | | 199 | const syncStatus = readAtom(syncStatusAtom)?.get(commit.hash); |
| b69ab31 | | | 200 | |
| b69ab31 | | | 201 | const items: Array<ContextMenuItem & {loggingLabel?: string}> = [ |
| b69ab31 | | | 202 | { |
| b69ab31 | | | 203 | label: <T replace={{$hash: short(commit?.hash)}}>Copy Commit Hash "$hash"</T>, |
| b69ab31 | | | 204 | onClick: () => clipboardCopy(commit.hash), |
| b69ab31 | | | 205 | loggingLabel: 'Copy Commit Hash', |
| b69ab31 | | | 206 | }, |
| b69ab31 | | | 207 | ]; |
| b69ab31 | | | 208 | if (isPublic && readAtom(supportsBrowseUrlForHash)) { |
| b69ab31 | | | 209 | items.push({ |
| b69ab31 | | | 210 | label: ( |
| b69ab31 | | | 211 | <Row> |
| b69ab31 | | | 212 | <T>Browse Repo At This Commit</T> |
| b69ab31 | | | 213 | <Icon icon="link-external" /> |
| b69ab31 | | | 214 | </Row> |
| b69ab31 | | | 215 | ), |
| b69ab31 | | | 216 | onClick: () => { |
| b69ab31 | | | 217 | openBrowseUrlForHash(commit.hash); |
| b69ab31 | | | 218 | }, |
| b69ab31 | | | 219 | loggingLabel: 'Browse Repo At This Commit', |
| b69ab31 | | | 220 | }); |
| b69ab31 | | | 221 | } |
| b69ab31 | | | 222 | const selectedDiffIDs = readAtom(selectedCommitInfos) |
| b69ab31 | | | 223 | .map(info => info.diffId) |
| b69ab31 | | | 224 | .filter(notEmpty); |
| b69ab31 | | | 225 | if (selectedDiffIDs.length > 1) { |
| b69ab31 | | | 226 | items.push({ |
| b69ab31 | | | 227 | label: ( |
| b69ab31 | | | 228 | <T replace={{$count: selectedDiffIDs.length < 10 ? selectedDiffIDs.length : '9+'}}> |
| b69ab31 | | | 229 | Copy $count Selected Diff Numbers |
| b69ab31 | | | 230 | </T> |
| b69ab31 | | | 231 | ), |
| b69ab31 | | | 232 | onClick: () => { |
| b69ab31 | | | 233 | const text = selectedDiffIDs.join(' '); |
| b69ab31 | | | 234 | clipboardCopy(text); |
| b69ab31 | | | 235 | }, |
| b69ab31 | | | 236 | loggingLabel: 'Copy Selected Diff Numbers', |
| b69ab31 | | | 237 | }); |
| b69ab31 | | | 238 | } else if (!isPublic && commit.diffId != null) { |
| b69ab31 | | | 239 | items.push({ |
| b69ab31 | | | 240 | label: <T replace={{$number: commit.diffId}}>Copy Diff Number "$number"</T>, |
| b69ab31 | | | 241 | onClick: () => { |
| b69ab31 | | | 242 | const info = readAtom(diffSummary(commit.diffId)); |
| b69ab31 | | | 243 | const url = info?.value?.url; |
| b69ab31 | | | 244 | clipboardCopy(commit.diffId ?? '', url); |
| b69ab31 | | | 245 | }, |
| b69ab31 | | | 246 | loggingLabel: 'Copy Diff Number', |
| b69ab31 | | | 247 | }); |
| b69ab31 | | | 248 | } |
| b69ab31 | | | 249 | if (!isPublic) { |
| b69ab31 | | | 250 | items.push({ |
| b69ab31 | | | 251 | label: <T>View Changes in Commit</T>, |
| b69ab31 | | | 252 | onClick: () => showComparison({type: ComparisonType.Committed, hash: commit.hash}), |
| b69ab31 | | | 253 | loggingLabel: 'View Changes in Commit', |
| b69ab31 | | | 254 | }); |
| b69ab31 | | | 255 | |
| b69ab31 | | | 256 | const provider = readAtom(codeReviewProvider); |
| b69ab31 | | | 257 | if (provider != null) { |
| b69ab31 | | | 258 | const selectedInfos = readAtom(selectedCommitInfos); |
| b69ab31 | | | 259 | const diffSummaries = readAtom(allDiffSummaries); |
| b69ab31 | | | 260 | const dag = readAtom(dagWithPreviews); |
| b69ab31 | | | 261 | |
| b69ab31 | | | 262 | const isMultiSelect = |
| b69ab31 | | | 263 | selectedInfos.length > 1 && selectedInfos.some(c => c.hash === commit.hash); |
| b69ab31 | | | 264 | const commits = isMultiSelect |
| b69ab31 | | | 265 | ? dag.getBatch(dag.sortAsc(dag.present(new Set(selectedInfos.map(c => c.hash))))) |
| b69ab31 | | | 266 | : [commit]; |
| b69ab31 | | | 267 | const submittable = |
| b69ab31 | | | 268 | (diffSummaries?.value != null |
| b69ab31 | | | 269 | ? provider.getSubmittableDiffs(commits, diffSummaries.value) |
| b69ab31 | | | 270 | : undefined) ?? []; |
| b69ab31 | | | 271 | |
| b69ab31 | | | 272 | if (submittable.length > 0) { |
| 8d8e815 | | | 273 | const actionLabel = provider.submitButtonLabel ?? 'Submit'; |
| b69ab31 | | | 274 | items.push({ |
| b69ab31 | | | 275 | label: |
| b69ab31 | | | 276 | submittable.length > 1 ? ( |
| 8d8e815 | | | 277 | <T replace={{$count: submittable.length, $action: actionLabel}}> |
| 8d8e815 | | | 278 | $action $count Commits |
| 8d8e815 | | | 279 | </T> |
| b69ab31 | | | 280 | ) : ( |
| 8d8e815 | | | 281 | <T replace={{$action: actionLabel}}>$action Commit</T> |
| b69ab31 | | | 282 | ), |
| b69ab31 | | | 283 | onClick: () => { |
| b69ab31 | | | 284 | runOperation( |
| b69ab31 | | | 285 | provider.submitOperation(submittable, { |
| b69ab31 | | | 286 | draft: readAtom(submitAsDraft), |
| b69ab31 | | | 287 | }), |
| b69ab31 | | | 288 | ); |
| b69ab31 | | | 289 | }, |
| 8d8e815 | | | 290 | loggingLabel: |
| 8d8e815 | | | 291 | submittable.length > 1 |
| 8d8e815 | | | 292 | ? `${actionLabel} Multiple Commits` |
| 8d8e815 | | | 293 | : `${actionLabel} Commit`, |
| b69ab31 | | | 294 | }); |
| b69ab31 | | | 295 | } |
| b69ab31 | | | 296 | } |
| b69ab31 | | | 297 | } |
| b69ab31 | | | 298 | if (!isPublic && syncStatus != null && syncStatus !== SyncStatus.InSync) { |
| b69ab31 | | | 299 | const provider = readAtom(codeReviewProvider); |
| b69ab31 | | | 300 | if (provider?.supportsComparingSinceLastSubmit) { |
| b69ab31 | | | 301 | items.push({ |
| b69ab31 | | | 302 | label: <T replace={{$provider: provider?.label ?? 'remote'}}>Compare with $provider</T>, |
| b69ab31 | | | 303 | onClick: () => { |
| b69ab31 | | | 304 | showComparison({type: ComparisonType.SinceLastCodeReviewSubmit, hash: commit.hash}); |
| b69ab31 | | | 305 | }, |
| b69ab31 | | | 306 | loggingLabel: 'Compare with Provider', |
| b69ab31 | | | 307 | }); |
| b69ab31 | | | 308 | } |
| b69ab31 | | | 309 | } |
| b69ab31 | | | 310 | if (!isPublic && commit.diffId != null) { |
| b69ab31 | | | 311 | const provider = readAtom(codeReviewProvider); |
| b69ab31 | | | 312 | const summary = readAtom(diffSummary(commit.diffId)); |
| b69ab31 | | | 313 | if (summary.value) { |
| b69ab31 | | | 314 | const actions = provider?.getUpdateDiffActions(summary.value); |
| b69ab31 | | | 315 | if (actions != null && actions.length > 0) { |
| b69ab31 | | | 316 | items.push({ |
| b69ab31 | | | 317 | label: <T replace={{$number: commit.diffId}}>Update Diff $number</T>, |
| b69ab31 | | | 318 | type: 'submenu', |
| b69ab31 | | | 319 | children: actions, |
| b69ab31 | | | 320 | }); |
| b69ab31 | | | 321 | } |
| b69ab31 | | | 322 | } |
| b69ab31 | | | 323 | } |
| b69ab31 | | | 324 | if (!isPublic && !actionsPrevented && !inConflicts) { |
| b69ab31 | | | 325 | const suggestedRebases = readAtom(suggestedRebaseDestinations); |
| b69ab31 | | | 326 | items.push({ |
| b69ab31 | | | 327 | label: 'Rebase onto', |
| b69ab31 | | | 328 | type: 'submenu', |
| b69ab31 | | | 329 | children: |
| b69ab31 | | | 330 | suggestedRebases?.map(([dest, name]) => ({ |
| b69ab31 | | | 331 | label: name, |
| b69ab31 | | | 332 | onClick: async () => { |
| b69ab31 | | | 333 | const operation = getSuggestedRebaseOperation( |
| b69ab31 | | | 334 | dest, |
| b69ab31 | | | 335 | latestSuccessorUnlessExplicitlyObsolete(commit), |
| b69ab31 | | | 336 | ); |
| b69ab31 | | | 337 | |
| b69ab31 | | | 338 | const shouldProceed = await runWarningChecks([ |
| b69ab31 | | | 339 | () => maybeWarnAboutRebaseOntoMaster(dest), |
| b69ab31 | | | 340 | () => maybeWarnAboutRebaseOffWarm(dest), |
| b69ab31 | | | 341 | ]); |
| b69ab31 | | | 342 | |
| b69ab31 | | | 343 | if (shouldProceed) { |
| b69ab31 | | | 344 | runOperation(operation); |
| b69ab31 | | | 345 | } |
| b69ab31 | | | 346 | }, |
| b69ab31 | | | 347 | })) ?? [], |
| b69ab31 | | | 348 | }); |
| b69ab31 | | | 349 | if (isAmendToAllowedForCommit(commit)) { |
| b69ab31 | | | 350 | items.push({ |
| b69ab31 | | | 351 | label: <T>Amend changes to here</T>, |
| b69ab31 | | | 352 | onClick: () => runOperation(getAmendToOperation(commit)), |
| b69ab31 | | | 353 | }); |
| b69ab31 | | | 354 | } |
| b69ab31 | | | 355 | if (!isObsoleted) { |
| b69ab31 | | | 356 | items.push({ |
| b69ab31 | | | 357 | label: hasUncommittedChanges ? ( |
| b69ab31 | | | 358 | <span className="context-menu-disabled-option"> |
| b69ab31 | | | 359 | <T>Split... </T> |
| b69ab31 | | | 360 | <Subtle> |
| b69ab31 | | | 361 | <T>(disabled due to uncommitted changes)</T> |
| b69ab31 | | | 362 | </Subtle> |
| b69ab31 | | | 363 | </span> |
| b69ab31 | | | 364 | ) : ( |
| b69ab31 | | | 365 | <T>Split...</T> |
| b69ab31 | | | 366 | ), |
| b69ab31 | | | 367 | onClick: hasUncommittedChanges ? () => null : handleSplit, |
| b69ab31 | | | 368 | loggingLabel: 'Split', |
| b69ab31 | | | 369 | }); |
| b69ab31 | | | 370 | } |
| b69ab31 | | | 371 | items.push({ |
| b69ab31 | | | 372 | label: <T>Create Bookmark...</T>, |
| b69ab31 | | | 373 | onClick: () => { |
| b69ab31 | | | 374 | createBookmarkAtCommit(commit); |
| b69ab31 | | | 375 | }, |
| b69ab31 | | | 376 | loggingLabel: 'Create Bookmark', |
| b69ab31 | | | 377 | }); |
| b69ab31 | | | 378 | items.push({ |
| b69ab31 | | | 379 | label: hasChildren ? <T>Hide Commit and Descendants</T> : <T>Hide Commit</T>, |
| b69ab31 | | | 380 | onClick: () => |
| b69ab31 | | | 381 | writeAtom( |
| b69ab31 | | | 382 | operationBeingPreviewed, |
| b69ab31 | | | 383 | new HideOperation(latestSuccessorUnlessExplicitlyObsolete(commit)), |
| b69ab31 | | | 384 | ), |
| b69ab31 | | | 385 | loggingLabel: 'Hide Commit', |
| b69ab31 | | | 386 | }); |
| b69ab31 | | | 387 | } |
| b69ab31 | | | 388 | if (!actionsPrevented && !commit.isDot) { |
| b69ab31 | | | 389 | items.push({ |
| b69ab31 | | | 390 | label: <T>Goto</T>, |
| b69ab31 | | | 391 | onClick: async () => { |
| b69ab31 | | | 392 | await gotoAction(runOperation, commit); |
| b69ab31 | | | 393 | }, |
| b69ab31 | | | 394 | loggingLabel: 'Goto', |
| b69ab31 | | | 395 | }); |
| b69ab31 | | | 396 | } |
| b69ab31 | | | 397 | if (commit.fullRepoBranch != null) { |
| b69ab31 | | | 398 | const fullRepoBranchItems = Internal.getFullRepoBranchMergeContextMenuItems?.( |
| b69ab31 | | | 399 | commit.fullRepoBranch, |
| b69ab31 | | | 400 | ); |
| b69ab31 | | | 401 | if (fullRepoBranchItems != null && fullRepoBranchItems instanceof Array) { |
| b69ab31 | | | 402 | items.push(...fullRepoBranchItems); |
| b69ab31 | | | 403 | } |
| b69ab31 | | | 404 | } |
| b69ab31 | | | 405 | return items; |
| b69ab31 | | | 406 | }; |
| b69ab31 | | | 407 | |
| b69ab31 | | | 408 | const contextMenu = useContextMenu((): Array<ContextMenuItem> => { |
| b69ab31 | | | 409 | return makeContextMenuOptions().map((item: ContextMenuItem & {loggingLabel?: string}) => { |
| b69ab31 | | | 410 | if (item.type == null && notEmpty(item.loggingLabel)) { |
| b69ab31 | | | 411 | return { |
| b69ab31 | | | 412 | ...item, |
| b69ab31 | | | 413 | onClick: () => { |
| b69ab31 | | | 414 | tracker.track('CommitContextMenuItemClick', { |
| b69ab31 | | | 415 | extras: {choice: item.loggingLabel}, |
| b69ab31 | | | 416 | }); |
| b69ab31 | | | 417 | item.onClick?.(); |
| b69ab31 | | | 418 | }, |
| b69ab31 | | | 419 | }; |
| b69ab31 | | | 420 | } |
| b69ab31 | | | 421 | return item; |
| b69ab31 | | | 422 | }); |
| b69ab31 | | | 423 | }); |
| b69ab31 | | | 424 | |
| b69ab31 | | | 425 | const commitActions = []; |
| b69ab31 | | | 426 | |
| b69ab31 | | | 427 | if (previewType === CommitPreview.REBASE_ROOT) { |
| b69ab31 | | | 428 | commitActions.push( |
| b69ab31 | | | 429 | <React.Fragment key="rebase"> |
| b69ab31 | | | 430 | <Button onClick={() => handlePreviewedOperation(/* cancel */ true)}> |
| b69ab31 | | | 431 | <T>Cancel</T> |
| b69ab31 | | | 432 | </Button> |
| b69ab31 | | | 433 | <Button |
| b69ab31 | | | 434 | primary |
| b69ab31 | | | 435 | onClick={() => { |
| b69ab31 | | | 436 | return handleRebaseConfirmation(commit, handlePreviewedOperation); |
| b69ab31 | | | 437 | }}> |
| b69ab31 | | | 438 | <T>Run Rebase</T> |
| b69ab31 | | | 439 | </Button> |
| b69ab31 | | | 440 | </React.Fragment>, |
| b69ab31 | | | 441 | ); |
| b69ab31 | | | 442 | } else if (previewType === CommitPreview.HIDDEN_ROOT) { |
| b69ab31 | | | 443 | commitActions.push( |
| b69ab31 | | | 444 | <React.Fragment key="hide"> |
| b69ab31 | | | 445 | <Button onClick={() => handlePreviewedOperation(/* cancel */ true)}> |
| b69ab31 | | | 446 | <T>Cancel</T> |
| b69ab31 | | | 447 | </Button> |
| b69ab31 | | | 448 | <ConfirmHideButton onClick={() => handlePreviewedOperation(/* cancel */ false)} /> |
| b69ab31 | | | 449 | </React.Fragment>, |
| b69ab31 | | | 450 | ); |
| b69ab31 | | | 451 | } else if (previewType === CommitPreview.FOLD_PREVIEW) { |
| b69ab31 | | | 452 | commitActions.push(<ConfirmCombineButtons key="fold" />); |
| b69ab31 | | | 453 | } |
| b69ab31 | | | 454 | |
| b69ab31 | | | 455 | if (!isPublic && !actionsPrevented && isSelected) { |
| b69ab31 | | | 456 | commitActions.push( |
| b69ab31 | | | 457 | <SubmitSelectionButton key="submit-selection-btn" commit={commit} />, |
| b69ab31 | | | 458 | <FoldButton key="fold-button" commit={commit} />, |
| b69ab31 | | | 459 | ); |
| b69ab31 | | | 460 | } |
| b69ab31 | | | 461 | |
| b69ab31 | | | 462 | if (!actionsPrevented && !commit.isDot) { |
| b69ab31 | | | 463 | commitActions.push( |
| b69ab31 | | | 464 | <span className="goto-button" key="goto-button"> |
| b69ab31 | | | 465 | <Tooltip |
| b69ab31 | | | 466 | title={t( |
| b69ab31 | | | 467 | 'Update files in the working copy to match this commit. Mark this commit as the "current commit".', |
| b69ab31 | | | 468 | )} |
| b69ab31 | | | 469 | delayMs={250}> |
| b69ab31 | | | 470 | <Button |
| b69ab31 | | | 471 | aria-label={t('Go to commit "$title"', {replace: {$title: commit.title}})} |
| b69ab31 | | | 472 | xstyle={styles.gotoButton} |
| b69ab31 | | | 473 | onClick={async event => { |
| b69ab31 | | | 474 | event.stopPropagation(); // don't toggle selection by letting click propagate onto selection target. |
| b69ab31 | | | 475 | await gotoAction(runOperation, commit); |
| b69ab31 | | | 476 | }}> |
| b69ab31 | | | 477 | <T>Goto</T> |
| b69ab31 | | | 478 | <Icon icon="newline" /> |
| b69ab31 | | | 479 | </Button> |
| b69ab31 | | | 480 | </Tooltip> |
| b69ab31 | | | 481 | </span>, |
| b69ab31 | | | 482 | ); |
| b69ab31 | | | 483 | } |
| b69ab31 | | | 484 | |
| b69ab31 | | | 485 | if (!isPublic && !actionsPrevented && commit.isDot && !inConflicts) { |
| b69ab31 | | | 486 | commitActions.push(<SubmitSingleCommitButton key="submit" />); |
| b69ab31 | | | 487 | commitActions.push(<UncommitButton key="uncommit" />); |
| b69ab31 | | | 488 | } |
| b69ab31 | | | 489 | |
| b69ab31 | | | 490 | if (!isPublic && !actionsPrevented && commit.isDot && !isObsoleted && !inConflicts) { |
| b69ab31 | | | 491 | commitActions.push( |
| b69ab31 | | | 492 | <SplitButton icon key="split" trackerEventName="SplitOpenFromHeadCommit" commit={commit} />, |
| b69ab31 | | | 493 | ); |
| b69ab31 | | | 494 | } |
| b69ab31 | | | 495 | |
| b69ab31 | | | 496 | const useV2SmartActions = useFeatureFlagSync(Internal.featureFlags?.SmartActionsRedesign); |
| b69ab31 | | | 497 | if (!isPublic && !actionsPrevented) { |
| b69ab31 | | | 498 | if (useV2SmartActions) { |
| b69ab31 | | | 499 | if (commit.isDot && !hasUncommittedChanges && !inConflicts) { |
| b69ab31 | | | 500 | commitActions.push(<SmartActionsDropdown key="smartActions" commit={commit} />); |
| b69ab31 | | | 501 | } |
| b69ab31 | | | 502 | } else { |
| b69ab31 | | | 503 | commitActions.push(<SmartActionsMenu key="smartActions" commit={commit} />); |
| b69ab31 | | | 504 | } |
| b69ab31 | | | 505 | } |
| b69ab31 | | | 506 | |
| ab83ad3 | | | 507 | if (!actionsPrevented) { |
| b69ab31 | | | 508 | commitActions.push( |
| b69ab31 | | | 509 | <OpenCommitInfoButton |
| b69ab31 | | | 510 | key="open-sidebar" |
| b69ab31 | | | 511 | revealCommit={onDoubleClickToShowDrawer} |
| b69ab31 | | | 512 | commit={commit} |
| b69ab31 | | | 513 | />, |
| b69ab31 | | | 514 | ); |
| b69ab31 | | | 515 | } |
| b69ab31 | | | 516 | |
| b69ab31 | | | 517 | if ((commit as DagCommitInfo).isYouAreHere) { |
| b69ab31 | | | 518 | return ( |
| b69ab31 | | | 519 | <div className="head-commit-info"> |
| b69ab31 | | | 520 | <UncommittedChanges place="main" /> |
| b69ab31 | | | 521 | </div> |
| b69ab31 | | | 522 | ); |
| b69ab31 | | | 523 | } |
| b69ab31 | | | 524 | |
| b69ab31 | | | 525 | return ( |
| b69ab31 | | | 526 | <div |
| b69ab31 | | | 527 | className={ |
| b69ab31 | | | 528 | 'commit' + |
| b69ab31 | | | 529 | (commit.isDot ? ' head-commit' : '') + |
| b69ab31 | | | 530 | (commit.successorInfo != null ? ' obsolete' : '') + |
| b69ab31 | | | 531 | (isIrrelevantToCwd ? ' irrelevant' : '') |
| b69ab31 | | | 532 | } |
| b69ab31 | | | 533 | onContextMenu={e => { |
| b69ab31 | | | 534 | writeAtom(actioningCommit, commit.hash); |
| b69ab31 | | | 535 | contextMenu(e); |
| b69ab31 | | | 536 | }} |
| b69ab31 | | | 537 | data-testid={`commit-${commit.hash}`}> |
| b69ab31 | | | 538 | <div |
| b69ab31 | | | 539 | className={ |
| b69ab31 | | | 540 | 'commit-rows' + |
| b69ab31 | | | 541 | (isSelected ? ' commit-row-selected' : '') + |
| b69ab31 | | | 542 | (isActioning ? ' commit-row-actioning' : '') |
| b69ab31 | | | 543 | } |
| b69ab31 | | | 544 | data-testid={isSelected ? 'selected-commit' : undefined}> |
| b69ab31 | | | 545 | <DragToRebase |
| b69ab31 | | | 546 | className={ |
| b69ab31 | | | 547 | 'commit-details' + (previewType != null ? ` commit-preview-${previewType}` : '') |
| b69ab31 | | | 548 | } |
| b69ab31 | | | 549 | commit={commit} |
| b69ab31 | | | 550 | previewType={previewType}> |
| b69ab31 | | | 551 | {!isPublic && isIrrelevantToCwd && ( |
| b69ab31 | | | 552 | <Tooltip |
| b69ab31 | | | 553 | title={ |
| b69ab31 | | | 554 | <T |
| b69ab31 | | | 555 | replace={{ |
| b69ab31 | | | 556 | $prefix: <pre>{commit.maxCommonPathPrefix}</pre>, |
| b69ab31 | | | 557 | $cwd: <pre>{readAtom(repoRelativeCwd)}</pre>, |
| b69ab31 | | | 558 | }}> |
| b69ab31 | | | 559 | This commit only contains files within: $prefix These are irrelevant to your |
| b69ab31 | | | 560 | current working directory: $cwd |
| b69ab31 | | | 561 | </T> |
| b69ab31 | | | 562 | }> |
| b69ab31 | | | 563 | <IrrelevantCwdIcon /> |
| b69ab31 | | | 564 | </Tooltip> |
| b69ab31 | | | 565 | )} |
| ab83ad3 | | | 566 | <span className="commit-title"> |
| ab83ad3 | | | 567 | {commitLabel && <CommitLabel>{commitLabel}</CommitLabel>} |
| ab83ad3 | | | 568 | <span>{title}</span> |
| ab83ad3 | | | 569 | <CommitDate date={commit.date} /> |
| ab83ad3 | | | 570 | </span> |
| b69ab31 | | | 571 | <UnsavedEditedMessageIndicator commit={commit} /> |
| b69ab31 | | | 572 | {!isPublic && <BranchingPrs bookmarks={commit.remoteBookmarks} />} |
| b69ab31 | | | 573 | <AllBookmarksTruncated |
| b69ab31 | | | 574 | local={commit.bookmarks} |
| b69ab31 | | | 575 | remote={ |
| b69ab31 | | | 576 | isPublic |
| b69ab31 | | | 577 | ? commit.remoteBookmarks |
| b69ab31 | | | 578 | : /* draft commits with remote bookmarks are probably branching PRs, rendered above. */ [] |
| b69ab31 | | | 579 | } |
| b69ab31 | | | 580 | stable={commit?.stableCommitMetadata ?? []} |
| b69ab31 | | | 581 | fullRepoBranch={commit.fullRepoBranch} |
| b69ab31 | | | 582 | /> |
| b69ab31 | | | 583 | {isNarrow ? commitActions : null} |
| b69ab31 | | | 584 | </DragToRebase> |
| b69ab31 | | | 585 | <DivIfChildren className="commit-second-row"> |
| e625552 | | | 586 | {!isPublic ? ( |
| b69ab31 | | | 587 | <DiffInfo commit={commit} hideActions={actionsPrevented || inlineProgress != null} /> |
| b69ab31 | | | 588 | ) : null} |
| 083fd5f | | | 589 | {isPublic ? <CanopySignal hash={commit.hash} /> : null} |
| b69ab31 | | | 590 | {commit.successorInfo != null ? ( |
| b69ab31 | | | 591 | <SuccessorInfoToDisplay successorInfo={commit.successorInfo} /> |
| b69ab31 | | | 592 | ) : null} |
| b69ab31 | | | 593 | {inlineProgress && <InlineProgressSpan message={inlineProgress} />} |
| b69ab31 | | | 594 | {commit.isFollower ? <DiffFollower commit={commit} /> : null} |
| b69ab31 | | | 595 | </DivIfChildren> |
| b69ab31 | | | 596 | {!isNarrow ? commitActions : null} |
| b69ab31 | | | 597 | </div> |
| b69ab31 | | | 598 | </div> |
| b69ab31 | | | 599 | ); |
| b69ab31 | | | 600 | }, |
| b69ab31 | | | 601 | (prevProps, nextProps) => { |
| b69ab31 | | | 602 | const prevCommit = prevProps.commit; |
| b69ab31 | | | 603 | const nextCommit = nextProps.commit; |
| b69ab31 | | | 604 | const commitEqual = |
| b69ab31 | | | 605 | 'equals' in nextCommit ? nextCommit.equals(prevCommit) : nextCommit === prevCommit; |
| b69ab31 | | | 606 | return ( |
| b69ab31 | | | 607 | commitEqual && |
| b69ab31 | | | 608 | nextProps.previewType === prevProps.previewType && |
| b69ab31 | | | 609 | nextProps.hasChildren === prevProps.hasChildren |
| b69ab31 | | | 610 | ); |
| b69ab31 | | | 611 | }, |
| b69ab31 | | | 612 | ); |
| b69ab31 | | | 613 | |
| b69ab31 | | | 614 | function BranchingPrs({bookmarks}: {bookmarks: ReadonlyArray<string>}) { |
| b69ab31 | | | 615 | const provider = useAtomValue(codeReviewProvider); |
| b69ab31 | | | 616 | if (provider == null || !provider.supportBranchingPrs) { |
| b69ab31 | | | 617 | // If we don't have a provider, just render them as bookmarks so they don't get hidden. |
| b69ab31 | | | 618 | return <Bookmarks bookmarks={bookmarks} kind="remote" />; |
| b69ab31 | | | 619 | } |
| b69ab31 | | | 620 | return bookmarks.map(bookmark => ( |
| b69ab31 | | | 621 | <BranchingPr key={bookmark} provider={provider} bookmark={bookmark} /> |
| b69ab31 | | | 622 | )); |
| b69ab31 | | | 623 | } |
| b69ab31 | | | 624 | |
| b69ab31 | | | 625 | function BranchingPr({bookmark, provider}: {bookmark: string; provider: UICodeReviewProvider}) { |
| b69ab31 | | | 626 | const branchName = nullthrows(provider.branchNameForRemoteBookmark)(bookmark); |
| b69ab31 | | | 627 | const info = useAtomValue(branchingDiffInfos(branchName)); |
| b69ab31 | | | 628 | return ( |
| b69ab31 | | | 629 | <> |
| b69ab31 | | | 630 | <Bookmark kind="remote">{bookmark}</Bookmark> |
| b69ab31 | | | 631 | {info.value == null ? null : ( |
| b69ab31 | | | 632 | <DiffBadge diff={info.value} provider={provider} url={info.value.url} /> |
| b69ab31 | | | 633 | )} |
| b69ab31 | | | 634 | </> |
| b69ab31 | | | 635 | ); |
| b69ab31 | | | 636 | } |
| b69ab31 | | | 637 | |
| b69ab31 | | | 638 | const styles = stylex.create({ |
| b69ab31 | | | 639 | commitLabel: { |
| b69ab31 | | | 640 | fontVariant: 'all-petite-caps', |
| b69ab31 | | | 641 | opacity: '0.8', |
| b69ab31 | | | 642 | fontWeight: 'bold', |
| b69ab31 | | | 643 | fontSize: '90%', |
| b69ab31 | | | 644 | }, |
| b69ab31 | | | 645 | gotoButton: { |
| b69ab31 | | | 646 | gap: spacing.half, |
| b69ab31 | | | 647 | }, |
| b69ab31 | | | 648 | }); |
| b69ab31 | | | 649 | |
| b69ab31 | | | 650 | function CommitLabel({children}: {children?: ReactNode}) { |
| b69ab31 | | | 651 | return <div {...stylex.props(styles.commitLabel)}>{children}</div>; |
| b69ab31 | | | 652 | } |
| b69ab31 | | | 653 | |
| b69ab31 | | | 654 | export function InlineProgressSpan(props: {message: string}) { |
| b69ab31 | | | 655 | return ( |
| b69ab31 | | | 656 | <span className="commit-inline-operation-progress"> |
| b69ab31 | | | 657 | <Icon icon="loading" /> <T>{props.message}</T> |
| b69ab31 | | | 658 | </span> |
| b69ab31 | | | 659 | ); |
| b69ab31 | | | 660 | } |
| b69ab31 | | | 661 | |
| b69ab31 | | | 662 | function OpenCommitInfoButton({ |
| b69ab31 | | | 663 | commit, |
| b69ab31 | | | 664 | revealCommit, |
| b69ab31 | | | 665 | }: { |
| b69ab31 | | | 666 | commit: CommitInfo; |
| b69ab31 | | | 667 | revealCommit: () => unknown; |
| b69ab31 | | | 668 | }) { |
| b69ab31 | | | 669 | return ( |
| b69ab31 | | | 670 | <Tooltip title={t("Open commit's details in sidebar")} delayMs={250}> |
| b69ab31 | | | 671 | <Button |
| b69ab31 | | | 672 | icon |
| b69ab31 | | | 673 | onClick={e => { |
| b69ab31 | | | 674 | revealCommit(); |
| b69ab31 | | | 675 | e.stopPropagation(); |
| b69ab31 | | | 676 | e.preventDefault(); |
| b69ab31 | | | 677 | }} |
| b69ab31 | | | 678 | className="open-commit-info-button" |
| b69ab31 | | | 679 | aria-label={t('Open commit "$title"', {replace: {$title: commit.title}})} |
| b69ab31 | | | 680 | data-testid="open-commit-info-button"> |
| b69ab31 | | | 681 | <Icon icon="chevron-right" /> |
| b69ab31 | | | 682 | </Button> |
| b69ab31 | | | 683 | </Tooltip> |
| b69ab31 | | | 684 | ); |
| b69ab31 | | | 685 | } |
| b69ab31 | | | 686 | |
| b69ab31 | | | 687 | function ConfirmHideButton({onClick}: {onClick: () => unknown}) { |
| b69ab31 | | | 688 | const ref = useAutofocusRef() as React.MutableRefObject<null>; |
| b69ab31 | | | 689 | return ( |
| b69ab31 | | | 690 | <Button ref={ref} primary onClick={onClick}> |
| b69ab31 | | | 691 | <T>Hide</T> |
| b69ab31 | | | 692 | </Button> |
| b69ab31 | | | 693 | ); |
| b69ab31 | | | 694 | } |
| b69ab31 | | | 695 | |
| b69ab31 | | | 696 | function ConfirmCombineButtons() { |
| b69ab31 | | | 697 | const ref = useAutofocusRef() as React.MutableRefObject<null>; |
| b69ab31 | | | 698 | const [cancel, run] = useRunFoldPreview(); |
| b69ab31 | | | 699 | |
| b69ab31 | | | 700 | return ( |
| b69ab31 | | | 701 | <> |
| b69ab31 | | | 702 | <Button onClick={cancel}> |
| b69ab31 | | | 703 | <T>Cancel</T> |
| b69ab31 | | | 704 | </Button> |
| b69ab31 | | | 705 | <Button ref={ref} primary onClick={run}> |
| b69ab31 | | | 706 | <T>Run Combine</T> |
| b69ab31 | | | 707 | </Button> |
| b69ab31 | | | 708 | </> |
| b69ab31 | | | 709 | ); |
| b69ab31 | | | 710 | } |
| b69ab31 | | | 711 | |
| b69ab31 | | | 712 | function CommitDate({date}: {date: Date}) { |
| b69ab31 | | | 713 | return ( |
| b69ab31 | | | 714 | <span className="commit-date" title={date.toLocaleString()}> |
| b69ab31 | | | 715 | <RelativeDate date={date} useShortVariant /> |
| b69ab31 | | | 716 | </span> |
| b69ab31 | | | 717 | ); |
| b69ab31 | | | 718 | } |
| b69ab31 | | | 719 | |
| b69ab31 | | | 720 | function DivIfChildren({ |
| b69ab31 | | | 721 | children, |
| b69ab31 | | | 722 | ...props |
| b69ab31 | | | 723 | }: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>) { |
| b69ab31 | | | 724 | if (!children || (Array.isArray(children) && children.filter(notEmpty).length === 0)) { |
| b69ab31 | | | 725 | return null; |
| b69ab31 | | | 726 | } |
| b69ab31 | | | 727 | return <div {...props}>{children}</div>; |
| b69ab31 | | | 728 | } |
| b69ab31 | | | 729 | |
| b69ab31 | | | 730 | function UnsavedEditedMessageIndicator({commit}: {commit: CommitInfo}) { |
| b69ab31 | | | 731 | const isEdted = useAtomValue(hasUnsavedEditedCommitMessage(commit.hash)); |
| b69ab31 | | | 732 | if (!isEdted) { |
| b69ab31 | | | 733 | return null; |
| b69ab31 | | | 734 | } |
| b69ab31 | | | 735 | return ( |
| b69ab31 | | | 736 | <div className="unsaved-message-indicator" data-testid="unsaved-message-indicator"> |
| b69ab31 | | | 737 | <Tooltip title={t('This commit has unsaved changes to its message')}> |
| b69ab31 | | | 738 | <IconStack> |
| b69ab31 | | | 739 | <Icon icon="output" /> |
| b69ab31 | | | 740 | <Icon icon="circle-large-filled" /> |
| b69ab31 | | | 741 | </IconStack> |
| b69ab31 | | | 742 | </Tooltip> |
| b69ab31 | | | 743 | </div> |
| b69ab31 | | | 744 | ); |
| b69ab31 | | | 745 | } |
| b69ab31 | | | 746 | |
| b69ab31 | | | 747 | export function SuccessorInfoToDisplay({successorInfo}: {successorInfo: SuccessorInfo}) { |
| b69ab31 | | | 748 | const successorType = successorInfo.type; |
| b69ab31 | | | 749 | const inner: JSX.Element = { |
| b69ab31 | | | 750 | pushrebase: <T>Landed as a newer commit</T>, |
| b69ab31 | | | 751 | land: <T>Landed as a newer commit</T>, |
| b69ab31 | | | 752 | amend: <T>Amended as a newer commit</T>, |
| b69ab31 | | | 753 | rebase: <T>Rebased as a newer commit</T>, |
| b69ab31 | | | 754 | split: <T>Split as a newer commit</T>, |
| b69ab31 | | | 755 | fold: <T>Folded as a newer commit</T>, |
| b69ab31 | | | 756 | histedit: <T>Histedited as a newer commit</T>, |
| b69ab31 | | | 757 | }[successorType] ?? <T>Rewritten as a newer commit</T>; |
| b69ab31 | | | 758 | const isSuccessorPublic = successorType === 'land' || successorType === 'pushrebase'; |
| b69ab31 | | | 759 | return ( |
| b69ab31 | | | 760 | <Row style={{gap: 'var(--halfpad)'}}> |
| b69ab31 | | | 761 | <HighlightCommitsWhileHovering toHighlight={[successorInfo.hash]}> |
| b69ab31 | | | 762 | {inner} |
| b69ab31 | | | 763 | </HighlightCommitsWhileHovering> |
| b69ab31 | | | 764 | <EducationInfoTip> |
| b69ab31 | | | 765 | <ObsoleteTip isSuccessorPublic={isSuccessorPublic} /> |
| b69ab31 | | | 766 | </EducationInfoTip> |
| b69ab31 | | | 767 | </Row> |
| b69ab31 | | | 768 | ); |
| b69ab31 | | | 769 | } |
| b69ab31 | | | 770 | |
| b69ab31 | | | 771 | function ObsoleteTipInner(props: {isSuccessorPublic?: boolean}) { |
| b69ab31 | | | 772 | const tips: string[] = props.isSuccessorPublic |
| b69ab31 | | | 773 | ? [ |
| b69ab31 | | | 774 | t('Avoid editing (e.g., amend, rebase) this obsoleted commit. It cannot be landed again.'), |
| b69ab31 | | | 775 | t( |
| b69ab31 | | | 776 | 'The new commit was landed in a public branch and became immutable. It cannot be edited or hidden.', |
| b69ab31 | | | 777 | ), |
| b69ab31 | | | 778 | t('If you want to make changes, create a new commit.'), |
| b69ab31 | | | 779 | ] |
| b69ab31 | | | 780 | : [ |
| b69ab31 | | | 781 | t( |
| b69ab31 | | | 782 | 'Avoid editing (e.g., amend, rebase) this obsoleted commit. You should use the new commit instead.', |
| b69ab31 | | | 783 | ), |
| b69ab31 | | | 784 | t( |
| b69ab31 | | | 785 | 'If you do edit, there will be multiple new versions. They look like duplications and there is no easy way to de-duplicate (e.g. merge all edits back into one commit).', |
| b69ab31 | | | 786 | ), |
| b69ab31 | | | 787 | t( |
| b69ab31 | | | 788 | 'To revert to this obsoleted commit, simply hide the new one. It will remove the "obsoleted" status.', |
| b69ab31 | | | 789 | ), |
| b69ab31 | | | 790 | ]; |
| b69ab31 | | | 791 | |
| b69ab31 | | | 792 | return ( |
| b69ab31 | | | 793 | <div style={{maxWidth: '60vw'}}> |
| b69ab31 | | | 794 | <T>This commit is "obsoleted" because a newer version exists.</T> |
| b69ab31 | | | 795 | <ul> |
| b69ab31 | | | 796 | {tips.map((tip, i) => ( |
| b69ab31 | | | 797 | <li key={i}>{tip}</li> |
| b69ab31 | | | 798 | ))} |
| b69ab31 | | | 799 | </ul> |
| b69ab31 | | | 800 | </div> |
| b69ab31 | | | 801 | ); |
| b69ab31 | | | 802 | } |
| b69ab31 | | | 803 | |
| b69ab31 | | | 804 | async function maybeWarnAboutOldDestination(dest: CommitInfo): Promise<WarningCheckResult> { |
| b69ab31 | | | 805 | const provider = readAtom(codeReviewProvider); |
| b69ab31 | | | 806 | // Cutoff age is determined by the code review provider since internal repos have different requirements than GitHub-backed repos. |
| b69ab31 | | | 807 | const MAX_AGE_CUTOFF_MS = provider?.gotoDistanceWarningAgeCutoff ?? 30 * MS_PER_DAY; |
| b69ab31 | | | 808 | |
| b69ab31 | | | 809 | const dag = readAtom(dagWithPreviews); |
| b69ab31 | | | 810 | const currentBase = findPublicBaseAncestor(dag); |
| b69ab31 | | | 811 | const destBase = findPublicBaseAncestor(dag, dest.hash); |
| b69ab31 | | | 812 | if (!currentBase || !destBase) { |
| b69ab31 | | | 813 | // can't determine if we can show warning |
| b69ab31 | | | 814 | return WarningCheckResult.PASS; |
| b69ab31 | | | 815 | } |
| b69ab31 | | | 816 | |
| b69ab31 | | | 817 | const ageDiff = currentBase.date.valueOf() - destBase.date.valueOf(); |
| b69ab31 | | | 818 | if (ageDiff < MAX_AGE_CUTOFF_MS) { |
| b69ab31 | | | 819 | // Either destination base is within time limit or destination base is newer than the current base. |
| b69ab31 | | | 820 | // No need to warn. |
| b69ab31 | | | 821 | return WarningCheckResult.PASS; |
| b69ab31 | | | 822 | } |
| b69ab31 | | | 823 | |
| b69ab31 | | | 824 | const confirmed = await platform.confirm( |
| b69ab31 | | | 825 | t( |
| b69ab31 | | | 826 | Internal.warnAboutOldGotoReason ?? |
| b69ab31 | | | 827 | 'The destination commit is $age older than the current commit. ' + |
| b69ab31 | | | 828 | "Going here may be slow. It's often faster to rebase the commit to a newer base before going. " + |
| b69ab31 | | | 829 | 'Do you want to `goto` anyway?', |
| b69ab31 | | | 830 | { |
| b69ab31 | | | 831 | replace: { |
| b69ab31 | | | 832 | $age: relativeDate(destBase.date, {reference: currentBase.date, useRelativeForm: true}), |
| b69ab31 | | | 833 | }, |
| b69ab31 | | | 834 | }, |
| b69ab31 | | | 835 | ), |
| b69ab31 | | | 836 | ); |
| b69ab31 | | | 837 | return confirmed ? WarningCheckResult.BYPASS : WarningCheckResult.FAIL; |
| b69ab31 | | | 838 | } |
| b69ab31 | | | 839 | |
| b69ab31 | | | 840 | async function maybeWarnAboutRebaseOffWarm(dest: CommitInfo): Promise<WarningCheckResult> { |
| b69ab31 | | | 841 | const isRebaseOffWarmWarningEnabled = readAtom(rebaseOffWarmWarningEnabled); |
| b69ab31 | | | 842 | if (!isRebaseOffWarmWarningEnabled || dest.stableCommitMetadata == null) { |
| b69ab31 | | | 843 | return WarningCheckResult.PASS; |
| b69ab31 | | | 844 | } |
| b69ab31 | | | 845 | |
| b69ab31 | | | 846 | const dag = readAtom(dagWithPreviews); |
| b69ab31 | | | 847 | const src = findPublicBaseAncestor(dag); |
| b69ab31 | | | 848 | const destBase = findPublicBaseAncestor(dag, dest.hash); |
| b69ab31 | | | 849 | |
| b69ab31 | | | 850 | if (!src || !destBase) { |
| b69ab31 | | | 851 | return WarningCheckResult.PASS; |
| b69ab31 | | | 852 | } |
| b69ab31 | | | 853 | |
| b69ab31 | | | 854 | if (Internal.maybeWarnAboutRebaseOffWarm?.(src, destBase)) { |
| b69ab31 | | | 855 | const buttons = [ |
| b69ab31 | | | 856 | t('Opt Out of Future Warnings'), |
| b69ab31 | | | 857 | {label: t('Cancel'), primary: true}, |
| b69ab31 | | | 858 | t('Continue Anyway'), |
| b69ab31 | | | 859 | ]; |
| b69ab31 | | | 860 | const answer = await showModal({ |
| b69ab31 | | | 861 | type: 'confirm', |
| b69ab31 | | | 862 | buttons, |
| b69ab31 | | | 863 | title: <T>Move off Warm Commit</T>, |
| b69ab31 | | | 864 | message: t( |
| b69ab31 | | | 865 | Internal.warnAboutRebaseOffWarmReason ?? |
| b69ab31 | | | 866 | "The commit you're on is a warmed up commit. Moving off will cause slower builds and performance.\n" + |
| b69ab31 | | | 867 | "It's recommended to rebase your changes onto the warmed up commit instead.\n" + |
| b69ab31 | | | 868 | "If you need fresher changes, it's recommended to reserve a new OD and work off the warm commit.\n" + |
| b69ab31 | | | 869 | 'Do you want to continue anyway?', |
| b69ab31 | | | 870 | ), |
| b69ab31 | | | 871 | }); |
| b69ab31 | | | 872 | const userEnv = (await Internal.getDevEnvType?.()) ?? 'NotImplemented'; |
| b69ab31 | | | 873 | const cwd = readAtom(repoRelativeCwd); |
| b69ab31 | | | 874 | tracker.track('WarnAboutRebaseOffWarm', { |
| b69ab31 | | | 875 | extras: { |
| b69ab31 | | | 876 | userAction: answer, |
| b69ab31 | | | 877 | envType: userEnv, |
| b69ab31 | | | 878 | cwd, |
| b69ab31 | | | 879 | }, |
| b69ab31 | | | 880 | }); |
| b69ab31 | | | 881 | if (answer === buttons[0]) { |
| b69ab31 | | | 882 | writeAtom(rebaseOffWarmWarningEnabled, false); |
| b69ab31 | | | 883 | return WarningCheckResult.PASS; |
| b69ab31 | | | 884 | } |
| b69ab31 | | | 885 | return answer === buttons[2] ? WarningCheckResult.BYPASS : WarningCheckResult.FAIL; |
| b69ab31 | | | 886 | } |
| b69ab31 | | | 887 | |
| b69ab31 | | | 888 | return WarningCheckResult.PASS; |
| b69ab31 | | | 889 | } |
| b69ab31 | | | 890 | |
| b69ab31 | | | 891 | async function maybeWarnAboutRebaseOntoMaster(commit: CommitInfo): Promise<WarningCheckResult> { |
| b69ab31 | | | 892 | const isRebaseOntoMasterWarningEnabled = readAtom(rebaseOntoMasterWarningEnabled); |
| b69ab31 | | | 893 | if (!isRebaseOntoMasterWarningEnabled) { |
| b69ab31 | | | 894 | return WarningCheckResult.PASS; |
| b69ab31 | | | 895 | } |
| b69ab31 | | | 896 | |
| b69ab31 | | | 897 | const dag = readAtom(dagWithPreviews); |
| b69ab31 | | | 898 | const src = findPublicBaseAncestor(dag); |
| b69ab31 | | | 899 | const destBase = findPublicBaseAncestor(dag, commit.hash); |
| b69ab31 | | | 900 | |
| b69ab31 | | | 901 | if (!src || !destBase) { |
| b69ab31 | | | 902 | // can't determine if we can show warning |
| b69ab31 | | | 903 | return WarningCheckResult.PASS; |
| b69ab31 | | | 904 | } |
| b69ab31 | | | 905 | |
| b69ab31 | | | 906 | if (Internal.maybeWarnAboutRebaseOntoMaster?.(src, destBase)) { |
| b69ab31 | | | 907 | const buttons = [ |
| b69ab31 | | | 908 | t('Opt Out of Future Warnings'), |
| b69ab31 | | | 909 | {label: t('Cancel'), primary: true}, |
| b69ab31 | | | 910 | t('Continue Anyway'), |
| b69ab31 | | | 911 | ]; |
| b69ab31 | | | 912 | const answer = await showModal({ |
| b69ab31 | | | 913 | type: 'confirm', |
| b69ab31 | | | 914 | buttons, |
| b69ab31 | | | 915 | title: <T>Rebase onto Master Warning</T>, |
| b69ab31 | | | 916 | message: t( |
| b69ab31 | | | 917 | Internal.warnAboutRebaseOntoMasterReason ?? |
| b69ab31 | | | 918 | 'You are about to rebase directly onto master/main. ' + |
| b69ab31 | | | 919 | 'This is generally not recommended as it can cause unexpected failures and slower builds. ' + |
| b69ab31 | | | 920 | 'Consider rebasing onto a stable or warm branch instead. ' + |
| b69ab31 | | | 921 | 'Do you want to continue anyway?', |
| b69ab31 | | | 922 | ), |
| b69ab31 | | | 923 | }); |
| b69ab31 | | | 924 | const userEnv = (await Internal.getDevEnvType?.()) ?? 'NotImplemented'; |
| b69ab31 | | | 925 | const cwd = readAtom(repoRelativeCwd); |
| b69ab31 | | | 926 | tracker.track('WarnAboutRebaseOntoMaster', { |
| b69ab31 | | | 927 | extras: { |
| b69ab31 | | | 928 | userAction: answer, |
| b69ab31 | | | 929 | envType: userEnv, |
| b69ab31 | | | 930 | cwd, |
| b69ab31 | | | 931 | }, |
| b69ab31 | | | 932 | }); |
| b69ab31 | | | 933 | if (answer === buttons[0]) { |
| b69ab31 | | | 934 | writeAtom(rebaseOntoMasterWarningEnabled, false); |
| b69ab31 | | | 935 | return WarningCheckResult.PASS; |
| b69ab31 | | | 936 | } |
| b69ab31 | | | 937 | return answer === buttons[2] ? WarningCheckResult.BYPASS : WarningCheckResult.FAIL; |
| b69ab31 | | | 938 | } |
| b69ab31 | | | 939 | |
| b69ab31 | | | 940 | return WarningCheckResult.PASS; |
| b69ab31 | | | 941 | } |
| b69ab31 | | | 942 | |
| b69ab31 | | | 943 | async function gotoAction(runOperation: ReturnType<typeof useRunOperation>, commit: CommitInfo) { |
| b69ab31 | | | 944 | const shouldProceed = await runWarningChecks([ |
| b69ab31 | | | 945 | () => maybeWarnAboutRebaseOntoMaster(commit), |
| b69ab31 | | | 946 | () => maybeWarnAboutOldDestination(commit), |
| b69ab31 | | | 947 | () => maybeWarnAboutRebaseOffWarm(commit), |
| b69ab31 | | | 948 | ]); |
| b69ab31 | | | 949 | |
| b69ab31 | | | 950 | if (!shouldProceed) { |
| b69ab31 | | | 951 | return; |
| b69ab31 | | | 952 | } |
| b69ab31 | | | 953 | |
| b69ab31 | | | 954 | const dest = |
| b69ab31 | | | 955 | // If the commit has a remote bookmark, use that instead of the hash. This is easier to read in the command history |
| b69ab31 | | | 956 | // and works better with optimistic state |
| b69ab31 | | | 957 | commit.remoteBookmarks.length > 0 |
| b69ab31 | | | 958 | ? succeedableRevset(commit.remoteBookmarks[0]) |
| b69ab31 | | | 959 | : latestSuccessorUnlessExplicitlyObsolete(commit); |
| b69ab31 | | | 960 | runOperation(new GotoOperation(dest)); |
| b69ab31 | | | 961 | // Instead of propagating, ensure we remove the selection, so we view the new head commit by default |
| b69ab31 | | | 962 | // (since the head commit is the default thing shown in the sidebar) |
| b69ab31 | | | 963 | writeAtom(selectedCommits, new Set()); |
| b69ab31 | | | 964 | } |
| b69ab31 | | | 965 | |
| b69ab31 | | | 966 | const ObsoleteTip = React.memo(ObsoleteTipInner); |
| b69ab31 | | | 967 | |
| b69ab31 | | | 968 | /** |
| b69ab31 | | | 969 | * Runs a series of validation checks sequentially. Returns true if all checks pass |
| b69ab31 | | | 970 | * or the user manually bypassed a warning, otherwise returns false if any check fails. |
| b69ab31 | | | 971 | */ |
| b69ab31 | | | 972 | async function runWarningChecks( |
| b69ab31 | | | 973 | checks: Array<() => Promise<WarningCheckResult>>, |
| b69ab31 | | | 974 | ): Promise<boolean> { |
| b69ab31 | | | 975 | for (const check of checks) { |
| b69ab31 | | | 976 | // eslint-disable-next-line no-await-in-loop |
| b69ab31 | | | 977 | const result = await check(); |
| b69ab31 | | | 978 | if (result !== WarningCheckResult.PASS) { |
| b69ab31 | | | 979 | return result === WarningCheckResult.BYPASS; |
| b69ab31 | | | 980 | } |
| b69ab31 | | | 981 | } |
| b69ab31 | | | 982 | return true; |
| b69ab31 | | | 983 | } |
| b69ab31 | | | 984 | |
| b69ab31 | | | 985 | async function handleRebaseConfirmation( |
| b69ab31 | | | 986 | commit: CommitInfo, |
| b69ab31 | | | 987 | handlePreviewedOperation: (cancel: boolean) => void, |
| b69ab31 | | | 988 | ): Promise<void> { |
| b69ab31 | | | 989 | const shouldProceed = await runWarningChecks([ |
| b69ab31 | | | 990 | () => maybeWarnAboutRebaseOntoMaster(commit), |
| b69ab31 | | | 991 | () => maybeWarnAboutDistantRebase(commit), |
| b69ab31 | | | 992 | () => maybeWarnAboutRebaseOffWarm(commit), |
| b69ab31 | | | 993 | ]); |
| b69ab31 | | | 994 | |
| b69ab31 | | | 995 | if (!shouldProceed) { |
| b69ab31 | | | 996 | return; |
| b69ab31 | | | 997 | } |
| b69ab31 | | | 998 | |
| b69ab31 | | | 999 | handlePreviewedOperation(/* cancel */ false); |
| b69ab31 | | | 1000 | |
| b69ab31 | | | 1001 | const dag = readAtom(dagWithPreviews); |
| b69ab31 | | | 1002 | const onto = dag.get(commit.parents[0]); |
| b69ab31 | | | 1003 | if (onto) { |
| b69ab31 | | | 1004 | tracker.track('ConfirmDragAndDropRebase', { |
| b69ab31 | | | 1005 | extras: { |
| b69ab31 | | | 1006 | remoteBookmarks: onto.remoteBookmarks, |
| b69ab31 | | | 1007 | locations: onto.stableCommitMetadata?.map(s => s.value), |
| b69ab31 | | | 1008 | }, |
| b69ab31 | | | 1009 | }); |
| b69ab31 | | | 1010 | } |
| b69ab31 | | | 1011 | } |
| b69ab31 | | | 1012 | |
| b69ab31 | | | 1013 | async function maybeWarnAboutDistantRebase(commit: CommitInfo): Promise<WarningCheckResult> { |
| b69ab31 | | | 1014 | const isDistantRebaseWarningEnabled = readAtom(distantRebaseWarningEnabled); |
| b69ab31 | | | 1015 | if (!isDistantRebaseWarningEnabled) { |
| b69ab31 | | | 1016 | return WarningCheckResult.PASS; |
| b69ab31 | | | 1017 | } |
| b69ab31 | | | 1018 | const dag = readAtom(dagWithPreviews); |
| b69ab31 | | | 1019 | const onto = dag.get(commit.parents[0]); |
| b69ab31 | | | 1020 | if (!onto) { |
| b69ab31 | | | 1021 | return WarningCheckResult.PASS; // If there's no target commit, proceed without warning |
| b69ab31 | | | 1022 | } |
| b69ab31 | | | 1023 | const currentBase = findPublicBaseAncestor(dag); |
| b69ab31 | | | 1024 | const destBase = findPublicBaseAncestor(dag, onto.hash); |
| b69ab31 | | | 1025 | if (!currentBase || !destBase) { |
| b69ab31 | | | 1026 | // can't determine if we can show warning |
| b69ab31 | | | 1027 | return WarningCheckResult.PASS; |
| b69ab31 | | | 1028 | } |
| b69ab31 | | | 1029 | |
| b69ab31 | | | 1030 | if (Internal.maybeWarnAboutDistantRebase?.(currentBase, destBase)) { |
| b69ab31 | | | 1031 | const buttons = [ |
| b69ab31 | | | 1032 | t('Opt Out of Future Warnings'), |
| b69ab31 | | | 1033 | {label: t('Cancel'), primary: true}, |
| b69ab31 | | | 1034 | t('Rebase Anyway'), |
| b69ab31 | | | 1035 | ]; |
| b69ab31 | | | 1036 | const answer = await showModal({ |
| b69ab31 | | | 1037 | type: 'confirm', |
| b69ab31 | | | 1038 | buttons, |
| b69ab31 | | | 1039 | title: <T>Distant Rebase Warning</T>, |
| b69ab31 | | | 1040 | message: t( |
| b69ab31 | | | 1041 | Internal.warnAboutDistantRebaseReason ?? |
| b69ab31 | | | 1042 | 'The target commit is $age away from your current commit. ' + |
| b69ab31 | | | 1043 | 'Rebasing across a large time gap may cause slower builds and performance. ' + |
| b69ab31 | | | 1044 | "It's recommended to rebase the destination commit(s) to the nearest stable or warm commit first and then attempt this rebase. " + |
| b69ab31 | | | 1045 | 'Do you want to `rebase` anyway?', |
| b69ab31 | | | 1046 | { |
| b69ab31 | | | 1047 | replace: { |
| b69ab31 | | | 1048 | $age: relativeDate(onto.date, {reference: commit.date, useRelativeForm: true}), |
| b69ab31 | | | 1049 | }, |
| b69ab31 | | | 1050 | }, |
| b69ab31 | | | 1051 | ), |
| b69ab31 | | | 1052 | }); |
| b69ab31 | | | 1053 | const userEnv = (await Internal.getDevEnvType?.()) ?? 'NotImplemented'; |
| b69ab31 | | | 1054 | const cwd = readAtom(repoRelativeCwd); |
| b69ab31 | | | 1055 | tracker.track('WarnAboutDistantRebase', { |
| b69ab31 | | | 1056 | extras: { |
| b69ab31 | | | 1057 | userAction: answer, |
| b69ab31 | | | 1058 | envType: userEnv, |
| b69ab31 | | | 1059 | cwd, |
| b69ab31 | | | 1060 | }, |
| b69ab31 | | | 1061 | }); |
| b69ab31 | | | 1062 | if (answer === buttons[0]) { |
| b69ab31 | | | 1063 | writeAtom(distantRebaseWarningEnabled, false); |
| b69ab31 | | | 1064 | return WarningCheckResult.PASS; |
| b69ab31 | | | 1065 | } |
| b69ab31 | | | 1066 | return answer === buttons[2] ? WarningCheckResult.BYPASS : WarningCheckResult.FAIL; |
| b69ab31 | | | 1067 | } |
| b69ab31 | | | 1068 | |
| b69ab31 | | | 1069 | return WarningCheckResult.PASS; |
| b69ab31 | | | 1070 | } |
| 083fd5f | | | 1071 | |
| 083fd5f | | | 1072 | function CanopySignal({hash}: {hash: Hash}) { |
| e7069e1 | | | 1073 | useEffect(() => { |
| e7069e1 | | | 1074 | ensureCanopySignalsFetched(); |
| e7069e1 | | | 1075 | }, []); |
| 9e488cc | | | 1076 | const info = useAtomValue(canopySignalForCommit(hash)); |
| 9e488cc | | | 1077 | const repoInfo = useAtomValue(repositoryInfo); |
| 9e488cc | | | 1078 | if (!info) { |
| 083fd5f | | | 1079 | return null; |
| 083fd5f | | | 1080 | } |
| 9e488cc | | | 1081 | const handleClick = |
| e7069e1 | | | 1082 | info.commitId != null && repoInfo?.codeReviewSystem.type === 'grove' |
| 9e488cc | | | 1083 | ? () => { |
| 9e488cc | | | 1084 | const {owner, repo, apiUrl} = repoInfo.codeReviewSystem as { |
| 9e488cc | | | 1085 | apiUrl: string; |
| 9e488cc | | | 1086 | owner: string; |
| 9e488cc | | | 1087 | repo: string; |
| 9e488cc | | | 1088 | }; |
| 9e488cc | | | 1089 | const baseUrl = apiUrl.replace('/api', '').replace(/^https?:\/\//, ''); |
| 9e488cc | | | 1090 | const canopyHost = `canopy.${baseUrl}`; |
| e7069e1 | | | 1091 | const url = `https://${canopyHost}/${owner}/${repo}/runs/${info.commitId}`; |
| 9e488cc | | | 1092 | platform.openExternalLink(url); |
| 9e488cc | | | 1093 | } |
| 9e488cc | | | 1094 | : undefined; |
| 9e488cc | | | 1095 | return ( |
| 9e488cc | | | 1096 | <span onClick={handleClick} style={handleClick ? {cursor: 'pointer'} : undefined}> |
| 9e488cc | | | 1097 | <SignalSummaryIcon signal={info.signal} /> |
| 9e488cc | | | 1098 | </span> |
| 9e488cc | | | 1099 | ); |
| 083fd5f | | | 1100 | } |