Skip to content

Commit 3578a54

Browse files
committed
Simplifies search by URL by removing merging of results
(#3543)
1 parent dc41015 commit 3578a54

File tree

2 files changed

+26
-77
lines changed

2 files changed

+26
-77
lines changed

src/plus/launchpad/launchpad.ts

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
422422
i: LaunchpadItem,
423423
ui: LaunchpadGroup,
424424
topItem: LaunchpadItem | undefined,
425+
alwaysShow: boolean | undefined,
425426
): LaunchpadItemQuickPickItem => {
426427
const buttons = [];
427428

@@ -452,6 +453,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
452453
i.actionableCategory === 'other' ? '' : `${actionGroupMap.get(i.actionableCategory)![0]} \u2022 `
453454
}${fromNow(i.updatedDate)} by @${i.author!.username}`,
454455

456+
alwaysShow: alwaysShow,
455457
buttons: buttons,
456458
iconPath: i.author?.avatarUrl != null ? Uri.parse(i.author.avatarUrl) : undefined,
457459
item: i,
@@ -460,7 +462,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
460462
};
461463
};
462464

463-
const getItems = (result: LaunchpadCategorizedResult, treatAllGroupAsExpanded?: boolean) => {
465+
const getItems = (result: LaunchpadCategorizedResult, isSearching?: boolean) => {
464466
const items: (LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem)[] = [];
465467

466468
if (result.items?.length) {
@@ -475,18 +477,21 @@ export class LaunchpadCommand extends QuickCommand<State> {
475477
for (const [ui, groupItems] of uiGroups) {
476478
if (!groupItems.length) continue;
477479

478-
items.push(...buildGroupHeading(ui, groupItems.length));
479-
480-
if (!treatAllGroupAsExpanded && context.collapsed.get(ui)) continue;
480+
if (!isSearching) {
481+
items.push(...buildGroupHeading(ui, groupItems.length));
482+
if (context.collapsed.get(ui)) {
483+
continue;
484+
}
485+
}
481486

482-
items.push(...groupItems.map(i => buildLaunchpadQuickPickItem(i, ui, topItem)));
487+
items.push(...groupItems.map(i => buildLaunchpadQuickPickItem(i, ui, topItem, isSearching)));
483488
}
484489
}
485490

486491
return items;
487492
};
488493

489-
function getItemsAndPlaceholder(treatAllGroupAsExpanded?: boolean) {
494+
function getItemsAndPlaceholder(isSearching?: boolean) {
490495
if (context.result.error != null) {
491496
return {
492497
placeholder: `Unable to load items (${
@@ -509,7 +514,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
509514

510515
return {
511516
placeholder: 'Choose an item to focus on',
512-
items: getItems(context.result, treatAllGroupAsExpanded),
517+
items: getItems(context.result, isSearching),
513518
};
514519
}
515520

@@ -539,8 +544,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
539544
};
540545

541546
const { items, placeholder } = getItemsAndPlaceholder();
542-
543-
let groupsHidden = false;
547+
const nonGroupedItems = items.filter(i => !isDirectiveQuickPickItem(i));
544548

