|
| 1 | +import type { IStrategy } from 'interfaces/strategy'; |
| 2 | +import { Link } from 'react-router-dom'; |
| 3 | +import { |
| 4 | + getFeatureStrategyIcon, |
| 5 | + formatStrategyName, |
| 6 | +} from 'utils/strategyNames'; |
| 7 | +import { formatCreateStrategyPath } from 'component/feature/FeatureStrategy/FeatureStrategyCreate/FeatureStrategyCreate'; |
| 8 | +import StringTruncator from 'component/common/StringTruncator/StringTruncator'; |
| 9 | +import { styled } from '@mui/material'; |
| 10 | +import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; |
| 11 | + |
| 12 | +interface IFeatureStrategyMenuCardProps { |
| 13 | + projectId: string; |
| 14 | + featureId: string; |
| 15 | + environmentId: string; |
| 16 | + strategy: Pick<IStrategy, 'name' | 'displayName' | 'description'> & |
| 17 | + Partial<IStrategy>; |
| 18 | + defaultStrategy?: boolean; |
| 19 | +} |
| 20 | + |
| 21 | +const StyledIcon = styled('div')(({ theme }) => ({ |
| 22 | + width: theme.spacing(4), |
| 23 | + height: 'auto', |
| 24 | + '& > svg': { |
| 25 | + // Styling for SVG icons. |
| 26 | + fill: theme.palette.primary.main, |
| 27 | + }, |
| 28 | + '& > div': { |
| 29 | + // Styling for the Rollout icon. |
| 30 | + height: theme.spacing(2), |
| 31 | + marginLeft: '-.75rem', |
| 32 | + color: theme.palette.primary.main, |
| 33 | + }, |
| 34 | +})); |
| 35 | + |
| 36 | +const StyledDescription = styled('div')(({ theme }) => ({ |
| 37 | + fontSize: theme.fontSizes.smallBody, |
| 38 | +})); |
| 39 | + |
| 40 | +const StyledName = styled(StringTruncator)(({ theme }) => ({ |
| 41 | + fontWeight: theme.fontWeight.bold, |
| 42 | +})); |
| 43 | + |
| 44 | +const StyledCard = styled(Link)(({ theme }) => ({ |
| 45 | + display: 'grid', |
| 46 | + gridTemplateColumns: '3rem 1fr', |
| 47 | + width: '20rem', |
| 48 | + padding: theme.spacing(2), |
| 49 | + color: 'inherit', |
| 50 | + textDecoration: 'inherit', |
| 51 | + lineHeight: 1.25, |
| 52 | + borderWidth: '1px', |
| 53 | + borderStyle: 'solid', |
| 54 | + borderColor: theme.palette.divider, |
| 55 | + borderRadius: theme.spacing(1), |
| 56 | + '&:hover, &:focus': { |
| 57 | + borderColor: theme.palette.primary.main, |
| 58 | + }, |
| 59 | +})); |
| 60 | + |
| 61 | +export const OldFeatureStrategyMenuCard = ({ |
| 62 | + projectId, |
| 63 | + featureId, |
| 64 | + environmentId, |
| 65 | + strategy, |
| 66 | + defaultStrategy, |
| 67 | +}: IFeatureStrategyMenuCardProps) => { |
| 68 | + const StrategyIcon = getFeatureStrategyIcon(strategy.name); |
| 69 | + const strategyName = formatStrategyName(strategy.name); |
| 70 | + const { trackEvent } = usePlausibleTracker(); |
| 71 | + |
| 72 | + const createStrategyPath = formatCreateStrategyPath( |
| 73 | + projectId, |
| 74 | + featureId, |
| 75 | + environmentId, |
| 76 | + strategy.name, |
| 77 | + defaultStrategy, |
| 78 | + ); |
| 79 | + |
| 80 | + const openStrategyCreationModal = () => { |
| 81 | + trackEvent('strategy-add', { |
| 82 | + props: { |
| 83 | + buttonTitle: strategy.displayName || strategyName, |
| 84 | + }, |
| 85 | + }); |
| 86 | + }; |
| 87 | + |
| 88 | + return ( |
| 89 | + <StyledCard to={createStrategyPath} onClick={openStrategyCreationModal}> |
| 90 | + <StyledIcon> |
| 91 | + <StrategyIcon /> |
| 92 | + </StyledIcon> |
| 93 | + <div> |
| 94 | + <StyledName |
| 95 | + text={strategy.displayName || strategyName} |
| 96 | + maxWidth='200' |
| 97 | + maxLength={25} |
| 98 | + /> |
| 99 | + <StyledDescription>{strategy.description}</StyledDescription> |
| 100 | + </div> |
| 101 | + </StyledCard> |
| 102 | + ); |
| 103 | +}; |
0 commit comments