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

plugins: sort plugins in the plugins-view #7601

Merged
merged 1 commit into from
Apr 22, 2020
Merged
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
21 changes: 20 additions & 1 deletion packages/plugin-ext/src/main/browser/plugin-ext-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class PluginWidget extends ReactWidget {

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

Expand Down Expand Up @@ -106,4 +106,23 @@ export class PluginWidget extends ReactWidget {
const classNames = ['pluginHeaderContainer'];
return classNames.join(' ');
}

/**
* Compare two plugins based on their names, and publishers.
* @param a the first plugin metadata.
* @param b the second plugin metadata.
*/
protected compareMetadata(a: PluginMetadata, b: PluginMetadata): number {
// Determine the name of the plugins.
const nameA = a.model.name.toLowerCase();
const nameB = b.model.name.toLowerCase();

// Determine the publisher of the plugin (when names are equal).
const publisherA = a.model.publisher.toLowerCase();
const publisherB = b.model.publisher.toLowerCase();

return (nameA === nameA)
? nameA.localeCompare(nameB)
: publisherA.localeCompare(publisherB);
}
}