Path: blob/main/extensions/copilot/test/simulation/workbench/components/toolbar.tsx
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Select, ToggleButton, Tooltip } from '@fluentui/react-components';6import { WeatherMoon20Regular, WeatherSunny20Regular } from '@fluentui/react-icons';7import * as mobx from 'mobx';8import * as mobxlite from 'mobx-react-lite';9import * as React from 'react';10import { InitArgs } from '../initArgs';11import { AMLProvider } from '../stores/amlSimulations';12import { NesExternalOptions } from '../stores/nesExternalOptions';13import { RunnerOptions } from '../stores/runnerOptions';14import { SimulationRunsProvider } from '../stores/simulationBaseline';15import { SimulationRunner } from '../stores/simulationRunner';16import { SimulationTestsProvider } from '../stores/simulationTestsProvider';17import { TestSource, TestSourceValue } from '../stores/testSource';18import { AMLModeToolbar } from './amlModeToolbar';19import { ThemeKind } from './app';20import { LocalModeToolbar } from './localModeToolbar';21import { NesExternalModeToolbar } from './nesExternalModeToolbar';22import { TestFilterer } from './testFilterer';2324type ToolbarProps = {25initArgs: InitArgs | undefined;26runner: SimulationRunner;27runnerOptions: RunnerOptions;28nesExternalOptions: NesExternalOptions;29amlProvider: AMLProvider;30simulationRunsProvider: SimulationRunsProvider;31simulationTestsProvider: SimulationTestsProvider;32testSource: TestSourceValue;33onFiltererChange: (filter: TestFilterer | undefined) => void;34allLanguageIds: readonly string[];35theme: ThemeKind;36toggleTheme: () => void;37};3839export const Toolbar = mobxlite.observer(40({41initArgs,42runner,43runnerOptions,44nesExternalOptions,45amlProvider,46simulationRunsProvider,47simulationTestsProvider,48testSource,49onFiltererChange,50allLanguageIds,51theme,52toggleTheme,53}: ToolbarProps) => {5455const toolbarContent = (() => {56switch (testSource.value) {57case TestSource.Local:58return (59<LocalModeToolbar60initArgs={initArgs}61runner={runner}62runnerOptions={runnerOptions}63simulationRunsProvider={simulationRunsProvider}64simulationTestsProvider={simulationTestsProvider}65onFiltererChange={onFiltererChange}66/>67);68case TestSource.NesExternal:69return (70<NesExternalModeToolbar71runner={runner}72runnerOptions={runnerOptions}73nesExternalOptions={nesExternalOptions}74simulationRunsProvider={simulationRunsProvider}75onFiltererChange={onFiltererChange}76/>77);78case TestSource.External:79return (80<AMLModeToolbar81amlProvider={amlProvider}82simulationTestsProvider={simulationTestsProvider}83onFiltererChange={onFiltererChange}84allLanguageIds={allLanguageIds}85/>86);87}88})();8990return (91<div style={{ padding: '5px', display: 'flex' }}>92{toolbarContent}93<div style={{ display: 'flex', justifyContent: 'end', maxHeight: '35px' }}>94<ThemeToggler theme={theme} toggleTheme={toggleTheme} />95<ModeToggler testSource={testSource} onFiltererChange={onFiltererChange} />96</div>97</div>98);99}100);101102const ThemeToggler = ({ theme, toggleTheme }: { theme: ThemeKind; toggleTheme: () => void }) => (103<Tooltip content='Toggle workbench theme' relationship='label'>104<ToggleButton105appearance='subtle'106icon={theme === 'dark' ? <WeatherSunny20Regular /> : <WeatherMoon20Regular />}107onClick={toggleTheme}108/>109</Tooltip>110);111112const testSourceOptions: { value: string; label: string; source: TestSource }[] = [113{ value: String(TestSource.Local), label: 'Local', source: TestSource.Local },114{ value: String(TestSource.NesExternal), label: 'NES External', source: TestSource.NesExternal },115{ value: String(TestSource.External), label: 'AML', source: TestSource.External },116];117118const ModeToggler = ({ testSource, onFiltererChange }: { testSource: TestSourceValue; onFiltererChange: (filter: TestFilterer | undefined) => void }) => (119<Select120style={{ marginLeft: '8px', minWidth: '140px' }}121value={String(testSource.value)}122onChange={mobx.action((_e, data) => {123const selected = testSourceOptions.find(o => o.value === data.value);124if (selected) {125testSource.value = selected.source;126onFiltererChange(undefined);127}128})}129>130{testSourceOptions.map(o => (131<option key={o.value} value={o.value}>{o.label}</option>132))}133</Select>134);135136137