-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): support specs and outputs creation from trigger respo…
…nse (#2703)
- Loading branch information
Showing
12 changed files
with
242 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
web/src/components/AttributeActions/AttributeActions.styled.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import styled from 'styled-components'; | ||
|
||
import moreIcon from 'assets/more.svg'; | ||
|
||
export const MoreIcon = styled.img.attrs({ | ||
src: moreIcon, | ||
})``; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {Dropdown, Menu, MenuProps, Space} from 'antd'; | ||
|
||
import useCopy from 'hooks/useCopy'; | ||
import TraceAnalyticsService from 'services/Analytics/TestRunAnalytics.service'; | ||
import {TSpanFlatAttribute} from 'types/Span.types'; | ||
import * as S from './AttributeActions.styled'; | ||
|
||
const Action = { | ||
Copy: '0', | ||
Create_Spec: '1', | ||
Create_Output: '2', | ||
} as const; | ||
|
||
const menuItems: MenuProps['items'] = [ | ||
{ | ||
key: Action.Copy, | ||
label: 'Copy value', | ||
}, | ||
{ | ||
key: Action.Create_Output, | ||
label: 'Create test output', | ||
}, | ||
{ | ||
key: Action.Create_Spec, | ||
label: 'Create test spec', | ||
}, | ||
]; | ||
|
||
interface IProps { | ||
attribute: TSpanFlatAttribute; | ||
children?: React.ReactNode; | ||
onCreateTestOutput(attribute: TSpanFlatAttribute): void; | ||
onCreateTestSpec(attribute: TSpanFlatAttribute): void; | ||
} | ||
|
||
const AttributeActions = ({attribute, children, onCreateTestOutput, onCreateTestSpec}: IProps) => { | ||
const copy = useCopy(); | ||
|
||
const handleOnClick = ({key: option}: {key: string}) => { | ||
if (option === Action.Copy) { | ||
TraceAnalyticsService.onAttributeCopy(); | ||
copy(attribute.value); | ||
} | ||
|
||
if (option === Action.Create_Spec) { | ||
return onCreateTestSpec(attribute); | ||
} | ||
|
||
if (option === Action.Create_Output) { | ||
return onCreateTestOutput(attribute); | ||
} | ||
}; | ||
return ( | ||
<Dropdown overlay={<Menu items={menuItems} onClick={handleOnClick} />}> | ||
{children || ( | ||
<a onClick={e => e.preventDefault()}> | ||
<Space> | ||
<S.MoreIcon /> | ||
</Space> | ||
</a> | ||
)} | ||
</Dropdown> | ||
); | ||
}; | ||
|
||
export default AttributeActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line no-restricted-exports | ||
export {default} from './AttributeActions'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 22 additions & 2 deletions
24
web/src/components/RunDetailTriggerResponse/ResponseBody.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
import AttributeActions from 'components/AttributeActions'; | ||
import {isRunStateFinished} from 'models/TestRun.model'; | ||
import {TSpanFlatAttribute} from 'types/Span.types'; | ||
import {TTestRunState} from 'types/TestRun.types'; | ||
import SkeletonResponse from './SkeletonResponse'; | ||
import CodeBlock from '../CodeBlock'; | ||
import * as S from './RunDetailTriggerResponse.styled'; | ||
|
||
interface IProps { | ||
body?: string; | ||
bodyMimeType?: string; | ||
state: TTestRunState; | ||
onCreateTestOutput(attribute: TSpanFlatAttribute): void; | ||
onCreateTestSpec(attribute: TSpanFlatAttribute): void; | ||
} | ||
|
||
const ResponseBody = ({body = '', bodyMimeType = '', state}: IProps) => | ||
isRunStateFinished(state) || !!body ? <CodeBlock value={body} mimeType={bodyMimeType} /> : <SkeletonResponse />; | ||
const ResponseBody = ({body = '', bodyMimeType = '', state, onCreateTestOutput, onCreateTestSpec}: IProps) => | ||
isRunStateFinished(state) || !!body ? ( | ||
<S.ResponseBodyContainer> | ||
<S.ResponseBodyContent> | ||
<CodeBlock value={body} mimeType={bodyMimeType} /> | ||
</S.ResponseBodyContent> | ||
<S.ResponseBodyActions> | ||
<AttributeActions | ||
attribute={{key: 'tracetest.response.body', value: body}} | ||
onCreateTestOutput={onCreateTestOutput} | ||
onCreateTestSpec={onCreateTestSpec} | ||
/> | ||
</S.ResponseBodyActions> | ||
</S.ResponseBodyContainer> | ||
) : ( | ||
<SkeletonResponse /> | ||
); | ||
|
||
export default ResponseBody; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.