1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/frontend/src/utils/strategyNames.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

57 lines
1.8 KiB
TypeScript

import { FC } from 'react';
import { SvgIcon, useTheme } from '@mui/material';
import LocationOnIcon from '@mui/icons-material/LocationOn';
import PeopleIcon from '@mui/icons-material/People';
import LanguageIcon from '@mui/icons-material/Language';
import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew';
import CodeIcon from '@mui/icons-material/Code';
import { ReactComponent as RolloutIcon } from 'assets/icons/rollout.svg';
export const formatStrategyName = (strategyName: string): string => {
return formattedStrategyNames[strategyName] ?? strategyName;
};
const RolloutSvgIcon: FC = (props) => (
<SvgIcon
{...props}
component={(rest) => <RolloutIcon {...rest} />}
inheritViewBox
/>
);
export const getFeatureStrategyIcon = (strategyName: string) => {
switch (strategyName) {
case 'default':
return PowerSettingsNewIcon;
case 'remoteAddress':
return LanguageIcon;
case 'flexibleRollout':
return RolloutSvgIcon;
case 'userWithId':
return PeopleIcon;
case 'applicationHostname':
return LocationOnIcon;
default:
return CodeIcon;
}
};
export const GetFeatureStrategyIcon: FC<{ strategyName: string }> = ({
strategyName,
}) => {
const theme = useTheme();
const Icon = getFeatureStrategyIcon(strategyName);
return <Icon style={{ color: theme.palette.neutral.main }} />;
};
export const formattedStrategyNames: Record<string, string> = {
applicationHostname: 'Hosts',
default: 'Standard',
flexibleRollout: 'Gradual rollout',
gradualRolloutRandom: 'Randomized',
gradualRolloutSessionId: 'Sessions',
gradualRolloutUserId: 'Users',
remoteAddress: 'IPs',
userWithId: 'UserIDs',
};