1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00
unleash.unleash/frontend/src/utils/strategyNames.tsx
Nuno Góis a00c17ba3d
chore: upgrade typescript in frontend to 5.4.2 (#6673)
Follow up to https://github.com/Unleash/unleash/pull/6605

This upgrades TypeScript in frontend to `5.4.2`, matching the version we
have on the server.
Only 2 things broke with this upgrade, so the changes are related to
fixing the types in those places.

This fixes https://github.com/Unleash/unleash/pull/6659
2024-03-22 10:13:44 +00:00

57 lines
1.8 KiB
TypeScript

import type { FC, SVGProps } 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: SVGProps<SVGSVGElement>) => <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',
};