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