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

Commit 5b99240

Browse files
authored
Merge pull request #272 from utkarsha-deriv/utkarsha/DERA-450/link-api-names-in-description-to-respective-api-calls
2 parents 6e2523e + ac6c95d commit 5b99240

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
@use 'src/styles/utility' as *;
22

33
.schemaRole {
4-
background-color: rgba(255, 255, 255, 0.16);
5-
border: none;
6-
font-size: rem(1.4);
7-
font-weight: 400;
8-
line-height: rem(2.4);
9-
color: var(--ifm-color-white);
10-
height: fit-content;
11-
padding: rem(0.5) rem(0.5);
12-
margin: 0 rem(0.5);
4+
background-color: rgba(255, 255, 255, 0.16);
5+
border: none;
6+
font-size: rem(1.4);
7+
font-weight: 400;
8+
line-height: rem(2.4);
9+
color: var(--ifm-color-white);
10+
height: fit-content;
11+
padding: rem(0.5) rem(0.5);
12+
margin: 0 rem(0.5);
1313
}
14-
14+
1515
.schemaCode {
16-
color: var(--ifm-color-white);
17-
font-size: rem(1.4);
16+
color: var(--ifm-color-white);
17+
font-size: rem(1.4);
18+
}
19+
20+
.schemaLink {
21+
text-decoration: underline;
22+
color: var(--ifm-link-white);
23+
&:hover {
24+
color: var(--ifm-link-white);
25+
}
1826
}

src/features/Apiexplorer/Schema/HighlightCode/__tests__/HighlightCode.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { HighlightCode } from '..';
33
import { render, screen } from '@testing-library/react';
4+
import userEvent from '@testing-library/user-event';
45

56
describe('HighlightCode', () => {
67
it('should render HighlightCode properly', async () => {
@@ -19,4 +20,13 @@ describe('HighlightCode', () => {
1920
const empty_highlight = render(<HighlightCode description={null} />);
2021
expect(empty_highlight.container.firstChild).toBe(null);
2122
});
23+
24+
it('should render page of the selected api call name in the description', async () => {
25+
render(<HighlightCode description={'This is a `residence_list` test'} />);
26+
const api_call_name = screen.getByText(/residence_list/i);
27+
28+
await userEvent.click(api_call_name);
29+
30+
expect(api_call_name.closest('a')).toHaveAttribute('href', '#residence_list');
31+
});
2232
});

src/features/Apiexplorer/Schema/HighlightCode/index.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
import React from 'react';
22
import clsx from 'clsx';
3-
import styles from './HighlightCode.module.scss';
3+
import { playground_requests } from '@site/src/utils/playground_requests';
44
import { SchemaDescriptionTypes } from '../RecursiveContent/SchemaDescription';
5+
import styles from './HighlightCode.module.scss';
56

67
export const HighlightCode = ({ description }: SchemaDescriptionTypes) => {
78
if (!description) return null;
89

910
const [first, code, ...rest] = description.split('`');
11+
12+
const has_api_call = playground_requests.some((el) => el.name === code);
13+
1014
return (
1115
<React.Fragment>
1216
{first}
13-
{code && <span className={clsx(styles.schemaRole, styles.schemaCode)}>{code}</span>}
17+
{code && (
18+
<span className={clsx(styles.schemaRole, styles.schemaCode)}>
19+
{has_api_call ? (
20+
<a
21+
href={`#${code}`}
22+
onClick={() => window.scrollTo(0, 0)}
23+
className={styles.schemaLink}
24+
>
25+
{code}
26+
</a>
27+
) : (
28+
code
29+
)}
30+
</span>
31+
)}
1432
{rest.length > 0 && <HighlightCode description={rest.join('`')} />}
1533
</React.Fragment>
1634
);

0 commit comments

Comments
 (0)