mirror of
https://github.com/kopia/kopia.git
synced 2026-03-12 11:16:25 -04:00
- added ability to make new snapshots from the UI
- added directory picker
- hide/show macOS dock icon automatically
- fixed copy/paste on Mac (apparently if you don't have 'Edit' menu
in your app, copy/paste and many other shortcut keys simply don't
work)
- added smart time formatting ("X minutes ago", etc.) in lists
using 'moment' library
- added progress information to snapshots
124 lines
3.2 KiB
JavaScript
124 lines
3.2 KiB
JavaScript
import React from 'react';
|
|
import Pagination from 'react-bootstrap/Pagination';
|
|
import Table from 'react-bootstrap/Table';
|
|
import { usePagination, useSortBy, useTable } from 'react-table';
|
|
|
|
function paginationItems(count, active, gotoPage) {
|
|
let items = [];
|
|
|
|
function pageWithNumber(number) {
|
|
return <Pagination.Item key={number} active={number === active} onClick={() => gotoPage(number-1)}>
|
|
{number}
|
|
</Pagination.Item>;
|
|
}
|
|
|
|
function dotDotDot() {
|
|
return <Pagination.Ellipsis />;
|
|
}
|
|
|
|
let minPageNumber = active - 10;
|
|
if (minPageNumber < 1) {
|
|
minPageNumber = 1;
|
|
}
|
|
|
|
let maxPageNumber = active + 9;
|
|
if (minPageNumber + 19 >= maxPageNumber) {
|
|
maxPageNumber = minPageNumber + 19;
|
|
}
|
|
if (maxPageNumber > count) {
|
|
maxPageNumber = count;
|
|
}
|
|
|
|
if (minPageNumber > 1) {
|
|
items.push(dotDotDot());
|
|
}
|
|
|
|
for (let number = minPageNumber; number <= maxPageNumber; number++) {
|
|
items.push(pageWithNumber(number));
|
|
}
|
|
|
|
if (maxPageNumber < count) {
|
|
items.push(dotDotDot());
|
|
}
|
|
|
|
return items;
|
|
}
|
|
|
|
export default function MyTable({ columns, data }) {
|
|
// Use the state and functions returned from useTable to build your UI
|
|
const {
|
|
getTableProps,
|
|
getTableBodyProps,
|
|
headerGroups,
|
|
page,
|
|
prepareRow,
|
|
canPreviousPage,
|
|
canNextPage,
|
|
pageOptions,
|
|
pageCount,
|
|
gotoPage,
|
|
nextPage,
|
|
previousPage,
|
|
state: { pageIndex },
|
|
} = useTable({
|
|
columns,
|
|
data,
|
|
initialState: { pageSize: 10 },
|
|
autoResetPage: false,
|
|
autoResetSortBy: false,
|
|
},
|
|
useSortBy,
|
|
usePagination,
|
|
)
|
|
|
|
const paginationUI = pageOptions.length > 1 &&
|
|
<>
|
|
<Pagination size="sm" variant="dark">
|
|
<Pagination.First onClick={() => gotoPage(0)} disabled={!canPreviousPage} />
|
|
<Pagination.Prev onClick={() => previousPage()} disabled={!canPreviousPage} />
|
|
<Pagination.Next onClick={() => nextPage()} disabled={!canNextPage} />
|
|
<Pagination.Last onClick={() => gotoPage(pageCount - 1)} disabled={!canNextPage} />
|
|
</Pagination>
|
|
|
|
|
|
<Pagination size="sm" variant="dark">
|
|
{paginationItems(pageOptions.length, pageIndex+1, gotoPage)}
|
|
</Pagination>
|
|
</>;
|
|
|
|
return (
|
|
<>
|
|
<Table size="sm" striped bordered hover {...getTableProps()}>
|
|
<thead className="thead-dark">
|
|
{headerGroups.map(headerGroup => (
|
|
<tr {...headerGroup.getHeaderGroupProps()}>
|
|
{headerGroup.headers.map(column => (
|
|
<th {...column.getHeaderProps({...column.getSortByToggleProps(), style: {
|
|
width: column.width,
|
|
}})}>{column.render('Header')}
|
|
{column.isSorted ? (column.isSortedDesc ? '🔽' : '🔼') : ''}
|
|
</th>
|
|
))}
|
|
</tr>
|
|
))}
|
|
</thead>
|
|
<tbody {...getTableBodyProps()}>
|
|
{page.map(
|
|
(row, i) => {
|
|
prepareRow(row);
|
|
return (
|
|
<tr {...row.getRowProps()}>
|
|
{row.cells.map(cell => {
|
|
return <td {...cell.getCellProps()}>{cell.render('Cell')}</td>
|
|
})}
|
|
</tr>
|
|
)
|
|
}
|
|
)}
|
|
</tbody>
|
|
</Table>
|
|
{ paginationUI }
|
|
</>
|
|
)
|
|
}
|