1.8 KB54 lines
Blame
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
8import type {CommitInfo} from './types';
9
10import * as stylex from '@stylexjs/stylex';
11import {useAtom, useAtomValue} from 'jotai';
12import {useRef} from 'react';
13import {diffUpdateMessagesState} from './CommitInfoView/CommitInfoState';
14import {MinHeightTextField} from './CommitInfoView/MinHeightTextField';
15import {codeReviewProvider} from './codeReview/CodeReviewInfo';
16import {T} from './i18n';
17
18const styles = stylex.create({
19 full: {
20 width: '100%',
21 },
22});
23
24export function multiSubmitUpdateMessage(commits: Array<CommitInfo>) {
25 // Combine hashes to key the typed update message.
26 // This is kind of volatile, since if you change your selection at all, the message will be cleared.
27 // Note: order must be deterministic so that your selection order doesn't affect this key
28 const orderedCommits = commits.map(c => c.hash);
29 orderedCommits.sort();
30 const key = orderedCommits.join(',');
31 return diffUpdateMessagesState(key);
32}
33
34export function SubmitUpdateMessageInput({commits}: {commits: Array<CommitInfo>}) {
35 const provider = useAtomValue(codeReviewProvider);
36 const ref = useRef(null);
37
38 // typically only one commit, but if you've selected multiple, we key the message on all hashes together.
39 const [message, setMessage] = useAtom(multiSubmitUpdateMessage(commits));
40 if (message == null || provider?.supportsUpdateMessage !== true) {
41 return null;
42 }
43 return (
44 <MinHeightTextField
45 ref={ref}
46 keepNewlines
47 containerXstyle={styles.full}
48 value={message}
49 onInput={e => setMessage(e.currentTarget.value)}>
50 <T>Update Message</T>
51 </MinHeightTextField>
52 );
53}
54