2023-03-15 13:22:06 +01:00
|
|
|
import {
|
|
|
|
IChangeRequestAddStrategy,
|
|
|
|
IChangeRequestDeleteStrategy,
|
|
|
|
IChangeRequestUpdateStrategy,
|
|
|
|
} from 'component/changeRequest/changeRequest.types';
|
|
|
|
import { FC } from 'react';
|
|
|
|
import {
|
|
|
|
formatStrategyName,
|
|
|
|
GetFeatureStrategyIcon,
|
|
|
|
} from 'utils/strategyNames';
|
|
|
|
import EventDiff from 'component/events/EventDiff/EventDiff';
|
|
|
|
import omit from 'lodash.omit';
|
|
|
|
import { TooltipLink } from 'component/common/TooltipLink/TooltipLink';
|
2023-04-26 11:41:24 +02:00
|
|
|
import { Typography, styled } from '@mui/material';
|
|
|
|
import { IFeatureStrategy } from 'interfaces/strategy';
|
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
|
|
|
import { textTruncated } from 'themes/themeStyles';
|
2023-03-15 13:22:06 +01:00
|
|
|
|
|
|
|
const StyledCodeSection = styled('div')(({ theme }) => ({
|
|
|
|
overflowX: 'auto',
|
|
|
|
'& code': {
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
whiteSpace: 'pre-wrap',
|
|
|
|
fontFamily: 'monospace',
|
|
|
|
lineHeight: 1.5,
|
|
|
|
fontSize: theme.fontSizes.smallBody,
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
export const StrategyDiff: FC<{
|
|
|
|
change:
|
|
|
|
| IChangeRequestAddStrategy
|
|
|
|
| IChangeRequestUpdateStrategy
|
|
|
|
| IChangeRequestDeleteStrategy;
|
2023-04-26 11:41:24 +02:00
|
|
|
currentStrategy?: IFeatureStrategy;
|
|
|
|
}> = ({ change, currentStrategy }) => {
|
2023-03-15 13:22:06 +01:00
|
|
|
const changeRequestStrategy =
|
|
|
|
change.action === 'deleteStrategy' ? undefined : change.payload;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StyledCodeSection>
|
|
|
|
<EventDiff
|
|
|
|
entry={{
|
|
|
|
preData: omit(currentStrategy, 'sortOrder'),
|
|
|
|
data: changeRequestStrategy,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</StyledCodeSection>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
interface IStrategyTooltipLinkProps {
|
|
|
|
change:
|
|
|
|
| IChangeRequestAddStrategy
|
|
|
|
| IChangeRequestUpdateStrategy
|
|
|
|
| IChangeRequestDeleteStrategy;
|
2023-04-26 11:41:24 +02:00
|
|
|
previousTitle?: string;
|
2023-03-15 13:22:06 +01:00
|
|
|
}
|
|
|
|
|
2023-05-16 13:15:59 +02:00
|
|
|
const StyledContainer: FC = styled('div')(({ theme }) => ({
|
|
|
|
display: 'grid',
|
|
|
|
gridAutoFlow: 'column',
|
|
|
|
gridTemplateColumns: 'auto 1fr',
|
|
|
|
gap: theme.spacing(1),
|
|
|
|
alignItems: 'center',
|
|
|
|
}));
|
|
|
|
|
|
|
|
const Truncated = styled('div')(() => ({
|
|
|
|
...textTruncated,
|
|
|
|
maxWidth: 500,
|
|
|
|
}));
|
|
|
|
|
2023-03-15 13:22:06 +01:00
|
|
|
export const StrategyTooltipLink: FC<IStrategyTooltipLinkProps> = ({
|
|
|
|
change,
|
2023-04-26 11:41:24 +02:00
|
|
|
previousTitle,
|
2023-03-15 13:22:06 +01:00
|
|
|
children,
|
|
|
|
}) => (
|
2023-05-16 13:15:59 +02:00
|
|
|
<StyledContainer>
|
2023-03-15 13:22:06 +01:00
|
|
|
<GetFeatureStrategyIcon strategyName={change.payload.name} />
|
2023-05-16 13:15:59 +02:00
|
|
|
<Truncated>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(
|
|
|
|
(previousTitle && previousTitle !== change.payload.title) ||
|
2023-05-23 14:16:20 +02:00
|
|
|
(!previousTitle && change.payload.title)
|
2023-05-16 13:15:59 +02:00
|
|
|
)}
|
|
|
|
show={
|
|
|
|
<Truncated>
|
|
|
|
<Typography component="s" color="text.secondary">
|
2023-05-23 14:16:20 +02:00
|
|
|
{previousTitle ||
|
|
|
|
formatStrategyName(change.payload.name)}
|
2023-05-16 13:15:59 +02:00
|
|
|
</Typography>{' '}
|
|
|
|
</Truncated>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Truncated>
|
|
|
|
<TooltipLink
|
|
|
|
tooltip={children}
|
|
|
|
tooltipProps={{
|
|
|
|
maxWidth: 500,
|
|
|
|
maxHeight: 600,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Typography component="span">
|
|
|
|
{change.payload.title ||
|
|
|
|
formatStrategyName(change.payload.name)}
|
|
|
|
</Typography>
|
|
|
|
</TooltipLink>
|
|
|
|
</Truncated>
|
|
|
|
</Truncated>
|
|
|
|
</StyledContainer>
|
2023-03-15 13:22:06 +01:00
|
|
|
);
|