Skip to content

Commit

Permalink
fix: Adjust segment not rule (#3267)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Jan 11, 2024
1 parent 972f1a3 commit 6edc932
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 59 deletions.
1 change: 1 addition & 0 deletions frontend/e2e/helpers.cafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ export const createSegment = async (
rules?: Rule[],
) => {
await click(byId('show-create-segment-btn'))
await click(byId('add-rule'))
await setText(byId('segmentID'), id)
for (let x = 0; x < rules.length; x++) {
const rule = rules[x]
Expand Down
99 changes: 41 additions & 58 deletions frontend/web/components/modals/CreateSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import ErrorMessage from 'components/ErrorMessage'
import ProjectStore from 'common/stores/project-store'
import Icon from 'components/Icon'
import Permission from 'common/providers/Permission'
import classNames from 'classnames'

type PageType = {
number: number
Expand Down Expand Up @@ -99,13 +100,7 @@ const CreateSegment: FC<CreateSegmentType> = ({
rules: [
{
conditions: [],
rules: [
{
conditions: [{ ...Constants.defaultRule }],
rules: [],
type: 'ANY',
},
],
rules: [],
type: 'ALL',
},
],
Expand Down Expand Up @@ -268,31 +263,38 @@ const CreateSegment: FC<CreateSegmentType> = ({
<div className='overflow-visible'>
<div>
<div className='mb-4'>
{rules[0].rules.map((rule, i) => {
if (rule.delete) {
return null
}
return (
<div key={i}>
{i > 0 && (
<Row className='and-divider my-1'>
{rules[0].rules
?.filter((v) => !v?.delete)
.map((rule, i) => {
return (
<div key={i}>
<Row
className={classNames('and-divider my-1', {
'text-danger': rule.type !== 'ANY',
})}
>
<Flex className='and-divider__line' />
{rule.type === 'ANY' ? 'AND' : 'AND NOT'}
{Format.camelCase(
`${i > 0 ? 'And ' : ''}${
rule.type === 'ANY'
? 'Any of the following'
: 'None of the following'
}`,
)}
<Flex className='and-divider__line' />
</Row>
)}
<Rule
showDescription={showDescriptions}
readOnly={readOnly}
data-test={`rule-${i}`}
rule={rule}
operators={operators}
onRemove={() => removeRule(0, i)}
onChange={(v: SegmentRule) => updateRule(0, i, v)}
/>
</div>
)
})}
<Rule
showDescription={showDescriptions}
readOnly={readOnly}
data-test={`rule-${i}`}
rule={rule}
operators={operators}
onRemove={() => removeRule(0, i)}
onChange={(v: SegmentRule) => updateRule(0, i, v)}
/>
</div>
)
})}
</div>
<Row className='justify-content-end'>
{!readOnly && (
Expand All @@ -303,34 +305,15 @@ const CreateSegment: FC<CreateSegmentType> = ({
</div>
)}
{!readOnly && Utils.getFlagsmithHasFeature('not_operator') && (
<div onClick={() => addRule('NOT')} className='text-center'>
{Utils.getFlagsmithValue('not_operator') ? (
<Tooltip
title={
<Button
theme='outline'
className='ml-2 btn--outline-danger'
data-test='add-rule'
type='button'
>
Add AND NOT Condition
</Button>
}
>
{`Note: If using clientside evaluations on your SDK, this feature is only supported by the following SDKs: ${JSON.parse(
Utils.getFlagsmithValue('not_operator'),
)}`}
</Tooltip>
) : (
<Button
theme='outline'
className='ml-2 btn--outline-danger'
data-test='add-rule'
type='button'
>
Add AND NOT Condition
</Button>
)}
<div onClick={() => addRule('NONE')} className='text-center'>
<Button
theme='outline'
className='ml-2 btn--outline-danger'
data-test='add-rule'
type='button'
>
Add AND NOT Condition
</Button>
</div>
)}
</Row>
Expand Down Expand Up @@ -419,7 +402,7 @@ const CreateSegment: FC<CreateSegmentType> = ({
</Row>
<Flex className='mb-3'>
<label className='cols-sm-2 control-label mb-1'>
Include users when the following rules apply:
Include users when all of the following rules apply:
</label>
<span className='fs-caption text-faint'>
Note: Trait names are case sensitive
Expand Down
1 change: 0 additions & 1 deletion frontend/web/styles/project/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
}
.and-divider {
color: $text-icon-light-grey;
text-transform: uppercase;
font-weight: 400;
font-size: $font-caption;
line-height: $line-height-xsm;
Expand Down

3 comments on commit 6edc932

@vercel
Copy link

@vercel vercel bot commented on 6edc932 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 6edc932 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 6edc932 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-flagsmith.vercel.app
docs.flagsmith.com
docs-git-main-flagsmith.vercel.app
docs.bullet-train.io

Please sign in to comment.