Skip to content

Commit 372463c

Browse files
quark-zjufacebook-github-bot
authored andcommitted
absorb: tweak the instruction text
Summary: The current instruction sounds like Drag-and-Drop has to be done to select amend destinations. Actually, the destinations are pre-selected and only needed to be adjusted. Make it clear about the pre-selection. Since the text becomes long, I made the "omitted" message only appear when omitting actually happens. I also added a message if there is no valid absorb destinations. Reviewed By: evangrayk Differential Revision: D67985670 fbshipit-source-id: d1a8a73feff0d082ef6f4a8b3bc61287b0c3ea3d
1 parent 74aa386 commit 372463c

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

addons/isl/src/stackEdit/ui/AbsorbStackEditPanel.tsx

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import type {DragHandler} from '../../DragHandle';
99
import type {RenderGlyphResult} from '../../RenderDag';
1010
import type {Dag} from '../../dag/dag';
1111
import type {DagCommitInfo} from '../../dag/dagCommitInfo';
12+
import type {HashSet} from '../../dag/set';
1213
import type {AbsorbEdit, AbsorbEditId} from '../absorb';
1314
import type {CommitStackState, FileRev, FileStackIndex, CommitRev} from '../commitStackState';
1415
import type {Map as ImMap} from 'immutable';
16+
import type {ReactNode} from 'react';
1517

1618
import {FileHeader, IconType} from '../../ComparisonView/SplitDiffView/SplitDiffFileHeader';
1719
import {ScrollY} from '../../ComponentUtils';
@@ -27,6 +29,7 @@ import * as stylex from '@stylexjs/stylex';
2729
import {Column, Row} from 'isl-components/Flex';
2830
import {Icon} from 'isl-components/Icon';
2931
import {atom, useAtomValue} from 'jotai';
32+
import React from 'react';
3033
import {nullthrows} from 'shared/utils';
3134

3235
const styles = stylex.create({
@@ -102,6 +105,9 @@ const styles = stylex.create({
102105
instruction: {
103106
padding: 'var(--halfpad) var(--pad)',
104107
},
108+
inlineIcon: {
109+
verticalAlign: 'bottom',
110+
},
105111
scrollYPadding: {
106112
paddingRight: 'var(--pad)',
107113
},
@@ -120,18 +126,7 @@ export function AbsorbStackEditPanel() {
120126
return (
121127
<>
122128
<Column>
123-
<div {...stylex.props(styles.instruction)}>
124-
<Row>
125-
<Icon icon="info" />
126-
<div>
127-
<T>Drag a diff chunk to a commit to amend the diff chunk into the commit.</T>
128-
<br />
129-
<T>Diff chunks under "You are here" will be left in the working copy.</T>
130-
<br />
131-
<T>Only commits that modify related files are shown.</T>
132-
</div>
133-
</Row>
134-
</div>
129+
<AbsorbInstruction dag={dag} subset={subset} />
135130
<ScrollY maxSize="calc(100vh - 200px)" {...stylex.props(styles.scrollYPadding)}>
136131
<RenderDag
137132
className="absorb-dag"
@@ -152,6 +147,45 @@ export function AbsorbStackEditPanel() {
152147
);
153148
}
154149

150+
function AbsorbInstruction(props: {subset: HashSet; dag: Dag}) {
151+
const {dag, subset} = props;
152+
const hasOmittedCommits = subset.size < dag.all().size;
153+
const hasDndDestinations = subset.intersect(dag.draft()).size > 1;
154+
const tips: ReactNode[] = [];
155+
if (hasDndDestinations) {
156+
tips.push(<T>Diff chunks under a commit will be amended to the commit.</T>);
157+
}
158+
tips.push(<T>Diff chunks under "You are here" will be left in the working copy.</T>);
159+
if (hasDndDestinations) {
160+
tips.push(
161+
<T
162+
replace={{$grabber: <Icon icon="grabber" size="S" {...stylex.props(styles.inlineIcon)} />}}>
163+
Commits are pre-selected based on blame information. Drag $grabber to adjust.
164+
</T>,
165+
);
166+
if (hasOmittedCommits) {
167+
tips.push(<T>Only commits that modify related files/areas are shown.</T>);
168+
}
169+
} else {
170+
tips.push(<T>Nothing to absorb. The commit stack did not modify relevant files.</T>);
171+
}
172+
return (
173+
<div {...stylex.props(styles.instruction)}>
174+
<Row>
175+
<Icon icon="info" />
176+
<div>
177+
{tips.map((tip, idx) => (
178+
<React.Fragment key={idx}>
179+
{idx > 0 && <br />}
180+
{tip}
181+
</React.Fragment>
182+
))}
183+
</div>
184+
</Row>
185+
</div>
186+
);
187+
}
188+
155189
const candidateDropTargetRevs = atom<readonly CommitRev[] | undefined>(get => {
156190
const edit = get(draggingAbsorbEdit);
157191
const stack = get(stackEditStack);

0 commit comments

Comments
 (0)