545549
const step = createPickStep({
546550
title: context.title,
@@ -556,32 +560,27 @@ export class LaunchpadCommand extends QuickCommand<State> {
556560
RefreshQuickInputButton,
557561
],
558562
onDidChangeValue: async quickpick => {
559-
const hideGroups = Boolean(quickpick.value?.length);
560-
561-
if (groupsHidden !== hideGroups) {
562-
groupsHidden = hideGroups;
563-
quickpick.items = hideGroups ? items.filter(i => !isDirectiveQuickPickItem(i)) : items;
564-
}
565563
const { value } = quickpick;
566-
const activeLaunchpadItems = quickpick.activeItems.filter(
567-
(i): i is LaunchpadItemQuickPickItem => 'item' in i && !i.alwaysShow,
568-
);
564+
const hideGroups = Boolean(value?.length);
565+
const consideredItems = hideGroups ? nonGroupedItems : items;
569566

570567
let updated = false;
571-
for (const item of quickpick.items) {
568+
for (const item of consideredItems) {
572569
if (item.alwaysShow) {
573570
item.alwaysShow = false;
574571
updated = true;
575572
}
576-
if ('item' in item && item.item?.isSearched) {
577-
updated = true;
578-
}
579-
}
580-
if (updated) {
581-
// Force quickpick to update by changing the items object:
582-
quickpick.items = [...quickpick.items.filter(i => !('item' in i && i.item?.isSearched))];
583573
}
584574

575+
// By doing the following we make sure we operate with the PRs that belong to Launchpad initially.
576+
// Also, when we re-create the array, we make sure that `alwaysShow` updates are applied.
577+
quickpick.items =
578+
updated && quickpick.items === consideredItems ? [...consideredItems] : consideredItems;
579+
580+
const activeLaunchpadItems = quickpick.activeItems.filter(
581+
(i): i is LaunchpadItemQuickPickItem => 'item' in i,
582+
);
583+
585584
if (!value?.length || activeLaunchpadItems.length) {
586585
// Nothing to search or use items that have been found locally
587586
this.updateItemsDebouncer.cancel();
@@ -622,13 +621,6 @@ export class LaunchpadCommand extends QuickCommand<State> {
622621
}
623622
// Nothing is found above, so let's perform search in the API:
624623
await updateItems(quickpick, value);
625-
quickpick.items.forEach(i => {
626-
if ('item' in i && doesPullRequestSatisfyRepositoryURLIdentity(i.item, prUrlIdentity)) {
627-
i.alwaysShow = true;
628-
}
629-
});
630-
quickpick.items = quickpick.items.filter((i): i is LaunchpadItemQuickPickItem => 'item' in i);
631-
groupsHidden = true;
632624
return true;
633625
},
634626
onDidClickButton: async (quickpick, button) => {
@@ -1369,12 +1361,7 @@ async function updateContextItems(
13691361
options?: { force?: boolean; search?: string },
13701362
cancellation?: CancellationToken,
13711363
) {
1372-
const result = await container.launchpad.getCategorizedItems(options, cancellation);
1373-
if (options?.search != null) {
1374-
context.result = container.launchpad.mergeSearchedCategorizedItems(context.result, result);
1375-
} else {
1376-
context.result = result;
1377-
}
1364+
context.result = await container.launchpad.getCategorizedItems(options, cancellation);
13781365
if (container.telemetry.enabled) {
13791366
updateTelemetryContext(context);
13801367
}

src/plus/launchpad/launchpadProvider.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ export type LaunchpadItem = LaunchpadPullRequest & {
193193
actionableCategory: LaunchpadActionCategory;
194194
suggestedActions: LaunchpadAction[];
195195
openRepository?: OpenRepository;
196-
isSearched?: boolean;
197196

198197
underlyingPullRequest: PullRequest;
199198
};
@@ -644,43 +643,6 @@ export class LaunchpadProvider implements Disposable {
644643
return repoRemotes;
645644
}
646645

647-
mergeSearchedCategorizedItems(
648-
prsOfTheLaunchpad: LaunchpadCategorizedResult,
649-
prsOfSearch: LaunchpadCategorizedResult | undefined,
650-
): LaunchpadCategorizedResult {
651-
if (prsOfSearch == null || prsOfSearch?.error) {
652-
if (prsOfTheLaunchpad.items == null) {
653-
return prsOfTheLaunchpad;
654-
}
655-
return {
656-
items: prsOfTheLaunchpad.items.filter(i => !i.isSearched),
657-
timings: prsOfTheLaunchpad.timings,
658-
};
659-
}
660-
661-
const result = [];
662-
const idsOfLaunchpadPrs = new Set();
663-
if (prsOfTheLaunchpad.items) {
664-
for (const item of prsOfTheLaunchpad.items) {
665-
if (!item.isSearched) {
666-
idsOfLaunchpadPrs.add(item.id);
667-
result.push(item);
668-
}
669-
}
670-
}
671-
for (const item of prsOfSearch.items) {
672-
if (!idsOfLaunchpadPrs.has(item.id)) {
673-
item.isSearched = true;
674-
result.push(item);
675-
}
676-
}
677-
678-
return {
679-
items: result,
680-
timings: prsOfSearch.timings,
681-
};
682-
}
683-
684646
@gate<LaunchpadProvider['getCategorizedItems']>(o => `${o?.force ?? false}`)
685647
@log<LaunchpadProvider['getCategorizedItems']>({ args: { 0: o => `force=${o?.force}`, 1: false } })
686648
async getCategorizedItems(

0 commit comments

Comments
 (0)