Skip to content

Commit d18df5f

Browse files
refactor(FOROME-933): use PopperButton for open conditions options popup
1 parent 68706a0 commit d18df5f

File tree

5 files changed

+71
-67
lines changed

5 files changed

+71
-67
lines changed

src/components/popper-menu/popper-menu-item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Icon, TIcons } from '@ui/icon'
66
export interface IPopperMenuItemProps {
77
iconName?: TIcons
88
className?: Argument
9-
onClick?: () => void
9+
onClick?: (event: any) => void
1010
isDisabled?: boolean
1111
}
1212

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { ReactElement } from 'react'
2+
3+
import { Button } from '@ui/button'
4+
import { Icon } from '@ui/icon'
5+
6+
interface IProps {
7+
refEl: any
8+
onClick?: () => void
9+
}
10+
11+
export const ConditionModalOptionsButton = ({
12+
refEl,
13+
...rest
14+
}: IProps): ReactElement => {
15+
return (
16+
<Button
17+
refEl={refEl}
18+
onClick={rest.onClick}
19+
className="bg-transparent hover:bg-transparent active:bg-transparent"
20+
append={
21+
<Icon
22+
name="Options"
23+
className="cursor-pointer text-blue-bright"
24+
stroke={false}
25+
/>
26+
}
27+
onMouseUp={e => e.stopPropagation()}
28+
/>
29+
)
30+
}
Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
import { ReactElement, useRef } from 'react'
1+
import { ReactElement } from 'react'
22

33
import { copyToClipboard } from '@core/copy-to-clipboard'
4-
import { useOutsideClick } from '@core/hooks/use-outside-click'
54
import { t } from '@i18n'
5+
import filterStore from '@store/filter'
66
import { Icon } from '@ui/icon'
77
import { DecisionTreeModalDataCy } from '@components/data-testid/decision-tree-modal.cy'
8+
import {
9+
IPopperMenuProps,
10+
PopperMenu,
11+
} from '@components/popper-menu/popper-menu'
12+
import { PopperMenuItem } from '@components/popper-menu/popper-menu-item'
813
import { showToast } from '@utils/notifications/showToast'
914

