Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect users to correct installation tab based on OS #3676

Merged
merged 10 commits into from
Dec 5, 2022
42 changes: 35 additions & 7 deletions website/src/theme/Tabs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ function getQueryVariable(query, variable) {
// substring query
const vars = query.substring(1).split('&');
for (let i = 0; i < vars.length; i++) {
let pair = vars[i].split('=');
console.log(decodeURIComponent(pair[0]), variable)
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
let pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
return null;
}
Expand All @@ -27,6 +26,34 @@ function getQueryVariable(query, variable) {
function isTabItem(comp) {
return 'value' in comp.props;
}

function getOSName() {
const userAgent = navigator.userAgent;
if (userAgent.indexOf('Windows') > -1) {
return 'Windows';
} else if (userAgent.indexOf('Mac') > -1) {
return 'Mac';
} else if (userAgent.indexOf('X11') > -1) {
return 'UNIX';
} else if (userAgent.indexOf('Linux') > -1) {
return 'Linux';
} else {
return 'Other';
}
}

function getInstallationTabType() {
const osName = getOSName();
if (osName === 'Windows') {
return 'windows';
} else if (osName === 'Mac') {
return 'mac';
} else if(osName === 'Linux' || osName === 'UNIX') {
return 'python';
}
return '';
}

function TabsComponent(props) {
const {
lazy,
Expand Down Expand Up @@ -82,10 +109,11 @@ function TabsComponent(props) {
);
}
const { tabGroupChoices, setTabGroupChoices } = useTabGroupChoice();

const { pathname, search } = useLocation()
const value = getQueryVariable(search, 'tab')
const [selectedValue, setSelectedValue] = useState(value ? value : defaultValue);
const osTabValue = getInstallationTabType()
const [selectedValue, setSelectedValue] = useState(pathname.startsWith("/terminal/quickstart/installation") ? value ? ['mac', 'windows', 'python', 'docker'].includes(value) ? value : osTabValue : osTabValue : defaultValue);
const tabRefs = [];
const { blockElementScrollPositionUntilNextRender } =
useScrollPositionBlocker();
Expand Down
7 changes: 1 addition & 6 deletions website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@
"fs-extra" "^10.1.0"
"lodash" "^4.17.21"
"tslib" "^2.4.0"

"@docusaurus/plugin-content-blog@2.2.0":
"integrity" "sha512-0mWBinEh0a5J2+8ZJXJXbrCk1tSTNf7Nm4tYAl5h2/xx+PvH/Bnu0V+7mMljYm/1QlDYALNIIaT/JcoZQFUN3w=="
"resolved" "https://registry.npmjs.org/@docusaurus/plugin-content-blog/-/plugin-content-blog-2.2.0.tgz"
Expand Down Expand Up @@ -4299,11 +4299,6 @@
"resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
"version" "1.0.0"

"fsevents@~2.3.2":
"integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA=="
"resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
"version" "2.3.2"

"function-bind@^1.1.1":
"integrity" "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
"resolved" "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"
Expand Down