-
-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: selector dropdown for milestone new strategy (#8841)
- Loading branch information
Showing
6 changed files
with
229 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
frontend/src/component/releases/ReleasePlanTemplate/MilestoneStrategyMenuCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { | ||
formatStrategyName, | ||
getFeatureStrategyIcon, | ||
} from 'utils/strategyNames'; | ||
import { styled } from '@mui/material'; | ||
import type { IStrategy } from 'interfaces/strategy'; | ||
import StringTruncator from 'component/common/StringTruncator/StringTruncator'; | ||
import type { IReleasePlanMilestoneStrategy } from 'interfaces/releasePlans'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { createFeatureStrategy } from 'utils/createFeatureStrategy'; | ||
|
||
const StyledIcon = styled('div')(({ theme }) => ({ | ||
width: theme.spacing(4), | ||
height: 'auto', | ||
'& > svg': { | ||
// Styling for SVG icons. | ||
fill: theme.palette.primary.main, | ||
}, | ||
'& > div': { | ||
// Styling for the Rollout icon. | ||
height: theme.spacing(2), | ||
marginLeft: '-.75rem', | ||
color: theme.palette.primary.main, | ||
}, | ||
})); | ||
|
||
const StyledDescription = styled('div')(({ theme }) => ({ | ||
fontSize: theme.fontSizes.smallBody, | ||
})); | ||
|
||
const StyledName = styled(StringTruncator)(({ theme }) => ({ | ||
fontWeight: theme.fontWeight.bold, | ||
})); | ||
|
||
const StyledCard = styled('div')(({ theme }) => ({ | ||
display: 'grid', | ||
gridTemplateColumns: '3rem 1fr', | ||
width: '20rem', | ||
padding: theme.spacing(2), | ||
color: 'inherit', | ||
textDecoration: 'inherit', | ||
lineHeight: 1.25, | ||
borderWidth: '1px', | ||
borderStyle: 'solid', | ||
borderColor: theme.palette.divider, | ||
borderRadius: theme.spacing(1), | ||
'&:hover, &:focus': { | ||
borderColor: theme.palette.primary.main, | ||
}, | ||
})); | ||
|
||
interface IMilestoneStrategyMenuCardProps { | ||
strategy: IStrategy; | ||
onClick: (strategy: IReleasePlanMilestoneStrategy) => void; | ||
} | ||
|
||
export const MilestoneStrategyMenuCard = ({ | ||
strategy, | ||
onClick, | ||
}: IMilestoneStrategyMenuCardProps) => { | ||
const StrategyIcon = getFeatureStrategyIcon(strategy.name); | ||
const strategyName = formatStrategyName(strategy.name); | ||
return ( | ||
<StyledCard | ||
onClick={() => { | ||
const strat = createFeatureStrategy('', strategy); | ||
onClick({ | ||
id: uuidv4(), | ||
name: strat.name, | ||
title: '', | ||
constraints: strat.constraints, | ||
parameters: strat.parameters, | ||
}); | ||
}} | ||
> | ||
<StyledIcon> | ||
<StrategyIcon /> | ||
</StyledIcon> | ||
<div> | ||
<StyledName | ||
text={strategy.displayName || strategyName} | ||
maxWidth='200' | ||
maxLength={25} | ||
/> | ||
<StyledDescription>{strategy.description}</StyledDescription> | ||
</div> | ||
</StyledCard> | ||
); | ||
}; |
50 changes: 50 additions & 0 deletions
50
frontend/src/component/releases/ReleasePlanTemplate/MilestoneStrategyMenuCards.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { List, ListItem, styled, Typography } from '@mui/material'; | ||
import { MilestoneStrategyMenuCard } from './MilestoneStrategyMenuCard'; | ||
import { useStrategies } from 'hooks/api/getters/useStrategies/useStrategies'; | ||
import type { IReleasePlanMilestoneStrategy } from 'interfaces/releasePlans'; | ||
|
||
const StyledTypography = styled(Typography)(({ theme }) => ({ | ||
fontSize: theme.fontSizes.smallBody, | ||
padding: theme.spacing(1, 2), | ||
})); | ||
|
||
interface IMilestoneStrategyMenuCardsProps { | ||
milestoneId: string; | ||
openAddStrategy: ( | ||
milestoneId: string, | ||
strategy: IReleasePlanMilestoneStrategy, | ||
) => void; | ||
} | ||
|
||
export const MilestoneStrategyMenuCards = ({ | ||
milestoneId, | ||
openAddStrategy, | ||
}: IMilestoneStrategyMenuCardsProps) => { | ||
const { strategies } = useStrategies(); | ||
|
||
const preDefinedStrategies = strategies.filter( | ||
(strategy) => !strategy.deprecated && !strategy.editable, | ||
); | ||
|
||
const onClick = (strategy: IReleasePlanMilestoneStrategy) => { | ||
openAddStrategy(milestoneId, strategy); | ||
}; | ||
|
||
return ( | ||
<List dense> | ||
<> | ||
<StyledTypography color='textSecondary'> | ||
Predefined strategy types | ||
</StyledTypography> | ||
{preDefinedStrategies.map((strategy) => ( | ||
<ListItem key={strategy.name}> | ||
<MilestoneStrategyMenuCard | ||
strategy={strategy} | ||
onClick={onClick} | ||
/> | ||
</ListItem> | ||
))} | ||
</> | ||
</List> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters