@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
38 lines • 2.84 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { Td } from "@patternfly/react-table";
import { Button, Dropdown, DropdownItem, DropdownList, MenuToggle, } from "@patternfly/react-core";
import useToggle from "../../utils/useToggle";
import useLocaleSort from "../../utils/useLocaleSort";
import { CredentialDataDialog } from "../../user/user-credentials/CredentialDataDialog";
import useFormatDate from "../../utils/useFormatDate";
import { EllipsisVIcon } from "@patternfly/react-icons";
export const CredentialRow = ({ credential, resetPassword, toggleDelete, children, }) => {
const formatDate = useFormatDate();
const { t } = useTranslation();
const [showData, toggleShow] = useToggle();
const [kebabOpen, toggleKebab] = useToggle();
const localeSort = useLocaleSort();
const rows = useMemo(() => {
if (!credential.credentialData) {
return [];
}
const credentialData = JSON.parse(credential.credentialData);
return localeSort(Object.entries(credentialData), ([key]) => key).map(([key, value]) => {
if (typeof value === "string") {
return [key, value];
}
return [key, JSON.stringify(value)];
});
}, [credential.credentialData]);
return (_jsxs(_Fragment, { children: [showData && Object.keys(credential).length !== 0 && (_jsx(CredentialDataDialog, { credentialData: rows, onClose: () => {
toggleShow();
} })), _jsx(Td, { children: children }), _jsx(Td, { children: formatDate(new Date(credential.createdDate)) }), _jsx(Td, { children: _jsx(Button, { className: "kc-showData-btn", variant: "link", "data-testid": "showDataBtn", onClick: toggleShow, children: t("showDataBtn") }) }), credential.type === "password" ? (_jsx(Td, { isActionCell: true, children: _jsx(Button, { variant: "secondary", "data-testid": "resetPasswordBtn", onClick: resetPassword, children: t("resetPasswordBtn") }) })) : (_jsx(Td, {})), _jsx(Td, { isActionCell: true, children: _jsx(Dropdown, { popperProps: {
position: "right",
}, onOpenChange: toggleKebab, toggle: (ref) => (_jsx(MenuToggle, { ref: ref, isExpanded: kebabOpen, onClick: toggleKebab, variant: "plain", "aria-label": "Kebab toggle", children: _jsx(EllipsisVIcon, {}) })), isOpen: kebabOpen, children: _jsx(DropdownList, { children: _jsx(DropdownItem, { "data-testid": "deleteDropdownItem", component: "button", onClick: () => {
toggleDelete();
toggleKebab();
}, children: t("deleteBtn") }, credential.id) }) }) })] }));
};
//# sourceMappingURL=CredentialRow.js.map