added import and save functions to resource tab (#1676)

* added import and save functions to resource tab

* added test

* fixed the test
This commit is contained in:
Erik Jan de Wit 2021-12-16 17:31:17 +01:00 committed by GitHub
parent 97641e51cb
commit a473a0b07f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 15 deletions

View file

@ -45,11 +45,7 @@ describe("Clients SAML tests", () => {
});
it("should save force name id format", () => {
const load = "auth/admin/realms/master/client-scopes";
cy.intercept(load).as("load");
cy.get(".pf-c-jump-links__list").contains("SAML capabilities").click();
cy.wait("@load");
cy.findByTestId("forceNameIdFormat").click({
force: true,
@ -142,6 +138,9 @@ describe("Clients SAML tests", () => {
it("Should update the resource server settings", () => {
listingPage.searchItem(clientName).goToItemDetails(clientName);
authenticationTab.goToTab();
authenticationTab.setPolicy("DISABLED").saveSettings();
masthead.checkNotificationMessage("Resource successfully updated");
});
it("Should create a resource", () => {

View file

@ -36,11 +36,21 @@ export default class AuthenticationTab {
return this;
}
setPolicy(policyName: string) {
cy.findByTestId(policyName).click();
return this;
}
save() {
cy.findByTestId("save").click();
return this;
}
saveSettings() {
cy.findByTestId("authenticationSettingsSave").click();
return this;
}
pressCancel() {
cy.findAllByTestId("cancel").click();
return this;

View file

@ -361,7 +361,7 @@ export default function ClientDetails() {
/>
<PageSection variant="light" className="pf-u-p-0">
<FormProvider {...form}>
<KeycloakTabs data-testid="client-tabs" isBox>
<KeycloakTabs data-testid="client-tabs" isBox mountOnEnter>
<Tab
id="settings"
eventKey="settings"
@ -467,6 +467,8 @@ export default function ClientDetails() {
<Tabs
activeKey={authorizationSubTab}
onSelect={(_, key) => setAuthorizationSubTab(key as number)}
mountOnEnter
unmountOnExit
>
<Tab
id="settings"

View file

@ -115,7 +115,7 @@ export default function ResourceDetails() {
AlertVariant.success
);
} catch (error) {
addError("client:resourceSaveError", error);
addError("clients:resourceSaveError", error);
}
};

View file

@ -2,6 +2,7 @@ import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { Controller, useForm } from "react-hook-form";
import {
AlertVariant,
Button,
Divider,
FormGroup,
@ -18,6 +19,7 @@ import { HelpItem } from "../../components/help-enabler/HelpItem";
import { SaveReset } from "../advanced/SaveReset";
import { ImportDialog } from "./ImportDialog";
import useToggle from "../../utils/useToggle";
import { useAlerts } from "../../components/alert/Alerts";
const POLICY_ENFORCEMENT_MODES = [
"ENFORCING",
@ -31,11 +33,13 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => {
const [resource, setResource] = useState<ResourceServerRepresentation>();
const [importDialog, toggleImportDialog] = useToggle();
const { control, reset } = useForm<ResourceServerRepresentation>({
const { control, reset, handleSubmit } =
useForm<ResourceServerRepresentation>({
shouldUnregister: false,
});
const adminClient = useAdminClient();
const { addAlert, addError } = useAlerts();
useFetch(
() => adminClient.clients.getResourceServer({ id: clientId }),
@ -46,8 +50,26 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => {
[]
);
const importResource = () => {
//different PR
const importResource = async (value: ResourceServerRepresentation) => {
try {
await adminClient.clients.importResource({ id: clientId }, value);
addAlert(t("importResourceSuccess"), AlertVariant.success);
reset({ ...value });
} catch (error) {
addError("clients:importResourceError", error);
}
};
const save = async (resource: ResourceServerRepresentation) => {
try {
await adminClient.clients.updateResourceServer(
{ id: clientId },
resource
);
addAlert(t("updateResourceSuccess"), AlertVariant.success);
} catch (error) {
addError("clients:resourceSaveError", error);
}
};
if (!resource) {
@ -174,10 +196,8 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => {
/>
</FormGroup>
<SaveReset
name="settings"
save={(): void => {
// another PR
}}
name="authenticationSettings"
save={() => handleSubmit(save)()}
reset={() => reset(resource)}
/>
</FormAccess>

View file

@ -64,6 +64,8 @@ export default {
importResources: "The following settings and data will be imported:",
importWarning:
"The data and settings imported above may overwrite the data and settings that already exist.",
importResourceSuccess: "The resource was successfully imported",
importResourceError: "Could not import the resource due to {{error}}",
createResource: "Create resource",
createResourceBasedPermission: "Create resource-based permission",
displayName: "Display name",