import React from "react";
import {
observable,
computed,
action,
runInAction,
makeObservable
} from "mobx";
import { observer } from "mobx-react";
import classNames from "classnames";
import { uniqBy } from "lodash";
import { IExtension } from "eez-studio-shared/extensions/extension";
import {
getManufacturer,
isInstrumentExtension
} from "eez-studio-shared/extensions/extensions";
import { List, IListNode, ListItem } from "eez-studio-ui/list";
import * as notification from "eez-studio-ui/notification";
import { Loader } from "eez-studio-ui/loader";
import {
ExtensionsManagerStore,
ViewFilter,
downloadAndInstallExtension
} from "home/extensions-manager/extensions-manager";
import { tabs } from "./tabs-store";
const BB3_INSTRUMENT_EXTENSION_ID = "687b6dee-2093-4c36-afb7-cfc7ea2bf262";
const BB3_INSTRUMENT_MANUFACTURER = "EEZ";
class SetupState {
selectedExtensionId: string | undefined = BB3_INSTRUMENT_EXTENSION_ID;
selectedManufacturer: string | undefined = BB3_INSTRUMENT_MANUFACTURER;
extensionsManagerStore: ExtensionsManagerStore;
constructor() {
makeObservable(this, {
selectedExtensionId: observable,
selectedManufacturer: observable,
reset: action,
instrumentExtensionNodes: computed,
manufacturers: computed,
extensionNodes: computed,
extensionInstalling: observable
});
this.extensionsManagerStore = new ExtensionsManagerStore();
this.extensionsManagerStore.viewFilter = ViewFilter.ALL;
}
reset() {
this.extensionInstalling = undefined;
}
get instrumentExtensionNodes() {
return this.extensionsManagerStore.all.filter(extension =>
isInstrumentExtension(extension.latestVersion)
);
}
get manufacturers() {
return uniqBy(this.instrumentExtensionNodes, extension =>
getManufacturer(extension.latestVersion)
).map(extension => ({
id: extension.latestVersion.id,
data: extension.latestVersion,
selected:
getManufacturer(extension.latestVersion) ==
this.selectedManufacturer
}));
}
get extensionNodes() {
return this.instrumentExtensionNodes
.filter(
extension =>
getManufacturer(extension.latestVersion) ==
this.selectedManufacturer
)
.map(extension => ({
id: extension.latestVersion.id,
data: extension.latestVersion,
selected: extension.latestVersion.id == this.selectedExtensionId
}));
}
selectManufacturer = action((node: IListNode) => {
this.selectedManufacturer = getManufacturer(node.data);
this.selectedExtensionId = undefined;
});
selectExtension = action((node: IListNode) => {
this.selectedExtensionId = (node.data as IExtension).id;
});
extensionInstalling:
| {
inProgress: boolean;
infoNode: React.ReactNode;
infoType?: notification.Type;
}
| undefined;
}
export const setupState = new SetupState();
function renderManufacturer(node: IListNode) {
let instrumentExtension = node.data as IExtension;
return