From 7b3376812904ce049c04856fdc2ab17a2de0381a Mon Sep 17 00:00:00 2001 From: Keith Daulton Date: Mon, 11 Sep 2023 18:17:55 -0400 Subject: [PATCH] Updates remote info for enriching issues --- src/plus/focus/focusService.ts | 18 +++++++-------- src/plus/webviews/focus/focusWebview.ts | 40 ++++++++++++++++++++++++++++----- src/plus/webviews/focus/protocol.ts | 11 ++++----- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/plus/focus/focusService.ts b/src/plus/focus/focusService.ts index 8ea0725..fe9eacc 100644 --- a/src/plus/focus/focusService.ts +++ b/src/plus/focus/focusService.ts @@ -10,7 +10,7 @@ import type { ServerConnection } from '../gk/serverConnection'; export interface FocusItem { type: EnrichedItemResponse['entityType']; id: string; - remote?: GitRemote; + remote: GitRemote; } export type EnrichedItem = { @@ -138,13 +138,13 @@ export class FocusService implements Disposable { type Result = { data: EnrichedItemResponse }; const rq: EnrichedItemRequest = { - provider: item.remote!.provider.id as EnrichedItemResponse['provider'], + provider: item.remote.provider.id as EnrichedItemResponse['provider'], entityType: item.type, entityId: item.id, gitRepoData: { - remoteUrl: item.remote!.url, - remotePath: item.remote!.provider.path, - remoteDomain: item.remote!.provider.domain, + remoteUrl: item.remote.url, + remotePath: item.remote.provider.path, + remoteDomain: item.remote.provider.domain, }, }; @@ -181,13 +181,13 @@ export class FocusService implements Disposable { type Result = { data: EnrichedItemResponse }; const rq: EnrichedItemRequest = { - provider: item.remote!.provider.id as EnrichedItemResponse['provider'], + provider: item.remote.provider.id as EnrichedItemResponse['provider'], entityType: item.type, entityId: item.id, gitRepoData: { - remoteUrl: item.remote!.url, - remotePath: item.remote!.provider.path, - remoteDomain: item.remote!.provider.domain, + remoteUrl: item.remote.url, + remotePath: item.remote.provider.path, + remoteDomain: item.remote.provider.domain, }, }; diff --git a/src/plus/webviews/focus/focusWebview.ts b/src/plus/webviews/focus/focusWebview.ts index 52e94e0..e03e0a6 100644 --- a/src/plus/webviews/focus/focusWebview.ts +++ b/src/plus/webviews/focus/focusWebview.ts @@ -66,10 +66,13 @@ interface SearchedPullRequestWithRemote extends SearchedPullRequest { hasWorktree?: boolean; isCurrentWorktree?: boolean; rank: number; + enriched?: EnrichedItem[]; } interface SearchedIssueWithRank extends SearchedIssue { + repoAndRemote: RepoWithRichRemote; rank: number; + enriched?: EnrichedItem[]; } export class FocusWebviewProvider implements WebviewProvider { @@ -132,11 +135,12 @@ export class FocusWebviewProvider implements WebviewProvider { if (pin) { await this.container.focus.unpinItem(issueWithRemote.issue.id); this._enrichedItems = this._enrichedItems?.filter(e => e.id !== pin); + issueWithRemote.enriched = issueWithRemote.enriched?.filter(e => e.id !== pin); } else { const focusItem: FocusItem = { type: 'issue', id: issueWithRemote.issue.id, - // remote: issueWithRemote.issue.remote, + remote: issueWithRemote.repoAndRemote.remote, }; const enrichedItem = await this.container.focus.pinItem(focusItem); if (enrichedItem == null) return; @@ -144,6 +148,10 @@ export class FocusWebviewProvider implements WebviewProvider { this._enrichedItems = []; } this._enrichedItems.push(enrichedItem); + if (issueWithRemote.enriched == null) { + issueWithRemote.enriched = []; + } + issueWithRemote.enriched.push(enrichedItem); } void this.notifyDidChangeState(); @@ -156,11 +164,12 @@ export class FocusWebviewProvider implements WebviewProvider { if (snooze) { await this.container.focus.unsnoozeItem(snooze); this._enrichedItems = this._enrichedItems?.filter(e => e.id !== snooze); + issueWithRemote.enriched = issueWithRemote.enriched?.filter(e => e.id !== snooze); } else { const focusItem: FocusItem = { type: 'issue', id: issueWithRemote.issue.id, - // remote: issueWithRemote.issue.remote, + remote: issueWithRemote.repoAndRemote.remote, }; const enrichedItem = await this.container.focus.snoozeItem(focusItem); if (enrichedItem == null) return; @@ -168,6 +177,10 @@ export class FocusWebviewProvider implements WebviewProvider { this._enrichedItems = []; } this._enrichedItems.push(enrichedItem); + if (issueWithRemote.enriched == null) { + issueWithRemote.enriched = []; + } + issueWithRemote.enriched.push(enrichedItem); } void this.notifyDidChangeState(); @@ -180,6 +193,7 @@ export class FocusWebviewProvider implements WebviewProvider { if (pin) { await this.container.focus.unpinItem(pin); this._enrichedItems = this._enrichedItems?.filter(e => e.id !== pin); + prWithRemote.enriched = prWithRemote.enriched?.filter(e => e.id !== pin); } else { const focusItem: FocusItem = { type: 'pr', @@ -192,6 +206,10 @@ export class FocusWebviewProvider implements WebviewProvider { this._enrichedItems = []; } this._enrichedItems.push(enrichedItem); + if (prWithRemote.enriched == null) { + prWithRemote.enriched = []; + } + prWithRemote.enriched.push(enrichedItem); } void this.notifyDidChangeState(); @@ -204,6 +222,7 @@ export class FocusWebviewProvider implements WebviewProvider { if (snooze) { await this.container.focus.unsnoozeItem(snooze); this._enrichedItems = this._enrichedItems?.filter(e => e.id !== snooze); + prWithRemote.enriched = prWithRemote.enriched?.filter(e => e.id !== snooze); } else { const focusItem: FocusItem = { type: 'pr', @@ -216,6 +235,10 @@ export class FocusWebviewProvider implements WebviewProvider { this._enrichedItems = []; } this._enrichedItems.push(enrichedItem); + if (prWithRemote.enriched == null) { + prWithRemote.enriched = []; + } + prWithRemote.enriched.push(enrichedItem); } void this.notifyDidChangeState(); @@ -546,7 +569,8 @@ export class FocusWebviewProvider implements WebviewProvider { private async getMyIssues(richRepos: RepoWithRichRemote[]): Promise { const allIssues = []; - for (const { remote } of richRepos) { + for (const richRepo of richRepos) { + const remote = richRepo.remote; const issues = await this.container.git.getMyIssues(remote); if (issues == null) { continue; @@ -558,6 +582,7 @@ export class FocusWebviewProvider implements WebviewProvider { } allIssues.push({ ...issue, + repoAndRemote: richRepo, rank: 0, // getIssueRank(issue), }); } @@ -592,7 +617,10 @@ export class FocusWebviewProvider implements WebviewProvider { } } -function findEnrichedItems(item: SearchedPullRequestWithRemote | SearchedIssue, enrichedItems?: EnrichedItem[]) { +function findEnrichedItems( + item: SearchedPullRequestWithRemote | SearchedIssueWithRank, + enrichedItems?: EnrichedItem[], +) { if (enrichedItems == null || enrichedItems.length === 0) return; let result; @@ -600,11 +628,13 @@ function findEnrichedItems(item: SearchedPullRequestWithRemote | SearchedIssue, if ((item as SearchedPullRequestWithRemote).pullRequest != null) { result = enrichedItems.filter(e => e.entityId === (item as SearchedPullRequestWithRemote).pullRequest.id); } else { - result = enrichedItems.filter(e => e.entityId === (item as SearchedIssue).issue.id); + result = enrichedItems.filter(e => e.entityId === (item as SearchedIssueWithRank).issue.id); } if (result.length === 0) return; + item.enriched = result; + return result.map(result => { return { id: result.id, diff --git a/src/plus/webviews/focus/protocol.ts b/src/plus/webviews/focus/protocol.ts index 956e2c4..f40778c 100644 --- a/src/plus/webviews/focus/protocol.ts +++ b/src/plus/webviews/focus/protocol.ts @@ -18,11 +18,12 @@ export interface State { export interface SearchResultBase { reasons: string[]; rank?: number; - // TODO: convert to array of EnrichedItem - enriched?: { - id: EnrichedItem['id']; - type: EnrichedItem['type']; - }[]; + enriched?: EnrichedItemSummary[]; +} + +export interface EnrichedItemSummary { + id: EnrichedItem['id']; + type: EnrichedItem['type']; } export interface IssueResult extends SearchResultBase {