Skip to content

Commit

Permalink
[web] Some code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Nov 3, 2023
1 parent 396c559 commit 89e629d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
20 changes: 12 additions & 8 deletions web/src/components/overview/ProductSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

import React, { useEffect, useState } from "react";
import { Text } from "@patternfly/react-core";
import { useCancellablePromise } from "~/utils";
import { toValidationError, useCancellablePromise } from "~/utils";
import { useInstallerClient } from "~/context/installer";
import { useProduct } from "~/context/product";
import { Section, SectionSkeleton } from "~/components/core";
import { If, Section, SectionSkeleton } from "~/components/core";
import { _ } from "~/i18n";

const errorsFrom = (issues) => {
const errors = issues.filter(i => i.severity === "error");
return errors.map(e => ({ message: e.description }));
return errors.map(toValidationError);
};

export default function ProductSection() {
Expand All @@ -44,12 +44,16 @@ export default function ProductSection() {
}, [cancellablePromise, setIssues, software]);

const Content = ({ isLoading = false }) => {
if (isLoading) return <SectionSkeleton numRows={1} />;

return (
<Text>
{selectedProduct?.name}
</Text>
<If
condition={isLoading}
then={<SectionSkeleton numRows={1} />}
else={
<Text>
{selectedProduct?.name}
</Text>
}
/>
);
};

Expand Down
14 changes: 5 additions & 9 deletions web/src/components/overview/SoftwareSection.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) [2022] SUSE LLC
* Copyright (c) [2022-2023] SUSE LLC
*
* All Rights Reserved.
*
Expand All @@ -20,13 +20,13 @@
*/

import React, { useReducer, useEffect } from "react";
import { BUSY } from "~/client/status";
import { Button } from "@patternfly/react-core";
import { ProgressText, Section } from "~/components/core";
import { Icon } from "~/components/layout";
import { ProgressText, Section } from "~/components/core";
import { toValidationError, useCancellablePromise } from "~/utils";
import { UsedSize } from "~/components/software";
import { useCancellablePromise } from "~/utils";
import { useInstallerClient } from "~/context/installer";
import { BUSY } from "~/client/status";
import { _ } from "~/i18n";

const initialState = {
Expand Down Expand Up @@ -78,10 +78,6 @@ export default function SoftwareSection({ showErrors }) {
return client.onStatusChange(updateStatus);
}, [client, cancellablePromise]);

useEffect(() => {
cancellablePromise(client.getStatus()).then(updateStatus);
}, [client, cancellablePromise]);

useEffect(() => {
const updateProposal = async () => {
const errors = await cancellablePromise(client.getIssues());
Expand Down Expand Up @@ -145,7 +141,7 @@ export default function SoftwareSection({ showErrors }) {
title={_("Software")}
icon="apps"
loading={state.busy}
errors={errors.map(e => ({ message: e.description }))}
errors={errors.map(toValidationError)}
path="/software"
>
<SectionContent />
Expand Down
3 changes: 2 additions & 1 deletion web/src/components/software/PatternSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useInstallerClient } from "~/context/installer";
import { ValidationErrors } from "~/components/core";
import PatternGroup from "./PatternGroup";
import PatternItem from "./PatternItem";
import { toValidationError } from "~/utils";
import UsedSize from "./UsedSize";
import { _ } from "~/i18n";

Expand Down Expand Up @@ -207,7 +208,7 @@ function PatternSelector() {

// FIXME: ValidationErrors should be replaced by an equivalent component to show issues.
// Note that only the Users client uses the old Validation D-Bus interface.
const validationErrors = errors.map(e => ({ message: e.description }));
const validationErrors = errors.map(toValidationError);

return (
<>
Expand Down

0 comments on commit 89e629d

Please sign in to comment.