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

Replaces search bar component with usememo logic #667

Merged
merged 3 commits into from
Nov 16, 2023
Merged
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
29 changes: 16 additions & 13 deletions ui/app/mirrors/edit/[mirrorId]/cdc.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use client';

import SearchBar from '@/components/Search';
import TimeLabel from '@/components/TimeComponent';
import { QRepMirrorStatus, SnapshotStatus } from '@/grpc_generated/route';
import { Button } from '@/lib/Button';
import { Icon } from '@/lib/Icon';
import { Label } from '@/lib/Label';
import { ProgressBar } from '@/lib/ProgressBar';
import { SearchField } from '@/lib/SearchField';
import { Table, TableCell, TableRow } from '@/lib/Table';
import moment, { Duration, Moment } from 'moment';
import Link from 'next/link';
import { useState } from 'react';
import { useMemo, useState } from 'react';

class TableCloneSummary {
flowJobName: string;
Expand Down Expand Up @@ -88,9 +88,17 @@ type SnapshotStatusProps = {
status: SnapshotStatus;
};
export const SnapshotStatusTable = ({ status }: SnapshotStatusProps) => {
const [snapshotRows, setSnapshotRows] = useState(
status.clones.map(summarizeTableClone)
const [searchQuery, setSearchQuery] = useState<string>('');
const snapshotRows = useMemo(
() =>
status.clones
.map(summarizeTableClone)
.filter((row: any) =>
row.tableName.toLowerCase().includes(searchQuery.toLowerCase())
),
[status.clones, searchQuery]
);

return (
<div style={{ marginTop: '2rem' }}>
<Table
Expand All @@ -113,15 +121,10 @@ export const SnapshotStatusTable = ({ status }: SnapshotStatusProps) => {
</>
),
right: (
<SearchBar
allItems={status.clones.map(summarizeTableClone)}
setItems={setSnapshotRows}
filterFunction={(query: string) =>
status.clones.map(summarizeTableClone).filter((row: any) => {
return row.tableName
.toLowerCase()
.includes(query.toLowerCase());
})
<SearchField
placeholder='Search by table name'
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearchQuery(e.target.value)
}
/>
),
Expand Down
28 changes: 14 additions & 14 deletions ui/app/mirrors/edit/[mirrorId]/syncStatusTable.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use client';

import SearchBar from '@/components/Search';
import TimeLabel from '@/components/TimeComponent';
import { Button } from '@/lib/Button';
import { Icon } from '@/lib/Icon';
import { Label } from '@/lib/Label';
import { ProgressCircle } from '@/lib/ProgressCircle';
import { SearchField } from '@/lib/SearchField';
import { Table, TableCell, TableRow } from '@/lib/Table';
import moment from 'moment';
import { useState } from 'react';
import { useMemo, useState } from 'react';

type SyncStatusRow = {
batchId: number;
Expand Down Expand Up @@ -53,13 +53,16 @@ const ROWS_PER_PAGE = 10;
export const SyncStatusTable = ({ rows }: SyncStatusTableProps) => {
const [currentPage, setCurrentPage] = useState(1);
const totalPages = Math.ceil(rows.length / ROWS_PER_PAGE);

const [searchQuery, setSearchQuery] = useState<string>('');
const startRow = (currentPage - 1) * ROWS_PER_PAGE;
const endRow = startRow + ROWS_PER_PAGE;
const allRows = rows.slice(startRow, endRow);
const [displayedRows, setDisplayedRows] = useState(
rows.slice(startRow, endRow)
);
const displayedRows = useMemo(() => {
const allRows = rows.slice(startRow, endRow);
const shownRows = allRows.filter(
(row: any) => row.batchId == parseInt(searchQuery, 10)
);
return shownRows.length > 0 ? shownRows : allRows;
serprex marked this conversation as resolved.
Show resolved Hide resolved
}, [searchQuery, endRow, startRow, rows]);
const handlePrevPage = () => {
if (currentPage > 1) setCurrentPage(currentPage - 1);
};
Expand Down Expand Up @@ -90,13 +93,10 @@ export const SyncStatusTable = ({ rows }: SyncStatusTableProps) => {
</>
),
right: (
<SearchBar
allItems={allRows}
setItems={setDisplayedRows}
filterFunction={(query: string) =>
allRows.filter((row: any) => {
return row.batchId == parseInt(query, 10);
})
<SearchField
placeholder='Search by batch ID'
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearchQuery(e.target.value)
}
/>
),
Expand Down
30 changes: 17 additions & 13 deletions ui/app/mirrors/status/qrep/[mirrorId]/qrepStatusTable.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use client';

import SearchBar from '@/components/Search';
import TimeLabel from '@/components/TimeComponent';
import { Button } from '@/lib/Button';
import { Icon } from '@/lib/Icon';
import { Label } from '@/lib/Label';
import { ProgressCircle } from '@/lib/ProgressCircle';
import { SearchField } from '@/lib/SearchField';
import { Table, TableCell, TableRow } from '@/lib/Table';
import moment from 'moment';
import { useState } from 'react';
import { useMemo, useState } from 'react';

export type QRepPartitionStatus = {
partitionId: string;
Expand Down Expand Up @@ -85,8 +85,17 @@ export default function QRepStatusTable({
(currentPage - 1) * ROWS_PER_PAGE,
currentPage * ROWS_PER_PAGE
);
const [displayedPartitions, setDisplayedPartitions] =
useState(visiblePartitions);

const [searchQuery, setSearchQuery] = useState<string>('');
const displayedPartitions = useMemo(
() =>
visiblePartitions.filter((partition: QRepPartitionStatus) => {
return partition.partitionId
.toLowerCase()
.includes(searchQuery.toLowerCase());
}),
[visiblePartitions, searchQuery]
);

const handleNext = () => {
if (currentPage < totalPages) setCurrentPage(currentPage + 1);
Expand Down Expand Up @@ -136,15 +145,10 @@ export default function QRepStatusTable({
</>
),
right: (
<SearchBar
allItems={visiblePartitions}
setItems={setDisplayedPartitions}
filterFunction={(query: string) =>
visiblePartitions.filter((partition: QRepPartitionStatus) => {
return partition.partitionId
.toLowerCase()
.includes(query.toLowerCase());
})
<SearchField
placeholder='Search by partition UUID'
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearchQuery(e.target.value)
}
/>
),
Expand Down
49 changes: 26 additions & 23 deletions ui/app/mirrors/tables.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
'use client';
import { DropDialog } from '@/components/DropDialog';
import PeerButton from '@/components/PeerComponent';
import SearchBar from '@/components/Search';
import TimeLabel from '@/components/TimeComponent';
import { Label } from '@/lib/Label';
import { SearchField } from '@/lib/SearchField';
import { Table, TableCell, TableRow } from '@/lib/Table';
import Link from 'next/link';
import { useState } from 'react';
import { useMemo, useState } from 'react';

export function CDCFlows({ cdcFlows }: { cdcFlows: any }) {
const [mirrors, setMirrors] = useState(cdcFlows);
const [searchQuery, setSearchQuery] = useState<string>('');
const mirrors = useMemo(
() =>
cdcFlows.filter((flow: any) => {
return flow.name.toLowerCase().includes(searchQuery.toLowerCase());
}),
[searchQuery, cdcFlows]
);

return (
<>
Expand All @@ -26,15 +33,10 @@ export function CDCFlows({ cdcFlows }: { cdcFlows: any }) {
toolbar={{
left: <></>,
right: (
<SearchBar
allItems={cdcFlows}
setItems={setMirrors}
filterFunction={(query: string) =>
cdcFlows.filter((flow: any) => {
return flow.name
.toLowerCase()
.includes(query.toLowerCase());
})
<SearchField
placeholder='Search by flow name'
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearchQuery(e.target.value)
}
/>
),
Expand Down Expand Up @@ -102,8 +104,14 @@ export function QRepFlows({
qrepFlows: any;
title: string;
}) {
const [mirrors, setMirrors] = useState(qrepFlows);

const [searchQuery, setSearchQuery] = useState<string>('');
const mirrors = useMemo(
() =>
qrepFlows.filter((flow: any) => {
return flow.name.toLowerCase().includes(searchQuery.toLowerCase());
}),
[searchQuery, qrepFlows]
);
return (
<>
<Label variant='headline'>{title}</Label>
Expand All @@ -119,15 +127,10 @@ export function QRepFlows({
toolbar={{
left: <></>,
right: (
<SearchBar
allItems={qrepFlows}
setItems={setMirrors}
filterFunction={(query: string) =>
qrepFlows.filter((flow: any) => {
return flow.name
.toLowerCase()
.includes(query.toLowerCase());
})
<SearchField
placeholder='Search by flow name'
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearchQuery(e.target.value)
}
/>
),
Expand Down
24 changes: 14 additions & 10 deletions ui/app/peers/peersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import { DropDialog } from '@/components/DropDialog';
import PeerButton from '@/components/PeerComponent';
import PeerTypeLabel from '@/components/PeerTypeComponent';
import SearchBar from '@/components/Search';
import { Peer } from '@/grpc_generated/peers';
import { Label } from '@/lib/Label';
import { SearchField } from '@/lib/SearchField';
import { Table, TableCell, TableRow } from '@/lib/Table';
import { useState } from 'react';
import { useMemo, useState } from 'react';

function PeerRow({ peer }: { peer: Peer }) {
return (
Expand All @@ -30,21 +30,25 @@ function PeerRow({ peer }: { peer: Peer }) {
}

function PeersTable({ title, peers }: { title: string; peers: Peer[] }) {
const [rows, setRows] = useState<Peer[]>(peers);
const [searchQuery, setSearchQuery] = useState<string>('');
const rows = useMemo(
() =>
peers.filter((peer) => {
return peer.name.toLowerCase().includes(searchQuery.toLowerCase());
}),
[peers, searchQuery]
);

return (
<Table
title={<Label variant='headline'>{title}</Label>}
toolbar={{
left: <></>,
right: (
<SearchBar
allItems={peers}
setItems={setRows}
filterFunction={(query: string) =>
peers.filter((peer) => {
return peer.name.toLowerCase().includes(query.toLowerCase());
})
<SearchField
placeholder='Search by peer name'
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearchQuery(e.target.value)
}
/>
),
Expand Down
29 changes: 0 additions & 29 deletions ui/components/Search.tsx

This file was deleted.

Loading