Skip to content

Commit 2aeda00

Browse files
committed
Add sort by date added for databases
This uses the dateAdded field on databases. It will only work for databases added after that field was added. Otherwise, the dateAdded property will be undefined.
1 parent 27623f3 commit 2aeda00

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

extensions/ql-vscode/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@
214214
"dark": "media/dark/sort-alpha.svg"
215215
}
216216
},
217+
{
218+
"command": "codeQLDatabases.sortByDateAdded",
219+
"title": "Sort by Date Added",
220+
"icon": {
221+
"light": "media/light/sort-date.svg",
222+
"dark": "media/dark/sort-date.svg"
223+
}
224+
},
217225
{
218226
"command": "codeQL.checkForUpdatesToCLI",
219227
"title": "CodeQL: Check for CLI Updates"
@@ -270,6 +278,11 @@
270278
"when": "view == codeQLDatabases",
271279
"group": "navigation"
272280
},
281+
{
282+
"command": "codeQLDatabases.sortByDateAdded",
283+
"when": "view == codeQLDatabases",
284+
"group": "navigation"
285+
},
273286
{
274287
"command": "codeQL.chooseDatabase",
275288
"when": "view == codeQLDatabases",
@@ -361,6 +374,10 @@
361374
"command": "codeQLDatabases.sortByName",
362375
"when": "false"
363376
},
377+
{
378+
"command": "codeQLDatabases.sortByDateAdded",
379+
"when": "false"
380+
},
364381
{
365382
"command": "codeQLDatabases.removeDatabase",
366383
"when": "false"

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ function joinThemableIconPath(base: string, iconPath: ThemableIconPath): Themabl
3636

3737
enum SortOrder {
3838
NameAsc = 'NameAsc',
39-
NameDesc = 'NameDesc'
39+
NameDesc = 'NameDesc',
40+
DateAddedAsc = 'DateAddedAsc',
41+
DateAddedDesc = 'DateAddedDesc'
4042
}
4143

4244
/**
@@ -97,6 +99,10 @@ class DatabaseTreeDataProvider extends DisposableObject
9799
return db1.name.localeCompare(db2.name);
98100
case SortOrder.NameDesc:
99101
return db2.name.localeCompare(db1.name);
102+
case SortOrder.DateAddedAsc:
103+
return (db1.dateAdded || 0) - (db2.dateAdded || 0);
104+
case SortOrder.DateAddedDesc:
105+
return (db2.dateAdded || 0) - (db1.dateAdded || 0);
100106
}
101107
});
102108
}
@@ -171,6 +177,7 @@ export class DatabaseUI extends DisposableObject {
171177
ctx.subscriptions.push(commands.registerCommand('codeQL.clearCache', this.handleClearCache));
172178
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.setCurrentDatabase', this.handleMakeCurrentDatabase));
173179
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.sortByName', this.handleSortByName));
180+
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.sortByDateAdded', this.handleSortByDateAdded));
174181
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.removeDatabase', this.handleRemoveDatabase));
175182
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.upgradeDatabase', this.handleUpgradeDatabase));
176183
}
@@ -191,6 +198,14 @@ export class DatabaseUI extends DisposableObject {
191198
}
192199
}
193200

201+
private handleSortByDateAdded = async () => {
202+
if (this.treeDataProvider.sortOrder === SortOrder.DateAddedAsc) {
203+
this.treeDataProvider.sortOrder = SortOrder.DateAddedDesc;
204+
} else {
205+
this.treeDataProvider.sortOrder = SortOrder.DateAddedAsc;
206+
}
207+
}
208+
194209
private handleUpgradeCurrentDatabase = async (): Promise<void> => {
195210
await this.handleUpgradeDatabase(this.databaseManager.currentDatabaseItem);
196211
}

extensions/ql-vscode/src/databases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ export class DatabaseManager extends DisposableObject {
554554
if (typeof state.options.ignoreSourceArchive === 'boolean') {
555555
ignoreSourceArchive = state.options.ignoreSourceArchive;
556556
}
557-
if (typeof state.dateAdded === 'number') {
558-
dateAdded = state.dateAdded;
557+
if (typeof state.options.dateAdded === 'number') {
558+
dateAdded = state.options.dateAdded;
559559
}
560560
}
561561
const fullOptions: FullDatabaseOptions = {

0 commit comments

Comments
 (0)