Skip to content

Commit e4180bf

Browse files
Revert "SCAL-243399 Developer docs versioning"
This reverts commit cb6e30c.
1 parent efe0d48 commit e4180bf

File tree

8 files changed

+29
-249
lines changed

8 files changed

+29
-249
lines changed

gatsby-node.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const fsExtra = require('fs-extra');
22
const {
33
DOC_NAV_PAGE_ID,
44
NOT_FOUND_PAGE_ID,
5-
VERSION_DROPDOWN,
65
} = require('./src/configs/doc-configs');
76
const { getDocLinkFromEdge } = require('./src/utils/gatsby-utils.js');
87

@@ -85,22 +84,4 @@ exports.createPages = async function ({ actions, graphql }) {
8584
});
8685
}
8786
});
88-
89-
VERSION_DROPDOWN.forEach((version) => {
90-
if (version.link === ' ' || !version.iframeUrl) {
91-
return;
92-
}
93-
94-
const versionPath = version.link.startsWith('/')
95-
? version.link.substring(1)
96-
: version.link;
97-
98-
actions.createPage({
99-
path: `/${versionPath}`,
100-
component: require.resolve(
101-
'./src/components/DevDocTemplate/index.tsx',
102-
),
103-
context: { iframeUrl: version.iframeUrl },
104-
});
105-
});
10687
};

src/components/DevDocTemplate/index.tsx

