Skip to content

Commit

Permalink
fixed linting
Browse files Browse the repository at this point in the history
Signed-off-by: c-r-dev <[email protected]>
  • Loading branch information
c-r-dev committed Jan 7, 2025
1 parent d95149c commit d93c4c9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 61 deletions.
72 changes: 36 additions & 36 deletions web/vtadmin/src/components/dataTable/SortedDataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { useCallback, useMemo, useState } from 'react';

export interface ColumnProps {
// Coulmn display name string | JSX.Element
display: string| JSX.Element,
// Column data accessor
accessor: string
display: string | JSX.Element;
// Column data accessor
accessor: string;
}

interface Props<T> {
Expand Down Expand Up @@ -79,53 +79,53 @@ export const SortedDataTable = <T extends object>({
const [sortColumn, setSortColumn] = useState(null);
const [sortOrder, setSortOrder] = useState('asc');

const handleSort = useCallback((column: any) => {
if (sortColumn === column) {
setSortOrder(sortOrder === 'asc' ? 'desc' : 'asc');
} else {
setSortColumn(column);
setSortOrder('asc');
}
}, [sortColumn, sortOrder]);

const sortedData = useMemo(() => {
const handleSort = useCallback(
(column: any) => {
if (sortColumn === column) {
setSortOrder(sortOrder === 'asc' ? 'desc' : 'asc');
} else {
setSortColumn(column);
setSortOrder('asc');
}
},
[sortColumn, sortOrder]
);

const sortedData = useMemo(() => {
if (!sortColumn) return data;
const compare = (a: { [x: string]: any; }, b: { [x: string]: any; }) => {
const valueA = a[sortColumn];
const valueB = b[sortColumn];
if (valueA < valueB) {
return sortOrder === 'asc' ? -1 : 1;
} else if (valueA > valueB) {
return sortOrder === 'asc' ? 1 : -1;
} else {
return 0;
}

const compare = (a: { [x: string]: any }, b: { [x: string]: any }) => {
const valueA = a[sortColumn];
const valueB = b[sortColumn];

if (valueA < valueB) {
return sortOrder === 'asc' ? -1 : 1;
} else if (valueA > valueB) {
return sortOrder === 'asc' ? 1 : -1;
} else {
return 0;
}
};

return [...data].sort(compare);
}, [data, sortColumn, sortOrder]);
}, [data, sortColumn, sortOrder]);

const dataPage = sortedData.slice(startIndex, endIndex);


return (
<div>
<table>
{title && <caption>{title}</caption>}
<thead>
<tr>
{columns.map((col, cdx) => (
<th key={cdx} onClick={()=> handleSort(col.accessor)}>
{columns.map((col, cdx) => (
<th key={cdx} onClick={() => handleSort(col.accessor)}>
<div style={{ display: 'flex' }}>
{col.display}
{sortColumn === col.accessor && (
<span>{sortOrder === 'asc' ? '▲' : '▼'}</span>
)}
{col.display}
{sortColumn === col.accessor && <span>{sortOrder === 'asc' ? '▲' : '▼'}</span>}
</div>
</th>
))}
</th>
))}
</tr>
</thead>
<tbody>{renderRows(dataPage)}</tbody>
Expand Down
62 changes: 37 additions & 25 deletions web/vtadmin/src/components/routes/Schemas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,43 @@ import { KeyspaceLink } from '../links/KeyspaceLink';
import { QueryLoadingPlaceholder } from '../placeholders/QueryLoadingPlaceholder';
import { HelpTooltip } from '../tooltip/HelpTooltip';

const TABLE_COLUMNS : Array<ColumnProps> = [
{display: 'Keyspace', accessor : 'keyspace'},
{display: 'Table' , accessor : 'table'},
{display : <div className="text-right">
Approx. Size{' '}
<HelpTooltip
text={
<span>
Size is an approximate value derived from <span className="font-mono">INFORMATION_SCHEMA</span>.
</span>
}
/>
</div>, accessor : '_tableSize'},
{display: <div className="text-right">
Approx. Rows{' '}
<HelpTooltip
text={
// c.f. https://dev.mysql.com/doc/refman/5.7/en/information-schema-tables-table.html
<span>
Row count is an approximate value derived from <span className="font-mono">INFORMATION_SCHEMA</span>
. Actual values may vary by as much as 40% to 50%.
</span>
}
/>
</div>, accessor : '_tableRowCount'},
const TABLE_COLUMNS: Array<ColumnProps> = [
{ display: 'Keyspace', accessor: 'keyspace' },
{ display: 'Table', accessor: 'table' },
{
display: (
<div className="text-right">
Approx. Size{' '}
<HelpTooltip
text={
<span>
Size is an approximate value derived from{' '}
<span className="font-mono">INFORMATION_SCHEMA</span>.
</span>
}
/>
</div>
),
accessor: '_tableSize',
},
{
display: (
<div className="text-right">
Approx. Rows{' '}
<HelpTooltip
text={
// c.f. https://dev.mysql.com/doc/refman/5.7/en/information-schema-tables-table.html
<span>
Row count is an approximate value derived from{' '}
<span className="font-mono">INFORMATION_SCHEMA</span>. Actual values may vary by as much as
40% to 50%.
</span>
}
/>
</div>
),
accessor: '_tableRowCount',
},
];

export const Schemas = () => {
Expand Down

0 comments on commit d93c4c9

Please sign in to comment.