import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { sortBy } from "lodash-es"; import { AlertVariant, Button, ButtonVariant, DataList, DataListCell, DataListControl, DataListDragButton, DataListItem, DataListItemCells, DataListItemRow, Modal, ModalVariant, TextContent, Text, } from "@patternfly/react-core"; import type IdentityProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/identityProviderRepresentation"; import { useAdminClient } from "../context/auth/AdminClient"; import { useAlerts } from "../components/alert/Alerts"; type ManageOderDialogProps = { providers: IdentityProviderRepresentation[]; onClose: () => void; }; export const ManageOderDialog = ({ providers, onClose, }: ManageOderDialogProps) => { const { t } = useTranslation("identity-providers"); const adminClient = useAdminClient(); const { addAlert, addError } = useAlerts(); const [alias, setAlias] = useState(""); const [liveText, setLiveText] = useState(""); const [order, setOrder] = useState( providers.map((provider) => provider.alias!) ); const onDragStart = (id: string) => { setAlias(id); setLiveText(t("common:onDragStart", { item: id })); }; const onDragMove = () => { setLiveText(t("common:onDragMove", { item: alias })); }; const onDragCancel = () => { setLiveText(t("common:onDragCancel")); }; const onDragFinish = (providerOrder: string[]) => { setLiveText(t("common:onDragFinish", { list: providerOrder })); setOrder(providerOrder); }; return ( { order.map(async (alias, index) => { const provider = providers.find((p) => p.alias === alias)!; provider.config!.guiOrder = index; try { await adminClient.identityProviders.update({ alias }, provider); addAlert(t("orderChangeSuccess"), AlertVariant.success); } catch (error) { addError("identity-providers:orderChangeError", error); } }); onClose(); }} > {t("common:save")} , , ]} > {t("oderDialogIntro")} {sortBy(providers, "config.guiOrder").map((provider) => ( {provider.alias} , ]} /> ))}
{liveText}
); };