Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Unleash/unleash into client…
Browse files Browse the repository at this point in the history
…-instance-service
  • Loading branch information
kwasniew committed Oct 23, 2023
2 parents ce99090 + 1d1aa27 commit e18eb42
Show file tree
Hide file tree
Showing 21 changed files with 226 additions and 65 deletions.
7 changes: 7 additions & 0 deletions frontend/cypress/integration/projects/overview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,16 @@ describe('project overview', () => {
});
cy.get(selectAll).click();

// Ensure button is enabled
cy.get(`[data-testid=${BATCH_ACTIONS_BAR}] button`)
.contains('Archive')
.should('not.have.attr', 'disabled');

// Separate click action
cy.get(`[data-testid=${BATCH_ACTIONS_BAR}] button`)
.contains('Archive')
.click();

cy.get('p')
.contains('Are you sure you want to archive ')
.should('exist');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface IConstraintAccordionViewProps {
onEdit?: () => void;
sx?: SxProps<Theme>;
compact?: boolean;
disabled?: boolean;
renderAfter?: JSX.Element;
}

Expand Down Expand Up @@ -68,6 +69,7 @@ export const ConstraintAccordionView = ({
onDelete,
sx = undefined,
compact = false,
disabled = false,
renderAfter,
}: IConstraintAccordionViewProps) => {
const [expandable, setExpandable] = useState(true);
Expand Down Expand Up @@ -102,6 +104,7 @@ export const ConstraintAccordionView = ({
onDelete={onDelete}
singleValue={singleValue}
allowExpand={setExpandable}
disabled={disabled}
expanded={expanded}
compact={compact}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface IConstraintAccordionViewHeaderProps {
expanded: boolean;
allowExpand: (shouldExpand: boolean) => void;
compact?: boolean;
disabled?: boolean;
}

const StyledContainer = styled('div')(({ theme }) => ({
Expand All @@ -34,6 +35,7 @@ export const ConstraintAccordionViewHeader = ({
allowExpand,
expanded,
compact,
disabled,
}: IConstraintAccordionViewHeaderProps) => {
const { context } = useUnleashContext();
const { contextName } = constraint;
Expand All @@ -44,12 +46,13 @@ export const ConstraintAccordionViewHeader = ({

return (
<StyledContainer>
<ConstraintIcon compact={compact} />
<ConstraintIcon compact={compact} disabled={disabled} />
<ConstraintAccordionViewHeaderInfo
constraint={constraint}
singleValue={singleValue}
allowExpand={allowExpand}
expanded={expanded}
disabled={disabled}
/>
<ConstraintAccordionHeaderActions
onEdit={onEdit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface ConstraintAccordionViewHeaderMetaInfoProps {
singleValue: boolean;
expanded: boolean;
allowExpand: (shouldExpand: boolean) => void;
disabled?: boolean;
maxLength?: number;
}

Expand All @@ -58,23 +59,34 @@ export const ConstraintAccordionViewHeaderInfo = ({
singleValue,
allowExpand,
expanded,
disabled = false,
maxLength = 112, //The max number of characters in the values text for NOT allowing expansion
}: ConstraintAccordionViewHeaderMetaInfoProps) => {
return (
<StyledHeaderWrapper>
<StyledHeaderMetaInfo>
<Tooltip title={constraint.contextName} arrow>
<StyledHeaderText>
<StyledHeaderText
sx={(theme) => ({
color: disabled
? theme.palette.text.secondary
: 'inherit',
})}
>
{constraint.contextName}
</StyledHeaderText>
</Tooltip>
<ConstraintViewHeaderOperator constraint={constraint} />
<ConstraintViewHeaderOperator
constraint={constraint}
disabled={disabled}
/>
<ConditionallyRender
condition={singleValue}
show={
<ConstraintAccordionViewHeaderSingleValue
constraint={constraint}
allowExpand={allowExpand}
disabled={disabled}
/>
}
elseShow={
Expand All @@ -83,6 +95,7 @@ export const ConstraintAccordionViewHeaderInfo = ({
expanded={expanded}
allowExpand={allowExpand}
maxLength={maxLength}
disabled={disabled}
/>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ConstraintSingleValueProps {
expanded: boolean;
maxLength: number;
allowExpand: (shouldExpand: boolean) => void;
disabled?: boolean;
}

const StyledHeaderValuesContainerWrapper = styled('div')(({ theme }) => ({
Expand Down Expand Up @@ -55,6 +56,7 @@ export const ConstraintAccordionViewHeaderMultipleValues = ({
expanded,
allowExpand,
maxLength,
disabled = false,
}: ConstraintSingleValueProps) => {
const [expandable, setExpandable] = useState(false);

Expand All @@ -72,7 +74,15 @@ export const ConstraintAccordionViewHeaderMultipleValues = ({
return (
<StyledHeaderValuesContainerWrapper>
<StyledHeaderValuesContainer>
<StyledValuesSpan>{text}</StyledValuesSpan>
<StyledValuesSpan
sx={(theme) => ({
color: disabled
? theme.palette.text.secondary
: 'inherit',
})}
>
{text}
</StyledValuesSpan>
<ConditionallyRender
condition={expandable}
show={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const StyledSingleValueChip = styled(Chip)(({ theme }) => ({
interface ConstraintSingleValueProps {
constraint: IConstraint;
allowExpand: (shouldExpand: boolean) => void;
disabled?: boolean;
}

const StyledHeaderValuesContainerWrapper = styled('div')(({ theme }) => ({
Expand All @@ -26,6 +27,7 @@ const StyledHeaderValuesContainerWrapper = styled('div')(({ theme }) => ({
export const ConstraintAccordionViewHeaderSingleValue = ({
constraint,
allowExpand,
disabled = false,
}: ConstraintSingleValueProps) => {
const { locationSettings } = useLocationSettings();

Expand All @@ -36,6 +38,9 @@ export const ConstraintAccordionViewHeaderSingleValue = ({
return (
<StyledHeaderValuesContainerWrapper>
<StyledSingleValueChip
sx={(theme) => ({
color: disabled ? theme.palette.text.secondary : 'inherit',
})}
label={formatConstraintValue(constraint, locationSettings)}
/>
</StyledHeaderValuesContainerWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { oneOf } from 'utils/oneOf';

interface ConstraintViewHeaderOperatorProps {
constraint: IConstraint;
disabled?: boolean;
}

const StyledHeaderValuesContainerWrapper = styled('div')(({ theme }) => ({
Expand All @@ -28,6 +29,7 @@ const StyledHeaderConstraintContainer = styled('div')(({ theme }) => ({

export const ConstraintViewHeaderOperator = ({
constraint,
disabled = false,
}: ConstraintViewHeaderOperatorProps) => {
return (
<StyledHeaderValuesContainerWrapper>
Expand All @@ -47,6 +49,7 @@ export const ConstraintViewHeaderOperator = ({
<ConstraintOperator
constraint={constraint}
hasPrefix={Boolean(constraint.inverted)}
disabled={disabled}
/>
</StyledHeaderConstraintContainer>
<ConditionallyRender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ import { TrackChanges } from '@mui/icons-material';

interface IConstraintIconProps {
compact?: boolean;
disabled?: boolean;
}

export const ConstraintIcon: VFC<IConstraintIconProps> = ({ compact }) => (
export const ConstraintIcon: VFC<IConstraintIconProps> = ({
compact,
disabled,
}) => (
<Box
sx={{
backgroundColor: 'primary.light',
sx={(theme) => ({
backgroundColor: disabled
? theme.palette.neutral.border
: 'primary.light',
p: compact ? '1px' : '2px',
borderRadius: '50%',
width: compact ? '18px' : '24px',
height: compact ? '18px' : '24px',
marginRight: '13px',
}}
})}
>
<TrackChanges
sx={(theme) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { styled } from '@mui/material';
interface IConstraintOperatorProps {
constraint: IConstraint;
hasPrefix?: boolean;
disabled?: boolean;
}

const StyledContainer = styled('div')(({ theme }) => ({
Expand All @@ -15,19 +16,25 @@ const StyledContainer = styled('div')(({ theme }) => ({
lineHeight: 1.25,
}));

const StyledName = styled('div')(({ theme }) => ({
const StyledName = styled('div', {
shouldForwardProp: (prop) => prop !== 'disabled',
})<{ disabled: boolean }>(({ theme, disabled }) => ({
fontSize: theme.fontSizes.smallBody,
lineHeight: 17 / 14,
color: disabled ? theme.palette.text.secondary : theme.palette.text.primary,
}));

const StyledText = styled('div')(({ theme }) => ({
const StyledText = styled('div', {
shouldForwardProp: (prop) => prop !== 'disabled',
})<{ disabled: boolean }>(({ theme, disabled }) => ({
fontSize: theme.fontSizes.smallerBody,
color: theme.palette.neutral.main,
color: disabled ? theme.palette.text.secondary : theme.palette.neutral.main,
}));

export const ConstraintOperator = ({
constraint,
hasPrefix,
disabled = false,
}: IConstraintOperatorProps) => {
const operatorName = constraint.operator;
const operatorText = formatOperatorDescription(constraint.operator);
Expand All @@ -40,8 +47,8 @@ export const ConstraintOperator = ({
paddingLeft: hasPrefix ? 0 : undefined,
}}
>
<StyledName>{operatorName}</StyledName>
<StyledText>{operatorText}</StyledText>
<StyledName disabled={disabled}>{operatorName}</StyledName>
<StyledText disabled={disabled}>{operatorText}</StyledText>
</StyledContainer>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { useTheme } from '@mui/material';
import { CSSProperties } from 'react';

interface IPercentageCircleProps {
percentage: number;
size?: `${number}rem`;
}

const PercentageCircle = ({
percentage,
size = '4rem',
}: IPercentageCircleProps) => {
const theme = useTheme();

const style: CSSProperties = {
display: 'block',
borderRadius: '100%',
transform: 'rotate(-90deg)',
height: size,
width: size,
background: theme.palette.background.elevation2,
};

// The percentage circle used to be drawn by CSS with a conic-gradient,
// but the result was either jagged or blurry. SVG seems to look better.
// See https://stackoverflow.com/a/70659532.
const radius = 100 / (2 * Math.PI);
const diameter = 2 * radius;

return (
<svg viewBox={`0 0 ${diameter} ${diameter}`} style={style} aria-hidden>
<title>A circle progress bar with {percentage}% completion.</title>
<circle
r={radius}
cx={radius}
cy={radius}
fill='none'
stroke={theme.palette.neutral.border}
strokeWidth={diameter}
strokeDasharray={`${percentage} 100`}
/>
</svg>
);
};

export default PercentageCircle;
18 changes: 16 additions & 2 deletions frontend/src/component/common/SegmentItem/SegmentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ConditionallyRender } from 'component/common/ConditionallyRender/Condit
interface ISegmentItemProps {
segment: Partial<ISegment>;
isExpanded?: boolean;
disabled?: boolean;
constraintList?: JSX.Element;
headerContent?: JSX.Element;
}
Expand Down Expand Up @@ -49,20 +50,33 @@ const StyledLink = styled(Link)(({ theme }) => ({
textDecoration: 'underline',
},
}));
const StyledText = styled('span', {
shouldForwardProp: (prop) => prop !== 'disabled',
})<{ disabled: boolean }>(({ theme, disabled }) => ({
color: disabled ? theme.palette.text.secondary : 'inherit',
}));

export const SegmentItem: VFC<ISegmentItemProps> = ({
segment,
isExpanded,
headerContent,
constraintList,
disabled = false,
}) => {
const [isOpen, setIsOpen] = useState(isExpanded || false);

return (
<StyledAccordion expanded={isOpen}>
<StyledAccordionSummary id={`segment-accordion-${segment.id}`}>
<DonutLarge color='secondary' sx={{ mr: 1 }} />
<span>Segment:</span>
<DonutLarge
sx={(theme) => ({
mr: 1,
color: disabled
? theme.palette.neutral.border
: theme.palette.secondary.main,
})}
/>
<StyledText disabled={disabled}>Segment:</StyledText>
<StyledLink to={`/segments/edit/${segment.id}`}>
{segment.name}
</StyledLink>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const StickyBanner = styled(Sticky)(({ theme }) => ({
borderBottom: `1px solid ${theme.palette.warning.border}`,
color: theme.palette.warning.contrastText,
backgroundColor: theme.palette.warning.light,
zIndex: 250,
}));

export const DraftBanner: VFC<IDraftBannerProps> = ({ project }) => {
Expand Down
Loading

0 comments on commit e18eb42

Please sign in to comment.