From 1721325ed4fba420ccce0b322be3ba1b22dcfb8d Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 28 Feb 2024 21:25:24 +0100 Subject: [PATCH 001/324] decockpize: remove DevServerWrapper --- web/src/DevServerWrapper.jsx | 129 ------------------------------ web/src/DevServerWrapper.test.jsx | 119 --------------------------- web/src/index.js | 53 +++++------- 3 files changed, 21 insertions(+), 280 deletions(-) delete mode 100644 web/src/DevServerWrapper.jsx delete mode 100644 web/src/DevServerWrapper.test.jsx diff --git a/web/src/DevServerWrapper.jsx b/web/src/DevServerWrapper.jsx deleted file mode 100644 index 456b9c24f1..0000000000 --- a/web/src/DevServerWrapper.jsx +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) [2023] SUSE LLC - * - * All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, contact SUSE LLC. - * - * To contact SUSE LLC about this file by physical or electronic mail, you may - * find current contact information at www.suse.com. - */ - -import React, { useEffect, useRef, useState } from "react"; -import { - Button, - Text, - EmptyState, EmptyStateBody, EmptyStateFooter, EmptyStateHeader, EmptyStateIcon -} from "@patternfly/react-core"; -import { Center, Icon, Loading } from "~/components/layout"; -import { _ } from "~/i18n"; - -// path to any internal Cockpit component to force displaying the login dialog -const loginPath = "/cockpit/@localhost/system/terminal.html"; -// id of the password field in the login dialog -const loginId = "login-password-input"; - -const ErrorIcon = () => ; - -/** - * This is a helper wrapper used in the development server only. It displays - * the Cockpit login page if the user is not authenticated. After successful - * authentication the Agama page is displayed. - * - * @param {React.ReactNode} [props.children] - content to display within the wrapper - * -*/ -export default function DevServerWrapper({ children }) { - const [isLoading, setIsLoading] = useState(true); - const [isAuthenticated, setIsAuthenticated] = useState(null); - const [isError, setIsError] = useState(false); - const iframeRef = useRef(null); - - useEffect(() => { - if (!isLoading) return; - - // get the current login state by querying the "/cockpit/login" path - const xhr = new XMLHttpRequest(); - xhr.ontimeout = () => { - setIsError(true); - setIsLoading(false); - }; - xhr.onloadend = () => { - // 200 = OK - if (xhr.status === 200) - setIsAuthenticated(true); - // 401 = Authentication failed - else if (xhr.status === 401) - setIsAuthenticated(false); - else - setIsError(true); - - setIsLoading(false); - }; - xhr.timeout = 5000; - xhr.open("GET", "/cockpit/login"); - xhr.send(); - }, [isLoading]); - - if (isLoading) return ; - - if (isError) { - // TRANSLATORS: error message, %s is replaced by the server URL - const [msg1, msg2] = _("The server at %s is not reachable.").split("%s"); - return ( -
- - } - /> - - - {msg1} {" "} - - {" "} {msg2} - - - - - - -
- ); - } - - if (isAuthenticated) { - // just display the wrapped content - return children; - } else { - // handle updating the iframe with the login form - const onFrameLoad = () => { - // have a full screen login form - document.getElementById("root").style.maxInlineSize = "none"; - - const passwordInput = iframeRef.current.contentWindow.document.getElementById(loginId); - // reload the window so the manifests.js file referenced from the - // index.html file is also loaded again - if (!passwordInput) window.location.reload(); - }; - - return