Skip to content

Commit 233d6fd

Browse files
committed
added-showEditOption-functionality
1 parent 8844cb5 commit 233d6fd

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

components/DocsHelp.tsx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment';
44

55
interface DocsHelpProps {
66
fileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md' | string;
7+
showEditOption?: boolean;
78
}
8-
export function DocsHelp({ fileRenderType }: DocsHelpProps) {
9+
export function DocsHelp({
10+
fileRenderType,
11+
showEditOption = true,
12+
}: DocsHelpProps) {
913
const router = useRouter();
1014
const [isFormOpen, setIsFormOpen] = useState(false);
1115
const [feedbackStatus, setFeedbackStatus] = useState('');
@@ -308,28 +312,30 @@ export function DocsHelp({ fileRenderType }: DocsHelpProps) {
308312
type of contribution!
309313
</p>
310314
</div>
311-
<div className='my-4 text-[14px]'>
312-
<a
313-
target='_blank'
314-
rel='noreferrer'
315-
className='px-[16px] py-[8px] cursor-pointer border-solid border-[#aaaaaa] border rounded-md hover:bg-gray-200 dark:hover:bg-gray-600'
316-
href={gitredirect}
317-
data-test='edit-on-github-link'
318-
>
319-
<svg
320-
className='inline-block select-none align-text-bottom mr-1'
321-
aria-hidden='true'
322-
role='img'
323-
viewBox='0 0 16 16'
324-
width='16'
325-
height='16'
326-
fill='currentColor'
315+
{showEditOption && (
316+
<div className='my-4 text-[14px]'>
317+
<a
318+
target='_blank'
319+
rel='noreferrer'
320+
className='px-[16px] py-[8px] cursor-pointer border-solid border-[#aaaaaa] border rounded-md hover:bg-gray-200 dark:hover:bg-gray-600'
321+
href={gitredirect} // Ensure gitredirect is defined
322+
data-test='edit-on-github-link'
327323
>
328-
<path d='M1.5 3.25a2.25 2.25 0 1 1 3 2.122v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.25 2.25 0 0 1 1.5 3.25Zm5.677-.177L9.573.677A.25.25 0 0 1 10 .854V2.5h1A2.5 2.5 0 0 1 13.5 5v5.628a2.251 2.251 0 1 1-1.5 0V5a1 1 0 0 0-1-1h-1v1.646a.25.25 0 0 1-.427.177L7.177 3.427a.25.25 0 0 1 0-.354ZM3.75 2.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm0 9.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm8.25.75a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Z' />
329-
</svg>
330-
Edit this page on Github
331-
</a>
332-
</div>
324+
<svg
325+
className='inline-block select-none align-text-bottom mr-1'
326+
aria-hidden='true'
327+
role='img'
328+
viewBox='0 0 16 16'
329+
width='16'
330+
height='16'
331+
fill='currentColor'
332+
>
333+
<path d='M1.5 3.25a2.25 2.25 0 1 1 3 2.122v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.25 2.25 0 0 1 1.5 3.25Zm5.677-.177L9.573.677A.25.25 0 0 1 10 .854V2.5h1A2.5 2.5 0 0 1 13.5 5v5.628a2.251 2.251 0 1 1-1.5 0V5a1 1 0 0 0-1-1h-1v1.646a.25.25 0 0 1-.427.177L7.177 3.427a.25.25 0 0 1 0-.354ZM3.75 2.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm0 9.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm8.25.75a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Z' />
334+
</svg>
335+
Edit this page on Github
336+
</a>
337+
</div>
338+
)}
333339
<div className='my-2 text-[14px]'>
334340
<a
335341
target='_blank'

cypress/components/DocsHelp.cy.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,14 @@ describe('DocsHelp Component', () => {
270270
customLink,
271271
);
272272
});
273+
// Check if the "Edit on GitHub" link is present when showEditOption is true
274+
it('should render the "Edit on GitHub" link when showEditOption is true', () => {
275+
cy.mount(<DocsHelp fileRenderType='indexmd' showEditOption={true} />);
276+
cy.get('[data-test="edit-on-github-link"]').should('exist');
277+
});
278+
// Check if the "Edit on GitHub" link is not present when showEditOption is false
279+
it('should not render the "Edit on GitHub" link when showEditOption is false', () => {
280+
cy.mount(<DocsHelp fileRenderType='indexmd' showEditOption={false} />);
281+
cy.get('[data-test="edit-on-github-link"]').should('not.exist');
282+
});
273283
});

0 commit comments

Comments
 (0)