Skip to content

Commit

Permalink
Fix UI to access Support tools if registered (#2624)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinapurapu committed Feb 2, 2023
1 parent fecf484 commit fba06cf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 44 deletions.
5 changes: 5 additions & 0 deletions portal-ui/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ export const getLogoVar = (): LogoVar => {
}
return logoVar;
};

export const registeredCluster = (): boolean => {
const plan = getLogoVar();
return plan === "standard" || plan === "enterprise";
};
16 changes: 6 additions & 10 deletions portal-ui/src/screens/Console/HealthInfo/HealthInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
healthInfoResetMessage,
} from "./healthInfoSlice";
import RegisterCluster from "../Support/RegisterCluster";
import { registeredCluster } from "../../../config";

const styles = (theme: Theme) =>
createStyles({
Expand Down Expand Up @@ -102,12 +103,7 @@ const HealthInfo = ({ classes }: IHealthInfo) => {

const message = useSelector((state: AppState) => state.healthInfo.message);

const licenseInfo = useSelector(
(state: AppState) => state?.system?.licenseInfo
);

const { plan = "" } = licenseInfo || {};
const registeredCluster = plan === "STANDARD" || plan === "ENTERPRISE";
const clusterRegistered = registeredCluster();

const serverDiagnosticStatus = useSelector(
(state: AppState) => state.system.serverDiagnosticStatus
Expand Down Expand Up @@ -256,7 +252,7 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
}, [startDiagnostic, dispatch]);

const startDiagnosticAction = () => {
if (plan !== "STANDARD" && plan !== "ENTERPRISE") {
if (!clusterRegistered) {
navigate("/support/register");
return;
}
Expand All @@ -267,7 +263,7 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
<Fragment>
<PageHeader label="Health" />
<PageLayout>
{!registeredCluster && <RegisterCluster compactMode />}
{!clusterRegistered && <RegisterCluster compactMode />}
<Grid item xs={12} className={classes.boxy}>
<TestWrapper title={title} advancedVisible={false}>
<Grid container className={classes.buttons}>
Expand Down Expand Up @@ -305,7 +301,7 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
<Button
id="start-new-diagnostic"
type="submit"
variant={!registeredCluster ? "regular" : "callAction"}
variant={!clusterRegistered ? "regular" : "callAction"}
disabled={startDiagnostic}
onClick={startDiagnosticAction}
label={buttonStartText}
Expand All @@ -317,7 +313,7 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
</Grid>
</TestWrapper>
</Grid>
{!startDiagnostic && registeredCluster && (
{!startDiagnostic && clusterRegistered && (
<Fragment>
<br />
<HelpBox
Expand Down
18 changes: 7 additions & 11 deletions portal-ui/src/screens/Console/Speedtest/Speedtest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { IMessageEvent, w3cwebsocket as W3CWebSocket } from "websocket";
import { Grid } from "@mui/material";
import { Theme } from "@mui/material/styles";
import { useNavigate } from "react-router-dom";
import { AppState } from "../../../store";
import {
Button,
HelpBox,
Expand Down Expand Up @@ -54,6 +53,7 @@ import DistributedOnly from "../Common/DistributedOnly/DistributedOnly";
import { selDistSet } from "../../../systemSlice";
import makeStyles from "@mui/styles/makeStyles";
import RegisterCluster from "../Support/RegisterCluster";
import { registeredCluster } from "../../../config";

const useStyles = makeStyles((theme: Theme) =>
createStyles({
Expand Down Expand Up @@ -85,13 +85,8 @@ const useStyles = makeStyles((theme: Theme) =>

const Speedtest = () => {
const distributedSetup = useSelector(selDistSet);
const licenseInfo = useSelector(
(state: AppState) => state?.system?.licenseInfo
);
const navigate = useNavigate();

const { plan = "" } = licenseInfo || {};
const registeredCluster = plan === "STANDARD" || plan === "ENTERPRISE";
const navigate = useNavigate();

const classes = useStyles();
const [start, setStart] = useState<boolean>(false);
Expand All @@ -108,6 +103,7 @@ const Speedtest = () => {
const [currentValue, setCurrentValue] = useState<number>(0);
const [totalSeconds, setTotalSeconds] = useState<number>(0);
const [speedometerValue, setSpeedometerValue] = useState<number>(0);
const clusterRegistered = registeredCluster();

useEffect(() => {
// begin watch if bucketName in bucketList and start pressed
Expand Down Expand Up @@ -199,7 +195,7 @@ const Speedtest = () => {
const buttonLabel = start ? "Start" : stoppedLabel;

const startSpeedtestButton = () => {
if (plan !== "STANDARD" && plan !== "ENTERPRISE") {
if (!clusterRegistered) {
navigate("/support/register");
return;
}
Expand All @@ -212,7 +208,7 @@ const Speedtest = () => {
<Fragment>
<PageHeader label="Performance" />
<PageLayout>
{!registeredCluster && <RegisterCluster compactMode />}
{!clusterRegistered && <RegisterCluster compactMode />}
{!distributedSetup ? (
<DistributedOnly
iconComponent={<SpeedtestIcon />}
Expand Down Expand Up @@ -313,7 +309,7 @@ const Speedtest = () => {
type="button"
id={"start-speed-test"}
variant={
registeredCluster && currStatus !== null && !start
clusterRegistered && currStatus !== null && !start
? "callAction"
: "regular"
}
Expand All @@ -340,7 +336,7 @@ const Speedtest = () => {
</Grid>
</Grid>

{!start && !currStatus && registeredCluster && (
{!start && !currStatus && clusterRegistered && (
<Fragment>
<br />
<HelpBox
Expand Down
17 changes: 5 additions & 12 deletions portal-ui/src/screens/Console/Support/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import {
containerForHeader,
inlineCheckboxes,
} from "../Common/FormComponents/common/styleLibrary";
import { useSelector } from "react-redux";
import { AppState } from "../../../store";
import { useNavigate } from "react-router-dom";
import RegisterCluster from "./RegisterCluster";
import { registeredCluster } from "../../../config";

const styles = (theme: Theme) =>
createStyles({
Expand Down Expand Up @@ -60,14 +59,8 @@ interface IProfileProps {
var c: any = null;

const Profile = ({ classes }: IProfileProps) => {
const licenseInfo = useSelector(
(state: AppState) => state?.system?.licenseInfo
);
const navigate = useNavigate();

const { plan = "" } = licenseInfo || {};
const registeredCluster = plan === "STANDARD" || plan === "ENTERPRISE";

const [profilingStarted, setProfilingStarted] = useState<boolean>(false);
const [types, setTypes] = useState<string[]>([
"cpu",
Expand All @@ -76,7 +69,7 @@ const Profile = ({ classes }: IProfileProps) => {
"mutex",
"goroutines",
]);

const clusterRegistered = registeredCluster();
const typesList = [
{ label: "cpu", value: "cpu" },
{ label: "mem", value: "mem" },
Expand Down Expand Up @@ -149,7 +142,7 @@ const Profile = ({ classes }: IProfileProps) => {
<Fragment>
<PageHeader label="Profile" />
<PageLayout>
{!registeredCluster && <RegisterCluster compactMode />}
{!clusterRegistered && <RegisterCluster compactMode />}
<Grid item xs={12} className={classes.boxy}>
<Grid item xs={12} className={classes.dropdown}>
<Grid
Expand Down Expand Up @@ -178,10 +171,10 @@ const Profile = ({ classes }: IProfileProps) => {
<Button
id={"start-profiling"}
type="submit"
variant={registeredCluster ? "callAction" : "regular"}
variant={clusterRegistered ? "callAction" : "regular"}
disabled={profilingStarted || types.length < 1}
onClick={() => {
if (!registeredCluster) {
if (!clusterRegistered) {
navigate("/support/register");
return;
}
Expand Down
17 changes: 6 additions & 11 deletions portal-ui/src/screens/Console/Tools/Inspect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ import {
import DistributedOnly from "../Common/DistributedOnly/DistributedOnly";
import KeyRevealer from "./KeyRevealer";
import { selDistSet, setErrorSnackMessage } from "../../../systemSlice";
import { AppState, useAppDispatch } from "../../../store";
import { useAppDispatch } from "../../../store";
import RegisterCluster from "../Support/RegisterCluster";
import { registeredCluster } from "../../../config";

const styles = (theme: Theme) =>
createStyles({
Expand Down Expand Up @@ -100,12 +101,6 @@ const Inspect = ({ classes }: { classes: any }) => {
const dispatch = useAppDispatch();
const navigate = useNavigate();
const distributedSetup = useSelector(selDistSet);
const licenseInfo = useSelector(
(state: AppState) => state?.system?.licenseInfo
);

const { plan = "" } = licenseInfo || {};
const registeredCluster = plan === "STANDARD" || plan === "ENTERPRISE";

const [volumeName, setVolumeName] = useState<string>("");
const [inspectPath, setInspectPath] = useState<string>("");
Expand All @@ -118,7 +113,7 @@ const Inspect = ({ classes }: { classes: any }) => {
const [isFormValid, setIsFormValid] = useState<boolean>(false);
const [volumeError, setVolumeError] = useState<string>("");
const [pathError, setPathError] = useState<string>("");

const clusterRegistered = registeredCluster();
/**
* Validation Effect
*/
Expand Down Expand Up @@ -205,7 +200,7 @@ const Inspect = ({ classes }: { classes: any }) => {
<Fragment>
<PageHeader label={"Inspect"} />
<PageLayout>
{!registeredCluster && <RegisterCluster compactMode />}
{!clusterRegistered && <RegisterCluster compactMode />}
{!distributedSetup ? (
<DistributedOnly
iconComponent={<InspectMenuIcon />}
Expand Down Expand Up @@ -259,7 +254,7 @@ const Inspect = ({ classes }: { classes: any }) => {
autoComplete="off"
onSubmit={(e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (plan !== "STANDARD" && plan !== "ENTERPRISE") {
if (!clusterRegistered) {
navigate("/support/register");
return;
}
Expand Down Expand Up @@ -349,7 +344,7 @@ const Inspect = ({ classes }: { classes: any }) => {
<Button
id={"inspect-start"}
type="submit"
variant={!registeredCluster ? "regular" : "callAction"}
variant={!clusterRegistered ? "regular" : "callAction"}
data-test-id="inspect-submit-button"
disabled={!isFormValid}
label={"Inspect"}
Expand Down

0 comments on commit fba06cf

Please sign in to comment.