2022-05-09 10:44:07 +00:00
|
|
|
import React, { useMemo } from "react";
|
2022-04-28 13:36:43 +00:00
|
|
|
import { useHistory } from "react-router-dom";
|
|
|
|
import { Trans, useTranslation } from "react-i18next";
|
|
|
|
import { xor } from "lodash-es";
|
2021-01-15 01:44:16 +00:00
|
|
|
import {
|
|
|
|
Brand,
|
|
|
|
Card,
|
|
|
|
CardBody,
|
|
|
|
CardTitle,
|
|
|
|
DescriptionList,
|
|
|
|
DescriptionListDescription,
|
|
|
|
DescriptionListGroup,
|
|
|
|
DescriptionListTerm,
|
|
|
|
EmptyState,
|
|
|
|
EmptyStateBody,
|
|
|
|
Grid,
|
|
|
|
GridItem,
|
|
|
|
Label,
|
|
|
|
List,
|
|
|
|
ListItem,
|
|
|
|
ListVariant,
|
|
|
|
PageSection,
|
2022-04-28 13:36:43 +00:00
|
|
|
Tab,
|
|
|
|
TabTitleText,
|
2021-01-15 01:44:16 +00:00
|
|
|
Text,
|
|
|
|
TextContent,
|
|
|
|
Title,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
|
|
|
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
|
2021-07-15 09:50:01 +00:00
|
|
|
import { toUpperCase } from "../util";
|
2021-01-31 17:58:16 +00:00
|
|
|
import { HelpItem } from "../components/help-enabler/HelpItem";
|
2021-07-15 09:50:01 +00:00
|
|
|
import environment from "../environment";
|
2022-04-28 13:36:43 +00:00
|
|
|
import { KeycloakSpinner } from "../components/keycloak-spinner/KeycloakSpinner";
|
2022-05-09 10:44:07 +00:00
|
|
|
import useLocaleSort from "../utils/useLocaleSort";
|
2022-04-28 13:36:43 +00:00
|
|
|
import {
|
|
|
|
routableTab,
|
|
|
|
RoutableTabs,
|
|
|
|
} from "../components/routable-tabs/RoutableTabs";
|
|
|
|
import { DashboardTab, toDashboard } from "./routes/Dashboard";
|
2022-05-09 10:44:07 +00:00
|
|
|
import { ProviderInfo } from "./ProviderInfo";
|
2021-01-15 01:44:16 +00:00
|
|
|
|
2022-02-08 22:10:27 +00:00
|
|
|
import "./dashboard.css";
|
|
|
|
|
2021-01-15 01:44:16 +00:00
|
|
|
const EmptyDashboard = () => {
|
|
|
|
const { t } = useTranslation("dashboard");
|
2021-07-14 15:35:49 +00:00
|
|
|
const { realm } = useRealm();
|
2021-01-15 01:44:16 +00:00
|
|
|
return (
|
|
|
|
<PageSection variant="light">
|
|
|
|
<EmptyState variant="large">
|
|
|
|
<Brand
|
2021-07-15 09:50:01 +00:00
|
|
|
src={environment.resourceUrl + "/icon.svg"}
|
2021-01-15 01:44:16 +00:00
|
|
|
alt="Keycloak icon"
|
|
|
|
className="keycloak__dashboard_icon"
|
|
|
|
/>
|
|
|
|
<Title headingLevel="h4" size="3xl">
|
|
|
|
{t("welcome")}
|
|
|
|
</Title>
|
|
|
|
<Title headingLevel="h4" size="4xl">
|
|
|
|
{realm}
|
|
|
|
</Title>
|
|
|
|
<EmptyStateBody>{t("introduction")}</EmptyStateBody>
|
|
|
|
</EmptyState>
|
|
|
|
</PageSection>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const Dashboard = () => {
|
|
|
|
const { t } = useTranslation("dashboard");
|
|
|
|
const { realm } = useRealm();
|
|
|
|
const serverInfo = useServerInfo();
|
2022-04-28 13:36:43 +00:00
|
|
|
const history = useHistory();
|
2022-05-09 10:44:07 +00:00
|
|
|
const localeSort = useLocaleSort();
|
2021-01-15 01:44:16 +00:00
|
|
|
|
2022-05-09 10:44:07 +00:00
|
|
|
const enabledFeatures = useMemo(
|
|
|
|
() =>
|
|
|
|
localeSort(
|
|
|
|
xor(
|
|
|
|
serverInfo.profileInfo?.disabledFeatures,
|
|
|
|
serverInfo.profileInfo?.experimentalFeatures,
|
|
|
|
serverInfo.profileInfo?.previewFeatures
|
|
|
|
),
|
|
|
|
(item) => item
|
|
|
|
),
|
|
|
|
[serverInfo.profileInfo]
|
|
|
|
);
|
|
|
|
|
|
|
|
const disabledFeatures = useMemo(
|
|
|
|
() =>
|
|
|
|
localeSort(
|
|
|
|
serverInfo.profileInfo?.disabledFeatures ?? [],
|
|
|
|
(item) => item
|
|
|
|
),
|
|
|
|
[serverInfo.profileInfo]
|
2021-01-15 01:44:16 +00:00
|
|
|
);
|
|
|
|
|
2022-04-28 13:36:43 +00:00
|
|
|
const isExperimentalFeature = (feature: string) =>
|
|
|
|
serverInfo.profileInfo?.experimentalFeatures?.includes(feature);
|
2021-01-15 01:44:16 +00:00
|
|
|
|
2022-04-28 13:36:43 +00:00
|
|
|
const isPreviewFeature = (feature: string) =>
|
|
|
|
serverInfo.profileInfo?.previewFeatures?.includes(feature);
|
2021-01-15 01:44:16 +00:00
|
|
|
|
2022-02-08 22:10:27 +00:00
|
|
|
if (Object.keys(serverInfo).length === 0) {
|
|
|
|
return <KeycloakSpinner />;
|
|
|
|
}
|
|
|
|
|
2022-04-28 13:36:43 +00:00
|
|
|
const route = (tab: DashboardTab) =>
|
|
|
|
routableTab({
|
|
|
|
to: toDashboard({
|
|
|
|
realm,
|
|
|
|
tab,
|
|
|
|
}),
|
|
|
|
history,
|
|
|
|
});
|
|
|
|
|
2021-01-15 01:44:16 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<PageSection variant="light">
|
|
|
|
<TextContent className="pf-u-mr-sm">
|
2021-11-26 10:28:00 +00:00
|
|
|
<Text component="h1">
|
|
|
|
{t("realmName", { name: toUpperCase(realm) })}
|
|
|
|
</Text>
|
|
|
|
<Text>
|
|
|
|
<Trans t={t} i18nKey="adminUiVersion">
|
|
|
|
<strong>Admin UI version</strong>
|
|
|
|
{{ version: environment.commitHash }}
|
|
|
|
</Trans>
|
|
|
|
</Text>
|
2021-01-15 01:44:16 +00:00
|
|
|
</TextContent>
|
|
|
|
</PageSection>
|
2022-04-28 13:36:43 +00:00
|
|
|
<PageSection variant="light" className="pf-u-p-0">
|
|
|
|
<RoutableTabs
|
|
|
|
data-testid="dashboard-tabs"
|
|
|
|
defaultLocation={toDashboard({
|
|
|
|
realm,
|
|
|
|
tab: "info",
|
|
|
|
})}
|
|
|
|
isBox
|
|
|
|
mountOnEnter
|
|
|
|
>
|
|
|
|
<Tab
|
|
|
|
id="info"
|
|
|
|
data-testid="infoTab"
|
|
|
|
title={<TabTitleText>{t("realmInfo")}</TabTitleText>}
|
|
|
|
{...route("info")}
|
|
|
|
>
|
|
|
|
<PageSection variant="light">
|
|
|
|
<Grid hasGutter>
|
|
|
|
<GridItem lg={2} sm={12}>
|
|
|
|
<Card className="keycloak__dashboard_card">
|
|
|
|
<CardTitle>{t("serverInfo")}</CardTitle>
|
|
|
|
<CardBody>
|
|
|
|
<DescriptionList>
|
|
|
|
<DescriptionListGroup>
|
|
|
|
<DescriptionListTerm>
|
|
|
|
{t("version")}
|
|
|
|
</DescriptionListTerm>
|
|
|
|
<DescriptionListDescription>
|
|
|
|
{serverInfo.systemInfo?.version}
|
|
|
|
</DescriptionListDescription>
|
|
|
|
<DescriptionListTerm>
|
|
|
|
{t("product")}
|
|
|
|
</DescriptionListTerm>
|
|
|
|
<DescriptionListDescription>
|
|
|
|
{toUpperCase(serverInfo.profileInfo?.name!)}
|
|
|
|
</DescriptionListDescription>
|
|
|
|
</DescriptionListGroup>
|
|
|
|
</DescriptionList>
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem lg={10} sm={12}>
|
|
|
|
<Card className="keycloak__dashboard_card">
|
|
|
|
<CardTitle>{t("profile")}</CardTitle>
|
|
|
|
<CardBody>
|
|
|
|
<DescriptionList>
|
|
|
|
<DescriptionListGroup>
|
|
|
|
<DescriptionListTerm>
|
|
|
|
{t("enabledFeatures")}{" "}
|
|
|
|
<HelpItem
|
|
|
|
fieldLabelId="dashboard:enabledFeatures"
|
|
|
|
helpText="dashboard:infoEnabledFeatures"
|
|
|
|
/>
|
|
|
|
</DescriptionListTerm>
|
|
|
|
<DescriptionListDescription>
|
|
|
|
<List variant={ListVariant.inline}>
|
|
|
|
{enabledFeatures.map((feature) => (
|
|
|
|
<ListItem key={feature}>
|
|
|
|
{feature}{" "}
|
|
|
|
{isExperimentalFeature(feature) ? (
|
|
|
|
<Label color="orange">
|
|
|
|
{t("experimental")}
|
|
|
|
</Label>
|
|
|
|
) : null}
|
|
|
|
{isPreviewFeature(feature) ? (
|
|
|
|
<Label color="blue">{t("preview")}</Label>
|
|
|
|
) : null}
|
|
|
|
</ListItem>
|
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
</DescriptionListDescription>
|
|
|
|
</DescriptionListGroup>
|
|
|
|
<DescriptionListGroup>
|
|
|
|
<DescriptionListTerm>
|
|
|
|
{t("disabledFeatures")}{" "}
|
|
|
|
<HelpItem
|
|
|
|
fieldLabelId="dashboard:disabledFeatures"
|
|
|
|
helpText="dashboard:infoDisabledFeatures"
|
|
|
|
/>
|
|
|
|
</DescriptionListTerm>
|
|
|
|
<DescriptionListDescription>
|
|
|
|
<List variant={ListVariant.inline}>
|
2022-05-09 10:44:07 +00:00
|
|
|
{disabledFeatures.map((feature) => (
|
|
|
|
<ListItem key={feature}>{feature}</ListItem>
|
|
|
|
))}
|
2022-04-28 13:36:43 +00:00
|
|
|
</List>
|
|
|
|
</DescriptionListDescription>
|
|
|
|
</DescriptionListGroup>
|
|
|
|
</DescriptionList>
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
</GridItem>
|
|
|
|
</Grid>
|
|
|
|
</PageSection>
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
id="providers"
|
|
|
|
data-testid="providersTab"
|
|
|
|
title={<TabTitleText>{t("providerInfo")}</TabTitleText>}
|
|
|
|
{...route("providers")}
|
|
|
|
>
|
2022-05-02 14:30:24 +00:00
|
|
|
<ProviderInfo />
|
2022-04-28 13:36:43 +00:00
|
|
|
</Tab>
|
|
|
|
</RoutableTabs>
|
2021-01-15 01:44:16 +00:00
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-10-29 16:11:06 +00:00
|
|
|
export default function DashboardSection() {
|
2021-01-15 01:44:16 +00:00
|
|
|
const { realm } = useRealm();
|
|
|
|
const isMasterRealm = realm === "master";
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{!isMasterRealm && <EmptyDashboard />}
|
|
|
|
{isMasterRealm && <Dashboard />}
|
|
|
|
</>
|
|
|
|
);
|
2021-10-29 16:11:06 +00:00
|
|
|
}
|