From d8d55fe3918e80b8b71a8a76a3a1eae9b38fcc78 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 6 Jul 2022 12:31:05 +0200 Subject: [PATCH] Fix order dialogs (#2922) --- .../IdentityProvidersSection.tsx | 16 ++++---- src/identity-providers/ManageOrderDialog.tsx | 36 ++++++++--------- src/user-federation/ManagePriorityDialog.tsx | 40 +++++++++---------- 3 files changed, 43 insertions(+), 49 deletions(-) diff --git a/src/identity-providers/IdentityProvidersSection.tsx b/src/identity-providers/IdentityProvidersSection.tsx index 14bff93eea..895869c8c2 100644 --- a/src/identity-providers/IdentityProvidersSection.tsx +++ b/src/identity-providers/IdentityProvidersSection.tsx @@ -48,7 +48,7 @@ export default function IdentityProvidersSection() { const { realm } = useRealm(); const history = useHistory(); const [key, setKey] = useState(0); - const refresh = () => setKey(new Date().getTime()); + const refresh = () => setKey(key + 1); const [addProviderOpen, setAddProviderOpen] = useState(false); const [manageDisplayDialog, setManageDisplayDialog] = useState(false); @@ -69,13 +69,11 @@ export default function IdentityProvidersSection() { return provider.identityProviders!; }, (providers) => { - setProviders(providers); + setProviders(sortBy(providers, ["config.guiOrder", "alias"])); }, - [] + [key] ); - const loader = () => Promise.resolve(sortBy(providers, "alias")); - const DetailLink = (identityProvider: IdentityProviderRepresentation) => ( {manageDisplayDialog && ( setManageDisplayDialog(false)} + onClose={() => { + setManageDisplayDialog(false); + refresh(); + }} providers={providers.filter((p) => p.enabled)} /> )} @@ -212,8 +213,7 @@ export default function IdentityProvidersSection() { )} {providers.length !== 0 && ( { - order.map(async (alias, index) => { + onClick={async () => { + const updates = order.map((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); - } + return adminClient.identityProviders.update({ alias }, provider); }); + try { + await Promise.all(updates); + addAlert(t("orderChangeSuccess")); + } catch (error) { + addError("identity-providers:orderChangeError", error); + } + onClose(); }} > @@ -111,28 +112,23 @@ export const ManageOrderDialog = ({ onDragCancel={onDragCancel} itemOrder={order} > - {sortBy(providers, "config.guiOrder").map((provider) => ( + {sortBy(providers, "config.guiOrder", "alias").map((provider) => ( - + - {provider.alias} + {provider.alias} , ]} /> diff --git a/src/user-federation/ManagePriorityDialog.tsx b/src/user-federation/ManagePriorityDialog.tsx index 6cf7623f28..a1a665b093 100644 --- a/src/user-federation/ManagePriorityDialog.tsx +++ b/src/user-federation/ManagePriorityDialog.tsx @@ -2,7 +2,6 @@ import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { sortBy } from "lodash-es"; import { - AlertVariant, Button, ButtonVariant, DataList, @@ -68,19 +67,23 @@ export const ManagePriorityDialog = ({