Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notification filtering #6317

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/notifications/notificationItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export enum NotificationsSortMethod {
Priority = 'Priority'
}

export enum NotificationFilterMethod {
All = 'All',
Open = 'open',
Closed = 'closed',
Issues = 'issues',
PullRequests = 'pullRequests'
}

export type NotificationTreeDataItem = NotificationTreeItem | LoadMoreNotificationsTreeItem;

export interface LoadMoreNotificationsTreeItem {
Expand Down
67 changes: 66 additions & 1 deletion src/notifications/notificationsFeatureRegistar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CredentialStore } from '../github/credentials';
import { RepositoriesManager } from '../github/repositoriesManager';
import { chatCommand } from '../lm/utils';
import { NotificationsDecorationProvider } from './notificationDecorationProvider';
import { isNotificationTreeItem, NotificationsSortMethod, NotificationTreeDataItem } from './notificationItem';
import { isNotificationTreeItem, NotificationFilterMethod, NotificationsSortMethod, NotificationTreeDataItem } from './notificationItem';
import { NotificationsManager } from './notificationsManager';
import { NotificationsProvider } from './notificationsProvider';
import { NotificationsTreeData } from './notificationsView';
Expand Down Expand Up @@ -69,6 +69,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');
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',
Expand Down
47 changes: 43 additions & 4 deletions src/notifications/notificationsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,16 +30,31 @@ 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<void>();
readonly onDidChangeSortingMethod = this._onDidChangeSortingMethod.event;

private readonly _onDidChangeFilterMethod = new vscode.EventEmitter<void>();
readonly onDidChangeFilterMethod = this._onDidChangeFilterMethod.event;

private _hasNextPage: boolean = false;
private _notifications = new Map<string, NotificationTreeItem>();

private readonly _disposable: vscode.Disposable[] = [];

constructor(private readonly _notificationProvider: NotificationsProvider) {
this._disposable.push(this._onDidChangeNotifications);
this._disposable.push(this._onDidChangeSortingMethod);
this._disposable.push(this._onDidChangeFilterMethod);
}

dispose() {
Expand All @@ -56,9 +73,11 @@ export class NotificationsManager {
public async getNotifications(compute: boolean, pageCount: number): Promise<INotificationTreeItems | undefined> {
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
};
}
Expand All @@ -82,7 +101,6 @@ export class NotificationsManager {
if (!model) {
return;
}

notificationItems.set(notification.key, {
notification, model, kind: 'notification'
});
Expand Down Expand Up @@ -115,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
};
}
Expand Down Expand Up @@ -148,4 +169,22 @@ export class NotificationsManager {

return notifications;
}

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;
}
});
}
}
3 changes: 3 additions & 0 deletions src/notifications/notificationsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export class NotificationsTreeData implements vscode.TreeDataProvider<Notificati
this._disposables.push(this._notificationsManager.onDidChangeSortingMethod(() => {
this.refresh(true);
}));
this._disposables.push(this._notificationsManager.onDidChangeFilterMethod(() => {
this.refresh(true);
}));
}

async getTreeItem(element: NotificationTreeDataItem): Promise<vscode.TreeItem> {
Expand Down