From 63770851f498015f9d3d5c5542d04aeb02b01398 Mon Sep 17 00:00:00 2001 From: Keith Daulton Date: Mon, 11 Sep 2023 17:33:57 -0400 Subject: [PATCH] Updates focus enrichment types --- src/plus/webviews/focus/focusWebview.ts | 16 +++++----- src/plus/webviews/focus/protocol.ts | 2 +- .../apps/plus/focus/components/focus-app.ts | 35 ++++++++++++---------- .../apps/plus/focus/components/gk-issue-row.ts | 11 +++---- .../plus/focus/components/gk-pull-request-row.ts | 15 ++++------ 5 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/plus/webviews/focus/focusWebview.ts b/src/plus/webviews/focus/focusWebview.ts index 7156de3..dc5378e 100644 --- a/src/plus/webviews/focus/focusWebview.ts +++ b/src/plus/webviews/focus/focusWebview.ts @@ -418,13 +418,13 @@ export class FocusWebviewProvider implements WebviewProvider { isCurrentWorktree: pr.isCurrentWorktree ?? false, hasWorktree: pr.hasWorktree ?? false, hasLocalBranch: pr.hasLocalBranch ?? false, - enriched: findEnrichedItem(pr, getSettledValue(enrichedItems)), + enriched: findEnrichedItems(pr, getSettledValue(enrichedItems)), rank: pr.rank, })), issues: getSettledValue(issuesResult)?.map(issue => ({ issue: serializeIssue(issue.issue), reasons: issue.reasons, - enriched: findEnrichedItem(issue, getSettledValue(enrichedItems)), + enriched: findEnrichedItems(issue, getSettledValue(enrichedItems)), rank: issue.rank, })), }; @@ -592,7 +592,7 @@ export class FocusWebviewProvider implements WebviewProvider { } } -function findEnrichedItem(item: SearchedPullRequestWithRemote | SearchedIssue, enrichedItems?: EnrichedItem[]) { +function findEnrichedItems(item: SearchedPullRequestWithRemote | SearchedIssue, enrichedItems?: EnrichedItem[]) { if (enrichedItems == null || enrichedItems.length === 0) return; let result; @@ -605,10 +605,12 @@ function findEnrichedItem(item: SearchedPullRequestWithRemote | SearchedIssue, e if (result == null) return; - return { - id: result.id, - type: result.type, - }; + return [ + { + id: result.id, + type: result.type, + }, + ]; } function getPrRank(pr: SearchedPullRequest) { diff --git a/src/plus/webviews/focus/protocol.ts b/src/plus/webviews/focus/protocol.ts index f422ec9..956e2c4 100644 --- a/src/plus/webviews/focus/protocol.ts +++ b/src/plus/webviews/focus/protocol.ts @@ -22,7 +22,7 @@ export interface SearchResultBase { enriched?: { id: EnrichedItem['id']; type: EnrichedItem['type']; - }; + }[]; } export interface IssueResult extends SearchResultBase { diff --git a/src/webviews/apps/plus/focus/components/focus-app.ts b/src/webviews/apps/plus/focus/components/focus-app.ts index 9adce0f..d75b95a 100644 --- a/src/webviews/apps/plus/focus/components/focus-app.ts +++ b/src/webviews/apps/plus/focus/components/focus-app.ts @@ -104,9 +104,8 @@ export class GlFocusApp extends LitElement { rank: number; state: Record; tags: string[]; - isPinned: boolean; - isSnoozed: boolean; - enrichedId?: string; + isPinned?: string; + isSnoozed?: string; }[] = []; this.state?.pullRequests?.forEach( @@ -120,8 +119,8 @@ export class GlFocusApp extends LitElement { rank, enriched, }) => { - const isPinned = enriched?.type === 'pin'; - const isSnoozed = enriched?.type === 'snooze'; + const isPinned = enriched?.find(item => item.type === 'pin')?.id; + const isSnoozed = enriched?.find(item => item.type === 'snooze')?.id; items.push({ isPullrequest: true, @@ -136,13 +135,12 @@ export class GlFocusApp extends LitElement { tags: reasons, isPinned: isPinned, isSnoozed: isSnoozed, - enrichedId: enriched?.id, }); }, ); this.state?.issues?.forEach(({ issue, reasons, rank, enriched }) => { - const isPinned = enriched?.type === 'pin'; - const isSnoozed = enriched?.type === 'snooze'; + const isPinned = enriched?.find(item => item.type === 'pin')?.id; + const isSnoozed = enriched?.find(item => item.type === 'snooze')?.id; items.push({ isPullrequest: false, @@ -153,7 +151,6 @@ export class GlFocusApp extends LitElement { tags: reasons, isPinned: isPinned, isSnoozed: isSnoozed, - enrichedId: enriched?.id, }); }); @@ -188,16 +185,21 @@ export class GlFocusApp extends LitElement { const hasMineFilter = this.selectedMineFilter != null && this.selectedMineFilter !== ''; const hasTabFilter = this.selectedTabFilter != null && this.selectedTabFilter !== ''; if (!hasSearch && !hasMineFilter && !hasTabFilter) { - return this.items; + return this.items.filter(i => i.isSnoozed == null); } const searchText = this.searchText?.toLowerCase(); return this.items.filter(i => { - if ( - hasTabFilter && - ((i.isPullrequest === true && this.selectedTabFilter === 'issues') || - (i.isPullrequest === false && this.selectedTabFilter === 'prs')) - ) { + if (hasTabFilter) { + if ( + (i.isSnoozed != null && this.selectedTabFilter !== 'snoozed') || + (i.isSnoozed == null && this.selectedTabFilter == 'snoozed') || + (i.isPullrequest === true && this.selectedTabFilter === 'issues') || + (i.isPullrequest === false && this.selectedTabFilter === 'prs') + ) { + return false; + } + } else if (i.isSnoozed != null) { return false; } @@ -222,7 +224,8 @@ export class GlFocusApp extends LitElement { get sortedItems() { return this.filteredItems.sort((a, b) => { if (a.isPinned === b.isPinned) { - return a.rank - b.rank; + return 0; + // return a.rank - b.rank; } return a.isPinned ? -1 : 1; }); diff --git a/src/webviews/apps/plus/focus/components/gk-issue-row.ts b/src/webviews/apps/plus/focus/components/gk-issue-row.ts index ddf3a00..30ab7ab 100644 --- a/src/webviews/apps/plus/focus/components/gk-issue-row.ts +++ b/src/webviews/apps/plus/focus/components/gk-issue-row.ts @@ -114,15 +114,12 @@ export class GkIssueRow extends LitElement { @property({ type: Object }) public issue?: IssueShape; - @property({ type: Boolean }) + @property() public pinned = false; - @property({ type: Boolean }) + @property() public snoozed = false; - @property({ attribute: 'enriched-id' }) - public enrichedId?: string; - constructor() { super(); @@ -247,7 +244,7 @@ export class GkIssueRow extends LitElement { onSnoozeClick(_e: Event) { this.dispatchEvent( new CustomEvent('snooze-item', { - detail: { item: this.issue!, snooze: this.snoozed ? this.enrichedId : undefined }, + detail: { item: this.issue!, snooze: this.snoozed }, }), ); } @@ -255,7 +252,7 @@ export class GkIssueRow extends LitElement { onPinClick(_e: Event) { this.dispatchEvent( new CustomEvent('pin-item', { - detail: { item: this.issue!, pin: this.pinned ? this.enrichedId : undefined }, + detail: { item: this.issue!, pin: this.pinned }, }), ); } diff --git a/src/webviews/apps/plus/focus/components/gk-pull-request-row.ts b/src/webviews/apps/plus/focus/components/gk-pull-request-row.ts index 483ffb9..2705e63 100644 --- a/src/webviews/apps/plus/focus/components/gk-pull-request-row.ts +++ b/src/webviews/apps/plus/focus/components/gk-pull-request-row.ts @@ -155,14 +155,11 @@ export class GkPullRequestRow extends LitElement { @property({ type: Boolean }) public hasLocalBranch = false; - @property({ type: Boolean }) - public pinned = false; - - @property({ type: Boolean }) - public snoozed = false; + @property() + public pinned?: string; - @property({ attribute: 'enriched-id' }) - public enrichedId?: string; + @property() + public snoozed?: string; constructor() { super(); @@ -395,7 +392,7 @@ export class GkPullRequestRow extends LitElement { onSnoozeClick(_e: Event) { this.dispatchEvent( new CustomEvent('snooze-item', { - detail: { item: this.pullRequest!, snooze: this.snoozed ? this.enrichedId : undefined }, + detail: { item: this.pullRequest!, snooze: this.snoozed }, }), ); } @@ -403,7 +400,7 @@ export class GkPullRequestRow extends LitElement { onPinClick(_e: Event) { this.dispatchEvent( new CustomEvent('pin-item', { - detail: { item: this.pullRequest!, pin: this.pinned ? this.enrichedId : undefined }, + detail: { item: this.pullRequest!, pin: this.pinned }, }), ); }