Skip to content

Commit 8955fa4

Browse files
Merge pull request #3847 from RedisInsight/fe/feature/RI-6122-improvements-to-filter-pub-sub-channels
RI-6122 improvements to filter pub-sub
2 parents 0950a64 + f0b87d9 commit 8955fa4

File tree

12 files changed

+144
-12
lines changed

12 files changed

+144
-12
lines changed

redisinsight/ui/src/pages/pub-sub/components/subscription-panel/SubscriptionPanel.spec.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { fireEvent } from '@testing-library/react'
2+
import { fireEvent, waitFor } from '@testing-library/react'
33
import { cloneDeep } from 'lodash'
44
import { toggleSubscribeTriggerPubSub } from 'uiSrc/slices/pubsub/pubsub'
55
import { cleanup, clearStoreActions, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
@@ -27,4 +27,13 @@ describe('SubscriptionPanel', () => {
2727

2828
expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions))
2929
})
30+
31+
it('should set default value on blur when empty', async () => {
32+
render(<SubscriptionPanel />)
33+
fireEvent.change(screen.getByTestId('channels-input'), { target: { value: '' } })
34+
fireEvent.blur(screen.getByTestId('channels-input'))
35+
36+
await waitFor(() => screen.getByDisplayValue('*'))
37+
expect(screen.getByDisplayValue('*')).toBeInTheDocument()
38+
})
3039
})

redisinsight/ui/src/pages/pub-sub/components/subscription-panel/SubscriptionPanel.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import SubscribedIconLight from 'uiSrc/assets/img/pub-sub/subscribed-lt.svg'
1414
import NotSubscribedIconDark from 'uiSrc/assets/img/pub-sub/not-subscribed.svg'
1515
import NotSubscribedIconLight from 'uiSrc/assets/img/pub-sub/not-subscribed-lt.svg'
1616

17+
import { DEFAULT_SEARCH_MATCH } from 'uiSrc/constants/api'
18+
import PatternsInfo from './components/patternsInfo'
19+
import AppendInfo from './components/append-info'
1720
import styles from './styles.module.scss'
1821

