ATL-938: Added menu group categories.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta
2021-02-10 16:41:20 +01:00
committed by Akos Kitta
parent 3e92567d52
commit ba8885c8c8
7 changed files with 189 additions and 66 deletions

View File

@@ -5,6 +5,25 @@ import { Installable } from './installable';
import { ArduinoComponent } from './arduino-component';
export type AvailablePorts = Record<string, [Port, Array<Board>]>;
export namespace AvailablePorts {
export function groupByProtocol(availablePorts: AvailablePorts): { serial: AvailablePorts, network: AvailablePorts, unknown: AvailablePorts } {
const serial: AvailablePorts = {};
const network: AvailablePorts = {};
const unknown: AvailablePorts = {};
for (const key of Object.keys(availablePorts)) {
const [port, boards] = availablePorts[key];
const { protocol } = port;
if (protocol === 'serial') {
serial[key] = [port, boards];
} else if (protocol === 'network') {
network[key] = [port, boards];
} else {
unknown[key] = [port, boards];
}
}
return { serial, network, unknown };
}
}
export interface AttachedBoardsChangeEvent {
readonly oldState: Readonly<{ boards: Board[], ports: Port[] }>;

View File

@@ -69,4 +69,17 @@ export namespace LibraryPackage {
return left.name === right.name && left.author === right.author;
}
export function groupByLocation(packages: LibraryPackage[]): { user: LibraryPackage[], rest: LibraryPackage[] } {
const user: LibraryPackage[] = [];
const rest: LibraryPackage[] = [];
for (const pkg of packages) {
if (pkg.location === LibraryLocation.USER) {
user.push(pkg);
} else {
rest.push(pkg);
}
}
return { user, rest };
}
}