Skip to content

Commit 8039970

Browse files
alexchantasticmeta-codesync[bot]
authored andcommitted
add submit button for single commits
Summary: Adds a submit button for single commits. This will only appear for commits that: * Are not in a stack * Are not associated with a diff Reviewed By: nsblake Differential Revision: D91435490 fbshipit-source-id: f7c99ccce6aab63e67b079615fe3bda25f735617
1 parent 6585281 commit 8039970

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

addons/isl-server/src/analytics/eventNames.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export type TrackEventName =
152152
| 'SplitOpenFromHeadCommit'
153153
| 'SplitOpenFromSmartActions'
154154
| 'SplitOpenRangeSelector'
155+
| 'SubmitSingleCommit'
155156
| 'AISplitButtonClick'
156157
| 'SuccessionsDetected'
157158
| 'BuggySuccessionDetected'

addons/isl/src/Commit.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {EducationInfoTip} from './Education';
3535
import {HighlightCommitsWhileHovering} from './HighlightedCommits';
3636
import {Internal} from './Internal';
3737
import {SubmitSelectionButton} from './SubmitSelectionButton';
38+
import {SubmitSingleCommitButton} from './SubmitSingleCommitButton';
3839
import {getSuggestedRebaseOperation, suggestedRebaseDestinations} from './SuggestedRebase';
3940
import {UncommitButton} from './UncommitButton';
4041
import {UncommittedChanges} from './UncommittedChanges';
@@ -436,8 +437,10 @@ export const Commit = memo(
436437
}
437438

438439
if (!isPublic && !actionsPrevented && commit.isDot && !inConflicts) {
440+
commitActions.push(<SubmitSingleCommitButton key="submit" />);
439441
commitActions.push(<UncommitButton key="uncommit" />);
440442
}
443+
441444
if (!isPublic && !actionsPrevented && commit.isDot && !isObsoleted && !inConflicts) {
442445
commitActions.push(
443446
<SplitButton icon key="split" trackerEventName="SplitOpenFromHeadCommit" commit={commit} />,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import {Button} from 'isl-components/Button';
9+
import {Icon} from 'isl-components/Icon';
10+
import {DOCUMENTATION_DELAY, Tooltip} from 'isl-components/Tooltip';
11+
import {useAtomValue} from 'jotai';
12+
import {tracker} from './analytics';
13+
import {codeReviewProvider, diffSummary} from './codeReview/CodeReviewInfo';
14+
import {submitAsDraft} from './codeReview/DraftCheckbox';
15+
import {t, T} from './i18n';
16+
import {readAtom} from './jotaiUtils';
17+
import {useRunOperation} from './operationsState';
18+
import {dagWithPreviews} from './previews';
19+
20+
export function SubmitSingleCommitButton() {
21+
const dag = useAtomValue(dagWithPreviews);
22+
const headCommit = dag.resolve('.');
23+
24+
const provider = useAtomValue(codeReviewProvider);
25+
const diff = useAtomValue(diffSummary(headCommit?.diffId));
26+
const isClosed = provider != null && diff.value != null && provider?.isDiffClosed(diff.value);
27+
28+
const runOperation = useRunOperation();
29+
30+
if (!headCommit || !provider) {
31+
return null;
32+
}
33+
34+
const draftAncestors = dag.ancestors(headCommit.hash, {within: dag.draft()});
35+
const isSingleCommit = draftAncestors.size === 1;
36+
const hasDiff = headCommit.diffId !== undefined;
37+
38+
if (!isSingleCommit || isClosed || hasDiff) {
39+
return null;
40+
}
41+
42+
const tooltip = t('Submit this commit for review with $cmd.', {
43+
replace: {$cmd: provider.submitCommandName()},
44+
});
45+
46+
return (
47+
<Tooltip delayMs={DOCUMENTATION_DELAY} title={tooltip}>
48+
<Button
49+
onClick={e => {
50+
e.stopPropagation();
51+
tracker.track('SubmitSingleCommit');
52+
const draft = readAtom(submitAsDraft);
53+
runOperation(
54+
provider.submitOperation([], {
55+
draft: draft ?? false,
56+
}),
57+
);
58+
}}
59+
icon
60+
data-testid="submit-button">
61+
<Icon icon="cloud-upload" slot="start" />
62+
<T>Submit</T>
63+
</Button>
64+
</Tooltip>
65+
);
66+
}

0 commit comments

Comments
 (0)