import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import _ from "lodash"; import { AlertVariant, Button, ButtonVariant, DataList, DataListCell, DataListControl, DataListDragButton, DataListItem, DataListItemCells, DataListItemRow, Modal, ModalVariant, TextContent, Text, } from "@patternfly/react-core"; import type IdentityProviderRepresentation from "keycloak-admin/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("onDragStart", { id })); }; const onDragMove = () => { setLiveText(t("onDragMove", { alias })); }; const onDragCancel = () => { setLiveText(t("onDragCancel")); }; const onDragFinish = (providerOrder: string[]) => { setLiveText(t("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}
); };