Skip to content

Commit 87d01dc

Browse files
committed
Show rule-type-appropriate text in config for Close & Timeout rules
1 parent 06a894f commit 87d01dc

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/components/mock/handler-config.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { uploadFile } from '../../util/ui';
1111
import { asError } from '../../util/error';
1212

1313
import {
14-
Handler
14+
Handler,
15+
RuleType
1516
} from '../../model/rules/rules';
1617
import {
1718
StaticResponseHandler,
@@ -47,6 +48,7 @@ import { FormatButton } from '../common/format-button';
4748
import { byteLength, asBuffer, isProbablyUtf8 } from '../../util';
4849

4950
type HandlerConfigProps<H extends Handler> = {
51+
ruleType: RuleType;
5052
handler: H;
5153
onChange: (handler: H) => void;
5254
onInvalidState: () => void;
@@ -70,13 +72,15 @@ const ConfigExplanation = styled.p`
7072
`;
7173

7274
export function HandlerConfiguration(props: {
75+
ruleType: RuleType,
7376
handler: Handler,
7477
onChange: (handler: Handler) => void,
7578
onInvalidState?: () => void // Currently unused - intended to improve invalid entry UX later on
7679
}) {
7780
const { handler, onChange, onInvalidState } = props;
7881

7982
const configProps = {
83+
ruleType: props.ruleType,
8084
handler: handler as any,
8185
onChange,
8286
onInvalidState: onInvalidState || _.noop
@@ -1154,9 +1158,14 @@ class TimeoutHandlerConfig extends HandlerConfig<TimeoutHandler> {
11541158
render() {
11551159
return <ConfigContainer>
11561160
<ConfigExplanation>
1157-
When a matching request is received, the server will keep the connection
1158-
open but do nothing. With no data or response, most clients will time out
1159-
and abort the request after sufficient time has passed.
1161+
When a matching {
1162+
this.props.ruleType === 'http'
1163+
? 'HTTP'
1164+
// ruleType === 'websocket'
1165+
: 'WebSocket'
1166+
} is received, the server will keep the connection open but do nothing.
1167+
With no data or response, most clients will time out and abort the
1168+
request after sufficient time has passed.
11601169
</ConfigExplanation>
11611170
</ConfigContainer>;
11621171
}
@@ -1167,8 +1176,12 @@ class CloseConnectionHandlerConfig extends HandlerConfig<CloseConnectionHandler>
11671176
render() {
11681177
return <ConfigContainer>
11691178
<ConfigExplanation>
1170-
As soon as a matching request is received, the connection will
1171-
be closed, with no response.
1179+
As soon as a matching {
1180+
this.props.ruleType === 'http'
1181+
? 'HTTP'
1182+
// ruleType === 'websocket'
1183+
: 'WebSocket'
1184+
} is received, the connection will be closed, with no response.
11721185
</ConfigExplanation>
11731186
</ConfigContainer>;
11741187
}

src/components/mock/mock-rule-row.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,13 @@ export class RuleRow extends React.Component<{
407407
// show a handler demo with a 'Get Pro' overlay:
408408
? <GetProOverlay getPro={getPro} source={`rule-${ruleHandler.type}`}>
409409
<HandlerConfiguration
410+
ruleType={rule.type}
410411
handler={ruleHandler}
411412
onChange={_.noop}
412413
/>
413414
</GetProOverlay>
414415
: <HandlerConfiguration
416+
ruleType={rule.type}
415417
handler={ruleHandler}
416418
onChange={this.updateHandler}
417419
/>

src/model/rules/rules.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ export type HtkMockRule =
104104
| WebSocketMockRule
105105
| HttpMockRule;
106106

107-
const matchRuleType = <T extends HtkMockRule['type']>(
107+
export type RuleType = HtkMockRule['type'];
108+
109+
const matchRuleType = <T extends RuleType>(
108110
type: T
109111
) => (rule: HtkMockRule): rule is HtkMockRule & { type: T } =>
110112
rule.type === type;

0 commit comments

Comments
 (0)