Fix order dialogs (#2922)
This commit is contained in:
parent
6caa64466e
commit
d8d55fe391
3 changed files with 43 additions and 49 deletions
|
@ -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) => (
|
||||
<Link
|
||||
key={identityProvider.providerId}
|
||||
|
@ -160,7 +158,10 @@ export default function IdentityProvidersSection() {
|
|||
<DeleteConfirm />
|
||||
{manageDisplayDialog && (
|
||||
<ManageOrderDialog
|
||||
onClose={() => setManageDisplayDialog(false)}
|
||||
onClose={() => {
|
||||
setManageDisplayDialog(false);
|
||||
refresh();
|
||||
}}
|
||||
providers={providers.filter((p) => p.enabled)}
|
||||
/>
|
||||
)}
|
||||
|
@ -212,8 +213,7 @@ export default function IdentityProvidersSection() {
|
|||
)}
|
||||
{providers.length !== 0 && (
|
||||
<KeycloakDataTable
|
||||
key={key}
|
||||
loader={loader}
|
||||
loader={providers}
|
||||
ariaLabelKey="common:identityProviders"
|
||||
searchPlaceholderKey="identity-providers:searchForProvider"
|
||||
toolbarItem={
|
||||
|
|
|
@ -2,7 +2,6 @@ import React, { useState } from "react";
|
|||
import { useTranslation } from "react-i18next";
|
||||
import { sortBy } from "lodash-es";
|
||||
import {
|
||||
AlertVariant,
|
||||
Button,
|
||||
ButtonVariant,
|
||||
DataList,
|
||||
|
@ -69,18 +68,20 @@ export const ManageOrderDialog = ({
|
|||
id="modal-confirm"
|
||||
data-testid="confirm"
|
||||
key="confirm"
|
||||
onClick={() => {
|
||||
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) => (
|
||||
<DataListItem
|
||||
aria-labelledby={provider.alias}
|
||||
id={`${provider.alias}-item`}
|
||||
aria-label={provider.alias}
|
||||
id={provider.alias}
|
||||
key={provider.alias}
|
||||
>
|
||||
<DataListItemRow>
|
||||
<DataListControl>
|
||||
<DataListDragButton
|
||||
aria-label="Reorder"
|
||||
aria-labelledby={provider.alias}
|
||||
aria-describedby={t("manageOrderItemAria")}
|
||||
aria-pressed="false"
|
||||
/>
|
||||
<DataListDragButton aria-label={t("manageOrderItemAria")} />
|
||||
</DataListControl>
|
||||
<DataListItemCells
|
||||
dataListCells={[
|
||||
<DataListCell
|
||||
key={`${provider.alias}-cell`}
|
||||
key={provider.alias}
|
||||
data-testid={provider.alias}
|
||||
>
|
||||
<span id={provider.alias}>{provider.alias}</span>
|
||||
{provider.alias}
|
||||
</DataListCell>,
|
||||
]}
|
||||
/>
|
||||
|
|
|
@ -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 = ({
|
|||
<Button
|
||||
id="modal-confirm"
|
||||
key="confirm"
|
||||
onClick={() => {
|
||||
order.map(async (name, index) => {
|
||||
onClick={async () => {
|
||||
const updates = order.map((name, index) => {
|
||||
const component = components!.find((c) => c.name === name)!;
|
||||
component.config!.priority = [index.toString()];
|
||||
try {
|
||||
const id = component.id!;
|
||||
await adminClient.components.update({ id }, component);
|
||||
addAlert(t("orderChangeSuccess"), AlertVariant.success);
|
||||
} catch (error) {
|
||||
addError("orderChangeError", error);
|
||||
}
|
||||
return adminClient.components.update(
|
||||
{ id: component.id! },
|
||||
component
|
||||
);
|
||||
});
|
||||
|
||||
try {
|
||||
await Promise.all(updates);
|
||||
addAlert(t("orderChangeSuccess"));
|
||||
} catch (error) {
|
||||
addError("orderChangeError", error);
|
||||
}
|
||||
|
||||
onClose();
|
||||
}}
|
||||
>
|
||||
|
@ -110,28 +113,23 @@ export const ManagePriorityDialog = ({
|
|||
onDragCancel={onDragCancel}
|
||||
itemOrder={order}
|
||||
>
|
||||
{sortBy(components, "config.priority").map((component) => (
|
||||
{sortBy(components, "config.priority", "name").map((component) => (
|
||||
<DataListItem
|
||||
aria-labelledby={component.name}
|
||||
id={`${component.name}-item`}
|
||||
aria-label={component.name}
|
||||
id={component.name}
|
||||
key={component.name}
|
||||
>
|
||||
<DataListItemRow>
|
||||
<DataListControl>
|
||||
<DataListDragButton
|
||||
aria-label="Reorder"
|
||||
aria-labelledby={component.name}
|
||||
aria-describedby={t("manageOrderItemAria")}
|
||||
aria-pressed="false"
|
||||
/>
|
||||
<DataListDragButton aria-label={t("manageOrderItemAria")} />
|
||||
</DataListControl>
|
||||
<DataListItemCells
|
||||
dataListCells={[
|
||||
<DataListCell
|
||||
key={`${component.name}-cell`}
|
||||
key={component.name}
|
||||
data-testid={component.name}
|
||||
>
|
||||
<span id={component.name}>{component.name}</span>
|
||||
{component.name}
|
||||
</DataListCell>,
|
||||
]}
|
||||
/>
|
||||
|
|
Loading…
Reference in a new issue