rebase and fix reload

This commit is contained in:
jenny-s51 2021-01-26 15:06:16 -05:00
parent a7fd36369e
commit 0bdb3b4a31
4 changed files with 24 additions and 16 deletions

View file

@ -80,7 +80,7 @@ export const RealmRoleForm = ({
<Button variant="primary" type="submit">
{t("common:save")}
</Button>
<Button onClick={reset} variant="link">
<Button onClick={() => reset()} variant="link">
{editMode ? t("common:reload") : t("common:cancel")}
</Button>
</ActionGroup>

View file

@ -170,7 +170,12 @@ export const RealmRoleTabs = () => {
eventKey="details"
title={<TabTitleText>{t("details")}</TabTitleText>}
>
<RealmRoleForm form={form} save={save} editMode={true} />
<RealmRoleForm
reset={() => form.reset(role)}
form={form}
save={save}
editMode={true}
/>
</Tab>
<Tab
eventKey="attributes"
@ -180,12 +185,20 @@ export const RealmRoleTabs = () => {
form={form}
save={save}
array={{ fields, append, remove }}
reset={() => form.reset(role)}
/>
</Tab>
</KeycloakTabs>
)}
{!id && <RealmRoleForm form={form} save={save} editMode={false} />}
{!id && (
<RealmRoleForm
reset={() => form.reset()}
form={form}
save={save}
editMode={false}
/>
)}
</PageSection>
</>
);
};
};

View file

@ -7,8 +7,7 @@ import {
ButtonVariant,
PageSection,
} from "@patternfly/react-core";
import { IFormatter, IFormatterValueType } from "@patternfly/react-table";
import { boolFormatter } from "../util";
import { useAdminClient } from "../context/auth/AdminClient";
import { ViewHeader } from "../components/view-header/ViewHeader";
import RoleRepresentation from "keycloak-admin/lib/defs/roleRepresentation";
@ -17,7 +16,7 @@ import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable
import { formattedLinkTableCell } from "../components/external-link/FormattedLink";
import { useAlerts } from "../components/alert/Alerts";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import { emptyFormatter, toUpperCase } from "../util";
import { emptyFormatter } from "../util";
export const RealmRolesSection = () => {
const { t } = useTranslation("roles");
@ -45,12 +44,6 @@ export const RealmRolesSection = () => {
</>
);
const boolFormatter = (): IFormatter => (data?: IFormatterValueType) => {
const boolVal = data?.toString();
return (boolVal ? toUpperCase(boolVal) : undefined) as string;
};
const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({
titleKey: "roles:roleDeleteConfirm",
messageKey: t("roles:roleDeleteConfirmDialog", {

View file

@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React from "react";
import { useTranslation } from "react-i18next";
import { ArrayField, UseFormMethods } from "react-hook-form";
import { ActionGroup, Button, TextInput } from "@patternfly/react-core";
@ -22,6 +22,7 @@ export type KeyValueType = { key: string; value: string };
type RoleAttributesProps = {
form: UseFormMethods<RoleFormType>;
save: (role: RoleFormType) => void;
reset: () => void;
array: {
fields: Partial<ArrayField<Record<string, any>, "id">>[];
append: (
@ -36,6 +37,7 @@ export const RoleAttributes = ({
form: { handleSubmit, register, formState, errors },
save,
array: { fields, append, remove },
reset,
}: RoleAttributesProps) => {
const { t } = useTranslation("roles");
@ -146,11 +148,11 @@ export const RoleAttributes = ({
>
{t("common:save")}
</Button>
<Button onClick={() => {}} variant="link">
<Button onClick={reset} variant="link">
{t("common:reload")}
</Button>
</ActionGroup>
</FormAccess>
</>
);
};
};