Skip to content

Commit

Permalink
Revert "Add button to disable expert mode from the banner (Issue #5942,…
Browse files Browse the repository at this point in the history
… PR #6000)"

This reverts commit 14147ab.
  • Loading branch information
arnaudsjs committed Nov 5, 2024
1 parent 7a154ab commit 4b8905e
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 291 deletions.
6 changes: 0 additions & 6 deletions changelogs/unreleased/5942-expert-button-banner.yml

This file was deleted.

12 changes: 10 additions & 2 deletions cypress/e2e/scenario-2.4-expert-mode.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,16 @@ if (Cypress.env("edition") === "iso") {
// expect to be redirected on the inventory page, and table to be empty
cy.get('[aria-label="ServiceInventory-Empty"]').should("to.be.visible");

// At the end turn expert mode off through the banner
cy.get("button").contains("Disable").click();
// At the end go back to settings and turn expert mode off
cy.get(".pf-v5-c-nav__item").contains("Settings").click();
cy.get("button").contains("Configuration").click();
cy.get('[aria-label="Row-enable_lsm_expert_mode"]')
.find(".pf-v5-c-switch")
.click();
cy.get('[data-testid="Warning"]').should("exist");
cy.get('[aria-label="Row-enable_lsm_expert_mode"]')
.find('[aria-label="SaveAction"]')
.click();
cy.get('[data-testid="Warning"]').should("not.exist");
cy.get("[id='expert-mode-banner']").should("not.exist");
});
Expand Down
12 changes: 10 additions & 2 deletions cypress/e2e/scenario-2.4-old-expert-mode.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,16 @@ if (Cypress.env("edition") === "iso") {
cy.get("button").contains("Yes").click();
cy.get('[aria-label="ServiceInventory-Empty"').should("to.be.visible");

// At the end turn expert mode off through the banner
cy.get("button").contains("Disable").click();
// At the end go back to settings and turn expert mode off
cy.get(".pf-v5-c-nav__item").contains("Settings").click();
cy.get("button").contains("Configuration").click();
cy.get('[aria-label="Row-enable_lsm_expert_mode"]')
.find(".pf-v5-c-switch")
.click();
cy.get('[data-testid="Warning"]').should("exist");
cy.get('[aria-label="Row-enable_lsm_expert_mode"]')
.find('[aria-label="SaveAction"]')
.click();
cy.get('[data-testid="Warning"]').should("not.exist");
cy.get("[id='expert-mode-banner']").should("not.exist");
});
Expand Down
1 change: 0 additions & 1 deletion src/Data/Managers/V2/POST/UpdateEnvConfig/index.ts

This file was deleted.

71 changes: 0 additions & 71 deletions src/Data/Managers/V2/POST/UpdateEnvConfig/useUpdateEnvConfig.ts

This file was deleted.

134 changes: 0 additions & 134 deletions src/UI/Components/ExpertBanner/ExpertBanner.test.tsx

This file was deleted.

66 changes: 6 additions & 60 deletions src/UI/Components/ExpertBanner/ExpertBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,74 +1,20 @@
import React, { useContext, useEffect, useState } from "react";
import { Banner, Button, Flex, Spinner } from "@patternfly/react-core";
import styled from "styled-components";
import { useUpdateEnvConfig } from "@/Data/Managers/V2/POST/UpdateEnvConfig";
import React, { useContext } from "react";
import { Banner } from "@patternfly/react-core";
import { DependencyContext } from "@/UI/Dependency";
import { words } from "@/UI/words";
import { ToastAlert } from "../ToastAlert";

interface Props {
environmentId: string;
}

