Skip to content

Commit 45d688c

Browse files
committed
Sort examples alphabetically
Signed-off-by: Seb Julliand <[email protected]>
1 parent 051eee0 commit 45d688c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/views/examples/exampleBrowser.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@ export class ExampleBrowser implements TreeDataProvider<any> {
7979
return Object.values(Examples)
8080
.flatMap(examples => examples.filter(exampleWorksForOnOS))
8181
.filter(example => example.name.toUpperCase().includes(upperFilter) || example.content.some(line => line.toUpperCase().includes(upperFilter)))
82+
.sort(sort)
8283
.map(example => new SQLExampleItem(example));
8384
}
8485
else {
85-
return Object.entries(Examples).map(([name, examples]) => new ExampleGroupItem(name, examples));
86+
return Object.entries(Examples)
87+
.sort(([name1], [name2]) => sort(name1, name2))
88+
.map(([name, examples]) => new ExampleGroupItem(name, examples));
8689
}
8790
}
8891
}
@@ -97,6 +100,7 @@ class ExampleGroupItem extends TreeItem {
97100
getChildren(): SQLExampleItem[] {
98101
return this.group
99102
.filter(example => exampleWorksForOnOS(example))
103+
.sort(sort)
100104
.map(example => new SQLExampleItem(example));
101105
}
102106
}
@@ -129,4 +133,10 @@ function exampleWorksForOnOS(example: SQLExample): boolean {
129133
}
130134

131135
return true;
136+
}
137+
138+
function sort(string1: string | SQLExample, string2: string | SQLExample) {
139+
string1 = typeof string1 === "string" ? string1 : string1.name;
140+
string2 = typeof string2 === "string" ? string2 : string2.name;
141+
return string1.localeCompare(string2);
132142
}

0 commit comments

Comments
 (0)