Change list view header action menu from select to dropdown (#179)
* change select to dropdown in viewheader * make the action happen * remove comment
This commit is contained in:
parent
be2d5d1249
commit
b5aa560dcc
3 changed files with 46 additions and 43 deletions
|
@ -10,8 +10,8 @@ import {
|
||||||
ActionGroup,
|
ActionGroup,
|
||||||
Button,
|
Button,
|
||||||
AlertVariant,
|
AlertVariant,
|
||||||
SelectOption,
|
|
||||||
ButtonVariant,
|
ButtonVariant,
|
||||||
|
DropdownItem,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
@ -116,16 +116,25 @@ export const ClientSettings = () => {
|
||||||
<ViewHeader
|
<ViewHeader
|
||||||
titleKey={name}
|
titleKey={name}
|
||||||
subKey="clients:clientsExplain"
|
subKey="clients:clientsExplain"
|
||||||
selectItems={[
|
dropdownItems={[
|
||||||
<SelectOption key="download" value="download">
|
<DropdownItem
|
||||||
|
key="download"
|
||||||
|
onClick={() => toggleDownloadDialog()}
|
||||||
|
>
|
||||||
{t("downloadAdapterConfig")}
|
{t("downloadAdapterConfig")}
|
||||||
</SelectOption>,
|
</DropdownItem>,
|
||||||
<SelectOption key="export" value="export">
|
<DropdownItem
|
||||||
|
key="export"
|
||||||
|
onClick={() => exportClient(form.getValues())}
|
||||||
|
>
|
||||||
{t("common:export")}
|
{t("common:export")}
|
||||||
</SelectOption>,
|
</DropdownItem>,
|
||||||
<SelectOption key="delete" value="delete">
|
<DropdownItem
|
||||||
|
key="delete"
|
||||||
|
onClick={() => toggleDeleteDialog()}
|
||||||
|
>
|
||||||
{t("common:delete")}
|
{t("common:delete")}
|
||||||
</SelectOption>,
|
</DropdownItem>,
|
||||||
]}
|
]}
|
||||||
isEnabled={value}
|
isEnabled={value}
|
||||||
onToggle={(value) => {
|
onToggle={(value) => {
|
||||||
|
@ -136,15 +145,6 @@ export const ClientSettings = () => {
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onSelect={(value) => {
|
|
||||||
if (value === "export") {
|
|
||||||
exportClient(form.getValues());
|
|
||||||
} else if (value === "delete") {
|
|
||||||
toggleDeleteDialog();
|
|
||||||
} else if (value === "download") {
|
|
||||||
toggleDownloadDialog();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,22 +11,24 @@ import {
|
||||||
ToolbarContent,
|
ToolbarContent,
|
||||||
ToolbarItem,
|
ToolbarItem,
|
||||||
Badge,
|
Badge,
|
||||||
Select,
|
|
||||||
ButtonProps,
|
ButtonProps,
|
||||||
|
Dropdown,
|
||||||
|
DropdownToggle,
|
||||||
|
DropdownPosition,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import { HelpContext } from "../help-enabler/HelpHeader";
|
import { HelpContext } from "../help-enabler/HelpHeader";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { PageBreadCrumbs } from "../bread-crumb/PageBreadCrumbs";
|
import { PageBreadCrumbs } from "../bread-crumb/PageBreadCrumbs";
|
||||||
import { ExternalLink } from "../external-link/ExternalLink";
|
import { ExternalLink } from "../external-link/ExternalLink";
|
||||||
|
import { isRowExpanded } from "@patternfly/react-table";
|
||||||
|
|
||||||
export type ViewHeaderProps = {
|
export type ViewHeaderProps = {
|
||||||
titleKey: string;
|
titleKey: string;
|
||||||
badge?: string;
|
badge?: string;
|
||||||
subKey: string;
|
subKey: string;
|
||||||
subKeyLinkProps?: ButtonProps;
|
subKeyLinkProps?: ButtonProps;
|
||||||
selectItems?: ReactElement[];
|
dropdownItems?: ReactElement[];
|
||||||
isEnabled?: boolean;
|
isEnabled?: boolean;
|
||||||
onSelect?: (value: string) => void;
|
|
||||||
onToggle?: (value: boolean) => void;
|
onToggle?: (value: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,14 +37,18 @@ export const ViewHeader = ({
|
||||||
badge,
|
badge,
|
||||||
subKey,
|
subKey,
|
||||||
subKeyLinkProps,
|
subKeyLinkProps,
|
||||||
selectItems,
|
dropdownItems,
|
||||||
isEnabled = true,
|
isEnabled = true,
|
||||||
onSelect,
|
|
||||||
onToggle,
|
onToggle,
|
||||||
}: ViewHeaderProps) => {
|
}: ViewHeaderProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { enabled } = useContext(HelpContext);
|
const { enabled } = useContext(HelpContext);
|
||||||
const [open, setOpen] = useState(false);
|
const [isDropdownOpen, setDropdownOpen] = useState(false);
|
||||||
|
|
||||||
|
const onDropdownToggle = () => {
|
||||||
|
setDropdownOpen(!isDropdownOpen);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageSection variant="light">
|
<PageSection variant="light">
|
||||||
|
@ -62,7 +68,7 @@ export const ViewHeader = ({
|
||||||
</Level>
|
</Level>
|
||||||
</LevelItem>
|
</LevelItem>
|
||||||
<LevelItem></LevelItem>
|
<LevelItem></LevelItem>
|
||||||
{selectItems && (
|
{dropdownItems && (
|
||||||
<LevelItem>
|
<LevelItem>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<ToolbarContent>
|
<ToolbarContent>
|
||||||
|
@ -81,19 +87,16 @@ export const ViewHeader = ({
|
||||||
/>
|
/>
|
||||||
</ToolbarItem>
|
</ToolbarItem>
|
||||||
<ToolbarItem>
|
<ToolbarItem>
|
||||||
<Select
|
<Dropdown
|
||||||
placeholderText={t("common:action")}
|
position={DropdownPosition.right}
|
||||||
isOpen={open}
|
toggle={
|
||||||
onToggle={() => setOpen(!open)}
|
<DropdownToggle onToggle={onDropdownToggle}>
|
||||||
onSelect={(_, value) => {
|
{t("common:action")}
|
||||||
if (onSelect) {
|
</DropdownToggle>
|
||||||
onSelect(value as string);
|
|
||||||
}
|
}
|
||||||
setOpen(false);
|
isOpen={isDropdownOpen}
|
||||||
}}
|
dropdownItems={dropdownItems}
|
||||||
>
|
/>
|
||||||
{selectItems}
|
|
||||||
</Select>
|
|
||||||
</ToolbarItem>
|
</ToolbarItem>
|
||||||
</ToolbarContent>
|
</ToolbarContent>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Meta, Story } from "@storybook/react";
|
import { Meta, Story } from "@storybook/react";
|
||||||
import { Page, SelectOption } from "@patternfly/react-core";
|
import { DropdownItem, Page } from "@patternfly/react-core";
|
||||||
import {
|
import {
|
||||||
ViewHeader,
|
ViewHeader,
|
||||||
ViewHeaderProps,
|
ViewHeaderProps,
|
||||||
|
@ -26,13 +26,13 @@ Extended.args = {
|
||||||
title: "More information",
|
title: "More information",
|
||||||
href: "http://google.com",
|
href: "http://google.com",
|
||||||
},
|
},
|
||||||
selectItems: [
|
dropdownItems: [
|
||||||
<SelectOption key="first" value="first-item">
|
<DropdownItem key="first" value="first-item" onClick={() => {}}>
|
||||||
First item
|
First item
|
||||||
</SelectOption>,
|
</DropdownItem>,
|
||||||
<SelectOption key="second" value="second-item">
|
<DropdownItem key="second" value="second-item" onClick={() => {}}>
|
||||||
Second item
|
Second item
|
||||||
</SelectOption>,
|
</DropdownItem>,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue