LCOV - code coverage report
Current view: top level - pkg/lib - cockpit-components-empty-state.tsx Coverage Total Hit
Test: cockpit Lines: 100.0 % 35 35
Test Date: 2026-06-16 14:09:37

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2019 Red Hat, Inc.
       3              :  * SPDX-License-Identifier: LGPL-2.1-or-later
       4              :  */
       5              : 
       6          243 : import React from "react";
       7              : import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js";
       8              : import type { ButtonProps } from "@patternfly/react-core/dist/esm/components/Button/index.js";
       9              : import {
      10              :     EmptyStateActions, EmptyState, EmptyStateBody, EmptyStateFooter, EmptyStateVariant
      11              : } from "@patternfly/react-core/dist/esm/components/EmptyState/index.js";
      12              : import type { EmptyStateProps } from "@patternfly/react-core/dist/esm/components/EmptyState/index.js";
      13              : import { Spinner } from "@patternfly/react-core/dist/esm/components/Spinner/index.js";
      14              : import "./cockpit-components-empty-state.css";
      15              : 
      16           86 : export const EmptyStatePanel = ({
      17           86 :     title,
      18           86 :     paragraph,
      19           86 :     loading = false,
      20           86 :     icon,
      21           86 :     action,
      22           86 :     isActionInProgress = false,
      23           86 :     onAction,
      24           86 :     actionVariant = "primary",
      25           86 :     secondary,
      26           86 :     headingLevel = "h1"
      27           86 : }: {
      28              :     title?: EmptyStateProps["titleText"],
      29              :     paragraph?: React.ReactNode,
      30              :     loading?: boolean,
      31              :     icon?: EmptyStateProps["icon"],
      32              :     action?: React.ReactNode | string,
      33              :     isActionInProgress?: boolean,
      34              :     onAction?: ButtonProps["onClick"],
      35              :     actionVariant?: ButtonProps["variant"],
      36              :     secondary?: React.ReactNode,
      37              :     headingLevel?: EmptyStateProps['headingLevel'],
      38           86 : }) => {
      39           23 :     const slimType = title || paragraph ? "" : "slim";
      40           37 :     const emptyStateHeaderIcon = loading ? Spinner : icon;
      41              : 
      42           86 :     return (
      43           86 :         <EmptyState headingLevel={headingLevel} titleText={title} variant={EmptyStateVariant.full} {...emptyStateHeaderIcon && { icon: emptyStateHeaderIcon }}>
      44           86 :             <EmptyStateBody>
      45           86 :                 {paragraph}
      46           86 :             </EmptyStateBody>
      47           84 :             {(action || secondary) &&
      48           36 :                 <EmptyStateFooter>
      49           36 :                     { action && (typeof action == "string"
      50           24 :                         ? <Button variant={actionVariant} className={slimType}
      51           24 :                               isLoading={isActionInProgress}
      52           24 :                               isDisabled={isActionInProgress}
      53           24 :                               onClick={onAction}>
      54           24 :                             {action}
      55           24 :                         </Button>
      56           22 :                         : action)}
      57           10 :                     { secondary && <EmptyStateActions>{secondary}</EmptyStateActions> }
      58           36 :                 </EmptyStateFooter>}
      59           86 :         </EmptyState>
      60              :     );
      61           86 : };
        

Generated by: LCOV version 2.0-1