Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit 61aa1ea

Browse files
authored
Merge pull request #390 from netdata/feat/track-autmatic-redirects-2903
Feat/track autmatic redirects 2903
2 parents 1db0625 + 247ac88 commit 61aa1ea

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

src/components/header/ACLK/cloud-connection-status.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useCallback } from "react"
1+
import React, { useState, useCallback, useEffect } from "react"
22
import useCloudConnectionStatus from "./use-cloud-connection-status"
33
import CloudConnectionStatusModal from "./cloud-connection-status-modal"
44

@@ -20,6 +20,14 @@ const CloudConnectionStatus = () => {
2020
date: "",
2121
})
2222

23+
useEffect(() => {
24+
if (isModalOpen) {
25+
document.documentElement.style.overflow = "hidden"
26+
} else {
27+
document.documentElement.style.overflow = "auto"
28+
}
29+
}, [isModalOpen])
30+
2331
const openModal = useCallback(() => {
2432
setModalOpen(true)
2533
}, [])

src/domains/dashboard/components/migration-manager/migration-manager.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { selectSignInUrl } from "domains/global/selectors"
1414
import { useRequestRefreshOfAccessMessage } from "hooks/use-user-node-access"
1515
import { selectIsCloudEnabled } from "domains/global/selectors"
16+
import { selectRegistry } from "domains/global/selectors"
1617

1718
// const PROMO_SIGN_UP_CLOUD: PromoProps = { userStatus: "UNKNOWN", nodeClaimedStatus: "NOT_CLAIMED" } //CLOUD
1819
// const PROMO_SIGN_IN_CLOUD: PromoProps = {
@@ -54,8 +55,12 @@ import { selectIsCloudEnabled } from "domains/global/selectors"
5455
// } //CLOUD
5556

5657
const MigrationManager = () => {
57-
const cloudUrl = useSelector(state => selectSignInUrl("go-to-cloud-migration")(state as any))
5858
const cloudEnabled = useSelector(selectIsCloudEnabled)
59+
const registry = useSelector(selectRegistry)
60+
61+
const cloudUrl = useSelector(state =>
62+
selectSignInUrl({ content: "agent-auto-redirect", term: registry.machineGuid })(state as any)
63+
)
5964

6065
const linkToCoud = useMemo(() => {
6166
const { href } = window.location
@@ -72,12 +77,21 @@ const MigrationManager = () => {
7277

7378
const prefrenceID = migrationModalPromoInfo?.tickBoxOption.prefrenceID || ""
7479

75-
const [hasPromoSelectionSaved, savePromoRemindMeSelection] = useLocalStorage(prefrenceID)
80+
/**
81+
* There is seem to be a bug when we are using the useLocalStorage,
82+
* the value to be returned does not change when prefrenceID is changing.
83+
* For that reason we acces the localStorage directly
84+
*/
85+
const [, savePromoRemindMeSelection] = useLocalStorage(prefrenceID)
86+
const hasPromoSelectionSaved = localStorage.getItem(prefrenceID)
7687

7788
const closeModal = () => {
7889
setModalOpen(false)
7990
}
8091

92+
const isPromoEligibleForShow =
93+
cloudEnabled && migrationModalPromoInfo && isModalOpen && !hasPromoSelectionSaved
94+
8195
const requestRefreshOfAccess = useRequestRefreshOfAccessMessage()
8296

8397
/** We are delaying the show of modal because some time the userNodeAccess is equal to null
@@ -93,14 +107,24 @@ const MigrationManager = () => {
93107
}, [])
94108

95109
useEffect(() => {
96-
if (goToCloud({ userSavedPreference, ...userNodeAccess })) window.location.href = linkToCoud
110+
if (goToCloud({ userSavedPreference, ...userNodeAccess })) {
111+
window.location.href = linkToCoud
112+
}
97113
}, [linkToCoud, userNodeAccess, userSavedPreference])
98114

99115
useEffect(() => {
100116
if (goToAgentDashboard({ userSavedPreference })) console.log("Lets go to Agent")
101117
}, [userSavedPreference])
102118

103-
if (cloudEnabled && migrationModalPromoInfo && isModalOpen && !hasPromoSelectionSaved)
119+
useEffect(() => {
120+
if (isPromoEligibleForShow) {
121+
document.documentElement.style.overflow = "hidden"
122+
} else {
123+
document.documentElement.style.overflow = "auto"
124+
}
125+
}, [isModalOpen])
126+
127+
if (isPromoEligibleForShow)
104128
return (
105129
<MigrationModal
106130
savePromoRemindMeSelection={savePromoRemindMeSelection}

0 commit comments

Comments
 (0)