Implement Search within Consumer group profile (#2629)
* Implement Search within Consumer group profile * use useSearchParams and add search test Co-authored-by: Roman Zabaluev <rzabaluev@provectus.com>
This commit is contained in:
parent
3733729a55
commit
f31b965d66
2 changed files with 24 additions and 2 deletions
|
@ -1,11 +1,12 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import useAppParams from 'lib/hooks/useAppParams';
|
import useAppParams from 'lib/hooks/useAppParams';
|
||||||
import {
|
import {
|
||||||
clusterConsumerGroupResetRelativePath,
|
clusterConsumerGroupResetRelativePath,
|
||||||
clusterConsumerGroupsPath,
|
clusterConsumerGroupsPath,
|
||||||
ClusterGroupParam,
|
ClusterGroupParam,
|
||||||
} from 'lib/paths';
|
} from 'lib/paths';
|
||||||
|
import Search from 'components/common/Search/Search';
|
||||||
import PageLoader from 'components/common/PageLoader/PageLoader';
|
import PageLoader from 'components/common/PageLoader/PageLoader';
|
||||||
import ClusterContext from 'components/contexts/ClusterContext';
|
import ClusterContext from 'components/contexts/ClusterContext';
|
||||||
import PageHeading from 'components/common/PageHeading/PageHeading';
|
import PageHeading from 'components/common/PageHeading/PageHeading';
|
||||||
|
@ -24,11 +25,14 @@ import {
|
||||||
} from 'redux/reducers/consumerGroups/consumerGroupsSlice';
|
} from 'redux/reducers/consumerGroups/consumerGroupsSlice';
|
||||||
import getTagColor from 'components/common/Tag/getTagColor';
|
import getTagColor from 'components/common/Tag/getTagColor';
|
||||||
import { Dropdown, DropdownItem } from 'components/common/Dropdown';
|
import { Dropdown, DropdownItem } from 'components/common/Dropdown';
|
||||||
|
import { ControlPanelWrapper } from 'components/common/ControlPanel/ControlPanel.styled';
|
||||||
|
|
||||||
import ListItem from './ListItem';
|
import ListItem from './ListItem';
|
||||||
|
|
||||||
const Details: React.FC = () => {
|
const Details: React.FC = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const searchValue = searchParams.get('q') || '';
|
||||||
const { isReadOnly } = React.useContext(ClusterContext);
|
const { isReadOnly } = React.useContext(ClusterContext);
|
||||||
const { consumerGroupID, clusterName } = useAppParams<ClusterGroupParam>();
|
const { consumerGroupID, clusterName } = useAppParams<ClusterGroupParam>();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
@ -62,6 +66,14 @@ const Details: React.FC = () => {
|
||||||
|
|
||||||
const partitionsByTopic = groupBy(consumerGroup.partitions, 'topic');
|
const partitionsByTopic = groupBy(consumerGroup.partitions, 'topic');
|
||||||
|
|
||||||
|
const filteredPartitionsByTopic = Object.keys(partitionsByTopic).filter(
|
||||||
|
(el) => el.includes(searchValue)
|
||||||
|
);
|
||||||
|
|
||||||
|
const currentPartitionsByTopic = searchValue.length
|
||||||
|
? filteredPartitionsByTopic
|
||||||
|
: Object.keys(partitionsByTopic);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -108,6 +120,9 @@ const Details: React.FC = () => {
|
||||||
</Metrics.Indicator>
|
</Metrics.Indicator>
|
||||||
</Metrics.Section>
|
</Metrics.Section>
|
||||||
</Metrics.Wrapper>
|
</Metrics.Wrapper>
|
||||||
|
<ControlPanelWrapper hasInput style={{ margin: '16px 0 20px' }}>
|
||||||
|
<Search placeholder="Search by Topic Name" />
|
||||||
|
</ControlPanelWrapper>
|
||||||
<Table isFullwidth>
|
<Table isFullwidth>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -116,7 +131,7 @@ const Details: React.FC = () => {
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{Object.keys(partitionsByTopic).map((key) => (
|
{currentPartitionsByTopic.map((key) => (
|
||||||
<ListItem
|
<ListItem
|
||||||
clusterName={clusterName}
|
clusterName={clusterName}
|
||||||
consumers={partitionsByTopic[key]}
|
consumers={partitionsByTopic[key]}
|
||||||
|
|
|
@ -77,6 +77,13 @@ describe('Details component', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders search input', async () => {
|
||||||
|
await renderComponent();
|
||||||
|
expect(
|
||||||
|
screen.getByPlaceholderText('Search by Topic Name')
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it('shows confirmation modal on consumer group delete', async () => {
|
it('shows confirmation modal on consumer group delete', async () => {
|
||||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
||||||
userEvent.click(screen.getByText('Delete consumer group'));
|
userEvent.click(screen.getByText('Delete consumer group'));
|
||||||
|
|
Loading…
Add table
Reference in a new issue