/**
* A React component that displays a banner when the expert mode is enabled.
*
* @props {object} props - The properties passed to the component.
* @prop {string} environmentId -The ID of the environment.
* @returns { React.FC<Props> | null} The rendered banner if the expert mode is enabled, otherwise null.
*/
export const ExpertBanner: React.FC<Props> = ({ environmentId }) => {
const [errorMessage, setMessage] = useState<string | undefined>(undefined);
export const ExpertBanner = () => {
const { environmentModifier } = useContext(DependencyContext);
const { mutate, isError, error } = useUpdateEnvConfig(environmentId);
const [isLoading, setIsLoading] = useState(false); // isLoading is to indicate the asynchronous operation is in progress, as we need to wait until setting will be updated, getters are still in the V1 - task https://github.com/inmanta/web-console/issues/5999

useEffect(() => {
if (isError) {
setMessage(error.message);
setIsLoading(false);
}
}, [isError, error]);

return environmentModifier.useIsExpertModeEnabled() ? (
<>
{isError && errorMessage && (
<ToastAlert
data-testid="ToastAlert"
title={words("error")}
message={errorMessage}
setMessage={setMessage}
/>
)}
<React.Fragment>
<Banner
isSticky
variant="red"
id="expert-mode-banner"
aria-label="expertModeActive"
>
<Flex
justifyContent={{ default: "justifyContentCenter" }}
gap={{ default: "gapXs" }}
>
{words("banner.expertMode")}
<Button
variant="link"
isInline
onClick={() => {
setIsLoading(true);
mutate({ id: "enable_lsm_expert_mode", value: false });
}}
>
{words("banner.disableExpertMode")}
</Button>
{isLoading && <StyledSpinner size="sm" />}
</Flex>
LSM expert mode is enabled, proceed with caution.
</Banner>
</>
</React.Fragment>
) : null;
};

const StyledSpinner = styled(Spinner)`
margin-left: 0.5rem;
--pf-v5-c-spinner--Color: white;
`;
6 changes: 2 additions & 4 deletions src/UI/Components/LicenseBanner/LicenseBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext } from "react";
import { Banner, Flex } from "@patternfly/react-core";
import { Banner } from "@patternfly/react-core";
import { DependencyContext } from "@/UI/Dependency";
import { words } from "@/UI/words";

Expand All @@ -16,9 +16,7 @@ export const LicenseBanner: React.FC = () => {

return expirationMessage ? (
<Banner isSticky variant="red" aria-label="licenceExpired">
<Flex justifyContent={{ default: "justifyContentCenter" }}>
{expirationMessage}
</Flex>
{expirationMessage}
</Banner>
) : null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Props {
isOptional: boolean;
isDisabled?: boolean;
handleInputChange: (value) => void;
alreadySelected: string[] | null;
alreadySelected: string[];
multi?: boolean;
}

Expand Down
9 changes: 4 additions & 5 deletions src/UI/Components/UpdateBanner/UpdateBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { useContext, useState } from "react";
import { Banner, Flex } from "@patternfly/react-core";
import { Banner } from "@patternfly/react-core";
import { ApiHelper } from "@/Core";
import { GetVersionFileQueryManager } from "@/Data/Managers/GetVersionFile/OnteTimeQueryManager";
import { DependencyContext } from "@/UI/Dependency";
import { words } from "@/UI/words";

interface Props {
apiHelper: ApiHelper;
Expand All @@ -26,9 +25,9 @@ export const UpdateBanner: React.FunctionComponent<Props> = (props) => {
const banner = (
<React.Fragment>
<Banner isSticky variant="gold" aria-label="newVersionAvailable">
<Flex justifyContent={{ default: "justifyContentCenter" }}>
{words("banner.updateBanner")(currentVersion)}
</Flex>
You are running {currentVersion}, a new version is available! Please
hard-reload (Ctrl+F5 | Cmd + Shift + R) your page to load the new
version.
</Banner>
</React.Fragment>
);
Expand Down
2 changes: 1 addition & 1 deletion src/UI/Root/Components/PageFrame/PageFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const PageFrame: React.FC<React.PropsWithChildren<Props>> = ({
return (
<>
<div role="alert" aria-label="bannerNotifications">
{environmentId && <ExpertBanner environmentId={environmentId} />}
<ExpertBanner />
<LicenseBanner />
</div>
<div className="pf-m-grow" style={{ minHeight: "0%" }}>
Expand Down
Loading

0 comments on commit 4b8905e

Please sign in to comment.