addons/isl/src/SubmitUpdateMessageInput.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {CommitInfo} from './types';
b69ab319
b69ab3110import * as stylex from '@stylexjs/stylex';
b69ab3111import {useAtom, useAtomValue} from 'jotai';
b69ab3112import {useRef} from 'react';
b69ab3113import {diffUpdateMessagesState} from './CommitInfoView/CommitInfoState';
b69ab3114import {MinHeightTextField} from './CommitInfoView/MinHeightTextField';
b69ab3115import {codeReviewProvider} from './codeReview/CodeReviewInfo';
b69ab3116import {T} from './i18n';
b69ab3117
b69ab3118const styles = stylex.create({
b69ab3119 full: {
b69ab3120 width: '100%',
b69ab3121 },
b69ab3122});
b69ab3123
b69ab3124export function multiSubmitUpdateMessage(commits: Array<CommitInfo>) {
b69ab3125 // Combine hashes to key the typed update message.
b69ab3126 // This is kind of volatile, since if you change your selection at all, the message will be cleared.
b69ab3127 // Note: order must be deterministic so that your selection order doesn't affect this key
b69ab3128 const orderedCommits = commits.map(c => c.hash);
b69ab3129 orderedCommits.sort();
b69ab3130 const key = orderedCommits.join(',');
b69ab3131 return diffUpdateMessagesState(key);
b69ab3132}
b69ab3133
b69ab3134export function SubmitUpdateMessageInput({commits}: {commits: Array<CommitInfo>}) {
b69ab3135 const provider = useAtomValue(codeReviewProvider);
b69ab3136 const ref = useRef(null);
b69ab3137
b69ab3138 // typically only one commit, but if you've selected multiple, we key the message on all hashes together.
b69ab3139 const [message, setMessage] = useAtom(multiSubmitUpdateMessage(commits));
b69ab3140 if (message == null || provider?.supportsUpdateMessage !== true) {
b69ab3141 return null;
b69ab3142 }
b69ab3143 return (
b69ab3144 <MinHeightTextField
b69ab3145 ref={ref}
b69ab3146 keepNewlines
b69ab3147 containerXstyle={styles.full}
b69ab3148 value={message}
b69ab3149 onInput={e => setMessage(e.currentTarget.value)}>
b69ab3150 <T>Update Message</T>
b69ab3151 </MinHeightTextField>
b69ab3152 );
b69ab3153}