Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE: Add Search Functionality to ACLs page #636

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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] = useSearchParams();
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
17 changes: 14 additions & 3 deletions frontend/src/lib/hooks/api/acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ import {
KafkaAcl,
} from 'generated-sources';

export function useAcls(clusterName: ClusterName) {
export function useAcls({
clusterName,
search,
}: {
clusterName: ClusterName;
search?: string;
}) {
return useQuery(
['clusters', clusterName, 'acls'],
() => api.listAcls({ clusterName }),
['clusters', clusterName, 'acls', { search }],
() =>
api.listAcls({
clusterName,
search,
}),
{
keepPreviousData: true,
suspense: false,
}
);
Expand Down
Loading