forked from cockpit-project/cockpit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-tabs.jsx
72 lines (65 loc) · 2.77 KB
/
service-tabs.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* This file is part of Cockpit.
*
* Copyright (C) 2020 Red Hat, Inc.
*
* Cockpit is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Cockpit is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/
import React, { useState } from "react";
import PropTypes from "prop-types";
import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js";
import { Nav, NavItem, NavList } from "@patternfly/react-core/dist/esm/components/Nav/index.js";
import { ExclamationCircleIcon } from '@patternfly/react-icons';
import cockpit from "cockpit";
const _ = cockpit.gettext;
export const service_tabs_suffixes = ["service", "target", "socket", "timer", "path"];
/*
* React component showing services tabs
* Required props:
* - onChange:
* When different tab is selected this callback is called
*/
export function ServiceTabs({ onChange, activeTab, tabErrors }) {
const service_tabs = {
service: _("Services"),
target: _("Targets"),
socket: _("Sockets"),
timer: _("Timers"),
path: _("Paths")
};
const [activeItem, setActiveItem] = useState(activeTab);
return (
<Nav variant="tertiary" id="services-filter"
onSelect={(_event, result) => { setActiveItem(result.itemId); onChange(result.itemId) }}>
<NavList>
{Object.keys(service_tabs).map(key => {
return (
<NavItem itemId={key}
key={key}
preventDefault
isActive={activeItem == key}>
<Button variant="link" component="a" style={{ "--pf-v5-c-button--m-link--Color": "var(--pf-v5-global--Color--200)", "--pf-v5-c-nav__link--m-current--Color": "var(--pf-v5-global--Color--100)", "--pf-v5-c-nav__link--hover--Color": "var(--pf-v5-global--Color--200)" }}>
{service_tabs[key]}
{tabErrors[key] ? <ExclamationCircleIcon className="ct-exclamation-circle" /> : null}
</Button>
</NavItem>
);
})}
</NavList>
</Nav>
);
}
ServiceTabs.propTypes = {
onChange: PropTypes.func.isRequired,
};