Skip to content

Commit

Permalink
apps: Warn if appstream data package is missing
Browse files Browse the repository at this point in the history
Fixes #18454

Co-Authored-By: Martin Pitt <[email protected]>
  • Loading branch information
leomoty and martinpitt committed Sep 19, 2023
1 parent a098482 commit 80b8161
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
45 changes: 38 additions & 7 deletions pkg/apps/application-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ import { Flex, FlexItem } from "@patternfly/react-core/dist/esm/layouts/Flex/ind
import { Page, PageSection, PageSectionVariants } from "@patternfly/react-core/dist/esm/components/Page/index.js";
import { RebootingIcon } from "@patternfly/react-icons";

import { check_missing_packages } from "packagekit.js";
import * as PackageKit from "./packagekit.js";
import { read_os_release } from "os-release.js";
import { icon_url, show_error, launch, ProgressBar, CancelButton } from "./utils.jsx";
import { ActionButton } from "./application.jsx";
import { EmptyStatePanel } from "cockpit-components-empty-state.jsx";
import { useInit } from "../lib/hooks.js";

const _ = cockpit.gettext;

Expand Down Expand Up @@ -93,6 +95,7 @@ const ApplicationRow = ({ comp, progress, progress_title, action }) => {

export const ApplicationList = ({ metainfo_db, appProgress, appProgressTitle, action }) => {
const [progress, setProgress] = useState(false);
const [dataPackagesInstalled, setDataPackagesInstalled] = useState(null);
const comps = [];
for (const id in metainfo_db.components)
comps.push(metainfo_db.components[id]);
Expand All @@ -117,14 +120,36 @@ export const ApplicationList = ({ metainfo_db, appProgress, appProgressTitle, ac
}
}

async function check_missing_data(packages) {
// avoid a metadata refresh at page load, too expensive; trust our OS map
try {
const data = await check_missing_packages(packages, null, true);
setDataPackagesInstalled(data.missing_names?.length === 0 && data.unavailable_names?.length === 0);
} catch (e) {
console.warn("Failed to check missing AppStream metadata packages:", e.toString());
}
}

useInit(async () => {
const os_release = await read_os_release();
const configPackages = get_config('appstream_config_packages', os_release, []);
const dataPackages = get_config('appstream_data_packages', os_release, []);
await check_missing_data([...dataPackages, ...configPackages]);
});

function refresh() {
read_os_release().then(os_release =>
read_os_release().then(os_release => {
const configPackages = get_config('appstream_config_packages', os_release, []);
const dataPackages = get_config('appstream_data_packages', os_release, []);
PackageKit.refresh(metainfo_db.origin_files,
get_config('appstream_config_packages', os_release, []),
get_config('appstream_data_packages', os_release, []),
setProgress))
.finally(() => setProgress(false))
.catch(show_error);
configPackages,
dataPackages,
setProgress)
.finally(async () => {
await check_missing_data([...dataPackages, ...configPackages]);
setProgress(false);
}).catch(show_error);
});
}

let refresh_progress, refresh_button, tbody;
Expand All @@ -147,6 +172,10 @@ export const ApplicationList = ({ metainfo_db, appProgress, appProgressTitle, ac
action={action} />);
}

const data_missing_msg = (dataPackagesInstalled == false && !refresh_progress)
? _("Appstream data package is missing, refresh to install it")
: null;

return (
<Page id="list-page">
<PageSection variant={PageSectionVariants.light}>
Expand All @@ -165,8 +194,10 @@ export const ApplicationList = ({ metainfo_db, appProgress, appProgressTitle, ac
</Flex>
</PageSection>
{comps.length == 0
? <EmptyStatePanel title={ _("No applications installed or available.") } />
? <EmptyStatePanel title={ _("No applications installed or available.") } paragraph={data_missing_msg} />
: <PageSection>
{!progress && data_missing_msg &&
<Alert variant="warning" isInline title={data_missing_msg} />}
<Card>
<DataList aria-label={_("Applications list")}>
{ tbody }
Expand Down
4 changes: 4 additions & 0 deletions test/verify/check-apps
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ class TestApps(packagelib.PackageCase):

self.login_and_go("/apps", urlroot=urlroot)
b.wait_in_text(".pf-v5-c-empty-state", "No applications installed or available")
b.wait_in_text(".pf-v5-c-empty-state", "Appstream data package is missing")

# still no metadata, but already installed application
self.createAppStreamPackage("already", "1.0", "1", install=True)
b.wait_not_present(".pf-v5-c-empty-state")
b.wait_visible(".app-list .pf-v5-c-data-list__item-row:contains('already') button:contains('Remove')")
b.wait_in_text(".pf-v5-c-alert", "Appstream data package is missing")

self.createAppStreamPackage("app-1", "1.0", "1")
self.createAppStreamRepoPackage()
Expand All @@ -114,7 +116,9 @@ class TestApps(packagelib.PackageCase):
b.click("#refresh")

with b.wait_timeout(30):
b.wait_not_present(".pf-v5-c-alert")
b.click(".app-list #app-1")

b.wait_visible('a[href="https://app-1.com"]')
b.wait_visible(f'#app-page img[src^="{urlroot}/cockpit/channel/"]')
b.click(".pf-v5-c-breadcrumb a:contains('Applications')")
Expand Down

0 comments on commit 80b8161

Please sign in to comment.