Lines changed: 21 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import RenderPlayGround from './playGround/RESTAPI';
2424
import GraphQLPlayGround from './playGround/GraphQL';
2525
import { AskDocs } from './askDocs';
2626
import {
27+
DOC_NAV_PAGE_ID,
2728
TS_HOST_PARAM,
2829
TS_ORIGIN_PARAM,
2930
TS_PAGE_ID_PARAM,
@@ -36,7 +37,6 @@ import {
3637
HOME_PAGE_ID,
3738
CUSTOM_PAGE_ID,
3839
BUILD_ENVS,
39-
VERSION_DROPDOWN,
4040
} from '../../configs/doc-configs';
4141
import {
4242
LEFT_NAV_WIDTH_DESKTOP,
@@ -46,19 +46,37 @@ import {
4646
MAX_CONTENT_WIDTH_DESKTOP,
4747
MAIN_HEIGHT_WITHOUT_DOC_CONTENT,
4848
} from '../../constants/uiConstants';
49+
import { getAllPageIds } from '../LeftSidebar/helper';
4950
import t from '../../utils/lang-utils';
5051
import { getHTMLFromComponent } from '../../utils/react-utils';
5152
import { ThemeBuilder } from './playGround/ThemeBuilder';
52-
import VersionIframe from '../VersionIframe';
5353

5454
const DevDocTemplate: FC<DevDocTemplateProps> = (props) => {
5555
const {
5656
data,
5757
location,
5858
pageContext: { namePageIdMap },
5959
} = props;
60+
6061
const isBrowser = () => typeof window !== 'undefined';
6162

63+
useEffect(() => {
64+
if (typeof window !== 'undefined') {
65+
const queryParams = new URLSearchParams(window.location.search);
66+
const pageId = queryParams.get('pageid');
67+
if (pageId) {
68+
queryParams.delete('pageid');
69+
if (queryParams.toString()) {
70+
navigate(`/${pageId}?${queryParams.toString()}`, {
71+
replace: true,
72+
});
73+
} else {
74+
navigate(`/${pageId}`, { replace: true });
75+
}
76+
}
77+
}
78+
}, [location.search, location.pathname]);
79+
6280
const { curPageNode, navNode } = data;
6381

6482
const isHomePage = curPageNode?.pageAttributes?.pageid === HOME_PAGE_ID;
@@ -117,19 +135,9 @@ const DevDocTemplate: FC<DevDocTemplateProps> = (props) => {
117135
const isThemeBuilder =
118136
params[TS_PAGE_ID_PARAM] === CUSTOM_PAGE_ID.THEME_BUILDER;
119137

120-
const isVersionedIframe = VERSION_DROPDOWN.some(
121-
(version) =>
122-
props?.pageContext?.iframeUrl &&
123-
version.iframeUrl === props?.pageContext?.iframeUrl,
124-
);
125-
126138
const isGQPlayGround =
127139
params[TS_PAGE_ID_PARAM] === CUSTOM_PAGE_ID.GQ_PLAYGROUND;
128-
const isPlayGround =
129-
isGQPlayGround ||
130-
isApiPlayground ||
131-
isThemeBuilder ||
132-
isVersionedIframe;
140+
const isPlayGround = isGQPlayGround || isApiPlayground || isThemeBuilder;
133141

134142
const isAskDocsPage = params[TS_PAGE_ID_PARAM] === CUSTOM_PAGE_ID.ASK_DOCS;
135143

@@ -155,23 +163,6 @@ const DevDocTemplate: FC<DevDocTemplateProps> = (props) => {
155163
setKey('dark');
156164
}
157165
}, []);
158-
159-
// Effect to handle URL parameters for dark mode
160-
useEffect(() => {
161-
if (isBrowser()) {
162-
// Check URL for isDarkMode parameter
163-
const urlParams = new URLSearchParams(window.location.search);
164-
const darkModeParam = urlParams.get('isDarkMode');
165-
166-
if (darkModeParam !== null) {
167-
// Update dark mode state from URL parameter
168-
const newDarkMode = darkModeParam === 'true';
169-
setDarkMode(newDarkMode);
170-
localStorage.setItem('theme', newDarkMode ? 'dark' : 'light');
171-
}
172-
}
173-
}, [location.search]);
174-
175166
const getSearch = () => {
176167
const SearchIconHTML = getHTMLFromComponent(<BiSearch />, 'searchIcon');
177168

@@ -224,43 +215,6 @@ const DevDocTemplate: FC<DevDocTemplateProps> = (props) => {
224215
);
225216
}, [location.search, location.hash]);
226217

227-
// Listen for messages from the iframe
228-
useEffect(() => {
229-
const handleMessage = (e) => {
230-
if (e.data?.params || e.data?.subsection) {
231-
console.log('Iframe message:', e.data);
232-
233-
if (e.data?.params?.pageid && typeof window !== 'undefined') {
234-
const isVersionedIframeMessage =
235-
e.origin &&
236-
VERSION_DROPDOWN.some(
237-
(version) =>
238-
version.iframeUrl &&
239-
e.origin.includes(
240-
new URL(version.iframeUrl).hostname,
241-
),
242-
);
243-
244-
if (!isVersionedIframeMessage) {
245-
return;
246-
}
247-
248-
const url = new URL(window.location.href);
249-
250-
// Check if URL has _iframe flag - prevents infinite loops
251-
if (url.searchParams.get('_iframe')) {
252-
return;
253-
}
254-
255-
url.searchParams.set('pageid', e.data.params.pageid);
256-
window.history.replaceState({}, '', url.toString());
257-
}
258-
}
259-
};
260-
window.addEventListener('message', handleMessage);
261-
return () => window.removeEventListener('message', handleMessage);
262-
}, []);
263-
264218
// fetch adoc translated doc edges using graphql
265219

266220
const [results, setResults] = useState([]);
@@ -488,16 +442,6 @@ const DevDocTemplate: FC<DevDocTemplateProps> = (props) => {
488442
return <ThemeBuilder backLink={backLink} />;
489443
}
490444

491-
if (isVersionedIframe) {
492-
return (
493-
<VersionIframe
494-
iframeUrl={props.pageContext.iframeUrl}
495-
isDarkMode={isDarkMode}
496-
location={location}
497-
/>
498-
);
499-
}
500-
501445
return (
502446
<GraphQLPlayGround
503447
location={location}
@@ -598,7 +542,6 @@ type DevDocTemplateProps = {
598542
namePageIdMap: {
599543
[key: string]: string;
600544
};
601-
iframeUrl?: string;
602545
};
603546
location: Location;
604547
};

src/components/Dropdown/index.tsx

Lines changed: 7 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,15 @@
11
import React, { useState, useEffect } from 'react';
22
import { AiOutlineCaretDown } from '@react-icons/all-files/ai/AiOutlineCaretDown';
3-
import { VERSION_DROPDOWN } from '../../configs/doc-configs';
3+
import { VERSION_DROPDOWN, TS_Version } from '../../configs/doc-configs';
44

55
import './index.scss';
66

7-
interface VersionOption {
8-
label: string;
9-
link: string;
10-
subLabel: string;
11-
iframeUrl?: string;
12-
}
13-
147
const Dropdown = (props: { location: Location; isMobile: boolean }) => {
158
const { location } = props;
169
const options = VERSION_DROPDOWN;
17-
const [currentVersion, setCurrentVersion] = useState(options[0]);
10+
const [currentVersion, setCurrentVersion] = useState({});
1811

1912
useEffect(() => {
20-
const currentPath = location.pathname;
21-
if (
22-
currentPath === '/' ||
23-
currentPath.startsWith('/introduction') ||
24-
!currentPath.includes('-')
25-
) {
26-
const latestVersion = options.find(
27-
(option) => option.link === ' ' || option.link === '',
28-
);
29-
if (latestVersion) {
30-
setCurrentVersion(latestVersion);
31-
return;
32-
}
33-
}
34-
35-
const versionFromPath = options.find(
36-
(option) =>
37-
option.link !== ' ' &&
38-
option.link !== '' &&
39-
currentPath.includes(option.link),
40-
);
41-
42-
if (versionFromPath) {
43-
setCurrentVersion(versionFromPath);
44-
return;
45-
}
46-
47-
if (currentPath.startsWith('/docs/')) {
48-
const pathParts = currentPath.split('/');
49-
if (pathParts.length >= 3) {
50-
const versionPathInDocs = pathParts.slice(2).join('/');
51-
const matchingVersion = options.find((option) => {
52-
if (option.link === ' ' || option.link === '') {
53-
return false;
54-
}
55-
const optionPath = option.link.startsWith('/')
56-
? option.link.substring(1)
57-
: option.link;
58-
return optionPath === versionPathInDocs;
59-
});
60-
if (matchingVersion) {
61-
setCurrentVersion(matchingVersion);
62-
return;
63-
}
64-
}
65-
}
66-
6713
const params = new URLSearchParams(location.search);
6814
const version =
6915
params.get('version') || localStorage.getItem('version');
@@ -72,35 +18,14 @@ const Dropdown = (props: { location: Location; isMobile: boolean }) => {
7218
return label === version;
7319
}) || options[0];
7420
if (selectedOption) setCurrentVersion(selectedOption);
75-
}, [location.pathname]);
21+
}, []);
7622

