| 
									
										
										
										
											2021-01-08 08: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-03-26 05:12:00 +08:00
										 |  |  | import { SplitView } from '@web/components/splitView'; | 
					
						
							|  |  |  | import * as React from 'react'; | 
					
						
							| 
									
										
										
										
											2021-01-08 08:15:34 +08:00
										 |  |  | import { ActionList } from './actionList'; | 
					
						
							| 
									
										
										
										
											2021-07-03 05:33:38 +08:00
										 |  |  | import { CallTab } from './callTab'; | 
					
						
							| 
									
										
										
										
											2021-07-02 05:31:20 +08:00
										 |  |  | import { ConsoleTab } from './consoleTab'; | 
					
						
							| 
									
										
										
										
											2023-07-11 03:56:56 +08:00
										 |  |  | import type * as modelUtil from './modelUtil'; | 
					
						
							| 
									
										
										
										
											2023-05-20 06:18:18 +08:00
										 |  |  | import type { ActionTraceEventInContext, MultiTraceModel } from './modelUtil'; | 
					
						
							| 
									
										
										
										
											2022-03-26 05:12:00 +08:00
										 |  |  | import { NetworkTab } from './networkTab'; | 
					
						
							|  |  |  | import { SnapshotTab } from './snapshotTab'; | 
					
						
							|  |  |  | import { SourceTab } from './sourceTab'; | 
					
						
							| 
									
										
										
										
											2023-02-18 03:19:53 +08:00
										 |  |  | import { TabbedPane } from '@web/components/tabbedPane'; | 
					
						
							| 
									
										
										
										
											2023-03-08 06:24:50 +08:00
										 |  |  | import type { TabbedPaneTabModel } from '@web/components/tabbedPane'; | 
					
						
							| 
									
										
										
										
											2022-03-26 05:12:00 +08:00
										 |  |  | import { Timeline } from './timeline'; | 
					
						
							|  |  |  | import './workbench.css'; | 
					
						
							| 
									
										
										
										
											2023-03-07 04:25:00 +08:00
										 |  |  | import { MetadataView } from './metadataView'; | 
					
						
							| 
									
										
										
										
											2023-05-10 08:53:01 +08:00
										 |  |  | import { AttachmentsTab } from './attachmentsTab'; | 
					
						
							| 
									
										
										
										
											2021-01-08 08:15:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-16 23:59:21 +08:00
										 |  |  | export const Workbench: React.FunctionComponent<{ | 
					
						
							| 
									
										
										
										
											2023-03-08 04:43:16 +08:00
										 |  |  |   model?: MultiTraceModel, | 
					
						
							| 
									
										
										
										
											2023-03-11 14:52:31 +08:00
										 |  |  |   hideTimelineBars?: boolean, | 
					
						
							|  |  |  |   hideStackFrames?: boolean, | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |   showSourcesFirst?: boolean, | 
					
						
							| 
									
										
										
										
											2023-03-20 03:04:19 +08:00
										 |  |  |   rootDir?: string, | 
					
						
							| 
									
										
										
										
											2023-05-09 09:51:27 +08:00
										 |  |  |   fallbackLocation?: modelUtil.SourceLocation, | 
					
						
							| 
									
										
										
										
											2023-05-20 06:18:18 +08:00
										 |  |  |   initialSelection?: ActionTraceEventInContext, | 
					
						
							|  |  |  |   onSelectionChanged?: (action: ActionTraceEventInContext) => void, | 
					
						
							| 
									
										
										
										
											2023-05-19 06:52:44 +08:00
										 |  |  |   isLive?: boolean, | 
					
						
							| 
									
										
										
										
											2023-06-02 06:49:48 +08:00
										 |  |  |   drawer?: 'bottom' | 'right', | 
					
						
							|  |  |  | }> = ({ model, hideTimelineBars, hideStackFrames, showSourcesFirst, rootDir, fallbackLocation, initialSelection, onSelectionChanged, isLive, drawer }) => { | 
					
						
							| 
									
										
										
										
											2023-05-20 06:18:18 +08:00
										 |  |  |   const [selectedAction, setSelectedAction] = React.useState<ActionTraceEventInContext | undefined>(undefined); | 
					
						
							|  |  |  |   const [highlightedAction, setHighlightedAction] = React.useState<ActionTraceEventInContext | undefined>(); | 
					
						
							| 
									
										
										
										
											2023-02-16 23:59:21 +08:00
										 |  |  |   const [selectedNavigatorTab, setSelectedNavigatorTab] = React.useState<string>('actions'); | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |   const [selectedPropertiesTab, setSelectedPropertiesTab] = React.useState<string>(showSourcesFirst ? 'source' : 'call'); | 
					
						
							| 
									
										
										
										
											2023-03-08 04:43:16 +08:00
										 |  |  |   const activeAction = model ? highlightedAction || selectedAction : undefined; | 
					
						
							| 
									
										
										
										
											2021-10-22 23:00:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-20 03:04:19 +08:00
										 |  |  |   const sources = React.useMemo(() => model?.sources || new Map(), [model]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-11 09:01:30 +08:00
										 |  |  |   React.useEffect(() => { | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |     if (selectedAction && model?.actions.includes(selectedAction)) | 
					
						
							| 
									
										
										
										
											2023-03-11 09:01:30 +08:00
										 |  |  |       return; | 
					
						
							|  |  |  |     const failedAction = model?.actions.find(a => a.error); | 
					
						
							| 
									
										
										
										
											2023-04-01 09:34:51 +08:00
										 |  |  |     if (initialSelection && model?.actions.includes(initialSelection)) | 
					
						
							|  |  |  |       setSelectedAction(initialSelection); | 
					
						
							|  |  |  |     else if (failedAction) | 
					
						
							| 
									
										
										
										
											2023-03-11 09:01:30 +08:00
										 |  |  |       setSelectedAction(failedAction); | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |     else if (model?.actions.length) | 
					
						
							|  |  |  |       setSelectedAction(model.actions[model.actions.length - 1]); | 
					
						
							| 
									
										
										
										
											2023-04-01 09:34:51 +08:00
										 |  |  |   }, [model, selectedAction, setSelectedAction, setSelectedPropertiesTab, initialSelection]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-20 06:18:18 +08:00
										 |  |  |   const onActionSelected = React.useCallback((action: ActionTraceEventInContext) => { | 
					
						
							| 
									
										
										
										
											2023-04-01 09:34:51 +08:00
										 |  |  |     setSelectedAction(action); | 
					
						
							|  |  |  |     onSelectionChanged?.(action); | 
					
						
							|  |  |  |   }, [setSelectedAction, onSelectionChanged]); | 
					
						
							| 
									
										
										
										
											2023-03-11 09:01:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 04:43:16 +08:00
										 |  |  |   const sdkLanguage = model?.sdkLanguage || 'javascript'; | 
					
						
							| 
									
										
										
										
											2021-07-02 11:46:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |   const callTab: TabbedPaneTabModel = { | 
					
						
							|  |  |  |     id: 'call', | 
					
						
							| 
									
										
										
										
											2023-05-13 10:15:31 +08:00
										 |  |  |     title: 'Call', | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |     render: () => <CallTab action={activeAction} sdkLanguage={sdkLanguage} /> | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   const sourceTab: TabbedPaneTabModel = { | 
					
						
							|  |  |  |     id: 'source', | 
					
						
							|  |  |  |     title: 'Source', | 
					
						
							| 
									
										
										
										
											2023-03-20 03:04:19 +08:00
										 |  |  |     render: () => <SourceTab | 
					
						
							|  |  |  |       action={activeAction} | 
					
						
							|  |  |  |       sources={sources} | 
					
						
							|  |  |  |       hideStackFrames={hideStackFrames} | 
					
						
							|  |  |  |       rootDir={rootDir} | 
					
						
							| 
									
										
										
										
											2023-05-09 09:51:27 +08:00
										 |  |  |       fallbackLocation={fallbackLocation} /> | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  |   const consoleTab: TabbedPaneTabModel = { | 
					
						
							|  |  |  |     id: 'console', | 
					
						
							|  |  |  |     title: 'Console', | 
					
						
							| 
									
										
										
										
											2023-07-11 03:56:56 +08:00
										 |  |  |     render: () => <ConsoleTab model={model} action={activeAction} /> | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  |   const networkTab: TabbedPaneTabModel = { | 
					
						
							|  |  |  |     id: 'network', | 
					
						
							|  |  |  |     title: 'Network', | 
					
						
							| 
									
										
										
										
											2023-07-11 03:56:56 +08:00
										 |  |  |     render: () => <NetworkTab model={model} action={activeAction} /> | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2023-05-10 08:53:01 +08:00
										 |  |  |   const attachmentsTab: TabbedPaneTabModel = { | 
					
						
							|  |  |  |     id: 'attachments', | 
					
						
							|  |  |  |     title: 'Attachments', | 
					
						
							| 
									
										
										
										
											2023-07-11 03:56:56 +08:00
										 |  |  |     render: () => <AttachmentsTab model={model} /> | 
					
						
							| 
									
										
										
										
											2023-05-10 08:53:01 +08:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2021-10-24 02:23:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |   const tabs: TabbedPaneTabModel[] = showSourcesFirst ? [ | 
					
						
							|  |  |  |     sourceTab, | 
					
						
							|  |  |  |     consoleTab, | 
					
						
							|  |  |  |     networkTab, | 
					
						
							|  |  |  |     callTab, | 
					
						
							| 
									
										
										
										
											2023-05-10 08:53:01 +08:00
										 |  |  |     attachmentsTab, | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |   ] : [ | 
					
						
							|  |  |  |     callTab, | 
					
						
							|  |  |  |     consoleTab, | 
					
						
							|  |  |  |     networkTab, | 
					
						
							|  |  |  |     sourceTab, | 
					
						
							| 
									
										
										
										
											2023-05-10 08:53:01 +08:00
										 |  |  |     attachmentsTab, | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |   ]; | 
					
						
							| 
									
										
										
										
											2021-10-24 02:23:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-16 23:59:21 +08:00
										 |  |  |   return <div className='vbox'> | 
					
						
							| 
									
										
										
										
											2023-03-07 13:37:39 +08:00
										 |  |  |     <Timeline | 
					
						
							|  |  |  |       model={model} | 
					
						
							|  |  |  |       selectedAction={activeAction} | 
					
						
							| 
									
										
										
										
											2023-04-01 09:34:51 +08:00
										 |  |  |       onSelected={onActionSelected} | 
					
						
							| 
									
										
										
										
											2023-03-11 14:52:31 +08:00
										 |  |  |       hideTimelineBars={hideTimelineBars} | 
					
						
							| 
									
										
										
										
											2023-06-16 23:56:11 +08:00
										 |  |  |       sdkLanguage={sdkLanguage} | 
					
						
							| 
									
										
										
										
											2023-03-07 13:37:39 +08:00
										 |  |  |     /> | 
					
						
							| 
									
										
										
										
											2023-06-02 06:49:48 +08:00
										 |  |  |     <SplitView sidebarSize={250} orientation={drawer === 'bottom' ? 'vertical' : 'horizontal'}> | 
					
						
							| 
									
										
										
										
											2023-03-08 06:24:50 +08:00
										 |  |  |       <SplitView sidebarSize={250} orientation='horizontal' sidebarIsFirst={true}> | 
					
						
							| 
									
										
										
										
											2023-03-08 04:43:16 +08:00
										 |  |  |         <SnapshotTab action={activeAction} sdkLanguage={sdkLanguage} testIdAttributeName={model?.testIdAttributeName || 'data-testid'} /> | 
					
						
							| 
									
										
										
										
											2023-03-08 06:24:50 +08:00
										 |  |  |         <TabbedPane tabs={ | 
					
						
							|  |  |  |           [ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               id: 'actions', | 
					
						
							|  |  |  |               title: 'Actions', | 
					
						
							|  |  |  |               component: <ActionList | 
					
						
							|  |  |  |                 sdkLanguage={sdkLanguage} | 
					
						
							|  |  |  |                 actions={model?.actions || []} | 
					
						
							|  |  |  |                 selectedAction={model ? selectedAction : undefined} | 
					
						
							| 
									
										
										
										
											2023-04-01 09:34:51 +08:00
										 |  |  |                 onSelected={onActionSelected} | 
					
						
							|  |  |  |                 onHighlighted={setHighlightedAction} | 
					
						
							| 
									
										
										
										
											2023-03-08 06:24:50 +08:00
										 |  |  |                 revealConsole={() => setSelectedPropertiesTab('console')} | 
					
						
							| 
									
										
										
										
											2023-05-19 06:52:44 +08:00
										 |  |  |                 isLive={isLive} | 
					
						
							| 
									
										
										
										
											2023-03-08 06:24:50 +08:00
										 |  |  |               /> | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               id: 'metadata', | 
					
						
							|  |  |  |               title: 'Metadata', | 
					
						
							|  |  |  |               component: <MetadataView model={model}/> | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           ] | 
					
						
							|  |  |  |         } selectedTab={selectedNavigatorTab} setSelectedTab={setSelectedNavigatorTab}/> | 
					
						
							| 
									
										
										
										
											2021-03-12 03:22:59 +08:00
										 |  |  |       </SplitView> | 
					
						
							| 
									
										
										
										
											2023-03-12 03:43:33 +08:00
										 |  |  |       <TabbedPane tabs={tabs} selectedTab={selectedPropertiesTab} setSelectedTab={setSelectedPropertiesTab} /> | 
					
						
							| 
									
										
										
										
											2021-04-06 11:27:57 +08:00
										 |  |  |     </SplitView> | 
					
						
							| 
									
										
										
										
											2021-01-08 08:15:34 +08:00
										 |  |  |   </div>; | 
					
						
							|  |  |  | }; |