added missing confirm dialog (#395)
This commit is contained in:
parent
ca92447444
commit
7924080847
3 changed files with 37 additions and 16 deletions
|
@ -3,6 +3,7 @@ import Masthead from "../support/pages/admin_console/Masthead";
|
||||||
import ListingPage from "../support/pages/admin_console/ListingPage";
|
import ListingPage from "../support/pages/admin_console/ListingPage";
|
||||||
import SidebarPage from "../support/pages/admin_console/SidebarPage";
|
import SidebarPage from "../support/pages/admin_console/SidebarPage";
|
||||||
import CreateClientPage from "../support/pages/admin_console/manage/clients/CreateClientPage";
|
import CreateClientPage from "../support/pages/admin_console/manage/clients/CreateClientPage";
|
||||||
|
import ModalUtils from "../support/util/ModalUtils";
|
||||||
|
|
||||||
let itemId = "client_crud";
|
let itemId = "client_crud";
|
||||||
const loginPage = new LoginPage();
|
const loginPage = new LoginPage();
|
||||||
|
@ -10,9 +11,9 @@ const masthead = new Masthead();
|
||||||
const sidebarPage = new SidebarPage();
|
const sidebarPage = new SidebarPage();
|
||||||
const listingPage = new ListingPage();
|
const listingPage = new ListingPage();
|
||||||
const createClientPage = new CreateClientPage();
|
const createClientPage = new CreateClientPage();
|
||||||
|
const modalUtils = new ModalUtils();
|
||||||
|
|
||||||
describe("Clients test", function () {
|
describe("Clients test", function () {
|
||||||
|
|
||||||
describe("Client creation", function () {
|
describe("Client creation", function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
cy.visit("");
|
cy.visit("");
|
||||||
|
@ -68,7 +69,8 @@ describe("Clients test", function () {
|
||||||
listingPage.searchItem(itemId).itemExist(itemId);
|
listingPage.searchItem(itemId).itemExist(itemId);
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
listingPage.deleteItem(itemId); // There should be a confirmation pop-up
|
listingPage.deleteItem(itemId);
|
||||||
|
modalUtils.checkModalTitle(`Delete ${itemId} ?`).confirmModal();
|
||||||
|
|
||||||
masthead.checkNotificationMessage("The client has been deleted");
|
masthead.checkNotificationMessage("The client has been deleted");
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Link, useHistory, useRouteMatch } from "react-router-dom";
|
import { Link, useHistory, useRouteMatch } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
AlertVariant,
|
AlertVariant,
|
||||||
Badge,
|
Badge,
|
||||||
Button,
|
Button,
|
||||||
|
ButtonVariant,
|
||||||
PageSection,
|
PageSection,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ import { emptyFormatter, exportClient, getBaseUrl } from "../util";
|
||||||
import { useAlerts } from "../components/alert/Alerts";
|
import { useAlerts } from "../components/alert/Alerts";
|
||||||
import ClientRepresentation from "keycloak-admin/lib/defs/clientRepresentation";
|
import ClientRepresentation from "keycloak-admin/lib/defs/clientRepresentation";
|
||||||
import { formattedLinkTableCell } from "../components/external-link/FormattedLink";
|
import { formattedLinkTableCell } from "../components/external-link/FormattedLink";
|
||||||
|
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
|
||||||
|
|
||||||
export const ClientsSection = () => {
|
export const ClientsSection = () => {
|
||||||
const { t } = useTranslation("clients");
|
const { t } = useTranslation("clients");
|
||||||
|
@ -25,6 +27,10 @@ export const ClientsSection = () => {
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
const baseUrl = getBaseUrl(adminClient);
|
const baseUrl = getBaseUrl(adminClient);
|
||||||
|
|
||||||
|
const [key, setKey] = useState(0);
|
||||||
|
const refresh = () => setKey(new Date().getTime());
|
||||||
|
const [selectedClient, setSelectedClient] = useState<ClientRepresentation>();
|
||||||
|
|
||||||
const loader = async (first?: number, max?: number, search?: string) => {
|
const loader = async (first?: number, max?: number, search?: string) => {
|
||||||
const params: { [name: string]: string | number } = {
|
const params: { [name: string]: string | number } = {
|
||||||
first: first!,
|
first: first!,
|
||||||
|
@ -37,6 +43,26 @@ export const ClientsSection = () => {
|
||||||
return await adminClient.clients.find({ ...params });
|
return await adminClient.clients.find({ ...params });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(refresh, [selectedClient]);
|
||||||
|
|
||||||
|
const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({
|
||||||
|
titleKey: t("clientDelete", { clientId: selectedClient?.clientId }),
|
||||||
|
messageKey: "clients:clientDeleteConfirm",
|
||||||
|
continueButtonLabel: "common:delete",
|
||||||
|
continueButtonVariant: ButtonVariant.danger,
|
||||||
|
onConfirm: async () => {
|
||||||
|
try {
|
||||||
|
await adminClient.clients.del({
|
||||||
|
id: selectedClient!.id!,
|
||||||
|
});
|
||||||
|
addAlert(t("clientDeletedSuccess"), AlertVariant.success);
|
||||||
|
setSelectedClient(undefined);
|
||||||
|
} catch (error) {
|
||||||
|
addAlert(t("clientDeleteError", { error }), AlertVariant.danger);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const ClientDetailLink = (client: ClientRepresentation) => (
|
const ClientDetailLink = (client: ClientRepresentation) => (
|
||||||
<>
|
<>
|
||||||
<Link key={client.id} to={`${url}/${client.id}`}>
|
<Link key={client.id} to={`${url}/${client.id}`}>
|
||||||
|
@ -56,7 +82,9 @@ export const ClientsSection = () => {
|
||||||
subKey="clients:clientsExplain"
|
subKey="clients:clientsExplain"
|
||||||
/>
|
/>
|
||||||
<PageSection variant="light" className="pf-u-p-0">
|
<PageSection variant="light" className="pf-u-p-0">
|
||||||
|
<DeleteConfirm />
|
||||||
<KeycloakDataTable
|
<KeycloakDataTable
|
||||||
|
key={key}
|
||||||
loader={loader}
|
loader={loader}
|
||||||
isPaginated
|
isPaginated
|
||||||
ariaLabelKey="clients:clientList"
|
ariaLabelKey="clients:clientList"
|
||||||
|
@ -83,19 +111,9 @@ export const ClientsSection = () => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("common:delete"),
|
title: t("common:delete"),
|
||||||
onRowClick: async (client) => {
|
onRowClick: (client) => {
|
||||||
try {
|
setSelectedClient(client);
|
||||||
await adminClient.clients.del({
|
toggleDeleteDialog();
|
||||||
id: client.id!,
|
|
||||||
});
|
|
||||||
addAlert(t("clientDeletedSuccess"), AlertVariant.success);
|
|
||||||
return true;
|
|
||||||
} catch (error) {
|
|
||||||
addAlert(
|
|
||||||
t("clientDeleteError", { error }),
|
|
||||||
AlertVariant.danger
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
|
|
@ -63,6 +63,7 @@
|
||||||
"clientSaveSuccess": "Client successfully updated",
|
"clientSaveSuccess": "Client successfully updated",
|
||||||
"clientSaveError": "Client could not be updated:",
|
"clientSaveError": "Client could not be updated:",
|
||||||
"clientImportSuccess": "Client imported successfully",
|
"clientImportSuccess": "Client imported successfully",
|
||||||
|
"clientDelete": "Delete {{clientId}} ?",
|
||||||
"clientDeletedSuccess": "The client has been deleted",
|
"clientDeletedSuccess": "The client has been deleted",
|
||||||
"clientDeleteError": "Could not delete client: {{error}}",
|
"clientDeleteError": "Could not delete client: {{error}}",
|
||||||
"clientDeleteConfirmTitle": "Delete client?",
|
"clientDeleteConfirmTitle": "Delete client?",
|
||||||
|
|
Loading…
Reference in a new issue