LCOV - code coverage report
Current view: top level - pkg/apps - apps.jsx Coverage Total Hit
Test: cockpit Lines: 100.0 % 38 38
Test Date: 2026-07-03 14:25:32

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2017 Red Hat, Inc.
       3              :  * SPDX-License-Identifier: LGPL-2.1-or-later
       4              :  */
       5              : 
       6              : import '../lib/patternfly/patternfly-6-cockpit.scss';
       7              : import "polyfills";
       8              : import 'cockpit-dark-theme'; // once per page
       9              : 
      10            7 : import cockpit from "cockpit";
      11              : 
      12            7 : import React, { useState } from "react";
      13            7 : import { createRoot } from 'react-dom/client';
      14              : 
      15              : import { EmptyStatePanel } from "cockpit-components-empty-state.jsx";
      16              : import { usePageLocation, useObject, useEvent } from "hooks";
      17              : 
      18              : import { ApplicationList } from "./application-list.jsx";
      19              : import { Application } from "./application.jsx";
      20              : import { get_metainfo_db } from "./appstream.js";
      21              : import { show_error } from "./utils";
      22              : 
      23            7 : const App = () => {
      24            7 :     const [progress, setProgress] = useState({});
      25            7 :     const [progressTitle, setProgressTitle] = useState({});
      26              : 
      27            2 :     function action(func, arg, progress_title, id) {
      28            2 :         setProgressTitle({ ...progressTitle, [id]: progress_title });
      29            2 :         func(arg, progress => setProgress({ ...progress, [id]: progress }))
      30            2 :                 .finally(() => setProgress({ ...progress, [id]: null }))
      31            2 :                 .catch(show_error);
      32            2 :     }
      33              : 
      34            7 :     const { path } = usePageLocation();
      35              : 
      36            7 :     const metainfo_db = useObject(get_metainfo_db, null, []);
      37            7 :     useEvent(metainfo_db, "changed");
      38              : 
      39            7 :     if (!metainfo_db.ready)
      40            7 :         return <EmptyStatePanel loading />;
      41              : 
      42            6 :     if (path.length === 0) {
      43            6 :         return <ApplicationList metainfo_db={metainfo_db}
      44            6 :                                 action={action}
      45            6 :                                 appProgress={progress}
      46            6 :                                 appProgressTitle={progressTitle} />;
      47            3 :     } else if (path.length == 1) {
      48            3 :         const id = path[0];
      49            3 :         return <Application metainfo_db={metainfo_db}
      50            3 :                             action={action}
      51            3 :                             progress={progress[id]}
      52            3 :                             id={id} />;
      53            1 :     } else { /* redirect */
      54            1 :         console.warn("not a apps location: " + path);
      55            1 :         cockpit.location = '';
      56            1 :     }
      57            7 : };
      58              : 
      59            7 : function init() {
      60            7 :     const root = createRoot(document.getElementById("apps-page"));
      61            7 :     root.render(<App />);
      62            7 : }
      63              : 
      64            7 : document.addEventListener("DOMContentLoaded", init);
        

Generated by: LCOV version 2.0-1