Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit a8bfb09

Browse files
Hubert KosterHubert Koster
authored andcommitted
chore: refactoring code
1 parent c90562a commit a8bfb09

File tree

3 files changed

+9
-40
lines changed

3 files changed

+9
-40
lines changed

src/features/Apiexplorer/RequestResponseRenderer/PlaygroundSection/JsonData/index.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,29 @@
11
import React from 'react';
22
import styles from './JsonData.module.scss';
33
import {
4-
TSocketResponseData,
54
TSocketEndpointNames,
65
TSocketSubscribableEndpointNames,
6+
TSocketResponse,
77
} from '@site/src/configs/websocket/types';
88

99
const ReactJson = React.lazy(() => import('react-json-view'));
1010

1111
type TJsonData<T extends TSocketEndpointNames> = {
12-
full_response: TSocketResponseData<T>;
12+
full_response: TSocketResponse<T>;
1313
error: unknown;
1414
name: string;
1515
};
1616

1717
const JsonData = <T extends TSocketEndpointNames | TSocketSubscribableEndpointNames>({
1818
full_response,
19-
name,
2019
error,
2120
}: TJsonData<T>) => {
22-
const getResponse = (key: string) => {
23-
const response = full_response;
24-
const selected_key = response[key] ?? name;
25-
if (response !== null) return selected_key;
26-
};
27-
28-
const key = getResponse('msg_type');
29-
const echo_req_json = {
30-
echo_req: getResponse('echo_req'),
31-
msg_type: getResponse('msg_type'),
32-
req_id: getResponse('req_id'),
33-
};
34-
const main_object_json = { [key]: getResponse(key) };
35-
3621
return (
3722
<React.Fragment>
3823
{full_response !== null ? (
3924
<div className={styles.reactJsonContainer}>
40-
<ReactJson src={echo_req_json} theme='tube' />
41-
<ReactJson src={main_object_json} theme='tube' />
25+
<ReactJson src={full_response.echo_req} theme='tube' />
26+
<ReactJson src={full_response} theme='tube' />
4227
</div>
4328
) : (
4429
<ReactJson src={{ error }} theme='tube' />

src/features/Apiexplorer/RequestResponseRenderer/PlaygroundSection/__tests__/PlaygroundSection.test.tsx

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,10 @@ import React from 'react';
22
import PlaygroundSection from '..';
33
import { render, screen } from '@testing-library/react';
44

5-
const fake_full_response = {
6-
msg_type: 'test',
7-
};
8-
95
describe('PlaygroundSection', () => {
106
it('should render the loader', async () => {
117
render(
12-
<PlaygroundSection
13-
loader
14-
response_state={false}
15-
full_response={fake_full_response}
16-
error={null}
17-
name=''
18-
/>,
8+
<PlaygroundSection loader response_state={false} full_response={null} error={null} name='' />,
199
);
2010
const loader = await screen.findByTestId('circles-loading');
2111
expect(loader).toBeVisible();
@@ -26,7 +16,7 @@ describe('PlaygroundSection', () => {
2616
<PlaygroundSection
2717
loader={false}
2818
response_state={false}
29-
full_response={fake_full_response}
19+
full_response={null}
3020
error={null}
3121
name=''
3222
/>,
@@ -37,13 +27,7 @@ describe('PlaygroundSection', () => {
3727

3828
it('should render the ReactJson', async () => {
3929
render(
40-
<PlaygroundSection
41-
loader={false}
42-
response_state
43-
full_response={fake_full_response}
44-
error={null}
45-
name=''
46-
/>,
30+
<PlaygroundSection loader={false} response_state full_response={null} error={null} name='' />,
4731
);
4832

4933
const playground_section = await screen.findByTestId('dt_playground_section');

src/features/Apiexplorer/RequestResponseRenderer/PlaygroundSection/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { Suspense } from 'react';
22
import {
33
TSocketEndpointNames,
4-
TSocketResponseData,
54
TSocketSubscribableEndpointNames,
5+
TSocketResponse,
66
} from '@site/src/configs/websocket/types';
77
import JsonData from './JsonData';
88
import Loader from '@site/src/components/Loader';
@@ -11,7 +11,7 @@ import styles from './PlaygroundSection.module.scss';
1111
type TPlaygroundSection<T extends TSocketEndpointNames> = {
1212
loader: boolean;
1313
response_state: boolean;
14-
full_response: TSocketResponseData<T>;
14+
full_response: TSocketResponse<T>;
1515
error: unknown;
1616
name: string;
1717
};

0 commit comments

Comments
 (0)