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.
|
|
|
|
*/
|
|
|
|
|
2023-03-08 17:33:27 -08:00
|
|
|
import { ActionTraceEvent } from '@trace/trace';
|
2022-03-25 13:12:00 -08:00
|
|
|
import { msToString } from '@web/uiUtils';
|
2023-02-16 07:59:21 -08:00
|
|
|
import { ListView } from '@web/components/listView';
|
2021-01-07 16:15:34 -08:00
|
|
|
import * as React from 'react';
|
2022-03-25 13:12:00 -08:00
|
|
|
import './actionList.css';
|
2021-07-01 20:46:56 -07:00
|
|
|
import * as modelUtil from './modelUtil';
|
2022-10-18 22:23:40 -04:00
|
|
|
import { asLocator } from '@isomorphic/locatorGenerators';
|
|
|
|
import type { Language } from '@isomorphic/locatorGenerators';
|
2021-01-07 16:15:34 -08:00
|
|
|
|
2021-01-21 08:29:01 -08:00
|
|
|
export interface ActionListProps {
|
2021-05-13 20:41:32 -07:00
|
|
|
actions: ActionTraceEvent[],
|
|
|
|
selectedAction: ActionTraceEvent | undefined,
|
2022-10-18 22:23:40 -04:00
|
|
|
sdkLanguage: Language | undefined;
|
2021-05-13 20:41:32 -07:00
|
|
|
onSelected: (action: ActionTraceEvent) => void,
|
|
|
|
onHighlighted: (action: ActionTraceEvent | undefined) => void,
|
2023-03-06 21:37:39 -08:00
|
|
|
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 = [],
|
2022-10-18 22:23:40 -04:00
|
|
|
selectedAction,
|
|
|
|
sdkLanguage,
|
2021-01-21 08:29:01 -08:00
|
|
|
onSelected = () => {},
|
|
|
|
onHighlighted = () => {},
|
2023-03-06 21:37:39 -08:00
|
|
|
revealConsole = () => {},
|
2021-01-21 08:29:01 -08:00
|
|
|
}) => {
|
2023-03-08 17:33:27 -08:00
|
|
|
return <ActionListView
|
2023-02-16 07:59:21 -08:00
|
|
|
items={actions}
|
2023-03-08 17:33:27 -08:00
|
|
|
id={action => action.callId}
|
2023-02-16 07:59:21 -08:00
|
|
|
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)}
|
|
|
|
/>;
|
2021-01-07 16:15:34 -08:00
|
|
|
};
|
2023-01-10 18:33:20 +01:00
|
|
|
|
2023-02-16 07:59:21 -08:00
|
|
|
const renderAction = (
|
2023-01-10 18:33:20 +01:00
|
|
|
action: ActionTraceEvent,
|
|
|
|
sdkLanguage: Language | undefined,
|
2023-03-06 21:37:39 -08:00
|
|
|
revealConsole: () => void
|
2023-02-16 07:59:21 -08:00
|
|
|
) => {
|
2023-01-10 18:33:20 +01:00
|
|
|
const { errors, warnings } = modelUtil.stats(action);
|
2023-02-27 15:29:20 -08:00
|
|
|
const locator = action.params.selector ? asLocator(sdkLanguage || 'javascript', action.params.selector) : undefined;
|
2023-01-10 18:33:20 +01:00
|
|
|
|
2023-03-14 15:24:48 -07:00
|
|
|
let time: string = '';
|
|
|
|
if (action.endTime)
|
|
|
|
time = msToString(action.endTime - action.startTime);
|
|
|
|
else if (action.error)
|
|
|
|
time = 'Timed out';
|
2023-02-16 07:59:21 -08:00
|
|
|
return <>
|
2023-01-10 18:33:20 +01:00
|
|
|
<div className='action-title'>
|
2023-02-27 15:29:20 -08:00
|
|
|
<span>{action.apiName}</span>
|
2023-01-10 18:33:20 +01:00
|
|
|
{locator && <div className='action-selector' title={locator}>{locator}</div>}
|
2023-02-27 15:29:20 -08:00
|
|
|
{action.method === 'goto' && action.params.url && <div className='action-url' title={action.params.url}>{action.params.url}</div>}
|
2023-01-10 18:33:20 +01:00
|
|
|
</div>
|
2023-03-14 15:24:48 -07:00
|
|
|
<div className='action-duration' style={{ flex: 'none' }}>{time || <span className='codicon codicon-loading'></span>}</div>
|
2023-03-06 21:37:39 -08:00
|
|
|
<div className='action-icons' onClick={() => revealConsole()}>
|
2023-03-14 15:24:48 -07:00
|
|
|
{!!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>}
|
2023-01-10 18:33:20 +01:00
|
|
|
</div>
|
2023-02-16 07:59:21 -08:00
|
|
|
</>;
|
2023-01-10 18:33:20 +01:00
|
|
|
};
|