2021-01-07 16:15:34 -08:00
|
|
|
/*
|
|
|
|
Copyright (c) Microsoft Corporation.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-09-20 18:41:51 -07:00
|
|
|
import type { ActionTraceEvent } from '@trace/trace';
|
2022-03-25 13:12:00 -08:00
|
|
|
import { SplitView } from '@web/components/splitView';
|
|
|
|
import * as React from 'react';
|
2021-01-07 16:15:34 -08:00
|
|
|
import { ActionList } from './actionList';
|
2021-07-02 14:33:38 -07:00
|
|
|
import { CallTab } from './callTab';
|
2021-07-01 14:31:20 -07:00
|
|
|
import { ConsoleTab } from './consoleTab';
|
2021-07-01 20:46:56 -07:00
|
|
|
import * as modelUtil from './modelUtil';
|
2023-03-06 12:25:00 -08:00
|
|
|
import type { MultiTraceModel } from './modelUtil';
|
2022-03-25 13:12:00 -08:00
|
|
|
import { NetworkTab } from './networkTab';
|
|
|
|
import { SnapshotTab } from './snapshotTab';
|
|
|
|
import { SourceTab } from './sourceTab';
|
2023-02-17 11:19:53 -08:00
|
|
|
import { TabbedPane } from '@web/components/tabbedPane';
|
2022-03-25 13:12:00 -08:00
|
|
|
import { Timeline } from './timeline';
|
|
|
|
import './workbench.css';
|
2023-03-06 12:25:00 -08:00
|
|
|
import { MetadataView } from './metadataView';
|
2021-01-07 16:15:34 -08:00
|
|
|
|
2023-02-16 07:59:21 -08:00
|
|
|
export const Workbench: React.FunctionComponent<{
|
2023-03-07 12:43:16 -08:00
|
|
|
model?: MultiTraceModel,
|
2023-03-06 12:25:00 -08:00
|
|
|
}> = ({ model }) => {
|
2023-02-16 07:59:21 -08:00
|
|
|
const [selectedAction, setSelectedAction] = React.useState<ActionTraceEvent | undefined>();
|
|
|
|
const [highlightedAction, setHighlightedAction] = React.useState<ActionTraceEvent | undefined>();
|
|
|
|
const [selectedNavigatorTab, setSelectedNavigatorTab] = React.useState<string>('actions');
|
|
|
|
const [selectedPropertiesTab, setSelectedPropertiesTab] = React.useState<string>('logs');
|
2023-03-07 12:43:16 -08:00
|
|
|
const activeAction = model ? highlightedAction || selectedAction : undefined;
|
2021-10-22 07:00:34 -08:00
|
|
|
|
2023-02-16 07:59:21 -08:00
|
|
|
const { errors, warnings } = activeAction ? modelUtil.stats(activeAction) : { errors: 0, warnings: 0 };
|
2021-07-02 14:33:38 -07:00
|
|
|
const consoleCount = errors + warnings;
|
2023-02-16 07:59:21 -08:00
|
|
|
const networkCount = activeAction ? modelUtil.resourcesForAction(activeAction).length : 0;
|
2023-03-07 12:43:16 -08:00
|
|
|
const sdkLanguage = model?.sdkLanguage || 'javascript';
|
2021-07-01 20:46:56 -07:00
|
|
|
|
2021-10-23 10:23:39 -08:00
|
|
|
const tabs = [
|
2023-03-07 12:43:16 -08:00
|
|
|
{ id: 'logs', title: 'Call', count: 0, render: () => <CallTab action={activeAction} sdkLanguage={sdkLanguage} /> },
|
2023-02-16 07:59:21 -08:00
|
|
|
{ id: 'console', title: 'Console', count: consoleCount, render: () => <ConsoleTab action={activeAction} /> },
|
|
|
|
{ id: 'network', title: 'Network', count: networkCount, render: () => <NetworkTab action={activeAction} /> },
|
2021-10-23 10:23:39 -08:00
|
|
|
];
|
|
|
|
|
2023-03-07 12:43:16 -08:00
|
|
|
if (model?.hasSource)
|
2023-03-06 12:25:00 -08:00
|
|
|
tabs.push({ id: 'source', title: 'Source', count: 0, render: () => <SourceTab action={activeAction} /> });
|
2021-10-23 10:23:39 -08:00
|
|
|
|
2023-02-16 07:59:21 -08:00
|
|
|
return <div className='vbox'>
|
2023-03-06 21:37:39 -08:00
|
|
|
<Timeline
|
|
|
|
model={model}
|
|
|
|
selectedAction={activeAction}
|
|
|
|
onSelected={action => setSelectedAction(action)}
|
|
|
|
/>
|
2021-04-19 19:50:11 -07:00
|
|
|
<SplitView sidebarSize={300} orientation='horizontal' sidebarIsFirst={true}>
|
2023-02-24 15:31:10 -08:00
|
|
|
<SplitView sidebarSize={300} orientation='vertical'>
|
2023-03-07 12:43:16 -08:00
|
|
|
<SnapshotTab action={activeAction} sdkLanguage={sdkLanguage} testIdAttributeName={model?.testIdAttributeName || 'data-testid'} />
|
2021-11-09 22:13:51 -08:00
|
|
|
<TabbedPane tabs={tabs} selectedTab={selectedPropertiesTab} setSelectedTab={setSelectedPropertiesTab}/>
|
2021-03-11 11:22:59 -08:00
|
|
|
</SplitView>
|
2021-11-09 22:13:51 -08:00
|
|
|
<TabbedPane tabs={
|
|
|
|
[
|
2023-03-07 12:43:16 -08:00
|
|
|
{
|
|
|
|
id: 'actions',
|
|
|
|
title: 'Actions',
|
|
|
|
count: 0,
|
|
|
|
component: <ActionList
|
|
|
|
sdkLanguage={sdkLanguage}
|
|
|
|
actions={model?.actions || []}
|
|
|
|
selectedAction={model ? selectedAction : undefined}
|
|
|
|
onSelected={action => {
|
|
|
|
setSelectedAction(action);
|
|
|
|
}}
|
|
|
|
onHighlighted={action => {
|
|
|
|
setHighlightedAction(action);
|
|
|
|
}}
|
|
|
|
revealConsole={() => setSelectedPropertiesTab('console')}
|
|
|
|
/>
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'metadata',
|
2023-03-06 12:25:00 -08:00
|
|
|
title: 'Metadata',
|
|
|
|
count: 0,
|
2023-03-07 12:43:16 -08:00
|
|
|
component: <MetadataView model={model}/>
|
2023-03-06 12:25:00 -08:00
|
|
|
},
|
2021-11-09 22:13:51 -08:00
|
|
|
]
|
|
|
|
} selectedTab={selectedNavigatorTab} setSelectedTab={setSelectedNavigatorTab}/>
|
2021-04-06 11:27:57 +08:00
|
|
|
</SplitView>
|
2021-01-07 16:15:34 -08:00
|
|
|
</div>;
|
|
|
|
};
|