Skip to content

Commit

Permalink
Removed type from url, query it (#3974)
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit authored Dec 11, 2022
1 parent 6f43a8d commit c7c7df8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
6 changes: 1 addition & 5 deletions apps/admin-ui/src/client-scopes/ClientScopesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,9 @@ export default function ClientScopesSection() {

const ClientScopeDetailLink = ({
id,
type,
name,
}: ClientScopeDefaultOptionalType) => (
<Link
key={id}
to={toClientScope({ realm, id: id!, type, tab: "settings" })}
>
<Link key={id} to={toClientScope({ realm, id: id!, tab: "settings" })}>
{name}
</Link>
);
Expand Down
6 changes: 3 additions & 3 deletions apps/admin-ui/src/client-scopes/details/MappingDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function MappingDetails() {
const { adminClient } = useAdminClient();
const { addAlert, addError } = useAlerts();

const { id, mapperId, type } = useParams<MapperParams>();
const { id, mapperId } = useParams<MapperParams>();
const form = useForm();
const { register, setValue, errors, handleSubmit } = form;
const [mapping, setMapping] = useState<ProtocolMapperTypeRepresentation>();
Expand All @@ -56,7 +56,7 @@ export default function MappingDetails() {
const isOnClientScope = !!useRouteMatch(MapperRoute.path);
const toDetails = () =>
isOnClientScope
? toClientScope({ realm, id, type: type!, tab: "mappers" })
? toClientScope({ realm, id, tab: "mappers" })
: `/${realm}/clients/${id}/mappers`;

useFetch(
Expand Down Expand Up @@ -92,7 +92,7 @@ export default function MappingDetails() {
data,
};
} else {
const model = type
const model = isOnClientScope
? await adminClient.clientScopes.findOne({ id })
: await adminClient.clients.findOne({ id });
if (!model) {
Expand Down
30 changes: 19 additions & 11 deletions apps/admin-ui/src/client-scopes/form/ClientScopeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useAlerts } from "../../components/alert/Alerts";
import {
AllClientScopes,
changeScope,
ClientScope,
ClientScopeDefaultOptionalType,
} from "../../components/client-scope/ClientScopeTypes";
import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog";
Expand Down Expand Up @@ -46,7 +47,7 @@ export default function ClientScopeForm() {
const { realm } = useRealm();

const { adminClient } = useAdminClient();
const { id, type } = useParams<{ id: string; type: AllClientScopes }>();
const { id } = useParams<{ id: string }>();

const { addAlert, addError } = useAlerts();

Expand All @@ -60,9 +61,23 @@ export default function ClientScopeForm() {
if (!clientScope) {
throw new Error(t("common:notFound"));
}

const defaultScopes =
await adminClient.clientScopes.listDefaultClientScopes();
const optionalScopes =
await adminClient.clientScopes.listDefaultOptionalClientScopes();

return {
...clientScope,
type,
type: defaultScopes.find(
(defaultScope) => defaultScope.name === clientScope.name
)
? ClientScope.default
: optionalScopes.find(
(optionalScope) => optionalScope.name === clientScope.name
)
? ClientScope.optional
: AllClientScopes.none,
};
}
},
Expand All @@ -81,11 +96,7 @@ export default function ClientScopeForm() {

if (id) {
await adminClient.clientScopes.update({ id }, clientScopes);
changeScope(
adminClient,
{ ...clientScopes, id, type },
clientScopes.type
);
changeScope(adminClient, { ...clientScopes, id }, clientScopes.type);
} else {
await adminClient.clientScopes.create(clientScopes);
const scope = await adminClient.clientScopes.findOneByName({
Expand All @@ -104,7 +115,6 @@ export default function ClientScopeForm() {
toClientScope({
realm,
id: scope.id!,
type: clientScopes.type || "none",
tab: "settings",
})
);
Expand Down Expand Up @@ -173,7 +183,6 @@ export default function ClientScopeForm() {
toMapper({
realm,
id: clientScope!.id!,
type,
mapperId: mapper.id!,
})
);
Expand Down Expand Up @@ -215,7 +224,6 @@ export default function ClientScopeForm() {
realm,
id,
tab,
type,
}),
history,
});
Expand Down Expand Up @@ -269,7 +277,7 @@ export default function ClientScopeForm() {
onAdd={addMappers}
onDelete={onDelete}
detailLink={(id) =>
toMapper({ realm, id: clientScope.id!, type, mapperId: id! })
toMapper({ realm, id: clientScope.id!, mapperId: id! })
}
/>
</Tab>
Expand Down
3 changes: 1 addition & 2 deletions apps/admin-ui/src/client-scopes/routes/ClientScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ export type ClientScopeParams = {
realm: string;
id: string;
tab: ClientScopeTab;
type?: string;
};

export const ClientScopeRoute: RouteDef = {
path: "/:realm/client-scopes/:id/:tab/:type",
path: "/:realm/client-scopes/:id/:tab",
component: lazy(() => import("../form/ClientScopeForm")),
breadcrumb: (t) => t("client-scopes:clientScopeDetails"),
access: "view-clients",
Expand Down
3 changes: 1 addition & 2 deletions apps/admin-ui/src/client-scopes/routes/Mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import type { RouteDef } from "../../route-config";
export type MapperParams = {
realm: string;
id: string;
type: string;
mapperId: string;
};

export const MapperRoute: RouteDef = {
path: "/:realm/client-scopes/:id/mappers/:type/:mapperId",
path: "/:realm/client-scopes/:id/mappers/:mapperId",
component: lazy(() => import("../details/MappingDetails")),
breadcrumb: (t) => t("common:mappingDetails"),
access: "view-clients",
Expand Down

0 comments on commit c7c7df8

Please sign in to comment.