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