| 1 |
/* |
| 2 |
* Copyright (C) 2016 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
import cockpit from "cockpit"; |
| 7 |
import React from "react"; |
| 8 |
|
| 9 |
import { Label, LabelGroup } from "@patternfly/react-core/dist/esm/components/Label/index.js"; |
| 10 |
import { Menu, MenuContent, MenuItem, MenuList } from "@patternfly/react-core/dist/esm/components/Menu/index.js"; |
| 11 |
import { Flex, FlexItem } from "@patternfly/react-core/dist/esm/layouts/Flex/index.js"; |
| 12 |
|
| 13 |
import "menu-select-widget.scss"; |
| 14 |
|
| 15 |
const _ = cockpit.gettext; |
| 16 |
|
| 17 |
export interface Profile { |
| 18 |
name: string; |
| 19 |
recommended: boolean; |
| 20 |
active: boolean; |
| 21 |
inconsistent?: boolean; |
| 22 |
title: string; |
| 23 |
description: string; |
| 24 |
} |
| 25 |
|
| 26 |
export const ProfilesMenuDialogBody = ({ active_profile, profiles, change_selected, isDisabled }: { |
| 27 |
active_profile: string; |
| 28 |
profiles: Profile[]; |
| 29 |
change_selected: (profile: string) => void; |
| 30 |
isDisabled?: boolean; |
| 31 |
}) => { |
| 32 |
const [selected_profile, setSelectedProfile] = React.useState(active_profile); |
| 33 |
|
| 34 |
const menuProfiles = profiles.map((itm) => { |
| 35 |
return ( |
| 36 |
<MenuItem itemId={itm.name} key={itm.name} data-value={itm.name} |
| 37 |
description={itm.description} isDisabled={!!isDisabled} |
| 38 |
isActive={itm.active}> |
| 39 |
<Flex alignItems={{ default: 'alignItemsCenter' }}> |
| 40 |
<p>{ itm.title }</p> |
| 41 |
<FlexItem> |
| 42 |
<LabelGroup> |
| 43 |
{itm.recommended && <Label color="green" variant='filled'>{_("recommended")}</Label>} |
| 44 |
{itm.active && <Label color="blue" variant='filled'>{_("active")}</Label>} |
| 45 |
{itm.inconsistent && <Label color="orange" variant='filled'>{_("inconsistent")}</Label>} |
| 46 |
</LabelGroup> |
| 47 |
</FlexItem> |
| 48 |
</Flex> |
| 49 |
</MenuItem> |
| 50 |
); |
| 51 |
}); |
| 52 |
return ( |
| 53 |
<Menu className="ct-menu-select-widget" |
| 54 |
isPlain |
| 55 |
isScrollable |
| 56 |
onSelect={(_, selected: string) => { |
| 57 |
setSelectedProfile(selected); |
| 58 |
change_selected(selected); |
| 59 |
}} |
| 60 |
selected={selected_profile}> |
| 61 |
<MenuContent> |
| 62 |
<MenuList> |
| 63 |
{menuProfiles} |
| 64 |
</MenuList> |
| 65 |
</MenuContent> |
| 66 |
</Menu> |
| 67 |
); |
| 68 |
}; |