Skip to content

Commit c9f0d89

Browse files
mrleemurraylemurra_microsoft
andauthored
Add viewport detection and count display for collapsed labels in sidebar (#7748)
Co-authored-by: lemurra_microsoft <Lee.Murray@microsoft.com>
1 parent 4f01688 commit c9f0d89

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

webviews/components/sidebar.tsx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,20 @@ export function CollapsibleSidebar(props: PullRequest) {
262262

263263
function CollapsedLabel(props: PullRequest) {
264264
const { reviewers, assignees, labels, projectItems, milestone, isIssue } = props;
265+
const [isNarrowViewport, setIsNarrowViewport] = useState(false);
266+
267+
useEffect(() => {
268+
const checkViewportWidth = () => {
269+
setIsNarrowViewport(window.innerWidth <= 350);
270+
};
271+
272+
checkViewportWidth();
273+
window.addEventListener('resize', checkViewportWidth);
274+
return () => window.removeEventListener('resize', checkViewportWidth);
275+
}, []);
265276

266277
const AvatarStack = ({ users }: { users: { avatarUrl: string; name: string }[] }) => (
267-
<span className="avatar-stack" style={{
278+
<span className="avatar-stack hello" style={{
268279
width: `${Math.min(users.length, 10) * 10 + 10}px`
269280
}}>
270281
{users.slice(0, 10).map((u, i) => (
@@ -343,21 +354,23 @@ function CollapsedLabel(props: PullRequest) {
343354
};
344355

345356
// Collect non-empty sections in order, with custom rendering
346-
const sections: { label: string; value: React.ReactNode }[] = [];
357+
const sections: { label: string; value: React.ReactNode; count: number }[] = [];
347358

348359
const reviewersWithAvatar = reviewers?.filter((r): r is ReviewState & { reviewer: { avatarUrl: string } } => !!r.reviewer.avatarUrl).map(r => ({ avatarUrl: r.reviewer.avatarUrl, name: reviewerLabel(r.reviewer) }));
349360
if (!isIssue && reviewersWithAvatar && reviewersWithAvatar.length) {
350361
sections.push({
351362
label: 'Reviewers',
352-
value: <AvatarStack users={reviewersWithAvatar} />
363+
value: <AvatarStack users={reviewersWithAvatar} />,
364+
count: reviewersWithAvatar.length
353365
});
354366
}
355367

356368
const assigneesWithAvatar = assignees?.filter((a): a is IAccount & { avatarUrl: string; login: string } => !!a.avatarUrl).map(a => ({ avatarUrl: a.avatarUrl, name: reviewerLabel(a) }));
357369
if (assigneesWithAvatar && assigneesWithAvatar.length) {
358370
sections.push({
359371
label: 'Assignees',
360-
value: <AvatarStack users={assigneesWithAvatar} />
372+
value: <AvatarStack users={assigneesWithAvatar} />,
373+
count: assigneesWithAvatar.length
361374
});
362375
}
363376
if (labels && labels.length) {
@@ -370,7 +383,8 @@ function CollapsedLabel(props: PullRequest) {
370383
getColor={l => gitHubLabelColor(l.color, props?.isDarkTheme, false)}
371384
getText={l => l.name}
372385
/>
373-
)
386+
),
387+
count: labels.length
374388
});
375389
}
376390
if (projectItems && projectItems.length) {
@@ -383,7 +397,8 @@ function CollapsedLabel(props: PullRequest) {
383397
getColor={() => gitHubLabelColor('#ededed', props?.isDarkTheme, false)}
384398
getText={p => p.project.title}
385399
/>
386-
)
400+
),
401+
count: projectItems.length
387402
});
388403
}
389404
if (milestone) {
@@ -396,7 +411,8 @@ function CollapsedLabel(props: PullRequest) {
396411
getColor={() => gitHubLabelColor('#ededed', props?.isDarkTheme, false)}
397412
getText={m => m.title}
398413
/>
399-
)
414+
),
415+
count: 1
400416
});
401417
}
402418

@@ -408,7 +424,14 @@ function CollapsedLabel(props: PullRequest) {
408424
<span className="collapsed-label">
409425
{sections.map((s) => (
410426
<span className='collapsed-section' key={s.label}>
411-
<span className='collapsed-section-label'>{s.label}</span> {s.value}
427+
<span className='collapsed-section-label'>{s.label}</span>
428+
{isNarrowViewport ? (
429+
<span className="collapsed-section-count">
430+
{s.count}
431+
</span>
432+
) : (
433+
s.value
434+
)}
412435
</span>
413436
))}
414437
</span>

webviews/editorWebview/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,10 @@ svg.octicon path {
15361536
flex-shrink: 0;
15371537
}
15381538

1539+
.collapsed-section-count {
1540+
color: var(--vscode-descriptionForeground);
1541+
}
1542+
15391543
.pill-container {
15401544
display: flex;
15411545
align-items: center;

0 commit comments

Comments
 (0)