Skip to content

Commit e5daaa8

Browse files
evangraykmeta-codesync[bot]
authored andcommitted
Make goto button not float right except on very narrow screens
Summary: A recent-ish change made the goto button float right on narrow screens. But the narrow definition was still kind of wide. I think we only want the float for extremely narrow screens where we have no better choice. Reviewed By: nsblake Differential Revision: D116831120 fbshipit-source-id: 88ccb5dba0f2fc9c551946626f56d738fb90d5d5
1 parent 5f46c42 commit e5daaa8

5 files changed

Lines changed: 90 additions & 17 deletions

File tree

addons/isl/src/Commit.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import platform from './platform';
8181
import {CommitPreview, dagWithPreviews, uncommittedChangesWithPreviews} from './previews';
8282
import {RelativeDate, relativeDate} from './relativeDate';
8383
import {repoRelativeCwd, useIsIrrelevantToCwd} from './repositoryData';
84-
import {isNarrowCommitTree} from './responsive';
84+
import {commitTreeWidth} from './responsive';
8585
import {
8686
actioningCommit,
8787
selectedCommitInfos,
@@ -193,7 +193,7 @@ export const Commit = memo(
193193

194194
const inConflicts = useAtomValue(inMergeConflicts);
195195

196-
const isNarrow = useAtomValue(isNarrowCommitTree);
196+
const treeWidth = useAtomValue(commitTreeWidth);
197197

198198
const title = useAtomValue(latestCommitMessageTitle(commit.hash));
199199

@@ -769,10 +769,14 @@ export const Commit = memo(
769769
fullRepoBranch={commit.fullRepoBranch}
770770
/>
771771
{isPublic ? <CommitDate date={commit.date} /> : null}
772-
{isNarrow ? (
772+
{treeWidth !== 'wide' ? (
773773
<>
774774
{inlineCommitActions}
775-
<div className="commit-narrow-right-actions">{floatingCommitActions}</div>
775+
{treeWidth === 'very-narrow' ? (
776+
<div className="commit-narrow-right-actions">{floatingCommitActions}</div>
777+
) : (
778+
floatingCommitActions
779+
)}
776780
</>
777781
) : null}
778782
</DragToRebase>
@@ -786,7 +790,7 @@ export const Commit = memo(
786790
{inlineProgress && <InlineProgressSpan message={inlineProgress} />}
787791
{commit.isFollower ? <DiffFollower commit={commit} /> : null}
788792
</DivIfChildren>
789-
{!isNarrow ? commitActions : null}
793+
{treeWidth === 'wide' ? commitActions : null}
790794
</div>
791795
</div>
792796
);

addons/isl/src/CommitTreeList.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,14 @@
143143
.commit-tree-narrow .commit-details {
144144
flex-wrap: wrap;
145145
margin-right: 0;
146-
padding-right: 60px;
146+
padding-right: 0;
147147
z-index: 0;
148148
}
149149

150+
.commit-tree-very-narrow .commit-details {
151+
padding-right: 60px;
152+
}
153+
150154
.commit-narrow-right-actions {
151155
display: flex;
152156
align-items: center;

addons/isl/src/CommitTreeList.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import type {RenderGlyphResult} from './RenderDag';
99
import type {DagCommitInfo} from './dag/dag';
1010
import type {ExtendedGraphRow} from './dag/render';
11+
import type {CommitTreeWidth} from './responsive';
1112
import type {Hash} from './types';
1213

1314
import {Button} from 'isl-components/Button';
@@ -33,7 +34,7 @@ import {CreateEmptyInitialCommitOperation} from './operations/CreateEmptyInitial
3334
import {inlineProgressByHash, useRunOperation} from './operationsState';
3435
import {dagWithPreviews, treeWithPreviews, useMarkOperationsCompleted} from './previews';
3536
import {hideIrrelevantCwdStacks, isIrrelevantToCwd, repoRelativeCwd} from './repositoryData';
36-
import {isNarrowCommitTree} from './responsive';
37+
import {commitTreeWidth} from './responsive';
3738
import {
3839
selectedCommits,
3940
useArrowKeysToChangeSelection,
@@ -49,7 +50,7 @@ import {tracker} from './analytics';
4950
import {focusMode} from './atoms/FocusModeState';
5051

5152
type DagCommitListProps = {
52-
isNarrow: boolean;
53+
width: CommitTreeWidth;
5354
};
5455

5556
const YOU_ARE_HERE_ANCHOR_ID = 'isl-you-are-here-anchor';
@@ -134,7 +135,7 @@ const renderSubsetUnionSelection = atom(get => {
134135
});
135136

136137
function DagCommitList(props: DagCommitListProps) {
137-
const {isNarrow} = props;
138+
const {width} = props;
138139

139140
const dag = useAtomValue(dagWithYouAreHere);
140141
const subset = useAtomValue(renderSubsetUnionSelection);
@@ -171,7 +172,11 @@ function DagCommitList(props: DagCommitListProps) {
171172
<RenderDag
172173
dag={dag}
173174
subset={subset}
174-
className={'commit-tree-root ' + (isNarrow ? ' commit-tree-narrow' : '')}
175+
className={
176+
'commit-tree-root ' +
177+
(width !== 'wide' ? ' commit-tree-narrow' : '') +
178+
(width === 'very-narrow' ? ' commit-tree-very-narrow' : '')
179+
}
175180
data-testid="commit-tree-root"
176181
renderCommit={renderCommit}
177182
renderCommitExtras={renderCommitExtras}
@@ -408,7 +413,7 @@ export function CommitTreeList() {
408413
useBackspaceToHideSelected();
409414
useShortcutToRebaseSelected();
410415

411-
const isNarrow = useAtomValue(isNarrowCommitTree);
416+
const treeWidth = useAtomValue(commitTreeWidth);
412417

413418
const {trees} = useAtomValue(treeWithPreviews);
414419
const fetchError = useAtomValue(commitFetchError);
@@ -430,7 +435,7 @@ export function CommitTreeList() {
430435
<>
431436
{fetchError ? <CommitFetchError error={fetchError} /> : null}
432437
<ScrollToCurrentCommitButton slot="above" />
433-
<DagCommitList isNarrow={isNarrow} />
438+
<DagCommitList width={treeWidth} />
434439
<ScrollToCurrentCommitButton slot="below" />
435440
<MaybeEditStackModal />
436441
</>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
8+
import {readAtom, writeAtom} from '../jotaiUtils';
9+
import {
10+
commitTreeWidth,
11+
mainContentWidthState,
12+
NARROW_COMMIT_TREE_WIDTH,
13+
NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT,
14+
renderCompactAtom,
15+
VERY_NARROW_COMMIT_TREE_WIDTH,
16+
VERY_NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT,
17+
} from '../responsive';
18+
19+
describe('commitTreeWidth', () => {
20+
beforeEach(() => {
21+
writeAtom(renderCompactAtom, false);
22+
});
23+
24+
it.each([
25+
[NARROW_COMMIT_TREE_WIDTH, 'wide'],
26+
[NARROW_COMMIT_TREE_WIDTH - 1, 'narrow'],
27+
[VERY_NARROW_COMMIT_TREE_WIDTH, 'narrow'],
28+
[VERY_NARROW_COMMIT_TREE_WIDTH - 1, 'very-narrow'],
29+
] as const)('categorizes a width of %s as %s', (width, expected) => {
30+
writeAtom(mainContentWidthState, width);
31+
expect(readAtom(commitTreeWidth)).toBe(expected);
32+
});
33+
34+
it.each([
35+
[NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT, 'wide'],
36+
[NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT - 1, 'narrow'],
37+
[VERY_NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT, 'narrow'],
38+
[VERY_NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT - 1, 'very-narrow'],
39+
] as const)('uses compact breakpoints to categorize a width of %s as %s', (width, expected) => {
40+
writeAtom(renderCompactAtom, true);
41+
writeAtom(mainContentWidthState, width);
42+
expect(readAtom(commitTreeWidth)).toBe(expected);
43+
});
44+
});

addons/isl/src/responsive.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,28 @@ export function useMainContentWidth() {
6161

6262
export const NARROW_COMMIT_TREE_WIDTH = 800;
6363
export const NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT = 300;
64+
export const VERY_NARROW_COMMIT_TREE_WIDTH = 500;
65+
export const VERY_NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT = 200;
6466

65-
export const isNarrowCommitTree = atom(
66-
get =>
67-
get(mainContentWidthState) <
68-
(get(renderCompactAtom) ? NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT : NARROW_COMMIT_TREE_WIDTH),
69-
);
67+
export type CommitTreeWidth = 'wide' | 'narrow' | 'very-narrow';
68+
69+
/**
70+
* Categorizes the available commit-tree width so layout consumers can coordinate their behavior
71+
* without independently combining overlapping breakpoint atoms.
72+
*/
73+
export const commitTreeWidth = atom<CommitTreeWidth>(get => {
74+
const width = get(mainContentWidthState);
75+
const compact = get(renderCompactAtom);
76+
const veryNarrowWidth = compact
77+
? VERY_NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT
78+
: VERY_NARROW_COMMIT_TREE_WIDTH;
79+
if (width < veryNarrowWidth) {
80+
return 'very-narrow';
81+
}
82+
83+
const narrowWidth = compact ? NARROW_COMMIT_TREE_WIDTH_WHEN_COMPACT : NARROW_COMMIT_TREE_WIDTH;
84+
return width < narrowWidth ? 'narrow' : 'wide';
85+
});
7086

7187
/**
7288
* Tracks the window/viewport width. Unlike mainContentWidthState, this is

0 commit comments

Comments
 (0)