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 { 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,
|
2021-07-01 20:46:56 -07:00
|
|
|
setSelectedTab: (tab: string) => void,
|
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 = () => {},
|
2021-07-01 20:46:56 -07:00
|
|
|
setSelectedTab = () => {},
|
2021-01-21 08:29:01 -08:00
|
|
|
}) => {
|
2023-02-16 07:59:21 -08:00
|
|
|
return <ListView
|
|
|
|
items={actions}
|
|
|
|
selectedItem={selectedAction}
|
|
|
|
onSelected={(action: ActionTraceEvent) => onSelected(action)}
|
|
|
|
onHighlighted={(action: ActionTraceEvent) => onHighlighted(action)}
|
|
|
|
itemKey={(action: ActionTraceEvent) => action.metadata.id}
|
2023-02-23 09:09:21 -08:00
|
|
|
itemType={(action: ActionTraceEvent) => action.metadata.error?.error?.message ? 'error' : undefined}
|
2023-02-16 07:59:21 -08:00
|
|
|
itemRender={(action: ActionTraceEvent) => renderAction(action, sdkLanguage, setSelectedTab)}
|
|
|
|
showNoItemsMessage={true}
|
|
|
|
></ListView>;
|
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-02-16 07:59:21 -08:00
|
|
|
setSelectedTab: (tab: string) => void
|
|
|
|
) => {
|
2023-01-10 18:33:20 +01:00
|
|
|
const { metadata } = action;
|
|
|
|
const { errors, warnings } = modelUtil.stats(action);
|
|
|
|
const locator = metadata.params.selector ? asLocator(sdkLanguage || 'javascript', metadata.params.selector) : undefined;
|
|
|
|
|
2023-02-16 07:59:21 -08:00
|
|
|
return <>
|
2023-01-10 18:33:20 +01:00
|
|
|
<div className='action-title'>
|
|
|
|
<span>{metadata.apiName}</span>
|
|
|
|
{locator && <div className='action-selector' title={locator}>{locator}</div>}
|
|
|
|
{metadata.method === 'goto' && metadata.params.url && <div className='action-url' title={metadata.params.url}>{metadata.params.url}</div>}
|
|
|
|
</div>
|
|
|
|
<div className='action-duration' style={{ flex: 'none' }}>{metadata.endTime ? msToString(metadata.endTime - metadata.startTime) : 'Timed Out'}</div>
|
|
|
|
<div className='action-icons' onClick={() => setSelectedTab('console')}>
|
|
|
|
{!!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>
|
2023-02-16 07:59:21 -08:00
|
|
|
</>;
|
2023-01-10 18:33:20 +01:00
|
|
|
};
|