Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topbar Dropdown Installer #1991

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions packages/admin-ui/src/components/topbar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
}) => (
<div id="topbar">
{/* Right justified items */}
}) => {
const progressLogsByDnp = useSelector(getProgressLogsByDnp);
const isPkgInstalling = Object.keys(progressLogsByDnp).length !== 0;

return (
<div id="topbar">
{/* Right justified items */}

{appContext.theme === "light" ? (
<div className="beta">
<span>BETA</span>
{/* Theme usage requires more feedback */}
{/*<UsageSwitch toggleUsage={toggleUsage} /> */}
{appContext.theme === "light" ? (
<div className="beta">
<span>BETA</span>
{/* Theme usage requires more feedback */}
{/*<UsageSwitch toggleUsage={toggleUsage} /> */}
<ThemeSwitch toggleTheme={appContext.toggleTheme} />
</div>
) : (
<ThemeSwitch toggleTheme={appContext.toggleTheme} />
</div>
) : (
<ThemeSwitch toggleTheme={appContext.toggleTheme} />
)}
)}

<DappnodeIdentity />
<div className="topnav-icon-separator" />
<Modules modulesContext={appContext} />
<ChainDataDropdown />
<Notifications />
<Profile username={username} />
</div>
);
<DappnodeIdentity />
<div className="topnav-icon-separator" />
{isPkgInstalling && <InstallerDropdown installLogs={progressLogsByDnp} />}
<Modules modulesContext={appContext} />
<ChainDataDropdown />
<Notifications />
<Profile username={username} />
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ interface BaseDropdownProps {
onClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
offset?: number;
moreVisible?: boolean;
unCollapsed?: boolean;
children?: React.JSX.Element;
}

function BaseDropdown({
Expand All @@ -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<HTMLDivElement>(null);

function onToggle(e: React.MouseEvent<HTMLDivElement, MouseEvent>) {
Expand Down Expand Up @@ -177,7 +181,8 @@ function BaseDropdown({
</div>
)
)}
{!messages.length && placeholder && (
{children && children}
{!messages.length && placeholder && !children && (
<div className="placeholder">{placeholder}</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<BaseDropdown
name="Installer"
messages={[{ type: "info" }]}
Icon={() => <FiDownload size={"1.4em"} />}
className="installer"
placeholder="No packages installing"
unCollapsed
children={
<div style={{ width: "100%" }}>
{progressCardLogs.map(log => (
<ProgressLogsView progressLogs={log} />
))}
</div>
}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
&.chainstatus > .menu {
right: -5.6rem;
}
&.installer > .menu {
right: -9rem;
}
&.dappnodeidentity > .menu {
right: -9.2rem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -30,7 +29,7 @@ export function ProgressLogsView({
if (!progressLogs || isEmpty(progressLogs)) return null;

return (
<Card>
<>
{Object.entries(progressLogs)
// Don't show "core.dnp.dappnode.eth" actual progress log information
.filter(([dnpName]) => dnpName !== "core.dnp.dappnode.eth")
Expand All @@ -39,10 +38,10 @@ export function ProgressLogsView({
const progressing = Boolean(percent) || stringIncludes(log, "...");
return (
<div key={dnpName} className="row">
<div className="col-6 text-truncate">
<div className="col-4 text-truncate">
<span>{prettyDnpName(dnpName)}</span>
</div>
<div className="col-6 text-truncate center">
<div className="col-8 text-truncate center">
<ProgressBar
now={percent ? parseInt(percent) : 100}
animated={progressing}
Expand All @@ -53,6 +52,6 @@ export function ProgressLogsView({
</div>
);
})}
</Card>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,19 @@ const InstallDnpView: React.FC<InstallDnpViewProps> = ({
return (
<>
{progressLogs ? (
<ProgressLogsView progressLogs={progressLogs} />
<Card>
<ProgressLogsView progressLogs={progressLogs} />
</Card>
) : showSuccess ? (
<Card spacing>
<StatusIcon success={true} message="Successfully installed!" />
</Card>
) : isInstalling ? (
<ProgressLogsView progressLogs={{ [dnpName]: "Sending request..." }} />
<Card>
<ProgressLogsView
progressLogs={{ [dnpName]: "Sending request..." }}
/>
</Card>
) : null}

{requiresCoreUpdate && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export default function SystemUpdate() {
<>
<SubTitle>Update</SubTitle>
{/* This component will automatically hide if logs are empty */}
<ProgressLogsView progressLogs={coreProgressLogs} />

{coreProgressLogs && (
<Card>
<ProgressLogsView progressLogs={coreProgressLogs} />
</Card>
)}
{coreUpdateAvailable ? (
<SystemUpdateDetails />
) : loading ? (
Expand Down
Loading