10-
interface IConditionModalOptionsPopup {
11-
onClose: () => void
12-
onDeleteCondition: () => void
13-
filterName: string
14-
}
15-
1615
export const ConditionModalOptionsPopup = ({
17-
onClose,
18-
onDeleteCondition,
19-
filterName,
20-
}: IConditionModalOptionsPopup): ReactElement => {
21-
const ref = useRef(null)
22-
23-
useOutsideClick(ref, () => onClose())
16+
close,
17+
}: IPopperMenuProps): ReactElement => {
18+
const { selectedConditionIndex, conditions } = filterStore
19+
const filterName = conditions[selectedConditionIndex]?.[1] ?? ''
2420

2521
const handleCopyFilterName = (e: React.MouseEvent) => {
2622
e.stopPropagation()
@@ -29,37 +25,38 @@ export const ConditionModalOptionsPopup = ({
2925

3026
showToast(t('ds.copied'), 'info')
3127

32-
onClose()
28+
close()
3329
}
3430

3531
const handleDeleteFilterBlock = (e: React.MouseEvent) => {
3632
e.stopPropagation()
37-
onDeleteCondition()
33+
filterStore.removeCondition(selectedConditionIndex)
34+
close()
3835
}
3936

4037
return (
41-
<div ref={ref} className="top-4 right-6 absolute z-50 text-14 font-normal">
42-
<div className="top-8 flex flex-col justify-between px-0 py-0 bg-white rounded-md shadow-dark">
43-
<div
44-
onClick={handleDeleteFilterBlock}
45-
className="flex items-center justify-between py-2 px-2 rounded-br-none rounded-bl-none rounded-l-md rounded-r-md cursor-pointer hover:bg-blue-bright hover:text-white"
46-
data-testId={DecisionTreeModalDataCy.joinByAnd}
47-
>
48-
<div className="mr-2">{t('filter.delete')}</div>
38+
<PopperMenu close={close} className="w-32">
39+
<PopperMenuItem
40+
onClick={handleDeleteFilterBlock}
41+
data-testid={DecisionTreeModalDataCy.joinByAnd}
42+
>
43+
<div className="flex items-center justify-between">
44+
<span className="mr-2">{t('filter.delete')}</span>
4945

5046
<Icon name="Delete" />
5147
</div>
48+
</PopperMenuItem>
5249

53-
<div
54-
onClick={handleCopyFilterName}
55-
className="flex items-center justify-between py-2 px-2 rounded-bl-md rounded-br-md cursor-pointer hover:bg-blue-bright hover:text-white"
56-
data-testId={DecisionTreeModalDataCy.joinByOr}
57-
>
58-
<div>{t('filter.copy')}</div>
50+
<PopperMenuItem
51+
onClick={handleCopyFilterName}
52+
data-testid={DecisionTreeModalDataCy.joinByOr}
53+
>
54+
<div className="flex items-center justify-between">
55+
<span className="mr-2">{t('filter.copy')}</span>
5956

6057
<Icon name="Copy" className="text-grey-blue" />
6158
</div>
62-
</div>
63-
</div>
59+
</PopperMenuItem>
60+
</PopperMenu>
6461
)
6562
}

src/pages/filter/refiner/components/right-column/query-results.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export const QueryResults = observer((): ReactElement => {
4040
<SelectedFilterCard
4141
isActive={index === selectedConditionIndex}
4242
condition={condition}
43-
onSelect={() => filterStore.selectCondition(index)}
44-
onDelete={() => filterStore.removeCondition(index)}
4543
/>
4644
</div>
4745
))}

src/pages/filter/refiner/components/right-column/selected-filter-card.tsx

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,31 @@ import { observer } from 'mobx-react-lite'
44

55
import { FilterKindEnum } from '@core/enum/filter-kind.enum'
66
import { useToggle } from '@core/hooks/use-toggle'
7+
import filterStore from '@store/filter'
78
import { Icon } from '@ui/icon'
9+
import { PopperButton } from '@components/popper-button'
810
import { ConditionJoinMode } from '@service-providers/common'
911
import {
1012
TCondition,
1113
TFuncArgs,
1214
TNumericConditionBounds,
1315
} from '@service-providers/common/common.interface'
1416
import { AllNotModeLabel } from './all-not-mode-label'
17+
import { ConditionModalOptionsButton } from './condition-modal-options-button'
1518
import { ConditionModalOptionsPopup } from './condition-modal-options-popup'
1619
import { EnumFilter } from './enum-filter'
1720
import { FuncFilter } from './func-filter'
1821
import { NumericFilter } from './numeric-filter'
1922

2023
interface ISelectedFilterCardProps {
2124
isActive: boolean
22-
onSelect: () => void
23-
onDelete: () => void
2425
condition: TCondition
2526
}
2627

2728
export const SelectedFilterCard = observer(
28-
({
29-
isActive,
30-
onSelect,
31-
onDelete,
32-
condition,
33-
}: ISelectedFilterCardProps): ReactElement => {
29+
({ isActive, condition }: ISelectedFilterCardProps): ReactElement => {
30+
const { selectedConditionIndex } = filterStore
31+
3432
// TODO: mobx warning for out of bounds read from condition
3533
// not all of conditions have 3rd and 4th value
3634
const filterType: string = condition[0]
@@ -45,28 +43,19 @@ export const SelectedFilterCard = observer(
4543
const [isFilterContentVisible, showFilterContent, hideFilterContent] =
4644
useToggle(true)
4745

48-
const [isModalOptionsVisible, showModalOptions, hideModalOptions] =
49-
useToggle(false)
50-
5146
const toggleFilterContentVisibility = (event: React.MouseEvent) => {
5247
event.stopPropagation()
5348

5449
isFilterContentVisible ? hideFilterContent() : showFilterContent()
5550
}
5651

57-
const toggleModalOptionsVisibility = (event: React.MouseEvent) => {
58-
event.stopPropagation()
59-
60-
isModalOptionsVisible ? hideModalOptions() : showModalOptions()
61-
}
62-
6352
return (
6453
<>
6554
<div
6655
className={cn('relative flex flex-col px-3 cursor-pointer', {
6756
'bg-blue-tertiary': isActive,
6857
})}
69-
onClick={onSelect}
58+
onClick={() => filterStore.selectCondition(selectedConditionIndex)}
7059
>
7160
<div className="flex py-4 justify-between">
7261
<div className="flex" onClick={toggleFilterContentVisibility}>
@@ -86,20 +75,10 @@ export const SelectedFilterCard = observer(
8675
/>
8776
</div>
8877

89-
<Icon
90-
name="Options"
91-
className="cursor-pointer text-blue-bright"
92-
stroke={false}
93-
onClick={toggleModalOptionsVisibility}
78+
<PopperButton
79+
ButtonElement={ConditionModalOptionsButton}
80+
ModalElement={ConditionModalOptionsPopup}
9481
/>
95-
96-
{isModalOptionsVisible && (
97-
<ConditionModalOptionsPopup
98-
onClose={hideModalOptions}
99-
onDeleteCondition={onDelete}
100-
filterName={filterName}
101-
/>
102-
)}
10382
</div>
10483

10584
<div className="bg-grey-light h-px w-full" />

0 commit comments

Comments
 (0)