All files / modules/75-cf/pages/segment-details SegmentRules.tsx

35.94% Statements 69/192
15.5% Branches 31/200
12.68% Functions 9/71
37.5% Lines 63/168

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664              1x 1x 1x                               1x 1x 1x 1x 1x 1x 1x 1x                 1x 1x 1x 1x 1x   1x       1x     1x               1x                                                           1x                                                                                                                                                                               1x 1x                                       1x                                 6x 6x   6x   6x                                                                                         6x 6x                                                                                         12x     6x                         6x                         6x       6x                                                                                                                                                                                                                                     4x   1x 2x                 2x       1x 1x 1x 2x                 1x                                         1x 6x 6x 6x 6x 6x 6x   6x                 6x                   6x   6x           6x 2x                 18x                   6x                                                                                             6x                         6x                 6x               6x                                        
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import React, { useEffect, useReducer, useState } from 'react'
import { useParams } from 'react-router-dom'
import {
  Avatar,
  AvatarGroup,
  Button,
  Card,
  Container,
  Icon,
  Layout,
  MultiSelect,
  MultiSelectOption,
  Select,
  SelectOption,
  SimpleTagInput,
  Text,
  TextInput
} from '@wings-software/uicore'
import { useModalHook } from '@harness/use-modal'
import { Color } from '@harness/design-system'
import { isEqual, omit } from 'lodash-es'
import { Dialog, Divider, Spinner } from '@blueprintjs/core'
import { useToaster } from '@common/exports'
import { useStrings } from 'framework/strings'
import { IsSingleValued, useOperatorsFromYaml } from '@cf/constants'
import {
  Clause,
  GetAllTargetsQueryParams,
  PatchSegmentQueryParams,
  Segment,
  Target,
  useGetAllTargets,
  usePatchSegment
} from 'services/cf'
import { getErrorMessage } from '@cf/utils/CFUtils'
import useActiveEnvironment from '@cf/hooks/useActiveEnvironment'
import patch, { getDiff } from '../../utils/instructions'
import SegmentRulesEditButton from './segment-rules-edit-button/SegmentRulesEditButton'
import css from './SegmentDetailsPage.module.scss'
 
const AddTargetAvatar: React.FC<{ onAdd: () => void }> = ({ onAdd }) => (
  <Avatar name="+" color={Color.BLUE_500} backgroundColor={Color.GREY_200} onClick={onAdd} />
)
 
const InlineBold: React.FC<{ children: string | string[] }> = ({ children }) => (
  <span style={{ fontWeight: 'bold' }}>{children}</span>
)
const safeJoin = (data: any[], separator: string): string => data?.join(separator) || `[${data}]`
interface ClauseProps {
  clause: Clause
  operators: {
    label: string
    value: string
  }[]
}
const ClauseViewMode: React.FC<ClauseProps> = ({ clause, operators }) => {
  return (
    <>
      If
      <InlineBold>{` ${clause.attribute} `} </InlineBold>{' '}
      {operators.find(op => op.value === clause.op)?.label || 'NO_OP'}{' '}
      <InlineBold>{` ${safeJoin(clause.values, ', ')}`}</InlineBold>
    </>
  )
}
 
type ClauseMutation =
  | { kind: 'op'; payload: string }
  | { kind: 'attribute'; payload: string }
  | { kind: 'values'; payload: string[] }
 
type ClauseEditProps = {
  index: number
  operator: string
  operators: {
    label: string
    value: string
  }[]
  attribute: string
  values: string[]
  error?: { attribute?: boolean; values?: boolean }
  isSingleValued: IsSingleValued
  onChange: (data: ClauseMutation) => void
}
 
