1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-24 17:51:14 +02:00
unleash.unleash/frontend/src/component/feature/CreateFeatureButton/CreateFeatureButton.tsx
Nuno Góis 4167a60588
feat: biome lint frontend (#4903)
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome
to the frontend as well.


![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65)

Added a few `biome-ignore` to speed up the process but we may want to
check and fix them in the future.
2023-10-02 13:25:46 +01:00

67 lines
2.3 KiB
TypeScript

import classnames from 'classnames';
import { Link, useNavigate } from 'react-router-dom';
import useMediaQuery from '@mui/material/useMediaQuery';
import { Add } from '@mui/icons-material';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { NAVIGATE_TO_CREATE_FEATURE } from 'utils/testIds';
import { useCreateFeaturePath } from 'component/feature/CreateFeatureButton/useCreateFeaturePath';
import PermissionButton from 'component/common/PermissionButton/PermissionButton';
import { CREATE_FEATURE } from 'component/providers/AccessProvider/permissions';
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
interface ICreateFeatureButtonProps {
loading: boolean;
filter: {
query?: string;
project: string;
};
}
export const CreateFeatureButton = ({
loading,
filter,
}: ICreateFeatureButtonProps) => {
const smallScreen = useMediaQuery('(max-width:800px)');
const createFeature = useCreateFeaturePath(filter);
const navigate = useNavigate();
if (!createFeature) {
return null;
}
return (
<ConditionallyRender
condition={smallScreen}
show={
<PermissionIconButton
permission={CREATE_FEATURE}
projectId={createFeature.projectId}
component={Link}
to={createFeature.path}
size='large'
tooltipProps={{
title: 'Create feature toggle',
}}
>
<Add />
</PermissionIconButton>
}
elseShow={
<PermissionButton
onClick={() => {
navigate(createFeature.path);
}}
permission={CREATE_FEATURE}
projectId={createFeature.projectId}
color='primary'
variant='contained'
data-testid={NAVIGATE_TO_CREATE_FEATURE}
className={classnames({ skeleton: loading })}
>
New feature toggle
</PermissionButton>
}
/>
);
};