1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-10 01:19:53 +01:00
unleash.unleash/frontend/src/component/layout/MainLayout/NavigationSidebar/NewInUnleash/NewInUnleashItem.tsx
Gastón Fournier 3d476c5113
feat: change how we calculate what to show new in Unleash (#10931)
## About the changes
This helps to specify how long to show new in Unleash so we don't forget
to remove it when doing a release. This doesn't mean we should keep this
list forever, but this helps us to keep it clean in the UI at least.

### Tests
We did unit test the logic as follows (manually because it's not an easy
piece of code to test in the UI):
```typescript
test('ui-test', () => {
    const showUntil = '7.3.0';
    expect(lt('6.9.3', showUntil)).toBe(true);
    expect(lt('7.2.3', showUntil)).toBe(true);
    expect(lt('7.3.0', showUntil)).toBe(false);
    expect(lt('7.3.1', showUntil)).toBe(false);
    expect(lt('7.4.0', showUntil)).toBe(false);
    expect(lt('8.0.0', showUntil)).toBe(false);
});
```
2025-11-06 13:13:37 +01:00

118 lines
3.3 KiB
TypeScript

import { type ReactNode, useState } from 'react';
import { ListItem } from '@mui/material';
import { NewInUnleashTooltip } from './NewInUnleashTooltip.tsx';
import { NewInUnleashDialog } from './NewInUnleashDialog.tsx';
import { NewInUnleashSideBarItem } from './NewInUnleashSideBarItem.tsx';
import type { UiFlags } from 'interfaces/uiConfig.ts';
export type NewInUnleashItemDetails = {
label: string;
summary: string;
icon: ReactNode;
onCheckItOut?: () => void;
docsLink?: string;
filter: {
versionLowerThan: string;
enterpriseOnly?: boolean;
flag?: keyof UiFlags; // if this is still controlled by a flag
};
longDescription?: ReactNode;
preview?: ReactNode;
beta?: boolean;
popout?: boolean;
};
interface INewInUnleashItemProps
extends Omit<NewInUnleashItemDetails, 'filter' | 'beta'> {
onClick: () => void;
onDismiss: () => void;
beta: boolean;
}
const useTooltip = () => {
const [open, setOpen] = useState(false);
const handleTooltipClose = () => {
setOpen(false);
};
const handleTooltipOpen = () => {
setOpen(true);
};
return { open, handleTooltipOpen, handleTooltipClose };
};
export const NewInUnleashItem = ({
icon,
onClick,
onDismiss,
label,
longDescription,
onCheckItOut,
docsLink,
preview,
summary,
beta,
popout,
}: INewInUnleashItemProps) => {
const { open, handleTooltipOpen, handleTooltipClose } = useTooltip();
const onDismissClick = (e: React.MouseEvent) => {
e.stopPropagation();
onDismiss();
};
const onOpen = () => {
onClick();
handleTooltipOpen();
};
return (
<ListItem disablePadding>
{popout ? (
<>
<NewInUnleashDialog
open={open}
onClose={handleTooltipClose}
title={label}
longDescription={longDescription}
onCheckItOut={onCheckItOut}
docsLink={docsLink}
preview={preview}
beta={beta}
/>
<NewInUnleashSideBarItem
label={label}
summary={summary}
icon={icon}
beta={beta}
onClick={onOpen}
onDismiss={onDismissClick}
/>
</>
) : (
<NewInUnleashTooltip
open={open}
onClose={handleTooltipClose}
title={label}
longDescription={longDescription}
onCheckItOut={onCheckItOut}
docsLink={docsLink}
preview={preview}
beta={beta}
>
<NewInUnleashSideBarItem
label={label}
summary={summary}
icon={icon}
beta={beta}
onClick={onOpen}
onDismiss={onDismissClick}
/>
</NewInUnleashTooltip>
)}
</ListItem>
);
};