Skip to content

Commit e152f85

Browse files
Merge pull request #307 from thoughtspot/dd
Dropdown selection not working
2 parents 68c3774 + 7d52604 commit e152f85

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/components/Dropdown/index.tsx

+26-13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,28 @@ const Dropdown = (props: { location: Location; isMobile: boolean }) => {
1818

1919
useEffect(() => {
2020
const currentPath = location.pathname;
21+
22+
// First check if we're on a versioned path
23+
const versionFromPath = options.find(
24+
(option) =>
25+
option.link !== ' ' &&
26+
option.link !== '' &&
27+
(currentPath.includes(`/${option.link}`) ||
28+
currentPath.includes(
29+
`/${option.link.replace(/\./g, '-')}`,
30+
)),
31+
);
32+
33+
if (versionFromPath) {
34+
setCurrentVersion(versionFromPath);
35+
return;
36+
}
37+
38+
// Check for latest version paths
2139
if (
2240
currentPath === '/' ||
41+
currentPath === '/docs' ||
42+
currentPath === '/docs/' ||
2343
currentPath.startsWith('/introduction') ||
2444
!currentPath.includes('-')
2545
) {
@@ -32,18 +52,7 @@ const Dropdown = (props: { location: Location; isMobile: boolean }) => {
3252
}
3353
}
3454

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-
55+
// Check in /docs/ path
4756
if (currentPath.startsWith('/docs/')) {
4857
const pathParts = currentPath.split('/');
4958
if (pathParts.length >= 3) {
@@ -55,7 +64,10 @@ const Dropdown = (props: { location: Location; isMobile: boolean }) => {
5564
const optionPath = option.link.startsWith('/')
5665
? option.link.substring(1)
5766
: option.link;
58-
return optionPath === versionPathInDocs;
67+
return (
68+
optionPath === versionPathInDocs ||
69+
optionPath.replace(/\./g, '-') === versionPathInDocs
70+
);
5971
});
6072
if (matchingVersion) {
6173
setCurrentVersion(matchingVersion);
@@ -64,6 +76,7 @@ const Dropdown = (props: { location: Location; isMobile: boolean }) => {
6476
}
6577
}
6678

79+
// Fallback to query params or localStorage
6780
const params = new URLSearchParams(location.search);
6881
const version =
6982
params.get('version') || localStorage.getItem('version');

0 commit comments

Comments
 (0)