From 20ea015a82096ee28e158c106d677329ede29068 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Fri, 18 Oct 2024 18:33:19 +0200 Subject: [PATCH 1/5] allow to filter --- src/notifications/notificationItem.ts | 8 ++++ src/notifications/notificationsProvider.ts | 53 ++++++++++++++++++++-- src/notifications/notificationsView.ts | 3 ++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/notifications/notificationItem.ts b/src/notifications/notificationItem.ts index 6a6f285c7b..8ba3e92a03 100644 --- a/src/notifications/notificationItem.ts +++ b/src/notifications/notificationItem.ts @@ -16,6 +16,14 @@ export enum NotificationsSortMethod { Priority = 'Priority' } +export enum NotificationFilterMethod { + All = 'All', + Open = 'open', + Closed = 'closed', + Issues = 'issues', + PullRequests = 'pullRequests' +} + export type NotificationTreeDataItem = INotificationItem | LoadMoreNotificationsTreeItem; export class LoadMoreNotificationsTreeItem { } diff --git a/src/notifications/notificationsProvider.ts b/src/notifications/notificationsProvider.ts index 3290765cf5..ba301513c6 100644 --- a/src/notifications/notificationsProvider.ts +++ b/src/notifications/notificationsProvider.ts @@ -14,7 +14,7 @@ import { PullRequestModel } from '../github/pullRequestModel'; import { RepositoriesManager } from '../github/repositoriesManager'; import { hasEnterpriseUri, parseNotification } from '../github/utils'; import { concatAsyncIterable } from '../lm/tools/toolsUtils'; -import { INotificationItem, NotificationsPaginationRange, NotificationsSortMethod } from './notificationItem'; +import { INotificationItem, NotificationFilterMethod, NotificationsPaginationRange, NotificationsSortMethod } from './notificationItem'; import { NotificationItem, NotificationsManager, NotificationUpdate } from './notificationsManager'; export class NotificationsProvider implements vscode.Disposable { @@ -28,12 +28,25 @@ export class NotificationsProvider implements vscode.Disposable { } private _sortingMethod: NotificationsSortMethod = NotificationsSortMethod.Timestamp; + + private _filterMethod: NotificationFilterMethod = NotificationFilterMethod.All; + public get sortingMethod(): NotificationsSortMethod { return this._sortingMethod; } + + public get filterMethod(): NotificationFilterMethod { return this._filterMethod; } + public set sortingMethod(value: NotificationsSortMethod) { if (this._sortingMethod === value) { return; } + this._sortingMethod = value; + this._onDidChangeSortingMethod.fire(); + } + public set filterMethod(value: NotificationsSortMethod) { + if (this._sortingMethod === value) { + return; + } this._sortingMethod = value; this._onDidChangeSortingMethod.fire(); } @@ -41,6 +54,9 @@ export class NotificationsProvider implements vscode.Disposable { private readonly _onDidChangeSortingMethod = new vscode.EventEmitter(); readonly onDidChangeSortingMethod = this._onDidChangeSortingMethod.event; + private readonly _onDidChangeFilterMethod = new vscode.EventEmitter(); + readonly onDidChangeFilterMethod = this._onDidChangeFilterMethod.event; + private _canLoadMoreNotifications: boolean = false; constructor( @@ -65,6 +81,7 @@ export class NotificationsProvider implements vscode.Disposable { ); this._disposables.push(this._onDidChangeSortingMethod); + this._disposables.push(this._onDidChangeFilterMethod); } private _getGitHub(): GitHub | undefined { @@ -97,7 +114,33 @@ export class NotificationsProvider implements vscode.Disposable { return undefined; } const notifications = await this._getResolvedNotifications(gitHub); - const filteredNotifications = notifications.filter(notification => notification !== undefined) as INotificationItem[]; + const filteredNotifications = this._filterNotifications(notifications); + return this._sortNotifications(filteredNotifications); + } + + private _filterNotifications(notifications: (INotificationItem | undefined)[]): INotificationItem[] { + let filteredNotifications: INotificationItem[]; + switch (this.filterMethod) { + case NotificationFilterMethod.All: + filteredNotifications = notifications.filter(notification => notification !== undefined); + break; + case NotificationFilterMethod.Open: + filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model.isOpen) as INotificationItem[]; + break; + case NotificationFilterMethod.Closed: + filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model.isClosed) as INotificationItem[]; + break; + case NotificationFilterMethod.Issues: + filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model instanceof IssueModel) as INotificationItem[]; + break; + case NotificationFilterMethod.PullRequests: + filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model instanceof PullRequestModel) as INotificationItem[]; + break; + } + return filteredNotifications; + } + + private async _sortNotifications(notifications: INotificationItem[]): Promise { if (this.sortingMethod === NotificationsSortMethod.Priority) { const models = await vscode.lm.selectChatModels({ vendor: 'copilot', @@ -106,13 +149,13 @@ export class NotificationsProvider implements vscode.Disposable { const model = models[0]; if (model) { try { - return this._sortNotificationsByLLMPriority(filteredNotifications, model); + return this._sortNotificationsByLLMPriority(notifications, model); } catch (e) { - return this._sortNotificationsByTimestamp(filteredNotifications); + return this._sortNotificationsByTimestamp(notifications); } } } - return this._sortNotificationsByTimestamp(filteredNotifications); + return this._sortNotificationsByTimestamp(notifications); } public getNotifications(): INotificationItem[] { diff --git a/src/notifications/notificationsView.ts b/src/notifications/notificationsView.ts index ca04ab2326..8ea6447c8c 100644 --- a/src/notifications/notificationsView.ts +++ b/src/notifications/notificationsView.ts @@ -28,6 +28,9 @@ export class NotificationsTreeData implements vscode.TreeDataProvider { this.computeAndRefresh(); })); + this._disposables.push(this._notificationsProvider.onDidChangeFilterMethod(() => { + this.computeAndRefresh(); + })); } async getTreeItem(element: NotificationTreeDataItem): Promise { From d036a27273f17b3ac2ae71d72ad4b1143e94b4e0 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Fri, 18 Oct 2024 18:34:49 +0200 Subject: [PATCH 2/5] fix --- src/notifications/notificationsProvider.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/notifications/notificationsProvider.ts b/src/notifications/notificationsProvider.ts index ba301513c6..cab4487495 100644 --- a/src/notifications/notificationsProvider.ts +++ b/src/notifications/notificationsProvider.ts @@ -43,12 +43,12 @@ export class NotificationsProvider implements vscode.Disposable { this._onDidChangeSortingMethod.fire(); } - public set filterMethod(value: NotificationsSortMethod) { - if (this._sortingMethod === value) { + public set filterMethod(value: NotificationFilterMethod) { + if (this._filterMethod === value) { return; } - this._sortingMethod = value; - this._onDidChangeSortingMethod.fire(); + this._filterMethod = value; + this._onDidChangeFilterMethod.fire(); } private readonly _onDidChangeSortingMethod = new vscode.EventEmitter(); From 0a30fc55c4ca1b5316146c243e509d86a3edbdf0 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 21 Oct 2024 10:18:27 +0200 Subject: [PATCH 3/5] adding link to the menu. --- package.json | 70 +++++++++++++++++++ package.nls.json | 5 ++ .../notificationsFeatureRegistar.ts | 67 +++++++++++++++++- src/notifications/notificationsProvider.ts | 4 +- 4 files changed, 143 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f8e2299859..5bcbe24486 100644 --- a/package.json +++ b/package.json @@ -1505,6 +1505,31 @@ "title": "%command.notifications.sortByPriority.title%", "category": "%command.notifications.category%" }, + { + "command": "notifications.filterByAll", + "title": "%command.notifications.filterByAll.title%", + "category": "%command.notifications.category%" + }, + { + "command": "notifications.filterByOpen", + "title": "%command.notifications.filterByOpen.title%", + "category": "%command.notifications.category%" + }, + { + "command": "notifications.filterByClosed", + "title": "%command.notifications.filterByClosed.title%", + "category": "%command.notifications.category%" + }, + { + "command": "notifications.filterByIssues", + "title": "%command.notifications.filterByIssues.title%", + "category": "%command.notifications.category%" + }, + { + "command": "notifications.filterByPullRequests", + "title": "%command.notifications.filterByPullRequests.title%", + "category": "%command.notifications.category%" + }, { "command": "notification.openOnGitHub", "title": "%command.notifications.openOnGitHub.title%", @@ -2158,6 +2183,26 @@ "command": "notifications.sortByPriority", "when": "false" }, + { + "command": "notifications.filterByAll", + "when": "false" + }, + { + "command": "notifications.filterByOpen", + "when": "false" + }, + { + "command": "notifications.filterByClosed", + "when": "false" + }, + { + "command": "notifications.filterByIssues", + "when": "false" + }, + { + "command": "notifications.filterByPullRequests", + "when": "false" + }, { "command": "notifications.loadMore", "when": "false" @@ -2295,6 +2340,31 @@ "when": "gitHubOpenRepositoryCount != 0 && github:initialized && view == notifications:github", "group": "sortNotifications@2" }, + { + "command": "notifications.filterByAll", + "when": "gitHubOpenRepositoryCount != 0 && github:initialized && view == notifications:github", + "group": "sortNotifications@3" + }, + { + "command": "notifications.filterByOpen", + "when": "gitHubOpenRepositoryCount != 0 && github:initialized && view == notifications:github", + "group": "sortNotifications@4" + }, + { + "command": "notifications.filterByClosed", + "when": "gitHubOpenRepositoryCount != 0 && github:initialized && view == notifications:github", + "group": "sortNotifications@5" + }, + { + "command": "notifications.filterByIssues", + "when": "gitHubOpenRepositoryCount != 0 && github:initialized && view == notifications:github", + "group": "sortNotifications@6" + }, + { + "command": "notifications.filterByPullRequests", + "when": "gitHubOpenRepositoryCount != 0 && github:initialized && view == notifications:github", + "group": "sortNotifications@7" + }, { "command": "notifications.refresh", "when": "gitHubOpenRepositoryCount != 0 && github:initialized && view == notifications:github", diff --git a/package.nls.json b/package.nls.json index 7405c4f414..64a5589518 100644 --- a/package.nls.json +++ b/package.nls.json @@ -286,6 +286,11 @@ "command.notifications.loadMore.title": "Load More Notifications", "command.notifications.sortByTimestamp.title": "Sort by Timestamp", "command.notifications.sortByPriority.title": "Sort by Priority using Copilot", + "command.notifications.filterByAll.title": "Filter by All", + "command.notifications.filterByOpen.title": "Filter by Open", + "command.notifications.filterByClosed.title": "Filter by Closed", + "command.notifications.filterByIssues.title": "Filter by Issues", + "command.notifications.filterByPullRequests.title": "Filter by Pull Requests", "command.notifications.openOnGitHub.title": "Open on GitHub", "command.notifications.markAsRead.title": "Mark as Read", "command.notification.chatSummarizeNotification.title": "Summarize With Copilot", diff --git a/src/notifications/notificationsFeatureRegistar.ts b/src/notifications/notificationsFeatureRegistar.ts index 9decf99928..b83be69ed7 100644 --- a/src/notifications/notificationsFeatureRegistar.ts +++ b/src/notifications/notificationsFeatureRegistar.ts @@ -10,7 +10,7 @@ import { CredentialStore } from '../github/credentials'; import { RepositoriesManager } from '../github/repositoriesManager'; import { chatCommand } from '../lm/utils'; import { NotificationsDecorationProvider } from './notificationDecorationProvider'; -import { NotificationsSortMethod } from './notificationItem'; +import { NotificationFilterMethod, NotificationsSortMethod } from './notificationItem'; import { NotificationItem, NotificationsManager } from './notificationsManager'; import { NotificationsProvider } from './notificationsProvider'; import { NotificationsTreeData } from './notificationsView'; @@ -67,6 +67,71 @@ export class NotificationsFeatureRegister implements vscode.Disposable { this, ), ); + this._disposables.push( + vscode.commands.registerCommand( + 'notifications.filterByAll', + async () => { + /* __GDPR__ + "notifications.filterByAll" : {} + */ + this._telemetry.sendTelemetryEvent('notifications.filterByAll'); + notificationsProvider.filterMethod = NotificationFilterMethod.All; + }, + this, + ), + ); + this._disposables.push( + vscode.commands.registerCommand( + 'notifications.filterByOpen', + async () => { + /* __GDPR__ + "notifications.filterByOpen" : {} + */ + this._telemetry.sendTelemetryEvent('notifications.filterByOpen'); + notificationsProvider.filterMethod = NotificationFilterMethod.Open; + }, + this, + ), + ); + this._disposables.push( + vscode.commands.registerCommand( + 'notifications.filterByClosed', + async () => { + /* __GDPR__ + "notifications.filterByClosed" : {} + */ + this._telemetry.sendTelemetryEvent('notifications.filterByClosed'); + notificationsProvider.filterMethod = NotificationFilterMethod.Closed; + }, + this, + ), + ); + this._disposables.push( + vscode.commands.registerCommand( + 'notifications.filterByIssues', + async () => { + /* __GDPR__ + "notifications.filterByIssues" : {} + */ + this._telemetry.sendTelemetryEvent('notifications.filterByIssues'); + notificationsProvider.filterMethod = NotificationFilterMethod.Issues; + }, + this, + ), + ); + this._disposables.push( + vscode.commands.registerCommand( + 'notifications.filterByPullRequests', + async () => { + /* __GDPR__ + "notifications.filterByPullRequests" : {} + */ + this._telemetry.sendTelemetryEvent('notifications.filterByPullRequests'); + notificationsProvider.filterMethod = NotificationFilterMethod.PullRequests; + }, + this, + ), + ); this._disposables.push( vscode.commands.registerCommand( 'notifications.refresh', diff --git a/src/notifications/notificationsProvider.ts b/src/notifications/notificationsProvider.ts index cab4487495..ac5924ce68 100644 --- a/src/notifications/notificationsProvider.ts +++ b/src/notifications/notificationsProvider.ts @@ -122,7 +122,7 @@ export class NotificationsProvider implements vscode.Disposable { let filteredNotifications: INotificationItem[]; switch (this.filterMethod) { case NotificationFilterMethod.All: - filteredNotifications = notifications.filter(notification => notification !== undefined); + filteredNotifications = notifications.filter(notification => notification !== undefined) as INotificationItem[]; break; case NotificationFilterMethod.Open: filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model.isOpen) as INotificationItem[]; @@ -131,7 +131,7 @@ export class NotificationsProvider implements vscode.Disposable { filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model.isClosed) as INotificationItem[]; break; case NotificationFilterMethod.Issues: - filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model instanceof IssueModel) as INotificationItem[]; + filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model instanceof IssueModel && !(notification.model instanceof PullRequestModel)) as INotificationItem[]; break; case NotificationFilterMethod.PullRequests: filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model instanceof PullRequestModel) as INotificationItem[]; From 1a027a8e76a15696349948bc26effe7cf040993f Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 21 Oct 2024 12:31:48 +0200 Subject: [PATCH 4/5] fixing merge conflict --- .../notificationsFeatureRegistar.ts | 22 ++-- src/notifications/notificationsManager.ts | 30 ++++- src/notifications/notificationsProvider.ts | 103 +----------------- src/notifications/notificationsView.ts | 4 +- 4 files changed, 45 insertions(+), 114 deletions(-) diff --git a/src/notifications/notificationsFeatureRegistar.ts b/src/notifications/notificationsFeatureRegistar.ts index 22ca7bd37b..fe1fb60e70 100644 --- a/src/notifications/notificationsFeatureRegistar.ts +++ b/src/notifications/notificationsFeatureRegistar.ts @@ -10,7 +10,7 @@ import { CredentialStore } from '../github/credentials'; import { RepositoriesManager } from '../github/repositoriesManager'; import { chatCommand } from '../lm/utils'; import { NotificationsDecorationProvider } from './notificationDecorationProvider'; -import { NotificationFilterMethod, isNotificationTreeItem, NotificationsSortMethod, NotificationTreeDataItem } from './notificationItem'; +import { isNotificationTreeItem, NotificationFilterMethod, NotificationsSortMethod, NotificationTreeDataItem } from './notificationItem'; import { NotificationsManager } from './notificationsManager'; import { NotificationsProvider } from './notificationsProvider'; import { NotificationsTreeData } from './notificationsView'; @@ -77,7 +77,7 @@ export class NotificationsFeatureRegister implements vscode.Disposable { "notifications.filterByAll" : {} */ this._telemetry.sendTelemetryEvent('notifications.filterByAll'); - notificationsProvider.filterMethod = NotificationFilterMethod.All; + notificationsManager.filterMethod = NotificationFilterMethod.All; }, this, ), @@ -90,7 +90,7 @@ export class NotificationsFeatureRegister implements vscode.Disposable { "notifications.filterByOpen" : {} */ this._telemetry.sendTelemetryEvent('notifications.filterByOpen'); - notificationsProvider.filterMethod = NotificationFilterMethod.Open; + notificationsManager.filterMethod = NotificationFilterMethod.Open; }, this, ), @@ -103,7 +103,7 @@ export class NotificationsFeatureRegister implements vscode.Disposable { "notifications.filterByClosed" : {} */ this._telemetry.sendTelemetryEvent('notifications.filterByClosed'); - notificationsProvider.filterMethod = NotificationFilterMethod.Closed; + notificationsManager.filterMethod = NotificationFilterMethod.Closed; }, this, ), @@ -116,7 +116,7 @@ export class NotificationsFeatureRegister implements vscode.Disposable { "notifications.filterByIssues" : {} */ this._telemetry.sendTelemetryEvent('notifications.filterByIssues'); - notificationsProvider.filterMethod = NotificationFilterMethod.Issues; + notificationsManager.filterMethod = NotificationFilterMethod.Issues; }, this, ), @@ -129,7 +129,7 @@ export class NotificationsFeatureRegister implements vscode.Disposable { "notifications.filterByPullRequests" : {} */ this._telemetry.sendTelemetryEvent('notifications.filterByPullRequests'); - notificationsProvider.filterMethod = NotificationFilterMethod.PullRequests; + notificationsManager.filterMethod = NotificationFilterMethod.PullRequests; }, this, ), @@ -142,7 +142,7 @@ export class NotificationsFeatureRegister implements vscode.Disposable { "notifications.filterByAll" : {} */ this._telemetry.sendTelemetryEvent('notifications.filterByAll'); - notificationsProvider.filterMethod = NotificationFilterMethod.All; + notificationsManager.filterMethod = NotificationFilterMethod.All; }, this, ), @@ -155,7 +155,7 @@ export class NotificationsFeatureRegister implements vscode.Disposable { "notifications.filterByOpen" : {} */ this._telemetry.sendTelemetryEvent('notifications.filterByOpen'); - notificationsProvider.filterMethod = NotificationFilterMethod.Open; + notificationsManager.filterMethod = NotificationFilterMethod.Open; }, this, ), @@ -168,7 +168,7 @@ export class NotificationsFeatureRegister implements vscode.Disposable { "notifications.filterByClosed" : {} */ this._telemetry.sendTelemetryEvent('notifications.filterByClosed'); - notificationsProvider.filterMethod = NotificationFilterMethod.Closed; + notificationsManager.filterMethod = NotificationFilterMethod.Closed; }, this, ), @@ -181,7 +181,7 @@ export class NotificationsFeatureRegister implements vscode.Disposable { "notifications.filterByIssues" : {} */ this._telemetry.sendTelemetryEvent('notifications.filterByIssues'); - notificationsProvider.filterMethod = NotificationFilterMethod.Issues; + notificationsManager.filterMethod = NotificationFilterMethod.Issues; }, this, ), @@ -194,7 +194,7 @@ export class NotificationsFeatureRegister implements vscode.Disposable { "notifications.filterByPullRequests" : {} */ this._telemetry.sendTelemetryEvent('notifications.filterByPullRequests'); - notificationsProvider.filterMethod = NotificationFilterMethod.PullRequests; + notificationsManager.filterMethod = NotificationFilterMethod.PullRequests; }, this, ), diff --git a/src/notifications/notificationsManager.ts b/src/notifications/notificationsManager.ts index 9e417ebb9a..c92924fbbe 100644 --- a/src/notifications/notificationsManager.ts +++ b/src/notifications/notificationsManager.ts @@ -5,7 +5,9 @@ import * as vscode from 'vscode'; import { dispose } from '../common/utils'; -import { NotificationsSortMethod, NotificationTreeItem } from './notificationItem'; +import { IssueModel } from '../github/issueModel'; +import { PullRequestModel } from '../github/pullRequestModel'; +import { NotificationFilterMethod, NotificationsSortMethod, NotificationTreeItem } from './notificationItem'; import { NotificationsProvider } from './notificationsProvider'; export interface INotificationTreeItems { @@ -28,9 +30,22 @@ export class NotificationsManager { this._onDidChangeSortingMethod.fire(); } + private _filterMethod: NotificationFilterMethod = NotificationFilterMethod.All; + public get filterMethod(): NotificationFilterMethod { return this._filterMethod; } + public set filterMethod(value: NotificationFilterMethod) { + if (this._filterMethod === value) { + return; + } + this._filterMethod = value; + this._onDidChangeFilterMethod.fire(); + } + private readonly _onDidChangeSortingMethod = new vscode.EventEmitter(); readonly onDidChangeSortingMethod = this._onDidChangeSortingMethod.event; + private readonly _onDidChangeFilterMethod = new vscode.EventEmitter(); + readonly onDidChangeFilterMethod = this._onDidChangeFilterMethod.event; + private _hasNextPage: boolean = false; private _notifications = new Map(); @@ -38,6 +53,8 @@ export class NotificationsManager { constructor(private readonly _notificationProvider: NotificationsProvider) { this._disposable.push(this._onDidChangeNotifications); + this._disposable.push(this._onDidChangeSortingMethod); + this._disposable.push(this._onDidChangeFilterMethod); } dispose() { @@ -83,6 +100,10 @@ export class NotificationsManager { return; } + const shouldFilter = this._shouldFilter(model); + if (shouldFilter) { + return; + } notificationItems.set(notification.key, { notification, model, kind: 'notification' }); @@ -148,4 +169,11 @@ export class NotificationsManager { return notifications; } + + private _shouldFilter(model: IssueModel): boolean { + return (this.filterMethod === NotificationFilterMethod.Open && !model.isOpen) + || (this.filterMethod === NotificationFilterMethod.Closed && !model.isClosed) + || (this.filterMethod === NotificationFilterMethod.Issues && (model instanceof PullRequestModel)) + || (this.filterMethod === NotificationFilterMethod.PullRequests && !(model instanceof PullRequestModel)); + } } \ No newline at end of file diff --git a/src/notifications/notificationsProvider.ts b/src/notifications/notificationsProvider.ts index 0de22ee439..1141514a7e 100644 --- a/src/notifications/notificationsProvider.ts +++ b/src/notifications/notificationsProvider.ts @@ -32,43 +32,6 @@ export class NotificationsProvider implements vscode.Disposable { private readonly _disposables: vscode.Disposable[] = []; - private readonly _notificationsPaginationRange: NotificationsPaginationRange = { - startPage: 1, - endPage: 1 - } - - private _sortingMethod: NotificationsSortMethod = NotificationsSortMethod.Timestamp; - - private _filterMethod: NotificationFilterMethod = NotificationFilterMethod.All; - - public get sortingMethod(): NotificationsSortMethod { return this._sortingMethod; } - - public get filterMethod(): NotificationFilterMethod { return this._filterMethod; } - - public set sortingMethod(value: NotificationsSortMethod) { - if (this._sortingMethod === value) { - return; - } - this._sortingMethod = value; - this._onDidChangeSortingMethod.fire(); - } - - public set filterMethod(value: NotificationFilterMethod) { - if (this._filterMethod === value) { - return; - } - this._filterMethod = value; - this._onDidChangeFilterMethod.fire(); - } - - private readonly _onDidChangeSortingMethod = new vscode.EventEmitter(); - readonly onDidChangeSortingMethod = this._onDidChangeSortingMethod.event; - - private readonly _onDidChangeFilterMethod = new vscode.EventEmitter(); - readonly onDidChangeFilterMethod = this._onDidChangeFilterMethod.event; - - private _canLoadMoreNotifications: boolean = false; - constructor( private readonly _credentialStore: CredentialStore, private readonly _repositoriesManager: RepositoriesManager @@ -88,9 +51,6 @@ export class NotificationsProvider implements vscode.Disposable { } }) ); - - this._disposables.push(this._onDidChangeSortingMethod); - this._disposables.push(this._onDidChangeFilterMethod); } private _getGitHub(): GitHub | undefined { @@ -117,67 +77,10 @@ export class NotificationsProvider implements vscode.Disposable { if (this._repositoriesManager.folderManagers.length === 0) { return undefined; } - const notifications = await this._getResolvedNotifications(gitHub); - const filteredNotifications = this._filterNotifications(notifications); - return this._sortNotifications(filteredNotifications); - } - - private _filterNotifications(notifications: (INotificationItem | undefined)[]): INotificationItem[] { - let filteredNotifications: INotificationItem[]; - switch (this.filterMethod) { - case NotificationFilterMethod.All: - filteredNotifications = notifications.filter(notification => notification !== undefined) as INotificationItem[]; - break; - case NotificationFilterMethod.Open: - filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model.isOpen) as INotificationItem[]; - break; - case NotificationFilterMethod.Closed: - filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model.isClosed) as INotificationItem[]; - break; - case NotificationFilterMethod.Issues: - filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model instanceof IssueModel && !(notification.model instanceof PullRequestModel)) as INotificationItem[]; - break; - case NotificationFilterMethod.PullRequests: - filteredNotifications = notifications.filter(notification => notification !== undefined && notification.model instanceof PullRequestModel) as INotificationItem[]; - break; - } - return filteredNotifications; - } - - private async _sortNotifications(notifications: INotificationItem[]): Promise { - if (this.sortingMethod === NotificationsSortMethod.Priority) { - const models = await vscode.lm.selectChatModels({ - vendor: 'copilot', - family: 'gpt-4o' - }); - const model = models[0]; - if (model) { - try { - return this._sortNotificationsByLLMPriority(notifications, model); - } catch (e) { - return this._sortNotificationsByTimestamp(notifications); - } - } - } - return this._sortNotificationsByTimestamp(notifications); - } - - public getNotifications(): INotificationItem[] { - return this._notificationsManager.getAllNotifications(); - } - - public get canLoadMoreNotifications(): boolean { - return this._canLoadMoreNotifications; - } - - public loadMore(): void { - this._notificationsPaginationRange.endPage += 1; - } - private async _getResolvedNotifications(gitHub: GitHub): Promise<(INotificationItem | undefined)[]> { - const notificationPromises: Promise<{ notifications: INotificationItem[], hasNextPage: boolean }>[] = []; - for (let i = this._notificationsPaginationRange.startPage; i <= this._notificationsPaginationRange.endPage; i++) { - notificationPromises.push(this._getResolvedNotificationsForPage(gitHub, i)); + const notificationPromises: Promise[] = []; + for (let i = 1; i <= pageCount; i++) { + notificationPromises.push(this._getNotificationsPage(gitHub, i)); } const notifications = await Promise.all(notificationPromises); diff --git a/src/notifications/notificationsView.ts b/src/notifications/notificationsView.ts index 2febcc187a..203efba381 100644 --- a/src/notifications/notificationsView.ts +++ b/src/notifications/notificationsView.ts @@ -28,8 +28,8 @@ export class NotificationsTreeData implements vscode.TreeDataProvider { this.refresh(true); })); - this._disposables.push(this._notificationsProvider.onDidChangeFilterMethod(() => { - this.computeAndRefresh(); + this._disposables.push(this._notificationsManager.onDidChangeFilterMethod(() => { + this.refresh(true); })); } From 92ebf75168116dfddc0200aad084a818694b135b Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 21 Oct 2024 13:18:26 +0200 Subject: [PATCH 5/5] adding filter method --- .../notificationsFeatureRegistar.ts | 65 ------------------- src/notifications/notificationsManager.ts | 35 ++++++---- 2 files changed, 23 insertions(+), 77 deletions(-) diff --git a/src/notifications/notificationsFeatureRegistar.ts b/src/notifications/notificationsFeatureRegistar.ts index fe1fb60e70..c4c661fbbd 100644 --- a/src/notifications/notificationsFeatureRegistar.ts +++ b/src/notifications/notificationsFeatureRegistar.ts @@ -134,71 +134,6 @@ export class NotificationsFeatureRegister implements vscode.Disposable { this, ), ); - this._disposables.push( - vscode.commands.registerCommand( - 'notifications.filterByAll', - async () => { - /* __GDPR__ - "notifications.filterByAll" : {} - */ - this._telemetry.sendTelemetryEvent('notifications.filterByAll'); - notificationsManager.filterMethod = NotificationFilterMethod.All; - }, - this, - ), - ); - this._disposables.push( - vscode.commands.registerCommand( - 'notifications.filterByOpen', - async () => { - /* __GDPR__ - "notifications.filterByOpen" : {} - */ - this._telemetry.sendTelemetryEvent('notifications.filterByOpen'); - notificationsManager.filterMethod = NotificationFilterMethod.Open; - }, - this, - ), - ); - this._disposables.push( - vscode.commands.registerCommand( - 'notifications.filterByClosed', - async () => { - /* __GDPR__ - "notifications.filterByClosed" : {} - */ - this._telemetry.sendTelemetryEvent('notifications.filterByClosed'); - notificationsManager.filterMethod = NotificationFilterMethod.Closed; - }, - this, - ), - ); - this._disposables.push( - vscode.commands.registerCommand( - 'notifications.filterByIssues', - async () => { - /* __GDPR__ - "notifications.filterByIssues" : {} - */ - this._telemetry.sendTelemetryEvent('notifications.filterByIssues'); - notificationsManager.filterMethod = NotificationFilterMethod.Issues; - }, - this, - ), - ); - this._disposables.push( - vscode.commands.registerCommand( - 'notifications.filterByPullRequests', - async () => { - /* __GDPR__ - "notifications.filterByPullRequests" : {} - */ - this._telemetry.sendTelemetryEvent('notifications.filterByPullRequests'); - notificationsManager.filterMethod = NotificationFilterMethod.PullRequests; - }, - this, - ), - ); this._disposables.push( vscode.commands.registerCommand( 'notifications.refresh', diff --git a/src/notifications/notificationsManager.ts b/src/notifications/notificationsManager.ts index c92924fbbe..3be6b2b920 100644 --- a/src/notifications/notificationsManager.ts +++ b/src/notifications/notificationsManager.ts @@ -73,9 +73,11 @@ export class NotificationsManager { public async getNotifications(compute: boolean, pageCount: number): Promise { if (!compute) { const notifications = Array.from(this._notifications.values()); + const filteredNotifications = this._filterNotifications(notifications); + const sortedFilteredNotifications = this._sortNotifications(filteredNotifications); return { - notifications: this._sortNotifications(notifications), + notifications: sortedFilteredNotifications, hasNextPage: this._hasNextPage }; } @@ -99,11 +101,6 @@ export class NotificationsManager { if (!model) { return; } - - const shouldFilter = this._shouldFilter(model); - if (shouldFilter) { - return; - } notificationItems.set(notification.key, { notification, model, kind: 'notification' }); @@ -136,8 +133,11 @@ export class NotificationsManager { const notifications = Array.from(this._notifications.values()); this._onDidChangeNotifications.fire(notifications); + const filteredNotifications = this._filterNotifications(notifications); + const sortedFilteredNotifications = this._sortNotifications(filteredNotifications); + return { - notifications: this._sortNotifications(notifications), + notifications: sortedFilteredNotifications, hasNextPage: this._hasNextPage }; } @@ -170,10 +170,21 @@ export class NotificationsManager { return notifications; } - private _shouldFilter(model: IssueModel): boolean { - return (this.filterMethod === NotificationFilterMethod.Open && !model.isOpen) - || (this.filterMethod === NotificationFilterMethod.Closed && !model.isClosed) - || (this.filterMethod === NotificationFilterMethod.Issues && (model instanceof PullRequestModel)) - || (this.filterMethod === NotificationFilterMethod.PullRequests && !(model instanceof PullRequestModel)); + private _filterNotifications(notifications: NotificationTreeItem[]): NotificationTreeItem[] { + return notifications.filter(notification => { + const model = notification.model; + switch (this._filterMethod) { + case NotificationFilterMethod.All: + return true; + case NotificationFilterMethod.Open: + return model.isOpen; + case NotificationFilterMethod.Closed: + return model.isClosed; + case NotificationFilterMethod.Issues: + return (model instanceof IssueModel) && !(model instanceof PullRequestModel); + case NotificationFilterMethod.PullRequests: + return model instanceof PullRequestModel; + } + }); } } \ No newline at end of file