Skip to content

Commit

Permalink
fix(frontend): skip polling improvements (#3472)
Browse files Browse the repository at this point in the history
* fix(frontend): skip polling improvements

* fix(frontend): attribute list open by default
  • Loading branch information
xoscar authored Dec 21, 2023
1 parent e7545bb commit 7518e5a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 25 deletions.
6 changes: 3 additions & 3 deletions web/src/components/RunDetailLayout/HeaderRight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as S from './RunDetailLayout.styled';
import EventLogPopover from '../EventLogPopover/EventLogPopover';
import RunStatusIcon from '../RunStatusIcon/RunStatusIcon';
import VariableSetSelector from '../VariableSetSelector/VariableSetSelector';
import TracePollingActions from '../SkipPollingPopover/SkipPollingPopover';
import SkipPollingPopover from '../SkipPollingPopover';
import useSkipPolling from './hooks/useSkipPolling';

interface IProps {
Expand All @@ -27,7 +27,7 @@ const HeaderRight = ({testId, triggerType}: IProps) => {
const {isDraftMode: isTestOutputsDraftMode} = useTestOutput();
const isDraftMode = isTestSpecsDraftMode || isTestOutputsDraftMode;
const {
run: {state, requiredGatesResult, createdAt},
run: {state, requiredGatesResult},
run,
runEvents,
} = useTestRun();
Expand All @@ -43,7 +43,7 @@ const HeaderRight = ({testId, triggerType}: IProps) => {
<S.StateText>Test status:</S.StateText>
<TestState testState={state} />
{isRunPollingState(state) && (
<TracePollingActions startTime={createdAt} isLoading={isLoading} skipPolling={onSkipPolling} />
<SkipPollingPopover isLoading={isLoading} skipPolling={onSkipPolling} />
)}
</S.StateContainer>
)}
Expand Down
15 changes: 12 additions & 3 deletions web/src/components/SkipPollingPopover/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Button, Checkbox, Typography} from 'antd';
import {ForwardOutlined} from '@ant-design/icons';
import {useState} from 'react';
import * as S from './SkipPollingPopover.styled';

Expand All @@ -13,14 +14,22 @@ const Content = ({skipPolling, isLoading}: IProps) => {
return (
<>
<Typography.Paragraph>
You can skip the <b>awaiting trace</b> step and use the current state to create test specs.
Hit &apos;Skip Trace collection&apos; to create a black box test using trigger response. Handy for testing
systems like a GET against <i>https://google.com</i> that won&apos;t send Tracetest a trace!
</Typography.Paragraph>
<S.Actions>
<div>
<Checkbox onChange={() => setShouldSave(prev => !prev)} value={shouldSave} /> Apply to all runs
</div>
<Button loading={isLoading} type="primary" ghost onClick={() => skipPolling(shouldSave)} size="small">
Skip awaiting trace
<Button
icon={<ForwardOutlined />}
loading={isLoading}
type="primary"
ghost
onClick={() => skipPolling(shouldSave)}
size="small"
>
Skip Trace collection
</Button>
</S.Actions>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {Typography} from 'antd';
import {Button, Typography} from 'antd';
import styled, {createGlobalStyle} from 'styled-components';

export const StopContainer = styled.div`
margin-left: 12px;
`;

export const GlobalStyle = createGlobalStyle`
.ant-popover.ant-popover-placement-bottomRight {
z-index: 9999;
}
#skip-trace-popover {
.ant-popover-title {
padding: 14px;
Expand All @@ -16,6 +20,7 @@ export const GlobalStyle = createGlobalStyle`
.ant-popover-inner-content {
padding: 14px;
padding-top: 0;
max-width: 520px;
}
}
`;
Expand All @@ -35,3 +40,23 @@ export const Title = styled(Typography.Title).attrs({
margin: 0;
}
`;

export const ForwardButton = styled(Button)`
&& {
font-size: ${({theme}) => theme.size.xl};
}
`;

export const ContentContainer = styled.div`
display: flex;
gap: 12px;
justify-content: space-between;
align-items: center;
`;

export const CloseIcon = styled(Typography.Text)`
&& {
cursor: pointer;
color: ${({theme}) => theme.color.textSecondary};
}
`;
34 changes: 17 additions & 17 deletions web/src/components/SkipPollingPopover/SkipPollingPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import {Button, Popover} from 'antd';
import {differenceInSeconds} from 'date-fns';
import {useEffect, useState} from 'react';
import {ForwardOutlined} from '@ant-design/icons';
import {Popover, Tooltip} from 'antd';
import {useState} from 'react';
import {CloseOutlined, ForwardOutlined} from '@ant-design/icons';
import * as S from './SkipPollingPopover.styled';
import Content from './Content';

interface IProps {
isLoading: boolean;
skipPolling(shouldSave: boolean): void;
startTime: string;
}

const TIMEOUT_TO_SHOW = 10; // seconds

const SkipPollingPopover = ({isLoading, skipPolling, startTime}: IProps) => {
const SkipPollingPopover = ({isLoading, skipPolling}: IProps) => {
const [isOpen, setIsOpen] = useState(false);
const diff = differenceInSeconds(new Date(), new Date(startTime));

useEffect(() => {
if (diff > TIMEOUT_TO_SHOW) setIsOpen(true);
}, [diff, isOpen]);

return (
<S.StopContainer>
<S.GlobalStyle />
<Popover
id="skip-trace-popover"
title={<S.Title level={3}>Taking too long to get the trace?</S.Title>}
title={
<S.ContentContainer>
<S.Title level={3}>Waiting too long for the trace?</S.Title>
<S.CloseIcon onClick={() => setIsOpen(false)}>
<CloseOutlined />
</S.CloseIcon>
</S.ContentContainer>
}
content={<Content isLoading={isLoading} skipPolling={skipPolling} />}
visible={isOpen}
placement="bottomRight"
>
<Button loading={isLoading} onClick={() => skipPolling(false)} type="link">
<ForwardOutlined />
</Button>
<Tooltip title="Skip Trace collection" placement="left">
<S.ForwardButton size="small" loading={isLoading} onClick={() => setIsOpen(true)} type="link">
<ForwardOutlined />
</S.ForwardButton>
</Tooltip>
</Popover>
</S.StopContainer>
);
Expand Down
2 changes: 2 additions & 0 deletions web/src/components/SkipPollingPopover/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line no-restricted-exports
export {default} from './SkipPollingPopover';
2 changes: 1 addition & 1 deletion web/src/services/Triggers/TraceID.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const TraceIDTriggerService = (): ITriggerService => ({
async getRequest(values) {
const {id} = values as ITraceIDValues;

return TraceIDRequest({id: id.includes('env:') ? id : `\${env:${id}}`});
return TraceIDRequest({id: id.includes('env:') || id.includes('var:') ? id : `\${env:${id}}`});
},

async validateDraft(draft) {
Expand Down

0 comments on commit 7518e5a

Please sign in to comment.