From 57469c2747d5a8712206e90d8b3e15fa93ad3f9e Mon Sep 17 00:00:00 2001 From: mateumiralles Date: Fri, 12 Jul 2024 12:53:32 +0000 Subject: [PATCH] Installer dropdown in TopBar --- .../admin-ui/src/components/topbar/TopBar.tsx | 51 +++++++++++-------- .../topbar/dropdownMenus/BaseDropdown.tsx | 11 ++-- .../dropdownMenus/InstallerDropdown.tsx | 37 ++++++++++++++ .../topbar/dropdownMenus/dropdown.scss | 3 ++ .../ProgressLogsView.tsx | 9 ++-- .../installer/components/InstallDnpView.tsx | 10 +++- .../system/components/SystemUpdate/index.tsx | 7 ++- 7 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 packages/admin-ui/src/components/topbar/dropdownMenus/InstallerDropdown.tsx diff --git a/packages/admin-ui/src/components/topbar/TopBar.tsx b/packages/admin-ui/src/components/topbar/TopBar.tsx index dc797b9f5..4e2099bc7 100644 --- a/packages/admin-ui/src/components/topbar/TopBar.tsx +++ b/packages/admin-ui/src/components/topbar/TopBar.tsx @@ -2,6 +2,7 @@ import React from "react"; // DropdownMenu components import DappnodeIdentity from "./dropdownMenus/DappnodeIdentity"; import ChainDataDropdown from "./dropdownMenus/ChainDataDropdown"; +import InstallerDropdown from "./dropdownMenus/InstallerDropdown"; import Notifications from "./dropdownMenus/Notifications"; import Profile from "./dropdownMenus/Profile"; import ThemeSwitch from "./dropdownMenus/ThemeSwitch"; @@ -13,32 +14,42 @@ import "./notifications.scss"; import { AppContextIface } from "types"; import Modules from "./dropdownMenus/Modules"; +// Pkgs Installing data +import { useSelector } from "react-redux"; +import { getProgressLogsByDnp } from "services/isInstallingLogs/selectors"; + export const TopBar = ({ username, appContext }: { username: string; appContext: AppContextIface; -}) => ( -
- {/* Right justified items */} +}) => { + const progressLogsByDnp = useSelector(getProgressLogsByDnp); + const isPkgInstalling = Object.keys(progressLogsByDnp).length !== 0; + + return ( +
+ {/* Right justified items */} - {appContext.theme === "light" ? ( -
- BETA - {/* Theme usage requires more feedback */} - {/* */} + {appContext.theme === "light" ? ( +
+ BETA + {/* Theme usage requires more feedback */} + {/* */} + +
+ ) : ( -
- ) : ( - - )} + )} - -
- - - - -
-); + +
+ {isPkgInstalling && } + + + + +
+ ); +}; diff --git a/packages/admin-ui/src/components/topbar/dropdownMenus/BaseDropdown.tsx b/packages/admin-ui/src/components/topbar/dropdownMenus/BaseDropdown.tsx index a4e6e8cbc..5c8e25aa9 100644 --- a/packages/admin-ui/src/components/topbar/dropdownMenus/BaseDropdown.tsx +++ b/packages/admin-ui/src/components/topbar/dropdownMenus/BaseDropdown.tsx @@ -65,6 +65,8 @@ interface BaseDropdownProps { onClick?: (e: React.MouseEvent) => void; offset?: number; moreVisible?: boolean; + unCollapsed?: boolean; + children?: React.JSX.Element; } function BaseDropdown({ @@ -74,9 +76,11 @@ function BaseDropdown({ onClick, className, placeholder, - moreVisible + moreVisible, + unCollapsed, + children }: BaseDropdownProps) { - const [collapsed, setCollapsed] = useState(true); + const [collapsed, setCollapsed] = useState(unCollapsed ? false : true); const dropdownEl = useRef(null); function onToggle(e: React.MouseEvent) { @@ -177,7 +181,8 @@ function BaseDropdown({
) )} - {!messages.length && placeholder && ( + {children && children} + {!messages.length && placeholder && !children && (
{placeholder}
)}
diff --git a/packages/admin-ui/src/components/topbar/dropdownMenus/InstallerDropdown.tsx b/packages/admin-ui/src/components/topbar/dropdownMenus/InstallerDropdown.tsx new file mode 100644 index 000000000..d5366d5b8 --- /dev/null +++ b/packages/admin-ui/src/components/topbar/dropdownMenus/InstallerDropdown.tsx @@ -0,0 +1,37 @@ +import React from "react"; +import BaseDropdown from "./BaseDropdown"; +import { FiDownload } from "react-icons/fi"; +import { ProgressLogs, ProgressLogsByDnp } from "types"; +import { ProgressLogsView } from "pages/installer/components/InstallCardComponents/ProgressLogsView"; + +export default function InstallerDropdown({ + installLogs +}: { + installLogs: ProgressLogsByDnp; +}) { + const progressCardLogs: ProgressLogs[] = []; + + for (const key in installLogs) { + progressCardLogs.push({ + [key]: installLogs[key][key].toString() + }); + } + + return ( + } + className="installer" + placeholder="No packages installing" + unCollapsed + children={ +
+ {progressCardLogs.map(log => ( + + ))} +
+ } + /> + ); +} diff --git a/packages/admin-ui/src/components/topbar/dropdownMenus/dropdown.scss b/packages/admin-ui/src/components/topbar/dropdownMenus/dropdown.scss index 19b32f626..a1de4118f 100644 --- a/packages/admin-ui/src/components/topbar/dropdownMenus/dropdown.scss +++ b/packages/admin-ui/src/components/topbar/dropdownMenus/dropdown.scss @@ -91,6 +91,9 @@ &.chainstatus > .menu { right: -5.6rem; } + &.installer > .menu { + right: -9rem; + } &.dappnodeidentity > .menu { right: -9.2rem; } diff --git a/packages/admin-ui/src/pages/installer/components/InstallCardComponents/ProgressLogsView.tsx b/packages/admin-ui/src/pages/installer/components/InstallCardComponents/ProgressLogsView.tsx index 9a2f2783f..48cb5d462 100644 --- a/packages/admin-ui/src/pages/installer/components/InstallCardComponents/ProgressLogsView.tsx +++ b/packages/admin-ui/src/pages/installer/components/InstallCardComponents/ProgressLogsView.tsx @@ -3,7 +3,6 @@ import { isEmpty } from "lodash-es"; import { prettyDnpName } from "utils/format"; // Components import ProgressBar from "react-bootstrap/ProgressBar"; -import Card from "components/Card"; import { stringIncludes } from "utils/strings"; import { ProgressLogs } from "types"; @@ -30,7 +29,7 @@ export function ProgressLogsView({ if (!progressLogs || isEmpty(progressLogs)) return null; return ( - + <> {Object.entries(progressLogs) // Don't show "core.dnp.dappnode.eth" actual progress log information .filter(([dnpName]) => dnpName !== "core.dnp.dappnode.eth") @@ -39,10 +38,10 @@ export function ProgressLogsView({ const progressing = Boolean(percent) || stringIncludes(log, "..."); return (
-
+
{prettyDnpName(dnpName)}
-
+
); })} - + ); } diff --git a/packages/admin-ui/src/pages/installer/components/InstallDnpView.tsx b/packages/admin-ui/src/pages/installer/components/InstallDnpView.tsx index 1163f8d22..72e9a6731 100644 --- a/packages/admin-ui/src/pages/installer/components/InstallDnpView.tsx +++ b/packages/admin-ui/src/pages/installer/components/InstallDnpView.tsx @@ -329,13 +329,19 @@ const InstallDnpView: React.FC = ({ return ( <> {progressLogs ? ( - + + + ) : showSuccess ? ( ) : isInstalling ? ( - + + + ) : null} {requiresCoreUpdate && ( diff --git a/packages/admin-ui/src/pages/system/components/SystemUpdate/index.tsx b/packages/admin-ui/src/pages/system/components/SystemUpdate/index.tsx index 16aa96918..f2c2caad4 100644 --- a/packages/admin-ui/src/pages/system/components/SystemUpdate/index.tsx +++ b/packages/admin-ui/src/pages/system/components/SystemUpdate/index.tsx @@ -27,8 +27,11 @@ export default function SystemUpdate() { <> Update {/* This component will automatically hide if logs are empty */} - - + {coreProgressLogs && ( + + + + )} {coreUpdateAvailable ? ( ) : loading ? (