Skip to content

Commit

Permalink
Bug 1978222: make Users list empty state message more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamilto committed Jul 8, 2021
1 parent e6db676 commit c7cf3e7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 41 deletions.
24 changes: 24 additions & 0 deletions frontend/packages/console-shared/src/hooks/oauth.ts
@@ -0,0 +1,24 @@
import { useK8sWatchResource } from '@console/internal/components/utils/k8s-watch-hook';
import { useAccessReview } from '@console/internal/components/utils/rbac';
import { OAuthModel } from '@console/internal/models';
import { OAuthKind, referenceForModel } from '@console/internal/module/k8s';

export const useCanEditIdentityProviders = () =>
useAccessReview({
group: OAuthModel.apiGroup,
resource: OAuthModel.plural,
name: 'cluster',
verb: 'patch',
});

export const useOAuthData = (canEdit: boolean) =>
useK8sWatchResource<OAuthKind>(
canEdit
? {
kind: referenceForModel(OAuthModel),
isList: false,
namespaced: false,
name: 'cluster',
}
: null,
);
Expand Up @@ -3,30 +3,8 @@ import { useTranslation } from 'react-i18next';
import { GettingStartedLink } from '@console/shared/src/components/getting-started';

import { OAuthModel } from '@console/internal/models';
import { OAuthKind, referenceForModel } from '@console/internal/module/k8s';
import { resourcePathFromModel } from '@console/internal/components/utils';
import { useAccessReview } from '@console/internal/components/utils/rbac';
import { useK8sWatchResource } from '@console/internal/components/utils/k8s-watch-hook';

const useCanEditIdentityProviders = () =>
useAccessReview({
group: OAuthModel.apiGroup,
resource: OAuthModel.plural,
name: 'cluster',
verb: 'patch',
});

const useOAuthData = (canEdit: boolean) =>
useK8sWatchResource<OAuthKind>(
canEdit
? {
kind: referenceForModel(OAuthModel),
isList: false,
namespaced: false,
name: 'cluster',
}
: null,
);
import { useCanEditIdentityProviders, useOAuthData } from '@console/shared/src/hooks/oauth';

export const useIdentityProviderLink = (): GettingStartedLink | null => {
const { t } = useTranslation();
Expand Down
56 changes: 39 additions & 17 deletions frontend/public/components/user.tsx
Expand Up @@ -5,6 +5,7 @@ import * as _ from 'lodash-es';
import { Button } from '@patternfly/react-core';
import { sortable } from '@patternfly/react-table';

import { useCanEditIdentityProviders, useOAuthData } from '@console/shared/src/hooks/oauth';
import * as UIActions from '../actions/ui';
import { OAuthModel, UserModel } from '../models';
import { K8sKind, referenceForModel, UserKind } from '../module/k8s';
Expand Down Expand Up @@ -67,35 +68,56 @@ const UserTableRow: RowFunction<UserKind> = ({ obj, index, key, style }) => {
);
};

const UsersHelpText = () => {
const { t } = useTranslation();
return <>{t('public~Users are automatically added the first time they log in.')}</>;
};

const EmptyMsg = () => {
const { t } = useTranslation();
return <MsgBox title={t('public~No Users found')} />;
};
const oAuthResourcePath = resourcePathFromModel(OAuthModel, 'cluster');

const NoDataEmptyMsg = () => {
const NoDataEmptyMsgDetail = () => {
const { t } = useTranslation();
const canEditIdentityProviders = useCanEditIdentityProviders();
const [oauth, oauthLoaded] = useOAuthData(canEditIdentityProviders);
return (
<MsgBox
title={t('public~No Users found')}
detail={
<>
<p>
{t(
'public~Add identity providers (IDPs) to the OAuth configuration to allow others to log in.',
)}
</p>
<>
{canEditIdentityProviders && oauthLoaded ? (
oauth?.spec?.identityProviders?.length > 0 ? (
<p>
<Link to={oAuthResourcePath}>
<Button variant="primary">{t('public~Add IDP')}</Button>
</Link>
<UsersHelpText />
</p>
</>
}
/>
) : (
<>
<p>
{t(
'public~Add identity providers (IDPs) to the OAuth configuration to allow others to log in.',
)}
</p>
<p>
<Link to={oAuthResourcePath}>
<Button variant="primary">{t('public~Add IDP')}</Button>
</Link>
</p>
</>
)
) : (
<p>
<UsersHelpText />
</p>
)}
</>
);
};

const NoDataEmptyMsg = () => {
const { t } = useTranslation();
return <MsgBox title={t('public~No Users found')} detail={<NoDataEmptyMsgDetail />} />;
};

export const UserList: React.FC = (props) => {
const { t } = useTranslation();
const UserTableHeader = () => {
Expand Down Expand Up @@ -144,7 +166,7 @@ export const UserPage: React.FC<UserPageProps> = (props) => {
<ListPage
{...props}
title={t('public~Users')}
helpText={<>{t('public~Users are automatically added the first time they log in.')}</>}
helpText={<UsersHelpText />}
kind={referenceForModel(UserModel)}
ListComponent={UserList}
canCreate={false}
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/en/public.json
Expand Up @@ -1440,12 +1440,12 @@
"Block": "Block",
"Collapse": "Collapse",
"Impersonate User {{name}}": "Impersonate User {{name}}",
"Users are automatically added the first time they log in.": "Users are automatically added the first time they log in.",
"No Users found": "No Users found",
"Add identity providers (IDPs) to the OAuth configuration to allow others to log in.": "Add identity providers (IDPs) to the OAuth configuration to allow others to log in.",
"Add IDP": "Add IDP",
"Full name": "Full name",
"Identities": "Identities",
"Users are automatically added the first time they log in.": "Users are automatically added the first time they log in.",
"User details": "User details",
"There is {{count}} {{variant}} alert.": "There is {{count}} {{variant}} alert.",
"There is {{count}} {{variant}} alert._plural": "There is {{count}} {{variant}} alert.s",
Expand Down

0 comments on commit c7cf3e7

Please sign in to comment.