const ClauseEditMode: React.FC<ClauseEditProps> = ({
  index,
  operator,
  operators,
  attribute,
  values,
  error,
  isSingleValued,
  onChange
}) => {
  const valueOpts = (values ?? []).map(toOption)
  const handleAttrChange = (e: React.ChangeEvent<HTMLInputElement>): void =>
    onChange({ kind: 'attribute', payload: e.target.value })
  const handleOperatorChange = (data: SelectOption): void => {
    onChange({ kind: 'op', payload: data.value as string })
    if (isSingleValued(data.value as string)) {
      onChange({ kind: 'values', payload: [values[0]] })
    }
  }
  const handleValuesChange = (data: MultiSelectOption[]): void =>
    onChange({
      kind: 'values',
      payload: data.map(x => (x.value as string).trim()).filter(x => x.length)
    })
  const handleSingleValueChange = (e: React.ChangeEvent<HTMLInputElement>): void =>
    handleValuesChange([toOption(e.target.value)])
 
  const height = '36px'
 
  return (
    <Layout.Horizontal spacing="xsmall">
      <Text
        color={Color.GREY_350}
        font="normal"
        style={{ display: 'flex', height, alignItems: 'center', justifyContent: 'flex-end' }}
      >
        {'If '}
      </Text>
      <div style={{ flex: '1' }}>
        <TextInput
          style={{ height }}
          id={`attribute-${index}`}
          value={attribute}
          onChange={handleAttrChange}
          intent={error?.attribute ? 'danger' : 'none'}
        />
      </div>
      <div style={{ flex: '1' }}>
        <Select
          inputProps={{ style: { height } }}
          value={operators.find(o => o.value === operator)}
          items={operators}
          onChange={handleOperatorChange}
        />
      </div>
      <div style={{ flex: '1.5' }}>
        {isSingleValued(operator) ? (
          <TextInput
            style={{ height }}
            id={`value-${index}`}
            value={valueOpts[0]?.value}
            onChange={handleSingleValueChange}
          />
        ) : (
          <MultiSelect
            fill
            className={css.valueMultiselect}
            tagInputProps={{
              className: css.valueMultiselect,
              inputProps: { className: css.valueMultiselect, intent: error?.values ? 'danger' : 'none' }
            }}
            items={valueOpts}
            value={valueOpts}
            onChange={handleValuesChange}
          />
        )}
      </div>
    </Layout.Horizontal>
  )
}
 
interface AvatarOption {
  name: string
}
interface Option<T> {
  label: string
  value: T
}
const toAvatar = (x: string): AvatarOption => ({ name: x })
const toOption = (x: string): Option<string> => ({ value: x, label: x })
 
interface RulesTabProps {
  excluded: string[]
  included: string[]
  availableTargets: string[]
  loadingTargets: boolean
  rules: Clause[]
  editing: boolean
  loadingSave: boolean
  errors?: RuleErrors
  setErrors: (errors: RuleErrors) => void
  onChangeIncluded: (data: string[]) => void
  onChangeExcluded: (data: string[]) => void
  onChangeRules: (data: Clause[]) => void
  onEdit: () => void
  onSave: () => void
  onCancel: () => void
}
 
