From f0271053e60e304743f64061e6616213612668a9 Mon Sep 17 00:00:00 2001
From: Yashwanth1906
Date: Fri, 20 Dec 2024 12:19:42 +0530
Subject: [PATCH 1/8] Link-redirect-fix
---
components/DocsHelp.tsx | 18 +++--
cypress/components/DocsHelp.cy.tsx | 70 +++++++++++--------
pages/[slug].page.tsx | 4 +-
pages/docs/index.page.tsx | 3 +-
pages/draft-05/index.page.tsx | 7 +-
pages/draft-06/[slug].page.tsx | 4 +-
pages/draft-06/index.page.tsx | 3 +-
pages/draft-07/[slug].page.tsx | 4 +-
pages/draft-07/index.page.tsx | 3 +-
pages/draft/2019-09/[slug].page.tsx | 4 +-
pages/draft/2019-09/index.page.tsx | 3 +-
pages/draft/2020-12/[slug].page.tsx | 4 +-
pages/draft/2020-12/index.page.tsx | 3 +-
pages/implementers/[slug].page.tsx | 4 +-
pages/implementers/index.page.tsx | 4 +-
pages/learn/[slug].page.tsx | 4 +-
.../index.page.tsx | 4 +-
pages/learn/index.page.tsx | 4 +-
pages/overview/[slug].page.tsx | 4 +-
pages/overview/case-studies/index.page.tsx | 4 +-
pages/overview/code-of-conduct/index.page.tsx | 4 +-
pages/overview/roadmap/index.page.tsx | 4 +-
pages/overview/sponsors/index.page.tsx | 4 +-
pages/overview/use-cases/index.page.tsx | 4 +-
.../json-hyper-schema/index.page.tsx | 4 +-
pages/specification/migration/index.page.tsx | 4 +-
.../release-notes/index.page.tsx | 4 +-
.../understanding-json-schema/[slug].page.tsx | 4 +-
.../understanding-json-schema/index.page.tsx | 4 +-
.../keywords/index.page.tsx | 4 +-
.../reference/[slug].page.tsx | 4 +-
.../reference/index.page.tsx | 4 +-
32 files changed, 118 insertions(+), 88 deletions(-)
diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx
index 544189b77..b81c6e02e 100644
--- a/components/DocsHelp.tsx
+++ b/components/DocsHelp.tsx
@@ -3,18 +3,26 @@ import React, { FormEvent, useRef, useState } from 'react';
import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment';
interface DocsHelpProps {
- markdownFile?: string;
+ fileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md';
}
-export function DocsHelp({ markdownFile }: DocsHelpProps) {
+export function DocsHelp({ fileRenderType }: DocsHelpProps) {
const router = useRouter();
- const path = encodeURIComponent(router.pathname);
const [isFormOpen, setIsFormOpen] = useState(false);
const [feedbackStatus, setFeedbackStatus] = useState('');
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState('');
const feedbackFormRef = useRef(null);
-
+ let gitredirect = '';
+ if (fileRenderType === 'tsx') {
+ gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.page.tsx'}`;
+ } else if (fileRenderType === '_indexmd') {
+ gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/_index.md'}`;
+ } else if (fileRenderType === 'indexmd') {
+ gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.md'}`;
+ } else {
+ gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '.md'}`;
+ }
async function createFeedbackHandler(event: FormEvent) {
event.preventDefault();
const formData = new FormData(feedbackFormRef.current!);
@@ -301,7 +309,7 @@ export function DocsHelp({ markdownFile }: DocsHelpProps) {
target='_blank'
rel='noreferrer'
className='px-[16px] py-[8px] cursor-pointer border-solid border-[#aaaaaa] border rounded-md hover:bg-gray-200 dark:hover:bg-gray-600'
- href={`https://github.com/json-schema-org/website/blob/main/pages${markdownFile ? (markdownFile === '_indexPage' ? extractPathWithoutFragment(router.asPath) + '/_index.md' : extractPathWithoutFragment(router.asPath) + '.md') : `/${path}/index.page.tsx`}`}
+ href={gitredirect}
data-test='edit-on-github-link'
>
-
+
);
}
From 579c8f2f5dc3bcf4068ce4c6cbbcb2a315612927 Mon Sep 17 00:00:00 2001
From: Yashwanth1906
Date: Fri, 27 Dec 2024 16:00:31 +0530
Subject: [PATCH 3/8] resolved-the-conflicts
---
pages/overview/roadmap/index.page.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pages/overview/roadmap/index.page.tsx b/pages/overview/roadmap/index.page.tsx
index feab740b4..e22e358f5 100644
--- a/pages/overview/roadmap/index.page.tsx
+++ b/pages/overview/roadmap/index.page.tsx
@@ -130,7 +130,7 @@ export default function Roadmap() {
})}
-
+
Date: Tue, 31 Dec 2024 15:19:56 +0530
Subject: [PATCH 4/8] changed-the-sponsors-and-code_of_conduct-redirect
---
components/DocsHelp.tsx | 14 +++++++++++++-
pages/overview/code-of-conduct/index.page.tsx | 2 +-
pages/overview/sponsors/index.page.tsx | 2 +-
.../reference/index.page.tsx | 2 +-
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx
index 60e95e1c5..355aeea45 100644
--- a/components/DocsHelp.tsx
+++ b/components/DocsHelp.tsx
@@ -3,7 +3,13 @@ import React, { FormEvent, useRef, useState } from 'react';
import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment';
interface DocsHelpProps {
- fileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md';
+ fileRenderType?:
+ | '_indexmd'
+ | 'indexmd'
+ | 'tsx'
+ | '_md'
+ | 'sponsors'
+ | 'code_of_conduct';
}
export function DocsHelp({ fileRenderType }: DocsHelpProps) {
const router = useRouter();
@@ -19,6 +25,12 @@ export function DocsHelp({ fileRenderType }: DocsHelpProps) {
gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/_index.md'}`;
} else if (fileRenderType === 'indexmd') {
gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.md'}`;
+ } else if (fileRenderType === 'sponsors') {
+ gitredirect =
+ 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md';
+ } else if (fileRenderType === 'code_of_conduct') {
+ gitredirect =
+ 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md';
} else {
gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '.md'}`;
}
diff --git a/pages/overview/code-of-conduct/index.page.tsx b/pages/overview/code-of-conduct/index.page.tsx
index d057a559c..c7370e69b 100644
--- a/pages/overview/code-of-conduct/index.page.tsx
+++ b/pages/overview/code-of-conduct/index.page.tsx
@@ -29,7 +29,7 @@ export default function Content({
content: any;
}) {
const newTitle = 'Code of Conduct';
- const fileRenderType = 'tsx';
+ const fileRenderType = 'code_of_conduct';
return (
diff --git a/pages/overview/sponsors/index.page.tsx b/pages/overview/sponsors/index.page.tsx
index a65500c3a..58a586d85 100644
--- a/pages/overview/sponsors/index.page.tsx
+++ b/pages/overview/sponsors/index.page.tsx
@@ -21,7 +21,7 @@ export async function getStaticProps() {
export default function ContentExample({ blocks }: { blocks: any[] }) {
const newTitle = 'Sponsors';
- const fileRenderType = '_indexmd';
+ const fileRenderType = 'sponsors';
return (
diff --git a/pages/understanding-json-schema/reference/index.page.tsx b/pages/understanding-json-schema/reference/index.page.tsx
index 76e3b7037..2447e6d6d 100644
--- a/pages/understanding-json-schema/reference/index.page.tsx
+++ b/pages/understanding-json-schema/reference/index.page.tsx
@@ -20,7 +20,7 @@ export async function getStaticProps() {
}
export default function ContentExample({ blocks }: { blocks: any[] }) {
- const fileRenderType = 'tsx';
+ const fileRenderType = '_indexmd';
return (
From 336c74749094ea97ba61e148bfe795d154d1b4b4 Mon Sep 17 00:00:00 2001
From: Yashwanth1906
Date: Tue, 31 Dec 2024 15:33:56 +0530
Subject: [PATCH 5/8] test-added-for-the-changes
---
cypress/components/DocsHelp.cy.tsx | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/cypress/components/DocsHelp.cy.tsx b/cypress/components/DocsHelp.cy.tsx
index c97a865b0..3a77c7508 100644
--- a/cypress/components/DocsHelp.cy.tsx
+++ b/cypress/components/DocsHelp.cy.tsx
@@ -234,12 +234,14 @@ describe('DocsHelp Component', () => {
// This test is to check component render correctly with different markdown files
it('should render component with different markdown files and validate gitredirect', () => {
- const fileRenderTypes: ('tsx' | 'indexmd' | '_indexmd' | '_md')[] = [
- 'tsx',
- '_indexmd',
- 'indexmd',
- '_md',
- ];
+ const fileRenderTypes: (
+ | 'tsx'
+ | 'indexmd'
+ | '_indexmd'
+ | '_md'
+ | 'sponsors'
+ | 'code_of_conduct'
+ )[] = ['tsx', '_indexmd', 'indexmd', '_md', 'sponsors', 'code_of_conduct'];
fileRenderTypes.forEach((type) => {
let expectedGitRedirect = '';
@@ -250,6 +252,12 @@ describe('DocsHelp Component', () => {
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/_index.md'}`;
} else if (type === 'indexmd') {
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/index.md'}`;
+ } else if (type === 'sponsors') {
+ expectedGitRedirect =
+ 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md';
+ } else if (type === 'code_of_conduct') {
+ expectedGitRedirect =
+ 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md';
} else {
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '.md'}`;
}
From 41029df87b01da0c3a3410d0feb8f4a27c791a46 Mon Sep 17 00:00:00 2001
From: Yashwanth1906
Date: Fri, 17 Jan 2025 18:17:12 +0530
Subject: [PATCH 6/8] made-the-component-flexible
---
components/DocsHelp.tsx | 21 ++++++----------
cypress/components/DocsHelp.cy.tsx | 25 +++++++------------
pages/implementers/index.page.tsx | 5 +---
pages/overview/code-of-conduct/index.page.tsx | 3 ++-
pages/overview/sponsors/index.page.tsx | 3 ++-
.../understanding-json-schema/index.page.tsx | 5 +---
6 files changed, 22 insertions(+), 40 deletions(-)
diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx
index 355aeea45..da58226e8 100644
--- a/components/DocsHelp.tsx
+++ b/components/DocsHelp.tsx
@@ -3,13 +3,7 @@ import React, { FormEvent, useRef, useState } from 'react';
import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment';
interface DocsHelpProps {
- fileRenderType?:
- | '_indexmd'
- | 'indexmd'
- | 'tsx'
- | '_md'
- | 'sponsors'
- | 'code_of_conduct';
+ fileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md' | string;
}
export function DocsHelp({ fileRenderType }: DocsHelpProps) {
const router = useRouter();
@@ -19,18 +13,17 @@ export function DocsHelp({ fileRenderType }: DocsHelpProps) {
const [error, setError] = useState('');
const feedbackFormRef = useRef(null);
let gitredirect = '';
- if (fileRenderType === 'tsx') {
+ if (
+ typeof fileRenderType === 'string' &&
+ fileRenderType.startsWith('https://')
+ ) {
+ gitredirect = fileRenderType;
+ } else if (fileRenderType === 'tsx') {
gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.page.tsx'}`;
} else if (fileRenderType === '_indexmd') {
gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/_index.md'}`;
} else if (fileRenderType === 'indexmd') {
gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.md'}`;
- } else if (fileRenderType === 'sponsors') {
- gitredirect =
- 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md';
- } else if (fileRenderType === 'code_of_conduct') {
- gitredirect =
- 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md';
} else {
gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '.md'}`;
}
diff --git a/cypress/components/DocsHelp.cy.tsx b/cypress/components/DocsHelp.cy.tsx
index 3a77c7508..42eaf7f41 100644
--- a/cypress/components/DocsHelp.cy.tsx
+++ b/cypress/components/DocsHelp.cy.tsx
@@ -234,30 +234,23 @@ describe('DocsHelp Component', () => {
// This test is to check component render correctly with different markdown files
it('should render component with different markdown files and validate gitredirect', () => {
- const fileRenderTypes: (
- | 'tsx'
- | 'indexmd'
- | '_indexmd'
- | '_md'
- | 'sponsors'
- | 'code_of_conduct'
- )[] = ['tsx', '_indexmd', 'indexmd', '_md', 'sponsors', 'code_of_conduct'];
+ const fileRenderTypes: ('tsx' | 'indexmd' | '_indexmd' | '_md')[] = [
+ 'tsx',
+ '_indexmd',
+ 'indexmd',
+ '_md',
+ ];
fileRenderTypes.forEach((type) => {
let expectedGitRedirect = '';
-
- if (type === 'tsx') {
+ if (typeof type === 'string' && type.startsWith('https://')) {
+ expectedGitRedirect = type;
+ } else if (type === 'tsx') {
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/index.page.tsx'}`;
} else if (type === '_indexmd') {
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/_index.md'}`;
} else if (type === 'indexmd') {
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/index.md'}`;
- } else if (type === 'sponsors') {
- expectedGitRedirect =
- 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md';
- } else if (type === 'code_of_conduct') {
- expectedGitRedirect =
- 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md';
} else {
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '.md'}`;
}
diff --git a/pages/implementers/index.page.tsx b/pages/implementers/index.page.tsx
index 0d49b0d42..6b056bd06 100644
--- a/pages/implementers/index.page.tsx
+++ b/pages/implementers/index.page.tsx
@@ -17,9 +17,6 @@ export async function getStaticProps() {
},
};
}
-
-export default function ContentExample({ blocks }: { blocks: any[] }) {
- const fileRenderType = '_indexmd';
export default function ContentExample({
blocks,
}: {
@@ -27,7 +24,7 @@ export default function ContentExample({
frontmatter: any;
content: any;
}) {
-
+ const fileRenderType = '_indexmd';
return (
diff --git a/pages/overview/code-of-conduct/index.page.tsx b/pages/overview/code-of-conduct/index.page.tsx
index ded68b47b..75e6000f2 100644
--- a/pages/overview/code-of-conduct/index.page.tsx
+++ b/pages/overview/code-of-conduct/index.page.tsx
@@ -29,7 +29,8 @@ export default function Content({
content: any;
}) {
const newTitle = 'Code of Conduct';
- const fileRenderType = 'code_of_conduct';
+ const fileRenderType =
+ 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md';
return (
diff --git a/pages/overview/sponsors/index.page.tsx b/pages/overview/sponsors/index.page.tsx
index 58a586d85..c3c59d4ee 100644
--- a/pages/overview/sponsors/index.page.tsx
+++ b/pages/overview/sponsors/index.page.tsx
@@ -21,7 +21,8 @@ export async function getStaticProps() {
export default function ContentExample({ blocks }: { blocks: any[] }) {
const newTitle = 'Sponsors';
- const fileRenderType = 'sponsors';
+ const fileRenderType =
+ 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md';
return (
diff --git a/pages/understanding-json-schema/index.page.tsx b/pages/understanding-json-schema/index.page.tsx
index 3ff5af08f..40ed5c449 100644
--- a/pages/understanding-json-schema/index.page.tsx
+++ b/pages/understanding-json-schema/index.page.tsx
@@ -19,9 +19,6 @@ export async function getStaticProps() {
},
};
}
-
-export default function ContentExample({ blocks }: { blocks: any[] }) {
- const fileRenderType = '_indexmd';
export default function ContentExample({
blocks,
}: {
@@ -29,7 +26,7 @@ export default function ContentExample({
frontmatter: any;
content: any;
}) {
-
+ const fileRenderType = '_indexmd';
return (
From 8844cb50d8840464be8d479cf3fc5fa2ac62cdfe Mon Sep 17 00:00:00 2001
From: Yashwanth1906
Date: Sat, 18 Jan 2025 00:25:39 +0530
Subject: [PATCH 7/8] fixed-the-test-issue
---
cypress/components/DocsHelp.cy.tsx | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/cypress/components/DocsHelp.cy.tsx b/cypress/components/DocsHelp.cy.tsx
index 42eaf7f41..7d2dd7162 100644
--- a/cypress/components/DocsHelp.cy.tsx
+++ b/cypress/components/DocsHelp.cy.tsx
@@ -262,5 +262,12 @@ describe('DocsHelp Component', () => {
expectedGitRedirect,
);
});
+ const customLink = 'https://example.com/custom-docs';
+ cy.mount();
+ cy.get('[data-test="edit-on-github-link"]').should(
+ 'have.attr',
+ 'href',
+ customLink,
+ );
});
});
From 233d6fd514bd2bd01e81f99cd120c171be1023e8 Mon Sep 17 00:00:00 2001
From: Yashwanth1906
Date: Sat, 18 Jan 2025 23:59:21 +0530
Subject: [PATCH 8/8] added-showEditOption-functionality
---
components/DocsHelp.tsx | 50 +++++++++++++++++-------------
cypress/components/DocsHelp.cy.tsx | 10 ++++++
2 files changed, 38 insertions(+), 22 deletions(-)
diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx
index da58226e8..8fa21d48b 100644
--- a/components/DocsHelp.tsx
+++ b/components/DocsHelp.tsx
@@ -4,8 +4,12 @@ import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment';
interface DocsHelpProps {
fileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md' | string;
+ showEditOption?: boolean;
}
-export function DocsHelp({ fileRenderType }: DocsHelpProps) {
+export function DocsHelp({
+ fileRenderType,
+ showEditOption = true,
+}: DocsHelpProps) {
const router = useRouter();
const [isFormOpen, setIsFormOpen] = useState(false);
const [feedbackStatus, setFeedbackStatus] = useState('');
@@ -308,28 +312,30 @@ export function DocsHelp({ fileRenderType }: DocsHelpProps) {
type of contribution!
-
+
+ Edit this page on Github
+
+
+ )}