Delete mapper (#1307)

This commit is contained in:
Jenny 2021-10-07 06:08:29 -04:00 committed by GitHub
parent f273ae70db
commit b942efc2aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 4 deletions

View file

@ -312,6 +312,18 @@ describe("Identity provider test", () => {
addMapperPage.editSocialMapper(); addMapperPage.editSocialMapper();
}); });
it("should delete facebook mapper", () => {
sidebarPage.goToIdentityProviders();
listingPage.goToItemDetails("facebook");
addMapperPage.goToMappersTab();
listingPage.deleteItem("facebook attribute importer");
cy.findByTestId("modalConfirm").click();
});
it("should edit SAML mapper", () => { it("should edit SAML mapper", () => {
sidebarPage.goToIdentityProviders(); sidebarPage.goToIdentityProviders();

View file

@ -42,7 +42,10 @@ import { toIdentityProviderAddMapper } from "../routes/AddMapper";
import { toIdentityProviderEditMapper } from "../routes/EditMapper"; import { toIdentityProviderEditMapper } from "../routes/EditMapper";
import { toUpperCase } from "../../util"; import { toUpperCase } from "../../util";
import type { IdentityProviderParams } from "../routes/IdentityProvider"; import {
IdentityProviderParams,
toIdentityProvider,
} from "../routes/IdentityProvider";
type HeaderProps = { type HeaderProps = {
onChange: (value: boolean) => void; onChange: (value: boolean) => void;
@ -105,11 +108,15 @@ export const DetailSettings = () => {
const form = useForm<IdentityProviderRepresentation>(); const form = useForm<IdentityProviderRepresentation>();
const { handleSubmit, getValues, reset } = form; const { handleSubmit, getValues, reset } = form;
const [provider, setProvider] = useState<IdentityProviderRepresentation>(); const [provider, setProvider] = useState<IdentityProviderRepresentation>();
const [selectedMapper, setSelectedMapper] =
useState<IdPWithMapperAttributes>();
const adminClient = useAdminClient(); const adminClient = useAdminClient();
const { addAlert, addError } = useAlerts(); const { addAlert, addError } = useAlerts();
const history = useHistory(); const history = useHistory();
const { realm } = useRealm(); const { realm } = useRealm();
const [key, setKey] = useState(0);
const refresh = () => setKey(key + 1);
const MapperLink = ({ name, mapperId }: IdPWithMapperAttributes) => ( const MapperLink = ({ name, mapperId }: IdPWithMapperAttributes) => (
<Link <Link
@ -166,6 +173,30 @@ export const DetailSettings = () => {
}, },
}); });
const [toggleDeleteMapperDialog, DeleteMapperConfirm] = useConfirmDialog({
titleKey: "identity-providers:deleteProviderMapper",
messageKey: t("identity-providers:deleteMapperConfirm", {
mapper: selectedMapper?.name,
}),
continueButtonLabel: "common:delete",
continueButtonVariant: ButtonVariant.danger,
onConfirm: async () => {
try {
await adminClient.identityProviders.delMapper({
alias: alias,
id: selectedMapper?.mapperId!,
});
addAlert(t("deleteMapperSuccess"), AlertVariant.success);
refresh();
history.push(
toIdentityProvider({ providerId, alias, tab: "mappers", realm })
);
} catch (error) {
addError("identity-providers:deleteErrorError", error);
}
},
});
if (!provider) { if (!provider) {
return <Spinner />; return <Spinner />;
} }
@ -212,6 +243,7 @@ export const DetailSettings = () => {
return ( return (
<> <>
<DeleteConfirm /> <DeleteConfirm />
<DeleteMapperConfirm />
<Controller <Controller
name="enabled" name="enabled"
control={form.control} control={form.control}
@ -315,6 +347,7 @@ export const DetailSettings = () => {
/> />
} }
loader={loader} loader={loader}
key={key}
isPaginated isPaginated
ariaLabelKey="identity-providers:mappersList" ariaLabelKey="identity-providers:mappersList"
searchPlaceholderKey="identity-providers:searchForMapper" searchPlaceholderKey="identity-providers:searchForMapper"
@ -348,6 +381,15 @@ export const DetailSettings = () => {
displayKey: "common:type", displayKey: "common:type",
}, },
]} ]}
actions={[
{
title: t("common:delete"),
onRowClick: (mapper) => {
setSelectedMapper(mapper);
toggleDeleteMapperDialog();
},
},
]}
/> />
</Tab> </Tab>
</KeycloakTabs> </KeycloakTabs>

View file

@ -20,10 +20,11 @@ export default {
deleteProvider: "Delete provider?", deleteProvider: "Delete provider?",
deleteProviderMapper: "Delete mapper?", deleteProviderMapper: "Delete mapper?",
deleteConfirm: deleteConfirm:
"Are you sure you want to permanently delete the provider '{{provider}}'", "Are you sure you want to permanently delete the provider '{{provider}}'?",
deleteMapperConfirm: deleteMapperConfirm:
"Are you sure you want to permanently delete the mapper '{{mapper}}'", "Are you sure you want to permanently delete the mapper {{mapper}}?",
deletedSuccess: "Provider successfully deleted", deleteMapperSuccess: "Mapper successfully deleted.",
deletedSuccess: "Provider successfully deleted.",
deleteError: "Could not delete the provider {{error}}", deleteError: "Could not delete the provider {{error}}",
disableProvider: "Disable provider?", disableProvider: "Disable provider?",
disableConfirm: disableConfirm: