Skip to content
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
2 changes: 2 additions & 0 deletions web/src/components/overview/InstallationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import StorageSummary from "~/components/overview/StorageSummary";
import NetworkSummary from "~/components/overview/NetworkSummary";
import SoftwareSummary from "~/components/overview/SoftwareSummary";
import RegistrationSummary from "~/components/overview/RegistrationSummary";
import UsersSummary from "~/components/overview/UsersSummary";
import { _ } from "~/i18n";

import a11yStyles from "@patternfly/react-styles/css/utilities/Accessibility/accessibility";
Expand All @@ -54,6 +55,7 @@ export default function InstallationSummarySection() {
<NetworkSummary />
<SoftwareSummary />
<StorageSummary />
<UsersSummary />
</div>
</NestedContent>
</>
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/overview/RegistrationSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { useIssues } from "~/hooks/model/issue";
const Content = () => {
const { registration } = useSystem();
const issues = useIssues("software");
const hasIssues = issues.find((i) => i.class === "software.register_system") !== undefined;
const hasIssues = issues.find((i) => i.class === "software.missing_registration") !== undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🙏


// TRANSLATORS: Brief summary about the product registration.
// %s will be replaced with the last 4 digits of the registration code.
Expand Down
9 changes: 2 additions & 7 deletions web/src/components/overview/StorageSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import React from "react";
import { sprintf } from "sprintf-js";
import { isEmpty } from "radashi";
import Summary from "~/components/core/Summary";
import Link from "~/components/core/Link";
import { useProgressTracking } from "~/hooks/use-progress-tracking";
Expand Down Expand Up @@ -156,15 +155,11 @@ const Description = () => {
*/
export default function StorageSummary() {
const { loading } = useProgressTracking("storage");
// FIXME: Refactor for avoid duplicating these checks about issues and actions
// TODO: extend tests for covering the hasIssues status
const actions = useActions();
const issues = useIssues("storage");
const configIssues = issues.filter((i) => i.class !== "proposal");
const hasIssues = !!useIssues("storage").length;

return (
<Summary
hasIssues={!isEmpty(configIssues) || isEmpty(actions)}
hasIssues={hasIssues}
icon="hard_drive"
title={
<Link to={STORAGE.root} variant="link" isInline>
Expand Down
105 changes: 105 additions & 0 deletions web/src/components/overview/UsersSummary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) [2026] SUSE LLC
*
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* 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 from "react";
import { sprintf } from "sprintf-js";
import { useProgressTracking } from "~/hooks/use-progress-tracking";
import { useConfig } from "~/hooks/model/config";
import { useIssues } from "~/hooks/model/issue";
import { USER } from "~/routes/paths";
import { _ } from "~/i18n";
import Summary from "~/components/core/Summary";
import Link from "~/components/core/Link";

const rootConfigured = (config) => {
if (!config.root) return false;

const { password, sshPublicKey } = config.root;
if (password && password !== "") return true;
if (sshPublicKey && sshPublicKey !== "") return true;

return false;
};

const userConfigured = (config) => {
if (!config.user) return false;

const { userName, fullName, password } = config.user;
return userName !== "" && fullName !== "" && password !== "";
};

/**
* Renders a summary text describing the authentication configuration.
*/
const Value = () => {
const config = useConfig();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP: this is fully ok, but I wanted to mention that I tend to get the config in the main component and pass down via prop. I do so just to save some observers at TanstackQuery layer and because in this kind of simple, one level nesting components looks like a good compromise.

const root = rootConfigured(config);
const user = userConfigured(config);

if (!root && !user) return _("Not configured yet");
if (root && !user) return _("Configured for the root user");

const userName = config.user.userName;
// TRANSLATORS: %s is a username like 'jdoe'
if (root) return sprintf(_("Configured for root and user '%s'"), userName);

// TRANSLATORS: %s is a username like 'jdoe'
return sprintf(_("Configured for user '%s'"), userName);
};

/**
* Renders the estimated disk space required for the installation.
*/
const Description = () => {
const config = useConfig();
if (!rootConfigured(config)) return;

const password = config.root.password || "";
const sshKey = config.root.sshPublicKey || "";

if (password !== "" && sshKey !== "") return _("Root login with password and SSH key");
if (password !== "") return _("Root login with password");
return _("Root login with SSH key");
};

/**
* A software installation summary.
*/
export default function UsersSummary() {
const { loading } = useProgressTracking("users");
const hasIssues = !!useIssues("users").length;

return (
<Summary
hasIssues={hasIssues}
icon="manage_accounts"
title={
<Link to={USER.root} variant="link" isInline>
{_("Authentication")}
</Link>
}
value={<Value />}
description={<Description />}
isLoading={loading}
/>
);
}
28 changes: 18 additions & 10 deletions web/src/components/users/FirstUser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,25 @@ import { installerRender } from "~/test-utils";
import FirstUser from "./FirstUser";
import { USER } from "~/routes/paths";

const mockFirstUser = jest.fn();
const mockRemoveFirstUserMutation = jest.fn();
const mockProposal = jest.fn();
const mockRemoveUser = jest.fn();

jest.mock("~/queries/users", () => ({
...jest.requireActual("~/queries/users"),
useFirstUser: () => mockFirstUser(),
useRemoveFirstUserMutation: () => ({
mutate: mockRemoveFirstUserMutation,
}),
jest.mock("~/hooks/model/proposal", () => ({
...jest.requireActual("~/hooks/model/proposal"),
useProposal: () => mockProposal(),
}));

jest.mock("~/hooks/model/config/user", () => ({
...jest.requireActual("~/hooks/model/config/user"),
useRemoveUser: () => mockRemoveUser,
}));

describe("FirstUser", () => {
describe("when the user is not defined yet", () => {
beforeEach(() => {
mockProposal.mockReturnValue({});
});

it("renders a link to define it", () => {
installerRender(<FirstUser />);
const createLink = screen.getByRole("link", { name: "Define a user now" });
Expand All @@ -48,7 +54,9 @@ describe("FirstUser", () => {

describe("when the user is already defined", () => {
beforeEach(() => {
mockFirstUser.mockReturnValue({ fullName: "Gecko Migo", userName: "gmigo" });
mockProposal.mockReturnValue({
users: { user: { fullName: "Gecko Migo", userName: "gmigo" } },
});
});

it("renders the fullname and username", () => {
Expand All @@ -69,7 +77,7 @@ describe("FirstUser", () => {
await user.click(moreActionsToggle);
const discardAction = screen.getByRole("menuitem", { name: "Discard" });
await user.click(discardAction);
expect(mockRemoveFirstUserMutation).toHaveBeenCalled();
expect(mockRemoveUser).toHaveBeenCalled();
});
});
});
19 changes: 13 additions & 6 deletions web/src/components/users/FirstUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,23 @@ import {
} from "@patternfly/react-core";
import { Link, Page, SplitButton } from "~/components/core";
import PasswordCheck from "~/components/users/PasswordCheck";
import { useFirstUser, useFirstUserChanges, useRemoveFirstUserMutation } from "~/queries/users";
// This should be based on the config, not on the proposal. As a temporary hack (introduced in a
// separate commit that should be easy to revert), we are using the proposal because the config
// does not emit an event on every change.
import { useProposal } from "~/hooks/model/proposal";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP: not related specifically to your code here, but it is kind of a mess sometimes having ~/hooks/model/proposal/whatever and sometimes, like here, not. Hard to follow/understand.

import { useRemoveUser } from "~/hooks/model/config/user";
import { PATHS } from "~/routes/users";
import { isEmpty } from "radashi";
import { _ } from "~/i18n";

const useUser = () => {
const proposal = useProposal().users;
return proposal?.user;
};

const UserActions = () => {
const user = useFirstUser();
const { mutate: removeUser } = useRemoveFirstUserMutation();
const user = useUser();
const removeUser = useRemoveUser();

if (isEmpty(user?.userName)) {
return (
Expand All @@ -60,7 +69,7 @@ const UserActions = () => {
};

const UserData = () => {
const user = useFirstUser();
const user = useUser();
const fullnameTermId = useId();
const usernameTermId = useId();

Expand Down Expand Up @@ -94,8 +103,6 @@ const UserData = () => {
};

export default function FirstUser() {
useFirstUserChanges();

return (
<Page.Section
title={_("First user")}
Expand Down
Loading