Skip to content

Commit 389c1d5

Browse files
authored
Merge pull request #18 from MegafonWebLab/mfru-12750
MFRU-12750 added simulations example template
2 parents 1b4e417 + 0379883 commit 389c1d5

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

src/components/Simulations/Simulations.pcss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,13 @@ $(b) {
327327

328328
&__import-buttons {
329329
display: flex;
330-
justify-content: space-around;
330+
gap: 24px;
331+
justify-content: center;
332+
}
333+
334+
&__import-button_example {
335+
color: var(--spbSky3) !important;
336+
337+
box-shadow: inset 0 0 0 1px var(--spbSky3) !important;
331338
}
332339
}

src/components/Simulations/Simulations.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ReactComponent as PlusIcon } from 'static/favicon/plus.svg';
1515
import { useSelector } from 'store/hooks';
1616
import { downloadFile } from 'utils';
1717
import Popup from '../Popup/Popup';
18+
import exampleData from './exampleData';
1819
import type { RouteItem } from './types';
1920
import { getRouteList, validateImport } from './utils';
2021
import './Simulations.pcss';
@@ -124,6 +125,10 @@ const Simulations: React.FC<ISimulationsProps> = ({ onChange, onDelete, onImport
124125
}
125126
}
126127

128+
function handleExample() {
129+
downloadFile(JSON.stringify(exampleData, null, 2), 'example.json');
130+
}
131+
127132
function handleSimulationEditButtonClick(index: number) {
128133
return () => onChange(index, 'edit');
129134
}
@@ -315,6 +320,15 @@ const Simulations: React.FC<ISimulationsProps> = ({ onChange, onDelete, onImport
315320
<div className={cn('import-pairs')}>File have {importData.pairs.length} valid simulations</div>
316321
)}
317322
<div className={cn('import-buttons')}>
323+
<Button
324+
className={cn('import-button', { example: true })}
325+
type="outline"
326+
theme="black"
327+
actionType="button"
328+
onClick={handleExample}
329+
>
330+
Example
331+
</Button>
318332
<Button
319333
disabled={importData.pairs.length === 0}
320334
actionType="button"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const exampleData = [
2+
{
3+
request: {
4+
path: [
5+
{
6+
matcher: 'exact',
7+
value: '/',
8+
},
9+
],
10+
method: [
11+
{
12+
matcher: 'exact',
13+
value: 'GET',
14+
},
15+
],
16+
destination: [
17+
{
18+
matcher: 'exact',
19+
value: '/',
20+
},
21+
],
22+
headers: {
23+
requestHeaderKey: [
24+
{
25+
matcher: 'exact',
26+
value: 'requestHeaderKeys',
27+
},
28+
],
29+
},
30+
query: {
31+
requestQueryKey: [
32+
{
33+
matcher: 'exact',
34+
value: 'requestQueryKeys',
35+
},
36+
],
37+
},
38+
requiresState: {
39+
requireStateKey: 'requireStateValue',
40+
},
41+
},
42+
response: {
43+
status: 200,
44+
body: '{\n "key": "value"\n}\n',
45+
encodedBody: false,
46+
headers: {
47+
responseHeaderKey: ['responseHeaderValue'],
48+
},
49+
templated: false,
50+
transitionsState: {
51+
newStateKey: 'newStateValue',
52+
},
53+
fixedDelay: 500,
54+
},
55+
},
56+
];
57+
58+
export default exampleData;

0 commit comments

Comments
 (0)