77-
const handelClick = (option: VersionOption) => {
78-
const { label, link, iframeUrl } = option;
79-
const currentPath = location.pathname;
23+
const handelClick = ({ label, link }) => {
24+
// const params = new URLSearchParams(location.search);
25+
// params.set('version', label);
8026

8127
localStorage.setItem('version', label);
82-
83-
// Handle latest version (empty or space link)
84-
if (link === ' ' || link === '') {
85-
// If we're in /docs, stay in /docs for the latest version
86-
if (currentPath.startsWith('/docs')) {
87-
window?.location?.assign('/docs');
88-
} else {
89-
window?.location?.assign('/');
90-
}
91-
return;
92-
}
93-
94-
if (iframeUrl) {
95-
const versionPath = link.startsWith('/') ? link.substring(1) : link;
96-
const targetUrl = currentPath.startsWith('/docs')
97-
? `/docs/${versionPath}`
98-
: `/${versionPath}`;
99-
100-
window?.location?.assign(targetUrl);
101-
} else {
102-
window?.location?.replace(link);
103-
}
28+
window?.location?.replace(link);
10429
};
10530

10631
return (

src/components/LeftSidebar/helper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const isCurrentNavOpen = (liEle: HTMLLIElement, activePageid: string) => {
113113
paraEle &&
114114
isLinkMatching(
115115
(paraEle.children[0] as HTMLAnchorElement)?.href ||
116-
(paraEle.children?.[0]?.children?.[0] as HTMLAnchorElement)
116+
(paraEle.children?.[0].children?.[0] as HTMLAnchorElement)
117117
?.href,
118118
window.location,
119119
activePageid,

src/components/LeftSidebar/index.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,6 @@ const LeftSideBar = (props: {
6161
if (tag) {
6262
tag.classList.add('active');
6363
}
64-
65-
divElement.querySelectorAll('a').forEach((link) => {
66-
const href = link.getAttribute('href');
67-
if (href && !href.includes('://') && !href.startsWith('#')) {
68-
// Only modify internal links (not external or anchor links)
69-
const hasParams = href.includes('?');
70-
const separator = hasParams ? '&' : '?';
71-
link.setAttribute(
72-
'href',
73-
`${href}${separator}isDarkMode=${props.isDarkMode}`,
74-
);
75-
}
76-
});
7764
const updatedHTML = addExpandCollapseImages(
7865
divElement.innerHTML,
7966
params[TS_PAGE_ID_PARAM],

src/components/VersionIframe/index.scss

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/components/VersionIframe/index.tsx

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)