/* * Copyright (C) 2010 Red Hat, Inc. * SPDX-License-Identifier: LGPL-2.1-or-later */ import React from "react"; import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js"; import { Flex, FlexItem } from "@patternfly/react-core/dist/esm/layouts/Flex/index.js"; import { Tooltip, TooltipPosition } from "@patternfly/react-core/dist/esm/components/Tooltip/index.js"; import { Badge } from "@patternfly/react-core/dist/esm/components/Badge/index.js"; import { ListingTable } from 'cockpit-components-table.jsx'; import { ExclamationCircleIcon, SearchIcon, ThumbtackIcon } from '@patternfly/react-icons'; import { EmptyStatePanel } from "cockpit-components-empty-state.jsx"; import cockpit from "cockpit"; const _ = cockpit.gettext; export const ServicesList = ({ units, isTimer, onClearAllFilters }) => { let columns; if (!isTimer) { columns = [ { title: _("Unit"), header: true }, { title: _("State") }, ]; } else { columns = [ { title: _("Unit"), header: true }, { title: _("Trigger"), props: { width: 20 } }, { title: _("State") }, ]; } return ( getServicesRow({ key: unit[0], isTimer, shortId: unit[0], ...unit[1] })) } emptyComponent={{_("Clear all filters")}} title={_("No matching results")} /> } className="services-list" /> ); }; const getServicesRow = ({ Id, shortId, AutomaticStartup, UnitFileState, LoadState, HasFailed, IsPinned, CombinedState, LastTriggerTime, NextRunTime, Description, isTimer }) => { let displayName = shortId; // Remove ".service" from services as this is not necessary if (shortId.endsWith(".service")) displayName = shortId.substring(0, shortId.length - 8); const props = { displayName, Description }; const enabled = UnitFileState && UnitFileState.includes("enabled"); const disabled = UnitFileState && UnitFileState.includes("disabled"); const isStatic = UnitFileState && UnitFileState === "static"; const masked = LoadState && LoadState.includes("masked"); let unitFileState; if (enabled || disabled) unitFileState = {AutomaticStartup}; else unitFileState = {AutomaticStartup}; let tooltipMessage = ""; if (enabled) tooltipMessage = _("Automatically starts"); else if (disabled) tooltipMessage = _("Does not automatically start"); else if (masked) tooltipMessage = _("Forbidden from running"); else if (isStatic) tooltipMessage = _("Cannot be enabled"); const columns = [ { title: (
{IsPinned && } {props.Description !== shortId &&
{props.Description}
}
) }, { title: ( {HasFailed && } {CombinedState} {tooltipMessage ? {unitFileState} : unitFileState} ), props: { className: 'service-unit-second-column' } }, ]; if (isTimer) { columns.splice( 1, 0, { title: (
{NextRunTime &&
{cockpit.format("Next run: $0", NextRunTime)}
} {LastTriggerTime &&
{cockpit.format("Last trigger: $0", LastTriggerTime)}
}
) } ); } return { props: { 'data-goto-unit': shortId, id: shortId, key: shortId, className: HasFailed ? "service-unit-failed" : "", }, columns }; };