Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/workbench/components/app.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 { Checkbox, FluentProvider, MessageBar, MessageBarBody, MessageBarTitle, Text, ToggleButton, Tooltip, webDarkTheme, webLightTheme } from '@fluentui/react-components';
7
import { ListBar20Filled, ListBarTree20Filled } 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 { SimulationStorage, SimulationStorageValue } from '../stores/simulationStorage';
18
import { ISimulationTest, SimulationTestsProvider } from '../stores/simulationTestsProvider';
19
import { useLocalStorageState } from '../stores/storage';
20
import { TestSource } from '../stores/testSource';
21
import { ContextMenu, ContextMenuProvider } from './contextMenu';
22
import { Scorecard } from './scorecard';
23
import { ScorecardByLanguage } from './scorecardByLanguage';
24
import { TestFilterer } from './testFilterer';
25
import { TestList } from './testList';
26
import { Toolbar } from './toolbar';
27
28
type Props = {
29
initArgs: InitArgs | undefined;
30
testsProvider: SimulationTestsProvider;
31
runner: SimulationRunner;
32
runnerOptions: RunnerOptions;
33
nesExternalOptions: NesExternalOptions;
34
simulationRunsProvider: SimulationRunsProvider;
35
amlProvider: AMLProvider;
36
displayOptions: DisplayOptions;
37
};
38
39
export type ThemeKind = 'light' | 'dark';
40
41
export const App = mobxlite.observer(
42
({ initArgs, testsProvider, runner, runnerOptions, nesExternalOptions, simulationRunsProvider, amlProvider, displayOptions }: Props) => {
43
44
const [theme, setTheme] = useLocalStorageState<ThemeKind>('appTheme', undefined, 'light');
45
46
const [filterer, setFilterer] = React.useState<TestFilterer | undefined>(undefined);
47
48
const displayedTests = filterer
49
? filterer.filter(testsProvider.tests)
50
: testsProvider.tests;
51
52
const toggleTheme = React.useCallback(() => setTheme(theme === 'dark' ? 'light' : 'dark'), [theme]);
53
54
return (
55
<FluentProvider theme={theme === 'light' ? webLightTheme : webDarkTheme} style={{ minHeight: 'inherit' }}>
56
<ContextMenuProvider>
57
<div>
58
<ContextMenu />
59
<Toolbar
60
initArgs={initArgs}
61
runner={runner}
62
runnerOptions={runnerOptions}
63
nesExternalOptions={nesExternalOptions}
64
simulationRunsProvider={simulationRunsProvider}
65
simulationTestsProvider={testsProvider}
66
amlProvider={amlProvider}
67
testSource={testsProvider.testSource}
68
onFiltererChange={setFilterer}
69
allLanguageIds={testsProvider.allLanguageIds}
70
theme={theme}
71
toggleTheme={toggleTheme}
72
/>
73
{testsProvider.testSource.value === TestSource.External && (
74
<Scorecard amlProvider={amlProvider} />
75
)}
76
{testsProvider.testSource.value === TestSource.External && (
77
<ScorecardByLanguage amlProvider={amlProvider} />
78
)}
79
{(testsProvider.testSource.value === TestSource.Local || testsProvider.testSource.value === TestSource.NesExternal) && <TerminationMessageBar runner={runner} />}
80
<div style={{ margin: '5px', display: 'flex', justifyContent: 'space-between' }}>
81
<div style={{ textAlign: 'left' }}>
82
<TestsInfo tests={testsProvider.tests} displayedTests={displayedTests} />
83
</div>
84
<div style={{ textAlign: 'right' }}>
85
<Checkbox
86
label='Expand prompts'
87
defaultChecked={displayOptions.expandPrompts.value}
88
onChange={mobx.action(() => displayOptions.expandPrompts.value = !displayOptions.expandPrompts.value)}
89
/>
90
<DisplayToggle displayOptions={displayOptions} />
91
</div>
92
</div>
93
<TestList tests={displayedTests} runner={runner} runnerOptions={runnerOptions} nesExternalOptions={nesExternalOptions} testSource={testsProvider.testSource} displayOptions={displayOptions} />
94
</div>
95
</ContextMenuProvider>
96
</FluentProvider>
97
);
98
}
99
);
100
101
const TerminationMessageBar = mobxlite.observer(({ runner }: { runner: SimulationRunner }) =>
102
runner.terminationReason === undefined
103
? null
104
: (
105
<MessageBar intent='error' layout='singleline'>
106
<MessageBarBody>
107
<MessageBarTitle>Simulation terminated early</MessageBarTitle>
108
<pre>{runner.terminationReason} </pre>
109
</MessageBarBody>
110
</MessageBar>
111
)
112
);
113
114
const DisplayToggle = mobxlite.observer(({ displayOptions }: { displayOptions: DisplayOptions }) => (
115
<Tooltip content='Show all tests or by suites' relationship='label'>
116
<ToggleButton
117
icon={displayOptions.testsKind.value === 'suiteList' ? <ListBarTree20Filled /> : <ListBar20Filled />}
118
onClick={mobx.action(() => displayOptions.testsKind.value = displayOptions.testsKind.value === 'suiteList' ? 'testList' : 'suiteList')}
119
/>
120
</Tooltip>
121
));
122
123
export class DisplayOptions {
124
125
public testsKind: SimulationStorageValue<'suiteList' | 'testList'>;
126
127
public expandPrompts: SimulationStorageValue<boolean>;
128
129
constructor(storage: SimulationStorage) {
130
this.testsKind = new SimulationStorageValue(storage, 'displayTestsKind', 'suiteList');
131
this.expandPrompts = new SimulationStorageValue(storage, 'expandPrompts', false);
132
}
133
}
134
135
type TestsInfoProps = {
136
tests: readonly ISimulationTest[];
137
displayedTests: readonly ISimulationTest[];
138
};
139
140
const TestsInfo = mobxlite.observer(({ tests, displayedTests }: TestsInfoProps) => {
141
// TODO@ulugbekna: don't show "failing" if tests weren't run yet
142
return (
143
<Text size={400}>
144
# of tests: {tests.length} (<span>displayed:</span> {displayedTests.length})
145
</Text>
146
);
147
});
148
149