From b5aa560dcc73f30aaa41ccef17d9fc7f35860f4e Mon Sep 17 00:00:00 2001 From: Sarah Rambacher Date: Mon, 19 Oct 2020 09:44:22 -0400 Subject: [PATCH] Change list view header action menu from select to dropdown (#179) * change select to dropdown in viewheader * make the action happen * remove comment --- src/clients/ClientSettings.tsx | 34 +++++++++--------- src/components/view-header/ViewHeader.tsx | 43 ++++++++++++----------- src/stories/ViewHeader.stories.tsx | 12 +++---- 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/src/clients/ClientSettings.tsx b/src/clients/ClientSettings.tsx index a9c2959e2b..4849889a39 100644 --- a/src/clients/ClientSettings.tsx +++ b/src/clients/ClientSettings.tsx @@ -10,8 +10,8 @@ import { ActionGroup, Button, AlertVariant, - SelectOption, ButtonVariant, + DropdownItem, } from "@patternfly/react-core"; import { useParams } from "react-router-dom"; import { Controller, useForm } from "react-hook-form"; @@ -116,16 +116,25 @@ export const ClientSettings = () => { + dropdownItems={[ + toggleDownloadDialog()} + > {t("downloadAdapterConfig")} - , - + , + exportClient(form.getValues())} + > {t("common:export")} - , - + , + toggleDeleteDialog()} + > {t("common:delete")} - , + , ]} isEnabled={value} onToggle={(value) => { @@ -136,15 +145,6 @@ export const ClientSettings = () => { save(); } }} - onSelect={(value) => { - if (value === "export") { - exportClient(form.getValues()); - } else if (value === "delete") { - toggleDeleteDialog(); - } else if (value === "download") { - toggleDownloadDialog(); - } - }} /> ); diff --git a/src/components/view-header/ViewHeader.tsx b/src/components/view-header/ViewHeader.tsx index f4c0fe0647..bc23b9f7be 100644 --- a/src/components/view-header/ViewHeader.tsx +++ b/src/components/view-header/ViewHeader.tsx @@ -11,22 +11,24 @@ import { ToolbarContent, ToolbarItem, Badge, - Select, ButtonProps, + Dropdown, + DropdownToggle, + DropdownPosition, } from "@patternfly/react-core"; import { HelpContext } from "../help-enabler/HelpHeader"; import { useTranslation } from "react-i18next"; import { PageBreadCrumbs } from "../bread-crumb/PageBreadCrumbs"; import { ExternalLink } from "../external-link/ExternalLink"; +import { isRowExpanded } from "@patternfly/react-table"; export type ViewHeaderProps = { titleKey: string; badge?: string; subKey: string; subKeyLinkProps?: ButtonProps; - selectItems?: ReactElement[]; + dropdownItems?: ReactElement[]; isEnabled?: boolean; - onSelect?: (value: string) => void; onToggle?: (value: boolean) => void; }; @@ -35,14 +37,18 @@ export const ViewHeader = ({ badge, subKey, subKeyLinkProps, - selectItems, + dropdownItems, isEnabled = true, - onSelect, onToggle, }: ViewHeaderProps) => { const { t } = useTranslation(); const { enabled } = useContext(HelpContext); - const [open, setOpen] = useState(false); + const [isDropdownOpen, setDropdownOpen] = useState(false); + + const onDropdownToggle = () => { + setDropdownOpen(!isDropdownOpen); + }; + return ( <> @@ -62,7 +68,7 @@ export const ViewHeader = ({ - {selectItems && ( + {dropdownItems && ( @@ -81,19 +87,16 @@ export const ViewHeader = ({ /> - + + {t("common:action")} + + } + isOpen={isDropdownOpen} + dropdownItems={dropdownItems} + /> diff --git a/src/stories/ViewHeader.stories.tsx b/src/stories/ViewHeader.stories.tsx index cad7095fbf..977c9be548 100644 --- a/src/stories/ViewHeader.stories.tsx +++ b/src/stories/ViewHeader.stories.tsx @@ -1,6 +1,6 @@ import React from "react"; import { Meta, Story } from "@storybook/react"; -import { Page, SelectOption } from "@patternfly/react-core"; +import { DropdownItem, Page } from "@patternfly/react-core"; import { ViewHeader, ViewHeaderProps, @@ -26,13 +26,13 @@ Extended.args = { title: "More information", href: "http://google.com", }, - selectItems: [ - + dropdownItems: [ + {}}> First item - , - + , + {}}> Second item - , + , ], };