1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-14 01:16:17 +02:00

Extract strategy list and list item to common

This commit is contained in:
Thomas Heartman 2025-03-21 10:07:07 +01:00
parent 37f6f7c43b
commit e50e705e96
No known key found for this signature in database
GPG Key ID: BD1F880DAED1EE78
6 changed files with 70 additions and 65 deletions

View File

@ -0,0 +1,18 @@
import { styled } from '@mui/material';
export const StrategyList = styled('ol')(({ theme }) => ({
listStyle: 'none',
padding: 0,
margin: 0,
'& > li': {
paddingBlock: theme.spacing(2.5),
position: 'relative',
},
'& > li + li': {
borderTop: `1px solid ${theme.palette.divider}`,
},
'& > li:first-of-type': {
paddingTop: theme.spacing(1),
},
}));

View File

@ -0,0 +1,15 @@
import { type Theme, styled } from '@mui/material';
export const releasePlanBackground = (theme: Theme) =>
theme.palette.background.elevation2;
export const strategyBackground = (theme: Theme) =>
theme.palette.background.elevation1;
export const StrategyListItem = styled('li')<{
'data-type'?: 'release-plan' | 'strategy';
}>(({ theme, ...props }) => ({
background:
props['data-type'] === 'release-plan'
? releasePlanBackground(theme)
: strategyBackground(theme),
}));

View File

