Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enhance Service Accounts #3301

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions src/resources/ServiceAccounts/ServiceAccountDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import ServiceAccountCreate from './ServiceAccountCreate';
import { Button } from '@ui5/webcomponents-react';
import { TokenRequestModal } from './TokenRequestModal/TokenRequestModal';
import { ResourceDescription } from 'resources/ServiceAccounts';
import { EventsList } from 'shared/components/EventsList';
import { filterByResource } from 'hooks/useMessageList';
import { UI5Panel } from 'shared/components/UI5Panel/UI5Panel';
import { LayoutPanelRow } from 'shared/components/LayoutPanelRow/LayoutPanelRow';

const ServiceAccountSecrets = serviceAccount => {
const namespace = serviceAccount.metadata.namespace;
Expand Down Expand Up @@ -59,17 +63,32 @@ const ServiceAccountImagePullSecrets = serviceAccount => {
export default function ServiceAccountDetails(props) {
const { t } = useTranslation();
const [isTokenModalOpen, setTokenModalOpen] = useState(false);
const customColumns = [
{
header: t('service-accounts.headers.auto-mount-token'),
value: value => (
<ServiceAccountTokenStatus
automount={value.automountServiceAccountToken}
/>
),
},
];

const Events = () => (
<EventsList
key="events"
namespace={props.namespace}
filter={filterByResource('ServiceAccount', props.resourceName)}
hideInvolvedObjects={true}
/>
);

const Configuration = value => (
<UI5Panel
fixed
keyComponent={'serviceaccount-configuration'}
title={t('configuration.title')}
>
<LayoutPanelRow
name={t('service-accounts.headers.auto-mount-token')}
value={
<ServiceAccountTokenStatus
automount={value.automountServiceAccountToken}
/>
}
/>
</UI5Panel>
);
const headerActions = [
<Button
key="generate-token-request"
Expand All @@ -83,10 +102,11 @@ export default function ServiceAccountDetails(props) {
<>
<ResourceDetails
customComponents={[
Configuration,
ServiceAccountSecrets,
ServiceAccountImagePullSecrets,
Events,
]}
customColumns={customColumns}
createResourceForm={ServiceAccountCreate}
description={ResourceDescription}
headerActions={headerActions}
Expand Down
32 changes: 0 additions & 32 deletions src/shared/components/ServiceAccountTokenStatus.js

This file was deleted.

77 changes: 77 additions & 0 deletions src/shared/components/ServiceAccountTokenStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { StatusBadge } from 'shared/components/StatusBadge/StatusBadge';
import { useTranslation } from 'react-i18next';
import { Popover, Token } from '@ui5/webcomponents-react';
import { createPortal } from 'react-dom';
import { useRef, useState } from 'react';

export const ServiceAccountTokenStatus = ({
automount,
}: {
automount: boolean;
}) => {
const { t } = useTranslation();
const [openPopover, setOpenPopover] = useState(false);
const popoverRef = useRef<any>(null);
const openerRef = useRef(null);

const handleOpenerClick = (e: React.MouseEvent) => {
e.stopPropagation();
if (popoverRef.current) {
popoverRef.current.opener = openerRef.current;
setOpenPopover(prev => !prev);
}
};

const accountTokenValues = automount
? {
type: 'Warning',
tooltipContent: t(
'service-accounts.auto-mount-token.descriptions.enabled',
),
status: t('service-accounts.auto-mount-token.enabled'),
}
: {
type: 'Neutral',
tooltipContent: t(
'service-accounts.auto-mount-token.descriptions.disabled',
),
status: t('service-accounts.auto-mount-token.disabled'),
};

const tokenElement = (
<button ref={openerRef} onClick={handleOpenerClick} className="badge-wrap">
<Token
style={{ textTransform: 'capitalize' }}
text={accountTokenValues.status}
readonly
></Token>
</button>
);

return automount ? (
<StatusBadge
type={accountTokenValues.type}
tooltipContent={accountTokenValues.tooltipContent}
>
{accountTokenValues.status}
</StatusBadge>
) : (
<>
{createPortal(
<Popover
ref={popoverRef}
open={openPopover}
onAfterClose={e => {
e.stopPropagation();
setOpenPopover(false);
}}
placementType="Right"
>
{accountTokenValues.tooltipContent}
</Popover>,
document.body,
)}
{tokenElement}
</>
);
};
Loading