2020-11-10 20:26:20 +00:00
|
|
|
import React, { ReactElement, useState } from "react";
|
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
CardHeader,
|
|
|
|
CardActions,
|
|
|
|
CardTitle,
|
|
|
|
CardBody,
|
|
|
|
CardFooter,
|
|
|
|
Dropdown,
|
|
|
|
KebabToggle,
|
|
|
|
Label,
|
2020-11-18 15:06:56 +00:00
|
|
|
Flex,
|
|
|
|
FlexItem,
|
2020-11-10 20:26:20 +00:00
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import "./keycloak-card.css";
|
2021-01-05 19:49:33 +00:00
|
|
|
import { useHistory, useRouteMatch } from "react-router-dom";
|
2020-11-10 20:26:20 +00:00
|
|
|
|
|
|
|
export type KeycloakCardProps = {
|
|
|
|
id: string;
|
|
|
|
title: string;
|
|
|
|
dropdownItems?: ReactElement[];
|
|
|
|
labelText?: string;
|
2020-11-16 19:09:39 +00:00
|
|
|
labelColor?: any;
|
2020-11-10 20:26:20 +00:00
|
|
|
footerText?: string;
|
|
|
|
configEnabled?: boolean;
|
|
|
|
providerId?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const KeycloakCard = ({
|
2020-12-08 06:30:53 +00:00
|
|
|
id,
|
2020-11-10 20:26:20 +00:00
|
|
|
title,
|
2020-12-16 07:02:41 +00:00
|
|
|
dropdownItems,
|
2020-11-10 20:26:20 +00:00
|
|
|
labelText,
|
2020-11-16 19:09:39 +00:00
|
|
|
labelColor,
|
2020-11-10 20:26:20 +00:00
|
|
|
footerText,
|
2020-12-16 07:02:41 +00:00
|
|
|
providerId,
|
2020-11-10 20:26:20 +00:00
|
|
|
}: KeycloakCardProps) => {
|
|
|
|
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
2020-12-08 06:30:53 +00:00
|
|
|
|
|
|
|
const history = useHistory();
|
2021-01-05 19:49:33 +00:00
|
|
|
const { url } = useRouteMatch();
|
2020-12-08 06:30:53 +00:00
|
|
|
|
2020-11-10 20:26:20 +00:00
|
|
|
const onDropdownToggle = () => {
|
|
|
|
setIsDropdownOpen(!isDropdownOpen);
|
|
|
|
};
|
|
|
|
|
2020-12-08 06:30:53 +00:00
|
|
|
const handleCardMenuClick = (e: any) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
};
|
|
|
|
|
|
|
|
const openSettings = () => {
|
2021-01-05 19:49:33 +00:00
|
|
|
history.push(`${url}/${providerId}/${id}`);
|
2020-12-08 06:30:53 +00:00
|
|
|
};
|
|
|
|
|
2020-11-10 20:26:20 +00:00
|
|
|
return (
|
2020-12-08 06:30:53 +00:00
|
|
|
<Card isSelectable onClick={openSettings}>
|
2020-11-10 20:26:20 +00:00
|
|
|
<CardHeader>
|
|
|
|
<CardActions>
|
|
|
|
{dropdownItems && (
|
|
|
|
<Dropdown
|
2021-02-19 21:22:05 +00:00
|
|
|
data-testid={`${title}-dropdown`}
|
2020-11-10 20:26:20 +00:00
|
|
|
isPlain
|
|
|
|
position={"right"}
|
|
|
|
toggle={<KebabToggle onToggle={onDropdownToggle} />}
|
2020-12-08 06:30:53 +00:00
|
|
|
onClick={(e) => handleCardMenuClick(e)}
|
2020-11-10 20:26:20 +00:00
|
|
|
isOpen={isDropdownOpen}
|
|
|
|
dropdownItems={dropdownItems}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</CardActions>
|
2021-02-19 21:22:05 +00:00
|
|
|
<CardTitle data-testid="keycloak-card-title">{title}</CardTitle>
|
2020-11-10 20:26:20 +00:00
|
|
|
</CardHeader>
|
|
|
|
<CardBody />
|
|
|
|
<CardFooter>
|
2020-11-18 15:06:56 +00:00
|
|
|
<Flex>
|
|
|
|
<FlexItem className="keycloak--keycloak-card__footer">
|
|
|
|
{footerText && footerText}
|
|
|
|
</FlexItem>
|
|
|
|
<FlexItem>
|
|
|
|
{labelText && (
|
|
|
|
<Label color={labelColor || "gray"}>{labelText}</Label>
|
|
|
|
)}
|
|
|
|
</FlexItem>
|
|
|
|
</Flex>
|
2020-11-10 20:26:20 +00:00
|
|
|
</CardFooter>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|