Skip to content

Commit a2f5910

Browse files
committed
Closes #621
1 parent 9ea1a4e commit a2f5910

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

api/src/main/java/io/kafbat/ui/controller/AclsController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public Mono<ResponseEntity<Flux<KafkaAclDTO>>> listAcls(String clusterName,
6767
KafkaAclResourceTypeDTO resourceTypeDto,
6868
String resourceName,
6969
KafkaAclNamePatternTypeDTO namePatternTypeDto,
70+
String search,
7071
ServerWebExchange exchange) {
7172
AccessContext context = AccessContext.builder()
7273
.cluster(clusterName)
@@ -87,7 +88,7 @@ public Mono<ResponseEntity<Flux<KafkaAclDTO>>> listAcls(String clusterName,
8788
return validateAccess(context).then(
8889
Mono.just(
8990
ResponseEntity.ok(
90-
aclsService.listAcls(getCluster(clusterName), filter)
91+
aclsService.listAcls(getCluster(clusterName), filter, search)
9192
.map(ClusterMapper::toKafkaAclDto)))
9293
).doOnEach(sig -> audit(context, sig));
9394
}

api/src/main/java/io/kafbat/ui/service/acl/AclsService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ public Mono<Void> deleteAcl(KafkaCluster cluster, AclBinding aclBinding) {
6868
.doOnSuccess(v -> log.info("ACL DELETED: [{}]", aclString));
6969
}
7070

71-
public Flux<AclBinding> listAcls(KafkaCluster cluster, ResourcePatternFilter filter) {
71+
public Flux<AclBinding> listAcls(KafkaCluster cluster, ResourcePatternFilter filter, String principalSearch) {
7272
return adminClientService.get(cluster)
7373
.flatMap(c -> c.listAcls(filter))
7474
.flatMapIterable(acls -> acls)
75+
.filter(acl -> principalSearch == null || acl.entry().principal().contains(principalSearch))
7576
.sort(Comparator.comparing(AclBinding::toString)); //sorting to keep stable order on different calls
7677
}
7778

contract/src/main/resources/swagger/kafbat-ui-api.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,11 @@ paths:
19651965
required: false
19661966
schema:
19671967
$ref: '#/components/schemas/KafkaAclNamePatternType'
1968+
- name: search
1969+
in: query
1970+
required: false
1971+
schema:
1972+
type: string
19681973
responses:
19691974
200:
19701975
description: OK

frontend/src/components/ACLPage/List/List.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
2+
import { useSearchParams } from 'react-router-dom';
23
import { ColumnDef, Row } from '@tanstack/react-table';
34
import PageHeading from 'components/common/PageHeading/PageHeading';
45
import Table from 'components/common/NewTable';
@@ -20,12 +21,16 @@ import { useTheme } from 'styled-components';
2021
import ACLFormContext from 'components/ACLPage/Form/AclFormContext';
2122
import PlusIcon from 'components/common/Icons/PlusIcon';
2223
import ActionButton from 'components/common/ActionComponent/ActionButton/ActionButton';
24+
import { ControlPanelWrapper } from 'components/common/ControlPanel/ControlPanel.styled';
25+
import Search from 'components/common/Search/Search';
2326

2427
import * as S from './List.styled';
2528

2629
const ACList: React.FC = () => {
2730
const { clusterName } = useAppParams<{ clusterName: ClusterName }>();
28-
const { data: aclList } = useAcls(clusterName);
31+
const [searchParams, setSearchParams] = useSearchParams();
32+
const [search, setSearch] = useState(searchParams.get('q') || '');
33+
const { data: aclList } = useAcls({ clusterName, search });
2934
const { deleteResource } = useDeleteAcl(clusterName);
3035
const modal = useConfirm(true);
3136
const theme = useTheme();
@@ -36,6 +41,11 @@ const ACList: React.FC = () => {
3641
} = useBoolean();
3742
const [rowId, setRowId] = React.useState('');
3843

44+
// Set the search params to the url based on the localStorage value
45+
useEffect(() => {
46+
setSearch(searchParams.get('q') || '');
47+
}, [searchParams]);
48+
3949
const handleDeleteClick = (acl: KafkaAcl | null) => {
4050
if (acl) {
4151
modal('Are you sure want to delete this ACL record?', () =>
@@ -162,6 +172,9 @@ const ACList: React.FC = () => {
162172
<PlusIcon /> Create ACL
163173
</ActionButton>
164174
</PageHeading>
175+
<ControlPanelWrapper hasInput>
176+
<Search placeholder="Search by Principle Name" />
177+
</ControlPanelWrapper>
165178
<Table
166179
columns={columns}
167180
data={aclList ?? []}

frontend/src/lib/hooks/api/acl.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ import {
1414
KafkaAcl,
1515
} from 'generated-sources';
1616

17-
export function useAcls(clusterName: ClusterName) {
17+
export function useAcls({ clusterName, search }: {
18+
clusterName: ClusterName;
19+
search?: string;
20+
}) {
1821
return useQuery(
19-
['clusters', clusterName, 'acls'],
20-
() => api.listAcls({ clusterName }),
22+
['clusters', clusterName, 'acls', { search }],
23+
() => api.listAcls({
24+
clusterName,
25+
search
26+
}),
2127
{
22-
suspense: false,
28+
keepPreviousData: true,
29+
suspense: false,
2330
}
2431
);
2532
}

0 commit comments

Comments
 (0)