Skip to content

Commit

Permalink
Closes #621
Browse files Browse the repository at this point in the history
  • Loading branch information
polegkashti committed Oct 26, 2024
1 parent 0ad8695 commit 4b97405
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public Mono<ResponseEntity<Flux<KafkaAclDTO>>> listAcls(String clusterName,
KafkaAclResourceTypeDTO resourceTypeDto,
String resourceName,
KafkaAclNamePatternTypeDTO namePatternTypeDto,
String search,
ServerWebExchange exchange) {
AccessContext context = AccessContext.builder()
.cluster(clusterName)
Expand All @@ -87,7 +88,7 @@ public Mono<ResponseEntity<Flux<KafkaAclDTO>>> listAcls(String clusterName,
return validateAccess(context).then(
Mono.just(
ResponseEntity.ok(
aclsService.listAcls(getCluster(clusterName), filter)
aclsService.listAcls(getCluster(clusterName), filter, search)
.map(ClusterMapper::toKafkaAclDto)))
).doOnEach(sig -> audit(context, sig));
}
Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/io/kafbat/ui/service/acl/AclsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ public Mono<Void> deleteAcl(KafkaCluster cluster, AclBinding aclBinding) {
.doOnSuccess(v -> log.info("ACL DELETED: [{}]", aclString));
}

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

Expand Down
5 changes: 5 additions & 0 deletions contract/src/main/resources/swagger/kafbat-ui-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,11 @@ paths:
required: false
schema:
$ref: '#/components/schemas/KafkaAclNamePatternType'
- name: search
in: query
required: false
schema:
type: string
responses:
200:
description: OK
Expand Down
17 changes: 15 additions & 2 deletions frontend/src/components/ACLPage/List/List.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { ColumnDef, Row } from '@tanstack/react-table';
import PageHeading from 'components/common/PageHeading/PageHeading';
import Table from 'components/common/NewTable';
Expand All @@ -20,12 +21,16 @@ import { useTheme } from 'styled-components';
import ACLFormContext from 'components/ACLPage/Form/AclFormContext';
import PlusIcon from 'components/common/Icons/PlusIcon';
import ActionButton from 'components/common/ActionComponent/ActionButton/ActionButton';
import { ControlPanelWrapper } from 'components/common/ControlPanel/ControlPanel.styled';
import Search from 'components/common/Search/Search';

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

const ACList: React.FC = () => {
const { clusterName } = useAppParams<{ clusterName: ClusterName }>();
const { data: aclList } = useAcls(clusterName);
const [searchParams, setSearchParams] = useSearchParams();

Check failure on line 31 in frontend/src/components/ACLPage/List/List.tsx

View workflow job for this annotation

GitHub Actions / build / build-and-test

'setSearchParams' is assigned a value but never used

Check failure on line 31 in frontend/src/components/ACLPage/List/List.tsx

View workflow job for this annotation

GitHub Actions / build / build-and-test

'setSearchParams' is assigned a value but never used
const [search, setSearch] = useState(searchParams.get('q') || '');
const { data: aclList } = useAcls({ clusterName, search });
const { deleteResource } = useDeleteAcl(clusterName);
const modal = useConfirm(true);
const theme = useTheme();
Expand All @@ -36,6 +41,11 @@ const ACList: React.FC = () => {
} = useBoolean();
const [rowId, setRowId] = React.useState('');

// Set the search params to the url based on the localStorage value
useEffect(() => {
setSearch(searchParams.get('q') || '');
}, [searchParams]);

const handleDeleteClick = (acl: KafkaAcl | null) => {
if (acl) {
modal('Are you sure want to delete this ACL record?', () =>
Expand Down Expand Up @@ -162,6 +172,9 @@ const ACList: React.FC = () => {
<PlusIcon /> Create ACL
</ActionButton>
</PageHeading>
<ControlPanelWrapper hasInput>
<Search placeholder="Search by Principle Name" />
</ControlPanelWrapper>
<Table
columns={columns}
data={aclList ?? []}
Expand Down
15 changes: 11 additions & 4 deletions frontend/src/lib/hooks/api/acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ import {
KafkaAcl,
} from 'generated-sources';

export function useAcls(clusterName: ClusterName) {
export function useAcls({ clusterName, search }: {

Check warning on line 17 in frontend/src/lib/hooks/api/acl.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Replace `·clusterName,·search·}:·{·` with `⏎··clusterName,⏎··search,⏎}:·{`
clusterName: ClusterName;

Check warning on line 18 in frontend/src/lib/hooks/api/acl.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Delete `·`
search?: string;

Check warning on line 19 in frontend/src/lib/hooks/api/acl.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Delete `·`
}) {
return useQuery(
['clusters', clusterName, 'acls'],
() => api.listAcls({ clusterName }),
['clusters', clusterName, 'acls', { search }],
() => api.listAcls({

Check warning on line 23 in frontend/src/lib/hooks/api/acl.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Insert `⏎·····`
clusterName,
search

Check warning on line 25 in frontend/src/lib/hooks/api/acl.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Insert `,`
}),

Check warning on line 26 in frontend/src/lib/hooks/api/acl.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Replace `····` with `······`
{
suspense: false,
keepPreviousData: true,

Check warning on line 28 in frontend/src/lib/hooks/api/acl.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Delete `··`
suspense: false,

Check warning on line 29 in frontend/src/lib/hooks/api/acl.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Delete `··`
}
);
}
Expand Down

0 comments on commit 4b97405

Please sign in to comment.