Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add default rule for segments #4095

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 41 additions & 39 deletions frontend/web/components/modals/CreateSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,49 +319,51 @@ const CreateSegment: FC<CreateSegmentType> = ({
}, [operators, rules])
//Find any non-deleted rules
const hasNoRules = !rules[0]?.rules?.find((v) => !v.delete)

const rulesToShow = rules[0].rules.filter((v) => !v.delete)
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to ignore this if I'm wrong - it just caught my attention that we're guarding against rules[0] being undefined or null on the line above, but not this one.

const rulesEl = (
<div className='overflow-visible'>
<div>
<div className='mb-4'>
{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' />
{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={() => {
setValueChanged(true)
removeRule(0, i)
}}
onChange={(v: SegmentRule) => {
setValueChanged(true)
updateRule(0, i, v)
}}
/>
</div>
)
})}
{rules[0].rules.map((rule, i) => {
if (rule.delete) {
return null
}
const displayIndex = rulesToShow.indexOf(rule)
return (
<div key={i}>
<Row
className={classNames('and-divider my-1', {
'text-danger': rule.type !== 'ANY',
})}
>
<Flex className='and-divider__line' />
{Format.camelCase(
`${displayIndex > 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-${displayIndex}`}
rule={rule}
operators={operators}
onRemove={() => {
setValueChanged(true)
removeRule(0, i)
}}
onChange={(v: SegmentRule) => {
setValueChanged(true)
updateRule(0, i, v)
}}
/>
</div>
)
})}
</div>
{hasNoRules && (
<InfoMessage>
Expand Down
Loading