82 lines
3.0 KiB
TypeScript
Raw Normal View History

/*
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.
*/
2023-03-08 17:33:27 -08:00
import { ActionTraceEvent } from '@trace/trace';
import { msToString } from '@web/uiUtils';
import { ListView } from '@web/components/listView';
import * as React from 'react';
import './actionList.css';
import * as modelUtil from './modelUtil';
import { asLocator } from '@isomorphic/locatorGenerators';
import type { Language } from '@isomorphic/locatorGenerators';
2021-01-21 08:29:01 -08:00
export interface ActionListProps {
actions: ActionTraceEvent[],
selectedAction: ActionTraceEvent | undefined,
sdkLanguage: Language | undefined;
onSelected: (action: ActionTraceEvent) => void,
onHighlighted: (action: ActionTraceEvent | undefined) => void,
revealConsole: () => void,
2021-01-21 08:29:01 -08:00
}
2023-03-08 17:33:27 -08:00
const ActionListView = ListView<ActionTraceEvent>;
2021-01-21 08:29:01 -08:00
export const ActionList: React.FC<ActionListProps> = ({
actions = [],
selectedAction,
sdkLanguage,
2021-01-21 08:29:01 -08:00
onSelected = () => {},
onHighlighted = () => {},
revealConsole = () => {},
2021-01-21 08:29:01 -08:00
}) => {
2023-03-08 17:33:27 -08:00
return <ActionListView
items={actions}
2023-03-08 17:33:27 -08:00
id={action => action.callId}
selectedItem={selectedAction}
2023-03-08 17:33:27 -08:00
onSelected={onSelected}
onHighlighted={onHighlighted}
isError={action => !!action.error?.message}
render={action => renderAction(action, sdkLanguage, revealConsole)}
/>;
};
const renderAction = (
action: ActionTraceEvent,
sdkLanguage: Language | undefined,
revealConsole: () => void
) => {
const { errors, warnings } = modelUtil.stats(action);
const locator = action.params.selector ? asLocator(sdkLanguage || 'javascript', action.params.selector) : undefined;
let time: string = '';
if (action.endTime)
time = msToString(action.endTime - action.startTime);
else if (action.error)
time = 'Timed out';
return <>
<div className='action-title'>
<span>{action.apiName}</span>
{locator && <div className='action-selector' title={locator}>{locator}</div>}
{action.method === 'goto' && action.params.url && <div className='action-url' title={action.params.url}>{action.params.url}</div>}
</div>
<div className='action-duration' style={{ flex: 'none' }}>{time || <span className='codicon codicon-loading'></span>}</div>
<div className='action-icons' onClick={() => revealConsole()}>
{!!errors && <div className='action-icon'><span className='codicon codicon-error'></span><span className="action-icon-value">{errors}</span></div>}
{!!warnings && <div className='action-icon'><span className='codicon codicon-warning'></span><span className="action-icon-value">{warnings}</span></div>}
</div>
</>;
};