Skip to content

Commit 181707e

Browse files
plugins: sort plugins in the plugins-view
The following commit adds a comparator method to the `plugins-view` so that plugins are sorted based on `name`, and `publisher` if required. Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
1 parent 2dc8dc4 commit 181707e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

packages/plugin-ext/src/main/browser/plugin-ext-widget.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class PluginWidget extends ReactWidget {
7878

7979
protected renderPlugins(plugins: PluginMetadata[]): React.ReactNode {
8080
return <div id='pluginListContainer'>
81-
{plugins.map(plugin => this.renderPlugin(plugin))}
81+
{plugins.sort((a, b) => this.compareMetadata(a, b)).map(plugin => this.renderPlugin(plugin))}
8282
</div>;
8383
}
8484

@@ -106,4 +106,23 @@ export class PluginWidget extends ReactWidget {
106106
const classNames = ['pluginHeaderContainer'];
107107
return classNames.join(' ');
108108
}
109+
110+
/**
111+
* Compare two plugins based on their names, and publishers.
112+
* @param a the first plugin metadata.
113+
* @param b the second plugin metadata.
114+
*/
115+
protected compareMetadata(a: PluginMetadata, b: PluginMetadata): number {
116+
// Determine the name of the plugins.
117+
const nameA = a.model.name.toLowerCase();
118+
const nameB = b.model.name.toLowerCase();
119+
120+
// Determine the publisher of the plugin (when names are equal).
121+
const publisherA = a.model.publisher.toLowerCase();
122+
const publisherB = b.model.publisher.toLowerCase();
123+
124+
return (nameA === nameA)
125+
? nameA.localeCompare(nameB)
126+
: publisherA.localeCompare(publisherB);
127+
}
109128
}

0 commit comments

Comments
 (0)