mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
add update message field to commit info view
Summary: We now support an update message field when you bulk submit your stack, but we should also let you do this in the commit info view. I don't love that we need to take up an additional line of space for this, it kind of gets in the way. But I think it's better to have this feature than not. Reviewed By: sggutier Differential Revision: D49338613 fbshipit-source-id: cbc26a3366d2419dda1380eb11b0cc18cf2fa578
This commit is contained in:
parent
c03465781d
commit
8a7fce2981
@ -68,6 +68,15 @@ export const commitMessageTemplate = atom<EditedMessage | undefined>({
|
||||
],
|
||||
});
|
||||
|
||||
/** Typed update messages when submitting a commit or set of commits.
|
||||
* Unlike editedCommitMessages, you can't provide an update message when committing the first time,
|
||||
* so we don't need to track this state for 'head'.
|
||||
*/
|
||||
export const diffUpdateMessagesState = atomFamily<string, Hash>({
|
||||
key: 'diffUpdateMessagesState',
|
||||
default: '',
|
||||
});
|
||||
|
||||
/**
|
||||
* Map of hash -> latest edited commit message, representing any changes made to the commit's message fields.
|
||||
* This also stores the state of new commit messages being written, keyed by "head" instead of a commit hash.
|
||||
@ -123,6 +132,12 @@ function updateEditedCommitMessagesFromSuccessions() {
|
||||
) {
|
||||
globalRecoil().set(editedCommitMessages(newHash), existing.valueOrThrow());
|
||||
}
|
||||
|
||||
const existingUpdateMessage = globalRecoil().getLoadable(diffUpdateMessagesState(oldHash));
|
||||
if (existingUpdateMessage.state === 'hasValue') {
|
||||
// TODO: this doesn't work if you have multiple commits selected...
|
||||
globalRecoil().set(diffUpdateMessagesState(oldHash), existingUpdateMessage.valueOrThrow());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import {Center} from '../ComponentUtils';
|
||||
import {HighlightCommitsWhileHovering} from '../HighlightedCommits';
|
||||
import {numPendingImageUploads} from '../ImageUpload';
|
||||
import {OperationDisabledButton} from '../OperationDisabledButton';
|
||||
import {SubmitUpdateMessageInput} from '../SubmitUpdateMessageInput';
|
||||
import {Subtle} from '../Subtle';
|
||||
import {Tooltip} from '../Tooltip';
|
||||
import {ChangedFiles, UncommittedChanges} from '../UncommittedChanges';
|
||||
@ -45,6 +46,7 @@ import {useModal} from '../useModal';
|
||||
import {assert, firstLine, firstOfIterable} from '../utils';
|
||||
import {CommitInfoField} from './CommitInfoField';
|
||||
import {
|
||||
diffUpdateMessagesState,
|
||||
commitInfoViewCurrentCommits,
|
||||
assertNonOptimistic,
|
||||
commitFieldsBeingEdited,
|
||||
@ -489,6 +491,8 @@ function ActionsBar({
|
||||
const schema = useRecoilValue(commitMessageFieldsSchema);
|
||||
const headCommit = useRecoilValue(latestHeadCommit);
|
||||
|
||||
const [updateMessage, setUpdateMessage] = useRecoilState(diffUpdateMessagesState(commit.hash));
|
||||
|
||||
const messageSyncEnabled = useRecoilValue(messageSyncingEnabledState);
|
||||
|
||||
// after committing/amending, if you've previously selected the head commit,
|
||||
@ -565,6 +569,9 @@ function ActionsBar({
|
||||
|
||||
return (
|
||||
<div className="commit-info-actions-bar" data-testid="commit-info-actions-bar">
|
||||
{isCommitMode || commit.diffId == null ? null : (
|
||||
<SubmitUpdateMessageInput commits={[commit]} />
|
||||
)}
|
||||
<div className="commit-info-actions-bar-left">
|
||||
<SubmitAsDraftCheckbox commitsToBeSubmit={isCommitMode ? [] : [commit]} />
|
||||
</div>
|
||||
@ -770,8 +777,14 @@ function ActionsBar({
|
||||
{
|
||||
draft: shouldSubmitAsDraft,
|
||||
updateFields: shouldUpdateMessage,
|
||||
updateMessage: updateMessage || undefined,
|
||||
},
|
||||
);
|
||||
// clear out the update message now that we've used it to submit
|
||||
if (updateMessage) {
|
||||
setUpdateMessage('');
|
||||
}
|
||||
|
||||
return [amendOrCommitOp, submitOp].filter(notEmpty);
|
||||
}}>
|
||||
{commit.isHead && anythingToCommit ? (
|
||||
|
32
addons/isl/src/SubmitUpdateMessageInput.tsx
Normal file
32
addons/isl/src/SubmitUpdateMessageInput.tsx
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import type {CommitInfo} from './types';
|
||||
|
||||
import {diffUpdateMessagesState} from './CommitInfoView/CommitInfoState';
|
||||
import {codeReviewProvider} from './codeReview/CodeReviewInfo';
|
||||
import {T} from './i18n';
|
||||
import {VSCodeTextField} from '@vscode/webview-ui-toolkit/react';
|
||||
import {useRecoilState, useRecoilValue} from 'recoil';
|
||||
|
||||
export function SubmitUpdateMessageInput({commits}: {commits: Array<CommitInfo>}) {
|
||||
const provider = useRecoilValue(codeReviewProvider);
|
||||
|
||||
// typically only one commit, but if you've selected multiple, we key the message on all hashes together.
|
||||
const key = commits.map(c => c.hash).join(',');
|
||||
const [message, setMessage] = useRecoilState(diffUpdateMessagesState(key));
|
||||
if (message == null || provider?.supportsUpdateMessage !== true) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<VSCodeTextField
|
||||
value={message}
|
||||
onChange={e => setMessage((e.target as HTMLInputElement).value)}>
|
||||
<T>Update Message</T>
|
||||
</VSCodeTextField>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user