1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-28 17:55:15 +02:00
unleash.unleash/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountTokensCell/ServiceAccountTokensCell.tsx
Nuno Góis 4286103850
feat: better tooltip links (#2891)
https://linear.app/unleash/issue/2-576/improve-how-text-that-has-tooltip-should-look-so-they-are-not


![image](https://user-images.githubusercontent.com/14320932/212140467-46d4f7f9-b5c1-40ea-9748-4a6ccc7950bb.png)


![image](https://user-images.githubusercontent.com/14320932/212140316-d6e88bc0-c26e-436b-855f-5f6e8697aed8.png)

- Adapts the existing `HtmlTooltip` component to support setting
`maxHeight` and `maxWidth` properties;
- Introduces a new common component: `TooltipLink`;
- Adapts SA (tokens), features (tags), variants (overrides, payloads)
and project access (role and role description);
- Role description in project access now uses this component instead of
the old jankier popover component;
2023-01-16 13:04:52 +01:00

56 lines
2.0 KiB
TypeScript

import { VFC } from 'react';
import { styled, Typography } from '@mui/material';
import { TextCell } from 'component/common/Table/cells/TextCell/TextCell';
import { Highlighter } from 'component/common/Highlighter/Highlighter';
import { useSearchHighlightContext } from 'component/common/Table/SearchHighlightContext/SearchHighlightContext';
import { IServiceAccount } from 'interfaces/service-account';
import { LinkCell } from 'component/common/Table/cells/LinkCell/LinkCell';
import { TooltipLink } from 'component/common/TooltipLink/TooltipLink';
const StyledItem = styled(Typography)(({ theme }) => ({
fontSize: theme.fontSizes.smallerBody,
}));
interface IServiceAccountTokensCellProps {
serviceAccount: IServiceAccount;
value: string;
onCreateToken: () => void;
}
export const ServiceAccountTokensCell: VFC<IServiceAccountTokensCellProps> = ({
serviceAccount,
value,
onCreateToken,
}) => {
const { searchQuery } = useSearchHighlightContext();
if (!serviceAccount.tokens || serviceAccount.tokens.length === 0)
return <LinkCell title="Create token" onClick={onCreateToken} />;
return (
<TextCell>
<TooltipLink
tooltip={
<>
{serviceAccount.tokens?.map(({ id, description }) => (
<StyledItem key={id}>
<Highlighter search={searchQuery}>
{description}
</Highlighter>
</StyledItem>
))}
</>
}
highlighted={
searchQuery.length > 0 &&
value.toLowerCase().includes(searchQuery.toLowerCase())
}
>
{serviceAccount.tokens?.length === 1
? '1 token'
: `${serviceAccount.tokens?.length} tokens`}
</TooltipLink>
</TextCell>
);
};