const RulesTab: React.FC<RulesTabProps> = ({
  excluded,
  included,
  rules,
  availableTargets,
  loadingTargets,
  editing,
  loadingSave,
  errors,
  setErrors,
  onChangeIncluded,
  onChangeExcluded,
  onChangeRules,
  onEdit,
  onSave,
  onCancel
}) => {
  const { getString } = useStrings()
  const [operators, isSingleValued] = useOperatorsFromYaml()
 
  const [tempIncluded, setTempIncluded] = useState(included.map(toOption))
 
  const [openIncluded, hideIncluded] = useModalHook(() => {
    const handleTempIncludedChange = (newData: any): void => {
      setTempIncluded(newData.map((x: any) => (typeof x === 'string' ? toOption(x) : x)))
    }
 
    const handleSaveTempIncluded = (): void => {
      onChangeIncluded(tempIncluded.map(x => x.value))
      hideIncluded()
    }
 
    const handleCancelIncluded = (): void => {
      setTempIncluded(included.map(toOption))
      hideIncluded()
    }
 
    return (
      <Dialog enforceFocus={false} isOpen onClose={hideIncluded} title={`Serve variation to the following`}>
        <Layout.Vertical spacing="medium" padding={{ left: 'large', right: 'medium' }}>
          {loadingTargets ? (
            <Spinner size={24} />
          ) : (
            <SimpleTagInput
              fill
              allowNewTag={false}
              selectedItems={tempIncluded}
              items={availableTargets.map(toOption)}
              onChange={handleTempIncludedChange}
            />
          )}
          <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center' }}>
            <Button intent="primary" onClick={handleSaveTempIncluded}>
              {getString('done')}
            </Button>
            <Button minimal onClick={handleCancelIncluded}>
              {getString('cancel')}
            </Button>
            <div style={{ marginLeft: 'auto' }}>
              <Text>{`${tempIncluded.length} total`}</Text>
            </div>
          </div>
        </Layout.Vertical>
      </Dialog>
    )
  }, [tempIncluded, availableTargets])
 
  const [tempExcluded, setTempExcluded] = useState(excluded.map(toOption))
  const [openExcluded, hideExcluded] = useModalHook(() => {
    const handleTempExcludedChange = (newData: any): void => {
      setTempExcluded(newData.map((x: any) => (typeof x === 'string' ? toOption(x) : x)))
    }
 
    const handleSaveTempExcluded = (): void => {
      onChangeExcluded(tempExcluded.map(x => x.value))
      hideExcluded()
    }
 
    const handleCancelExcluded = (): void => {
      setTempExcluded(excluded.map(toOption))
      hideExcluded()
    }
 
    return (
      <Dialog enforceFocus={false} isOpen onClose={hideExcluded} title={`Serve variation to the following`}>
        <Layout.Vertical spacing="medium" padding={{ left: 'large', right: 'medium' }}>
          {loadingTargets ? (
            <Spinner size={24} />
          ) : (
            <SimpleTagInput
              fill
              allowNewTag={false}
              selectedItems={tempExcluded}
              items={availableTargets.map(toOption)}
              onChange={handleTempExcludedChange}
            />
          )}
          <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center' }}>
            <Button intent="primary" onClick={handleSaveTempExcluded}>
              {getString('done')}
            </Button>
            <Button minimal onClick={handleCancelExcluded}>
              {getString('cancel')}
            </Button>
            <div style={{ marginLeft: 'auto' }}>
              <Text>{`${tempExcluded.length} total`}</Text>
            </div>
          </div>
        </Layout.Vertical>
      </Dialog>
    )
  }, [tempExcluded, availableTargets])
 
  const [includedAvatars, excludedAvatars] = [included, excluded].map(x => x.map(toAvatar))
 
  const handleClauseChange =
    (idx: number) =>
    ({ kind, payload }: ClauseMutation) => {
      if (errors?.[idx]) {
        errors[idx] = {}
        setErrors(errors)
      }
      rules[idx] = {
        ...rules[idx],
        [kind]: payload
      }
      onChangeRules([...rules])
    }
 
  const handleNewClause = (): void => {
    onChangeRules([
      ...rules,
      {
        id: '',
        op: 'starts_with',
        attribute: '',
        values: [],
        negate: false
      }
    ])
  }
 
  const handleDelete = (idx: number) => () => {
    onChangeRules(rules.filter((_, index) => index !== idx))
  }
 
  return (
    <Layout.Vertical spacing="medium" padding="large">
      <Layout.Horizontal style={{ alignItems: 'center', justifyContent: 'flex-end' }}>
        {!editing && <SegmentRulesEditButton onEdit={onEdit} />}
      </Layout.Horizontal>
      <Card style={{ width: '100%', padding: 'var(--spacing-medium)' }}>
        <Layout.Vertical spacing="small">
          <Text font={{ size: 'medium', weight: 'bold' }}>Individual Targets</Text>
          <Layout.Horizontal
            style={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-start' }}
            padding="small"
          >
            <Text>Include the following:</Text>{' '}
            {editing && includedAvatars.length === 0 ? (
              <AddTargetAvatar onAdd={openIncluded} />
            ) : (
              <AvatarGroup overlap avatars={includedAvatars} onAdd={editing ? openIncluded : undefined} />
            )}
          </Layout.Horizontal>
          <Divider />
          <Layout.Horizontal
            style={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-start' }}
            padding="small"
          >
            <Text>Exclude the following:</Text>{' '}
            {editing && excludedAvatars.length === 0 ? (
              <AddTargetAvatar onAdd={openExcluded} />
            ) : (
              <AvatarGroup overlap avatars={excludedAvatars} onAdd={editing ? openExcluded : undefined} />
            )}
          </Layout.Horizontal>
        </Layout.Vertical>
        {}
      </Card>
      {rules.map((clause, idx) => {
        const hasError = Boolean(errors?.[idx]?.attribute || errors?.[idx]?.values)
        const errorMsg = [errors?.[idx]?.attribute && 'Attribute', errors?.[idx]?.values && 'Values']
          .filter(Boolean)
          .join(' and ')
          .concat(' required')
 
        return (
          <Layout.Horizontal spacing="medium" flex={{ align: 'center-center' }} width="100%" key={idx}>
            <Card style={{ flexGrow: 1 }}>
              {editing ? (
                <ClauseEditMode
                  key={idx}
                  index={idx}
                  attribute={clause.attribute}
                  operator={clause.op}
                  operators={operators}
                  values={clause.values}
                  error={errors?.[idx]}
                  isSingleValued={isSingleValued}
                  onChange={handleClauseChange(idx)}
                />
              ) : (
                <ClauseViewMode key={idx} clause={clause} operators={operators} />
              )}
              {hasError && <Text intent="danger">{errorMsg}</Text>}
            </Card>
            {editing && (
              <Icon
                name="trash"
                size={24}
                color={Color.GREY_300}
                onClick={handleDelete(idx)}
                style={{ cursor: 'pointer', height: 'fit-content' }}
              />
            )}
          </Layout.Horizontal>
        )
      })}
      {editing && (
        <Text color={Color.AQUA_500} onClick={handleNewClause} style={{ cursor: 'pointer' }}>
          + Check for condition and include target to segment
        </Text>
      )}
      {editing && (
        <Layout.Horizontal spacing="small" padding="medium" style={{ marginTop: 'auto' }}>
          <Button
            text="Save"
            intent="primary"
            onClick={() => {
              onSave()
            }}
          />
          <Button
            minimal
            text="Cancel"
            onClick={() => {
              onCancel()
            }}
          />
          {loadingSave && <Spinner size={24} />}
        </Layout.Horizontal>
      )}
    </Layout.Vertical>
  )
}
 
type TempSegment = {
  excluded: string[]
  included: string[]
  rules: Clause[]
}
 
type SegmentMutation =
  | { type: 'included'; payload: string[] }
  | { type: 'excluded'; payload: string[] }
  | { type: 'rules'; payload: Clause[] }
  | { type: 'set'; payload: TempSegment }
 
type MutationType = 'included' | 'excluded' | 'rules'
 
const toIdentifiers = (targets?: Target[]): string[] => targets?.map(target => target.identifier) || []
 
const tempSegmentReducer = (state: TempSegment, action: SegmentMutation) => {
  switch (action.type) {
    case 'included':
    case 'excluded':
    case 'rules':
      return {
        ...state,
        [action.type]: action.payload
      }
    case 'set':
      return action.payload
  }
}
 
const setIncluded = (payload: string[]): SegmentMutation => ({ type: 'included', payload })
const setExcluded = (payload: string[]): SegmentMutation => ({ type: 'excluded', payload })
const setRules = (payload: Clause[]): SegmentMutation => ({ type: 'rules', payload })
const setTempSegment = (payload: TempSegment): SegmentMutation => ({ type: 'set', payload })
 
type RuleErrors = {
  [K: number]: {
    attribute?: boolean
    values?: boolean
  }
}
 
const validateRules = (rules: Clause[]): [boolean, RuleErrors] => {
  let valid = true
  const ruleErr = rules.reduce((errors: RuleErrors, rule: Clause, idx: number) => {
    if (!rule.attribute.length) {
      valid = false
      errors[idx] = {
        attribute: true
      }
    }
    if (!rule.values.length) {
      valid = false
      errors[idx] = {
        ...(errors[idx] || {}),
        values: true
      }
    }
    return errors
  }, {} as RuleErrors)
  return [valid, ruleErr]
}
 
export const SegmentRules: React.FC<{ segment: Segment; onUpdate: () => void }> = ({ segment, onUpdate }) => {
  const { showError } = useToaster()
  const [editing, setEditing] = useState(false)
  const [errors, setErrors] = useState<RuleErrors>({})
  const { orgIdentifier, accountId: accountIdentifier } = useParams<Record<string, string>>()
  const { projectIdentifier, segmentIdentifier: identifier } = useParams<any>()
  const { activeEnvironment: environmentIdentifier } = useActiveEnvironment()
 
  const { data: rawTargets, loading: loadingTargets } = useGetAllTargets({
    queryParams: {
      environmentIdentifier,
      projectIdentifier,
      accountIdentifier,
      orgIdentifier
    } as GetAllTargetsQueryParams
  })
 
  const { mutate: sendPatch, loading: loadingPatch } = usePatchSegment({
    identifier,
    queryParams: {
      environmentIdentifier,
      projectIdentifier,
      accountIdentifier,
      orgIdentifier
    } as PatchSegmentQueryParams
  })
 
  const targets = rawTargets?.targets?.map(t => t.identifier || '') || []
 
  const [tempSegment, dispatch] = useReducer(tempSegmentReducer, {
    included: [...(segment.included || [])].map(target => target.identifier),
    excluded: [...(segment.excluded || [])].map(target => target.identifier),
    rules: [...(segment.rules || [])]
  })
 
  useEffect(() => {
    dispatch(
      setTempSegment({
        included: toIdentifiers([...(segment.included || [])]),
        excluded: toIdentifiers([...(segment.excluded || [])]),
        rules: [...(segment.rules || [])]
      })
    )
  }, [segment.included, segment.excluded, segment.rules])
 
  const handleSegmentChange = (type: MutationType) => (newData: any) => {
    if (type === 'included') {
      dispatch(setIncluded(newData))
    } else if (type === 'excluded') {
      dispatch(setExcluded(newData))
    } else if (type === 'rules') {
      dispatch(setRules(newData))
    }
  }
 
  const handleValid = (): void => {
    const instructions = []
    const [addedToInc, removedFromInc] = getDiff(toIdentifiers(segment.included), tempSegment.included)
    const [addedToExc, removedFromExc] = getDiff(toIdentifiers(segment.excluded), tempSegment.excluded)
 
    removedFromExc.length > 0 && instructions.push(patch.creators.removeFromExcludeList(removedFromExc))
    removedFromInc.length > 0 && instructions.push(patch.creators.removeFromIncludeList(removedFromInc))
    addedToExc.length > 0 && instructions.push(patch.creators.addToExcludeList(addedToExc))
    addedToInc.length > 0 && instructions.push(patch.creators.addToIncludeList(addedToInc))
 
    const removedClauses = (segment.rules || []).filter(c => !tempSegment.rules.find(x => x.id === c.id))
    const updatedClauses = (tempSegment.rules || []).filter(c => {
      const oldClause = segment.rules?.find(x => x.id === c.id)
      return oldClause && !isEqual(c, oldClause)
    })
    const newClauses = tempSegment.rules.filter(c => c.id === '')
 
    removedClauses.length > 0 &&
      instructions.push(...removedClauses.map(cl => patch.creators.removeClauseOnSegment(cl.id as string)))
    updatedClauses.length > 0 &&
      instructions.push(
        ...updatedClauses.map(cl =>
          patch.creators.updateClauseOnSegment({
            ...omit(cl, ['id', 'negate']),
            clauseID: cl.id as string
          })
        )
      )
    newClauses.length > 0 &&
      instructions.push(...newClauses.map(cl => patch.creators.addClauseToSegment(omit(cl, ['id']))))
 
    patch.segment.addAllInstructions(instructions)
    patch.segment
      .onPatchAvailable(patchData => {
        sendPatch(patchData)
          .then(() => {
            onUpdate()
            setEditing(false)
          })
          .catch(err => {
            showError(getErrorMessage(err), undefined, 'cf.send.patch.error')
          })
          .finally(() => patch.segment.reset())
      })
      .onEmptyPatch(() => setEditing(false))
  }
 
  const handleCancel = (): void => {
    patch.segment.reset()
    dispatch(
      setTempSegment({
        included: toIdentifiers([...(segment.included || [])]),
        excluded: toIdentifiers([...(segment.excluded || [])]),
        rules: [...(segment.rules || [])]
      })
    )
    setErrors({})
    setEditing(false)
  }
 
  const handleSave = (): void => {
    const [valid, newError] = validateRules(tempSegment.rules)
    if (valid) {
      handleValid()
    } else {
      setErrors(newError)
    }
  }
 
  Iif (loadingTargets) {
    return (
      <Container flex style={{ justifyContent: 'center', height: '100%' }}>
        <Spinner size={50} />
      </Container>
    )
  }
 
  return (
    <RulesTab
      availableTargets={targets}
      loadingTargets={loadingTargets}
      rules={tempSegment.rules || []}
      included={tempSegment.included}
      excluded={tempSegment.excluded}
      editing={editing}
      loadingSave={loadingPatch}
      errors={errors}
      setErrors={setErrors}
      onChangeIncluded={handleSegmentChange('included')}
      onChangeExcluded={handleSegmentChange('excluded')}
      onChangeRules={handleSegmentChange('rules')}
      onEdit={() => setEditing(true)}
      onSave={handleSave}
      onCancel={handleCancel}
    />
  )
}