This commit is contained in:
Christie Molloy 2020-10-14 16:47:29 -04:00
commit a4b858cdc0
10 changed files with 96 additions and 72 deletions

View file

@ -31,6 +31,7 @@ import { useAlerts } from "../components/alert/Alerts";
import { ViewHeader } from "../components/view-header/ViewHeader";
import { exportClient } from "../util";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import { useDownloadDialog } from "../components/download-dialog/DownloadDialog";
export const ClientSettings = () => {
const { t } = useTranslation("clients");
@ -74,6 +75,11 @@ export const ClientSettings = () => {
},
});
const [toggleDownloadDialog, DownloadDialog] = useDownloadDialog({
id,
protocol: form.getValues("protocol"),
});
const save = async () => {
if (await form.trigger()) {
const redirectUris = toValue(form.getValues()["redirectUris"]);
@ -89,6 +95,7 @@ export const ClientSettings = () => {
return (
<>
<DeleteConfirm />
<DownloadDialog />
<Controller
name="enabled"
control={form.control}
@ -110,6 +117,9 @@ export const ClientSettings = () => {
titleKey={name}
subKey="clients:clientsExplain"
selectItems={[
<SelectOption key="download" value="download">
{t("downloadAdapterConfig")}
</SelectOption>,
<SelectOption key="export" value="export">
{t("common:export")}
</SelectOption>,
@ -131,6 +141,8 @@ export const ClientSettings = () => {
exportClient(form.getValues());
} else if (value === "delete") {
toggleDeleteDialog();
} else if (value === "download") {
toggleDownloadDialog();
}
}}
/>

View file

@ -28,6 +28,7 @@
"clientDeleteError": "Could not delete client:",
"clientDeleteConfirmTitle": "Delete client?",
"disableConfirmTitle": "Disable client?",
"downloadAdapterConfig": "Download adapter config",
"disableConfirm": "If you disable this client, you cannot initiate a login or obtain access tokens.",
"clientDeleteConfirm": "If you delete this client, all associated data will be removed.",
"clientAuthentication": "Client authentication",

View file

@ -11,11 +11,15 @@ import {
StackItem,
TextArea,
} from "@patternfly/react-core";
import FileSaver from "file-saver";
import { ConfirmDialogModal } from "../confirm-dialog/ConfirmDialog";
import { HttpClientContext } from "../../context/http-service/HttpClientContext";
import { RealmContext } from "../../context/realm-context/RealmContext";
import { HelpItem } from "../help-enabler/HelpItem";
import { useTranslation } from "react-i18next";
import { useServerInfo } from "../../context/server-info/ServerInfoProvider";
import { HelpContext } from "../help-enabler/HelpHeader";
export type DownloadDialogProps = {
id: string;
@ -27,39 +31,6 @@ type DownloadDialogModalProps = DownloadDialogProps & {
toggleDialog: () => void;
};
const serverInfo = [
{
id: "keycloak-oidc-jboss-subsystem-cli",
protocol: "openid-connect",
downloadOnly: false,
displayType: "Keycloak OIDC JBoss Subsystem CLI",
helpText:
"CLI script you must edit and apply to your client app server. This type of configuration is useful when you can't or don't want to crack open your WAR file.",
filename: "keycloak-oidc-subsystem.cli",
mediaType: "text/plain",
},
{
id: "keycloak-oidc-jboss-subsystem",
protocol: "openid-connect",
downloadOnly: false,
displayType: "Keycloak OIDC JBoss Subsystem XML",
helpText:
"XML snippet you must edit and add to the Keycloak OIDC subsystem on your client app server. This type of configuration is useful when you can't or don't want to crack open your WAR file.",
filename: "keycloak-oidc-subsystem.xml",
mediaType: "application/xml",
},
{
id: "keycloak-oidc-keycloak-json",
protocol: "openid-connect",
downloadOnly: false,
displayType: "Keycloak OIDC JSON",
helpText:
"keycloak.json file used by the Keycloak OIDC client adapter to configure clients. This must be saved to a keycloak.json file and put in your WEB-INF directory of your WAR file. You may also want to tweak this file after you download it.",
filename: "keycloak.json",
mediaType: "application/json",
},
];
export const useDownloadDialog = (
props: DownloadDialogProps
): [() => void, () => ReactElement] => {
@ -84,8 +55,10 @@ export const DownloadDialog = ({
const httpClient = useContext(HttpClientContext)!;
const { realm } = useContext(RealmContext);
const { t } = useTranslation("common");
const { enabled } = useContext(HelpContext);
const serverInfo = useServerInfo();
const configFormats = serverInfo; //serverInfo.clientInstallations[protocol];
const configFormats = serverInfo.clientInstallations[protocol];
const [selected, setSelected] = useState(
configFormats[configFormats.length - 1].id
);
@ -95,21 +68,28 @@ export const DownloadDialog = ({
useEffect(() => {
(async () => {
const response = await httpClient.doGet<string>(
`admin/${realm}/master/clients/${id}/installation/providers/${selected}`
`/admin/realms/${realm}/clients/${id}/installation/providers/${selected}`
);
setSnippet(response.data!);
setSnippet(await response.text());
})();
}, [selected]);
}, [selected, snippet]);
return (
<ConfirmDialogModal
titleKey={t("clients:downloadAdaptorTitle")}
continueButtonLabel={t("download")}
onConfirm={() => {}}
onConfirm={() => {
const config = configFormats.find((config) => config.id === selected)!;
FileSaver.saveAs(
new Blob([snippet], { type: config.mediaType }),
config.filename
);
}}
open={open}
toggleDialog={toggleDialog}
>
<Form>
<Stack hasGutter>
{enabled && (
<StackItem>
<Alert
id={id}
@ -124,6 +104,7 @@ export const DownloadDialog = ({
}
</Alert>
</StackItem>
)}
<StackItem>
<FormGroup
fieldId="type"
@ -171,7 +152,7 @@ export const DownloadDialog = ({
<HelpItem
helpText={t("clients-help:details")}
forLabel={t("clients:details")}
forID=""
forID="details"
/>
}
>

View file

@ -9,6 +9,7 @@ import {
EmptyStateSecondaryActions,
} from "@patternfly/react-core";
import { PlusCircleIcon } from "@patternfly/react-icons";
import { SearchIcon } from "@patternfly/react-icons";
export type Action = {
text: string;
@ -19,8 +20,10 @@ export type Action = {
export type ListEmptyStateProps = {
message: string;
instructions: string;
primaryActionText: string;
onPrimaryAction: MouseEventHandler<HTMLButtonElement>;
primaryActionText?: string;
onPrimaryAction?: MouseEventHandler<HTMLButtonElement>;
hasIcon?: boolean;
isSearchVariant?: boolean;
secondaryActions?: Action[];
};
@ -28,26 +31,34 @@ export const ListEmptyState = ({
message,
instructions,
onPrimaryAction,
hasIcon,
isSearchVariant,
primaryActionText,
secondaryActions,
}: ListEmptyStateProps) => {
return (
<>
<EmptyState variant="large">
{hasIcon && isSearchVariant ? (
<EmptyStateIcon icon={SearchIcon} />
) : (
<EmptyStateIcon icon={PlusCircleIcon} />
)}
<Title headingLevel="h4" size="lg">
{message}
</Title>
<EmptyStateBody>{instructions}</EmptyStateBody>
{primaryActionText && (
<Button variant="primary" onClick={onPrimaryAction}>
{primaryActionText}
</Button>
)}
{secondaryActions && (
<EmptyStateSecondaryActions>
{secondaryActions.map((action) => (
<Button
key={action.text}
variant={action.type || ButtonVariant.primary}
variant={action.type || ButtonVariant.secondary}
onClick={action.onClick}
>
{action.text}

View file

@ -47,8 +47,8 @@ exports[`<ListEmptyState /> render 1`] = `
>
<button
aria-disabled="false"
class="pf-c-button pf-m-primary"
data-ouia-component-id="OUIA-Generated-Button-primary-2"
class="pf-c-button pf-m-secondary"
data-ouia-component-id="OUIA-Generated-Button-secondary-1"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"

View file

@ -1,5 +1,5 @@
import Keycloak, { KeycloakInstance } from "keycloak-js";
const keycloak: KeycloakInstance = Keycloak();
const keycloak: KeycloakInstance = Keycloak("/keycloak.json");
export default async function (): Promise<KeycloakInstance> {
await keycloak.init({ onLoad: "check-sso", pkceMethod: "S256" }).catch(() => {

View file

@ -76,6 +76,7 @@ export const GroupsCreateModal = ({
>
<Form isHorizontal>
<FormGroup
name="create-modal-group"
label={t("name")}
fieldId="group-id"
helperTextInvalid={t("common:required")}

View file

@ -10,6 +10,7 @@ import {
} from "./models/server-info";
import { TableToolbar } from "../components/table-toolbar/TableToolbar";
import { ViewHeader } from "../components/view-header/ViewHeader";
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
import {
Button,
Dropdown,
@ -90,10 +91,10 @@ export const GroupsSection = () => {
};
return (
<React.Fragment>
<>
<ViewHeader titleKey="groups:groups" subKey="groups:groupsDescription" />
<PageSection variant={PageSectionVariants.light}>
{rawData ? (
{rawData && rawData.length > 0 ? (
<>
<TableToolbar
inputGroupName="groupsToolbarTextInput"
@ -125,7 +126,17 @@ export const GroupsSection = () => {
</>
}
>
<GroupsList list={filteredData || rawData} refresh={loader} />
{rawData && (
<GroupsList list={filteredData ? filteredData : rawData} refresh={loader}/>
)}
{filteredData && filteredData.length === 0 && (
<ListEmptyState
hasIcon={true}
isSearchVariant={true}
message={t("noSearchResults")}
instructions={t("noSearchResultsInstructions")}
/>
)}
</TableToolbar>
<GroupsCreateModal
isCreateModalOpen={isCreateModalOpen}
@ -137,11 +148,14 @@ export const GroupsSection = () => {
/>
</>
) : (
<div className="pf-u-text-align-center">
<Spinner />
</div>
<ListEmptyState
hasIcon={true}
message={t("noGroupsInThisRealm")}
instructions={t("noGroupsInThisRealmInstructions")}
primaryActionText={t("createGroup")}
/>
)}
</PageSection>
</React.Fragment>
</>
);
};

View file

@ -15,6 +15,10 @@
"groupCreated": "Group created",
"couldNotCreateGroup": "Could not create group",
"createAGroup": "Create a group",
"create": "Create"
"create": "Create",
"noSearchResults": "No search results",
"noSearchResultsInstructions" : "Click on the search bar above to search for groups",
"noGroupsInThisRealm" : "No groups in this Realm",
"noGroupsInThisRealmInstructions" : "You haven't created any groups in this realm. Create a group to get started."
}
}

View file

@ -15237,7 +15237,7 @@ prepend-http@^1.0.0:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=
prettier@^2.0.5:
prettier@2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==