@ -4,7 +4,7 @@ import {
useEffect, useEffect,
useState, useState,
} from 'react'; } from 'react';
import { Alert, Pagination, type Theme, styled } from '@mui/material'; import { Alert, Pagination, styled } from '@mui/material';
import useFeatureStrategyApi from 'hooks/api/actions/useFeatureStrategyApi/useFeatureStrategyApi'; import useFeatureStrategyApi from 'hooks/api/actions/useFeatureStrategyApi/useFeatureStrategyApi';
import { formatUnknownError } from 'utils/formatUnknownError'; import { formatUnknownError } from 'utils/formatUnknownError';
import useToast from 'hooks/useToast'; import useToast from 'hooks/useToast';
@ -22,6 +22,12 @@ import { useReleasePlans } from 'hooks/api/getters/useReleasePlans/useReleasePla
import { ReleasePlan } from '../../../ReleasePlan/ReleasePlan'; import { ReleasePlan } from '../../../ReleasePlan/ReleasePlan';
import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator'; import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator';
import { ProjectEnvironmentStrategyDraggableItem } from './StrategyDraggableItem/ProjectEnvironmentStrategyDraggableItem'; import { ProjectEnvironmentStrategyDraggableItem } from './StrategyDraggableItem/ProjectEnvironmentStrategyDraggableItem';
import {
StrategyListItem,
releasePlanBackground,
strategyBackground,
} from 'component/common/StrategyList/StrategyListItem';
import { StrategyList } from 'component/common/StrategyList/StrategyList';
interface IEnvironmentAccordionBodyProps { interface IEnvironmentAccordionBodyProps {
isDisabled: boolean; isDisabled: boolean;
@ -33,37 +39,6 @@ const StyledAccordionBodyInnerContainer = styled('div')(({ theme }) => ({
borderBottom: `1px solid ${theme.palette.divider}`, borderBottom: `1px solid ${theme.palette.divider}`,
})); }));
export const StyledContentList = styled('ol')(({ theme }) => ({
listStyle: 'none',
padding: 0,
margin: 0,
'& > li': {
paddingBlock: theme.spacing(2.5),
position: 'relative',
},
'& > li + li': {
borderTop: `1px solid ${theme.palette.divider}`,
},
'& > li:first-of-type': {
paddingTop: theme.spacing(1),
},
}));
const releasePlanBackground = (theme: Theme) =>
theme.palette.background.elevation2;
const strategyBackground = (theme: Theme) =>
theme.palette.background.elevation1;
export const StyledListItem = styled('li')<{
'data-type'?: 'release-plan' | 'strategy';
}>(({ theme, ...props }) => ({
background:
props['data-type'] === 'release-plan'
? releasePlanBackground(theme)
: strategyBackground(theme),
}));
const AlertContainer = styled('div')(({ theme }) => ({ const AlertContainer = styled('div')(({ theme }) => ({
padding: theme.spacing(2), padding: theme.spacing(2),
paddingBottom: theme.spacing(0), paddingBottom: theme.spacing(0),
@ -248,19 +223,19 @@ export const EnvironmentAccordionBody = ({
</Alert> </Alert>
</AlertContainer> </AlertContainer>
) : null} ) : null}
<StyledContentList> <StrategyList>
{releasePlans.map((plan) => ( {releasePlans.map((plan) => (
<StyledListItem data-type='release-plan' key={plan.id}> <StrategyListItem data-type='release-plan' key={plan.id}>
<ReleasePlan <ReleasePlan
plan={plan} plan={plan}
environmentIsDisabled={isDisabled} environmentIsDisabled={isDisabled}
/> />
</StyledListItem> </StrategyListItem>
))} ))}
{paginateStrategies ? ( {paginateStrategies ? (
<> <>
{page.map((strategy, index) => ( {page.map((strategy, index) => (
<StyledListItem key={strategy.id}> <StrategyListItem key={strategy.id}>
{index > 0 || releasePlans.length > 0 ? ( {index > 0 || releasePlans.length > 0 ? (
<StrategySeparator /> <StrategySeparator />
) : null} ) : null}
@ -271,13 +246,13 @@ export const EnvironmentAccordionBody = ({
environmentName={featureEnvironment.name} environmentName={featureEnvironment.name}
otherEnvironments={otherEnvironments} otherEnvironments={otherEnvironments}
/> />
</StyledListItem> </StrategyListItem>
))} ))}
</> </>
) : ( ) : (
<> <>
{strategies.map((strategy, index) => ( {strategies.map((strategy, index) => (
<StyledListItem key={strategy.id}> <StrategyListItem key={strategy.id}>
{index > 0 || releasePlans.length > 0 ? ( {index > 0 || releasePlans.length > 0 ? (
<StrategySeparator /> <StrategySeparator />
) : null} ) : null}
@ -292,11 +267,11 @@ export const EnvironmentAccordionBody = ({
onDragOver={onDragOver(strategy.id)} onDragOver={onDragOver(strategy.id)}
onDragEnd={onDragEnd} onDragEnd={onDragEnd}
/> />
</StyledListItem> </StrategyListItem>
))} ))}
</> </>
)} )}
</StyledContentList> </StrategyList>
{paginateStrategies ? ( {paginateStrategies ? (
<Pagination <Pagination
count={pages.length} count={pages.length}

View File

@ -11,12 +11,11 @@ import {
type MilestoneStatus, type MilestoneStatus,
} from './ReleasePlanMilestoneStatus'; } from './ReleasePlanMilestoneStatus';
import { useState } from 'react'; import { useState } from 'react';
import {
StyledContentList,
StyledListItem,
} from '../../FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/EnvironmentAccordionBody';
import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator'; import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator';
import { StrategyItem } from '../../FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/StrategyDraggableItem/StrategyItem/StrategyItem'; import { StrategyItem } from '../../FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/StrategyDraggableItem/StrategyItem/StrategyItem';
import { StrategyList } from 'component/common/StrategyList/StrategyList';
import { StrategyListItem } from 'component/common/StrategyList/StrategyListItem';
const StyledAccordion = styled(Accordion, { const StyledAccordion = styled(Accordion, {
shouldForwardProp: (prop) => prop !== 'status', shouldForwardProp: (prop) => prop !== 'status',
@ -117,9 +116,9 @@ export const ReleasePlanMilestone = ({
</StyledSecondaryLabel> </StyledSecondaryLabel>
</StyledAccordionSummary> </StyledAccordionSummary>
<StyledAccordionDetails> <StyledAccordionDetails>
<StyledContentList> <StrategyList>
{milestone.strategies.map((strategy, index) => ( {milestone.strategies.map((strategy, index) => (
<StyledListItem key={strategy.id}> <StrategyListItem key={strategy.id}>
{index > 0 ? <StrategySeparator /> : null} {index > 0 ? <StrategySeparator /> : null}
<StrategyItem <StrategyItem
@ -132,9 +131,9 @@ export const ReleasePlanMilestone = ({
'', '',
}} }}
/> />
</StyledListItem> </StrategyListItem>
))} ))}
</StyledContentList> </StrategyList>
</StyledAccordionDetails> </StyledAccordionDetails>
</StyledAccordion> </StyledAccordion>
); );

View File

@ -3,12 +3,11 @@ import type {
PlaygroundStrategySchema, PlaygroundStrategySchema,
PlaygroundRequestSchema, PlaygroundRequestSchema,
} from 'openapi'; } from 'openapi';
import {
StyledContentList,
StyledListItem,
} from 'component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/EnvironmentAccordionBody';
import { FeatureStrategyItem } from './StrategyItem/FeatureStrategyItem'; import { FeatureStrategyItem } from './StrategyItem/FeatureStrategyItem';
import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator'; import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator';
import { StrategyList } from 'component/common/StrategyList/StrategyList';
import { StrategyListItem } from 'component/common/StrategyList/StrategyListItem';
interface PlaygroundResultStrategyListProps { interface PlaygroundResultStrategyListProps {
strategies: PlaygroundStrategySchema[]; strategies: PlaygroundStrategySchema[];
@ -31,7 +30,7 @@ const StyledListTitleDescription = styled('p')(({ theme }) => ({
fontSize: theme.typography.body2.fontSize, fontSize: theme.typography.body2.fontSize,
})); }));
const RestyledContentList = styled(StyledContentList)(({ theme }) => ({ const StyledStrategyList = styled(StrategyList)(({ theme }) => ({
marginInline: `calc(var(--popover-inline-padding) * -1)`, marginInline: `calc(var(--popover-inline-padding) * -1)`,
borderTop: `1px solid ${theme.palette.divider}`, borderTop: `1px solid ${theme.palette.divider}`,
'> li:last-of-type': { '> li:last-of-type': {
@ -63,17 +62,17 @@ export const PlaygroundResultStrategyLists = ({
</StyledListTitleDescription> </StyledListTitleDescription>
) : null} ) : null}
</StyledHeaderGroup> </StyledHeaderGroup>
<RestyledContentList> <StyledStrategyList>
{strategies?.map((strategy, index) => ( {strategies?.map((strategy, index) => (
<StyledListItem key={strategy.id}> <StrategyListItem key={strategy.id}>
{index > 0 ? <StrategySeparator /> : ''} {index > 0 ? <StrategySeparator /> : ''}
<FeatureStrategyItem <FeatureStrategyItem
strategy={strategy} strategy={strategy}
input={input} input={input}
/> />
</StyledListItem> </StrategyListItem>
))} ))}
</RestyledContentList> </StyledStrategyList>
</div> </div>
); );
}; };

View File

@ -19,15 +19,14 @@ import { ReleasePlanTemplateAddStrategyForm } from '../../MilestoneStrategy/Rele
import DragIndicator from '@mui/icons-material/DragIndicator'; import DragIndicator from '@mui/icons-material/DragIndicator';
import { type OnMoveItem, useDragItem } from 'hooks/useDragItem'; import { type OnMoveItem, useDragItem } from 'hooks/useDragItem';
import type { IExtendedMilestonePayload } from 'component/releases/hooks/useTemplateForm'; import type { IExtendedMilestonePayload } from 'component/releases/hooks/useTemplateForm';
import {
StyledContentList,
StyledListItem,
} from 'component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/EnvironmentAccordionBody';
import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator'; import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator';
import Edit from '@mui/icons-material/Edit'; import Edit from '@mui/icons-material/Edit';
import Delete from '@mui/icons-material/DeleteOutlined'; import Delete from '@mui/icons-material/DeleteOutlined';
import { StrategyDraggableItem } from 'component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/StrategyDraggableItem/StrategyDraggableItem'; import { StrategyDraggableItem } from 'component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/StrategyDraggableItem/StrategyDraggableItem';
import { ScreenReaderOnly } from 'component/common/ScreenReaderOnly/ScreenReaderOnly'; import { ScreenReaderOnly } from 'component/common/ScreenReaderOnly/ScreenReaderOnly';
import { StrategyList } from 'component/common/StrategyList/StrategyList';
import { StrategyListItem } from 'component/common/StrategyList/StrategyListItem';
const leftPadding = 3; const leftPadding = 3;
@ -469,9 +468,9 @@ export const MilestoneCard = ({
/> />
</StyledAccordionSummary> </StyledAccordionSummary>
<StyledAccordionDetails> <StyledAccordionDetails>
<StyledContentList> <StrategyList>
{milestone.strategies.map((strg, index) => ( {milestone.strategies.map((strg, index) => (
<StyledListItem key={strg.id}> <StrategyListItem key={strg.id}>
{index > 0 ? <StrategySeparator /> : null} {index > 0 ? <StrategySeparator /> : null}
<StrategyDraggableItem <StrategyDraggableItem
@ -513,9 +512,9 @@ export const MilestoneCard = ({
</> </>
} }
/> />
</StyledListItem> </StrategyListItem>
))} ))}
</StyledContentList> </StrategyList>
<StyledAccordionFooter> <StyledAccordionFooter>
<Button <Button
variant='text' variant='text'