1922
const SubscriptionPanel = () => {
@@ -24,7 +27,7 @@ const SubscriptionPanel = () => {
2427

2528
const { instanceId = '' } = useParams<{ instanceId: string }>()
2629

27-
const [channels, setChannels] = useState('')
30+
const [channels, setChannels] = useState(DEFAULT_SEARCH_MATCH)
2831

2932
const toggleSubscribe = () => {
3033
dispatch(toggleSubscribeTriggerPubSub(channels))
@@ -41,6 +44,12 @@ const SubscriptionPanel = () => {
4144
})
4245
}
4346

47+
const onFocusOut = () => {
48+
if (!channels) {
49+
setChannels(DEFAULT_SEARCH_MATCH)
50+
}
51+
}
52+
4453
const subscribedIcon = theme === Theme.Dark ? SubscribedIconDark : SubscribedIconLight
4554
const notSubscribedIcon = theme === Theme.Dark ? NotSubscribedIconDark : NotSubscribedIconLight
4655

@@ -61,6 +70,11 @@ const SubscriptionPanel = () => {
6170
You are { !isSubscribed && 'not' } subscribed
6271
</EuiText>
6372
</EuiFlexItem>
73+
{isSubscribed && (
74+
<EuiFlexItem grow={false} style={{ marginLeft: 12 }}>
75+
<PatternsInfo channels={channels} />
76+
</EuiFlexItem>
77+
)}
6478
{displayMessages && (
6579
<EuiFlexItem grow={false} style={{ marginLeft: 12 }}>
6680
<EuiText color="subdued" size="s" data-testid="messages-count">Messages: {count}</EuiText>
@@ -75,11 +89,13 @@ const SubscriptionPanel = () => {
7589
<EuiFieldText
7690
value={channels}
7791
disabled={isSubscribed}
78-
className={styles.channels}
92+
compressed
7993
onChange={(e) => setChannels(e.target.value)}
80-
placeholder="Enter Channel to Subscribe"
94+
onBlur={onFocusOut}
95+
placeholder="Enter Pattern"
8196
aria-label="channel names for filtering"
8297
data-testid="channels-input"
98+
append={<AppendInfo title={null} content="Subscribe to one or more channels or patterns by entering them, separated by spaces." />}
8399
/>
84100
</EuiFlexItem>
85101
<EuiFlexItem grow={false}>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react'
2+
import { fireEvent, render, screen, waitFor } from 'uiSrc/utils/test-utils'
3+
import AppendInfo from './AppendInfo'
4+
5+
describe('AppendInfo', () => {
6+
it('should render', () => {
7+
expect(
8+
render(
9+
<AppendInfo />
10+
)
11+
).toBeTruthy()
12+
})
13+
14+
it('should show info text on hover', async () => {
15+
const content = 'Some content'
16+
render(<AppendInfo content={content} />)
17+
fireEvent.mouseOver(screen.getByTestId('append-info-icon'))
18+
await waitFor(() => screen.getByText(content))
19+
expect(screen.getByText(content)).toBeInTheDocument()
20+
})
21+
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
import { EuiIcon, EuiToolTip, EuiToolTipProps, ToolTipPositions } from '@elastic/eui'
3+
4+
export interface AppendInfoProps extends Omit<EuiToolTipProps, 'children' | 'delay' | 'position'> {
5+
position?: ToolTipPositions
6+
}
7+
const AppendInfo = ({ title, content, ...rest }: AppendInfoProps) => (
8+
<EuiToolTip
9+
anchorClassName="inputAppendIcon"
10+
position="right"
11+
title={title}
12+
content={content}
13+
{...rest}
14+
>
15+
<EuiIcon
16+
type="iInCircle"
17+
style={{ cursor: 'pointer' }}
18+
data-testid="append-info-icon"
19+
/>
20+
</EuiToolTip>
21+
)
22+
23+
export default AppendInfo
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import AppendInfo from './AppendInfo'
2+
3+
export default AppendInfo
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
import { fireEvent, render, screen, waitFor } from 'uiSrc/utils/test-utils'
3+
import PatternsInfo from './PatternsInfo'
4+
5+
describe('PatternsInfo', () => {
6+
it('should render', () => {
7+
expect(
8+
render(
9+
<PatternsInfo />
10+
)
11+
).toBeTruthy()
12+
})
13+
14+
it('should show info text on hover', async () => {
15+
const content = 'hello'
16+
render(<PatternsInfo channels={content} />)
17+
expect(screen.getByText('Patterns: 1')).toBeInTheDocument()
18+
fireEvent.mouseOver(screen.getByTestId('append-info-icon'))
19+
await waitFor(() => screen.getByText(content))
20+
expect(screen.getByText(content)).toBeInTheDocument()
21+
})
22+
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { EuiText } from '@elastic/eui'
2+
import React from 'react'
3+
import { DEFAULT_SEARCH_MATCH } from 'uiSrc/constants/api'
4+
import AppendInfo from '../append-info'
5+
6+
import styles from './styles.module.scss'
7+
8+
export interface PatternsInfoProps {
9+
channels?: string
10+
}
11+
12+
const PatternsInfo = ({ channels }: PatternsInfoProps) => {
13+
const getChannelsCount = () => {
14+
if (!channels || channels?.trim() === DEFAULT_SEARCH_MATCH) return 'All'
15+
return channels.trim().split(' ').length
16+
}
17+
18+
return (
19+
<div className={styles.patternsContainer}>
20+
<EuiText color="subdued" size="s" data-testid="patterns-count">Patterns:&nbsp;{getChannelsCount()} </EuiText>
21+
<AppendInfo title={<>{channels?.trim().split(' ').map((ch) => <p>{ch}</p>)}</>} />
22+
</div>
23+
)
24+
}
25+
26+
export default PatternsInfo
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import PatternsInfo from './PatternsInfo'
2+
3+
export default PatternsInfo
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.patternsContainer {
2+
display: flex;
3+
align-items: center;
4+
}

redisinsight/ui/src/pages/pub-sub/components/subscription-panel/styles.module.scss

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
.channels {
2525
margin-right: 8px;
2626

27-
input {
28-
width: 210px;
29-
}
30-
31-
:global(.euiFormControlLayout), input {
32-
height: 30px;
27+
:global(.euiFormControlLayout--compressed .inputAppendIcon > svg) {
28+
height: 31px !important;
3329
}
3430
}

0 commit comments

Comments
 (0)