Skip to content

Commit

Permalink
fix warnings show
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed Feb 20, 2024
1 parent d24c874 commit b088b86
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { continueIfCalleDisconnected } from "api/utils";
import { enableAutoUpdatesForPackageWithConfirm } from "pages/system/components/AutoUpdates";
import Warnings from "./Steps/Warnings";
import { RequestedDnp, UserSettingsAllDnps } from "@dappnode/types";
import computeSemverUpdateType from "utils/computeSemverUpdateType";

interface InstallDnpViewProps {
dnp: RequestedDnp;
Expand Down Expand Up @@ -65,12 +66,11 @@ const InstallDnpView: React.FC<InstallDnpViewProps> = ({
settings,
manifest,
setupWizard,
isInstalled
isInstalled,
installedVersion
} = dnp;
const isWarningUpdate =
manifest.warnings?.onMajorUpdate ||
manifest.warnings?.onMinorUpdate ||
manifest.warnings?.onPatchUpdate;
const updateType =
installedVersion && computeSemverUpdateType(installedVersion, reqVersion);
const isCore = manifest.type === "dncore";
const permissions = dnp.specialPermissions;
const hasPermissions = Object.values(permissions).some(p => p.length > 0);
Expand Down Expand Up @@ -239,10 +239,10 @@ const InstallDnpView: React.FC<InstallDnpViewProps> = ({
goBack={goBack}
warnings={manifest.warnings || {}}
isInstalled={isInstalled}
updateType={updateType}
/>
),
available:
manifest.warnings?.onInstall || (isInstalled && isWarningUpdate)
available: manifest.warnings?.onInstall || (isInstalled && updateType)
},
{
name: "Disclaimer",
Expand Down
83 changes: 42 additions & 41 deletions packages/admin-ui/src/pages/installer/components/Steps/Warnings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export default function Warnings({
goNext,
goBack,
warnings,
isInstalled
isInstalled,
updateType
}: {
goNext: () => void;
goBack: () => void;
warnings: Manifest["warnings"];
isInstalled: RequestedDnp["isInstalled"];
updateType?: "" | "downgrade" | "major" | "minor" | "patch" | null;
}) {
if (!warnings)
return (
Expand All @@ -25,54 +27,53 @@ export default function Warnings({

return (
<Card>
{warnings.onInstall && (
<div>
<div className="card-section-header">
<span>
<strong>Installation Warning</strong>
</span>
</div>
{isInstalled ? (
warnings.onInstall ? (
<div>
<RenderMarkdown source={warnings.onInstall} />
</div>
</div>
)}
{isInstalled && warnings.onPatchUpdate && (
<div>
<div className="card-section-header">
<span>
<strong>Patch Update Warning</strong>
</span>
<div className="card-section-header">
<span>
<strong>Installation Warning</strong>
</span>
</div>
<div>
<RenderMarkdown source={warnings.onInstall} />
</div>
</div>
) : updateType === "patch" && warnings.onPatchUpdate ? (
<div>
<RenderMarkdown source={warnings.onPatchUpdate} />
</div>
</div>
)}
{isInstalled && warnings.onMinorUpdate && (
<div>
<div className="card-section-header">
<span>
<strong>Minor Update Warning</strong>
</span>
<div className="card-section-header">
<span>
<strong>Patch Update Warning</strong>
</span>
</div>
<div>
<RenderMarkdown source={warnings.onPatchUpdate} />
</div>
</div>
) : updateType === "minor" && warnings.onMinorUpdate ? (
<div>
<RenderMarkdown source={warnings.onMinorUpdate} />
</div>
</div>
)}
{isInstalled && warnings.onMajorUpdate && (
<div>
<div className="card-section-header">
<span>
<strong>Major Update Warning</strong>
</span>
<div className="card-section-header">
<span>
<strong>Minor Update Warning</strong>
</span>
</div>
<div>
<RenderMarkdown source={warnings.onMinorUpdate} />
</div>
</div>
) : updateType === "major" && warnings.onMajorUpdate ? (
<div>
<RenderMarkdown source={warnings.onMajorUpdate} />
<div className="card-section-header">
<span>
<strong>Major Update Warning</strong>
</span>
</div>
<div>
<RenderMarkdown source={warnings.onMajorUpdate} />
</div>
</div>
</div>
)}
) : null
) : null}

<div className="button-group">
<Button onClick={goBack}>Back</Button>
Expand Down
8 changes: 8 additions & 0 deletions packages/dappmanager/src/calls/fetchDnpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export async function fetchDnpRequest({
imageSize: mainRelease.imageFile.size,
isUpdated: getIsUpdated(mainRelease, dnpList),
isInstalled: getIsInstalled(mainRelease, dnpList),
installedVersion: getInstalledVersion(mainRelease, dnpList),
// Prevent sending duplicated data
manifest: omit(mainRelease.manifest, ["setupWizard"]),
specialPermissions, // Decoupled metadata
Expand Down Expand Up @@ -214,3 +215,10 @@ function getReleaseSignedSafeMessage(release: PackageRelease): string {
}
}
}

function getInstalledVersion(
{ dnpName }: { dnpName: string },
dnpList: InstalledPackageData[]
): string | undefined {
return dnpList.find(dnp => dnp.dnpName === dnpName)?.version;
}
1 change: 1 addition & 0 deletions packages/types/src/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export interface RequestedDnp {
imageSize: number;
isUpdated: boolean;
isInstalled: boolean;
installedVersion?: string;
// Decoupled metadata
manifest: Manifest;
specialPermissions: SpecialPermissionAllDnps;
Expand Down

0 comments on commit b088b86

Please sign in to comment.