Removed type from url, query it (#3974)

This commit is contained in:
Erik Jan de Wit 2022-12-11 18:46:40 -05:00 committed by GitHub
parent 6f43a8d9ff
commit c7c7df872f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 23 deletions

View file

@ -160,13 +160,9 @@ export default function ClientScopesSection() {
const ClientScopeDetailLink = ({ const ClientScopeDetailLink = ({
id, id,
type,
name, name,
}: ClientScopeDefaultOptionalType) => ( }: ClientScopeDefaultOptionalType) => (
<Link <Link key={id} to={toClientScope({ realm, id: id!, tab: "settings" })}>
key={id}
to={toClientScope({ realm, id: id!, type, tab: "settings" })}
>
{name} {name}
</Link> </Link>
); );

View file

@ -38,7 +38,7 @@ export default function MappingDetails() {
const { adminClient } = useAdminClient(); const { adminClient } = useAdminClient();
const { addAlert, addError } = useAlerts(); const { addAlert, addError } = useAlerts();
const { id, mapperId, type } = useParams<MapperParams>(); const { id, mapperId } = useParams<MapperParams>();
const form = useForm(); const form = useForm();
const { register, setValue, errors, handleSubmit } = form; const { register, setValue, errors, handleSubmit } = form;
const [mapping, setMapping] = useState<ProtocolMapperTypeRepresentation>(); const [mapping, setMapping] = useState<ProtocolMapperTypeRepresentation>();
@ -56,7 +56,7 @@ export default function MappingDetails() {
const isOnClientScope = !!useRouteMatch(MapperRoute.path); const isOnClientScope = !!useRouteMatch(MapperRoute.path);
const toDetails = () => const toDetails = () =>
isOnClientScope isOnClientScope
? toClientScope({ realm, id, type: type!, tab: "mappers" }) ? toClientScope({ realm, id, tab: "mappers" })
: `/${realm}/clients/${id}/mappers`; : `/${realm}/clients/${id}/mappers`;
useFetch( useFetch(
@ -92,7 +92,7 @@ export default function MappingDetails() {
data, data,
}; };
} else { } else {
const model = type const model = isOnClientScope
? await adminClient.clientScopes.findOne({ id }) ? await adminClient.clientScopes.findOne({ id })
: await adminClient.clients.findOne({ id }); : await adminClient.clients.findOne({ id });
if (!model) { if (!model) {

View file

@ -18,6 +18,7 @@ import { useAlerts } from "../../components/alert/Alerts";
import { import {
AllClientScopes, AllClientScopes,
changeScope, changeScope,
ClientScope,
ClientScopeDefaultOptionalType, ClientScopeDefaultOptionalType,
} from "../../components/client-scope/ClientScopeTypes"; } from "../../components/client-scope/ClientScopeTypes";
import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog"; import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog";
@ -46,7 +47,7 @@ export default function ClientScopeForm() {
const { realm } = useRealm(); const { realm } = useRealm();
const { adminClient } = useAdminClient(); const { adminClient } = useAdminClient();
const { id, type } = useParams<{ id: string; type: AllClientScopes }>(); const { id } = useParams<{ id: string }>();
const { addAlert, addError } = useAlerts(); const { addAlert, addError } = useAlerts();
@ -60,9 +61,23 @@ export default function ClientScopeForm() {
if (!clientScope) { if (!clientScope) {
throw new Error(t("common:notFound")); throw new Error(t("common:notFound"));
} }
const defaultScopes =
await adminClient.clientScopes.listDefaultClientScopes();
const optionalScopes =
await adminClient.clientScopes.listDefaultOptionalClientScopes();
return { return {
...clientScope, ...clientScope,
type, type: defaultScopes.find(
(defaultScope) => defaultScope.name === clientScope.name
)
? ClientScope.default
: optionalScopes.find(
(optionalScope) => optionalScope.name === clientScope.name
)
? ClientScope.optional
: AllClientScopes.none,
}; };
} }
}, },
@ -81,11 +96,7 @@ export default function ClientScopeForm() {
if (id) { if (id) {
await adminClient.clientScopes.update({ id }, clientScopes); await adminClient.clientScopes.update({ id }, clientScopes);
changeScope( changeScope(adminClient, { ...clientScopes, id }, clientScopes.type);
adminClient,
{ ...clientScopes, id, type },
clientScopes.type
);
} else { } else {
await adminClient.clientScopes.create(clientScopes); await adminClient.clientScopes.create(clientScopes);
const scope = await adminClient.clientScopes.findOneByName({ const scope = await adminClient.clientScopes.findOneByName({
@ -104,7 +115,6 @@ export default function ClientScopeForm() {
toClientScope({ toClientScope({
realm, realm,
id: scope.id!, id: scope.id!,
type: clientScopes.type || "none",
tab: "settings", tab: "settings",
}) })
); );
@ -173,7 +183,6 @@ export default function ClientScopeForm() {
toMapper({ toMapper({
realm, realm,
id: clientScope!.id!, id: clientScope!.id!,
type,
mapperId: mapper.id!, mapperId: mapper.id!,
}) })
); );
@ -215,7 +224,6 @@ export default function ClientScopeForm() {
realm, realm,
id, id,
tab, tab,
type,
}), }),
history, history,
}); });
@ -269,7 +277,7 @@ export default function ClientScopeForm() {
onAdd={addMappers} onAdd={addMappers}
onDelete={onDelete} onDelete={onDelete}
detailLink={(id) => detailLink={(id) =>
toMapper({ realm, id: clientScope.id!, type, mapperId: id! }) toMapper({ realm, id: clientScope.id!, mapperId: id! })
} }
/> />
</Tab> </Tab>

View file

@ -9,11 +9,10 @@ export type ClientScopeParams = {
realm: string; realm: string;
id: string; id: string;
tab: ClientScopeTab; tab: ClientScopeTab;
type?: string;
}; };
export const ClientScopeRoute: RouteDef = { export const ClientScopeRoute: RouteDef = {
path: "/:realm/client-scopes/:id/:tab/:type", path: "/:realm/client-scopes/:id/:tab",
component: lazy(() => import("../form/ClientScopeForm")), component: lazy(() => import("../form/ClientScopeForm")),
breadcrumb: (t) => t("client-scopes:clientScopeDetails"), breadcrumb: (t) => t("client-scopes:clientScopeDetails"),
access: "view-clients", access: "view-clients",

View file

@ -6,12 +6,11 @@ import type { RouteDef } from "../../route-config";
export type MapperParams = { export type MapperParams = {
realm: string; realm: string;
id: string; id: string;
type: string;
mapperId: string; mapperId: string;
}; };
export const MapperRoute: RouteDef = { export const MapperRoute: RouteDef = {
path: "/:realm/client-scopes/:id/mappers/:type/:mapperId", path: "/:realm/client-scopes/:id/mappers/:mapperId",
component: lazy(() => import("../details/MappingDetails")), component: lazy(() => import("../details/MappingDetails")),
breadcrumb: (t) => t("common:mappingDetails"), breadcrumb: (t) => t("common:mappingDetails"),
access: "view-clients", access: "view-clients",