Moved v3 code from NginxProxyManager/nginx-proxy-manager-3 to NginxProxyManager/nginx-proxy-manager
This commit is contained in:
155
frontend/src/pages/CertificateAuthorities/Table.tsx
Normal file
155
frontend/src/pages/CertificateAuthorities/Table.tsx
Normal file
@ -0,0 +1,155 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
import {
|
||||
tableEvents,
|
||||
ActionsFormatter,
|
||||
BooleanFormatter,
|
||||
TableFilter,
|
||||
TableLayout,
|
||||
TablePagination,
|
||||
TableSortBy,
|
||||
TextFilter,
|
||||
} from "components";
|
||||
import { intl } from "locale";
|
||||
import { CertificateAuthorityEditModal } from "modals";
|
||||
import { FiEdit } from "react-icons/fi";
|
||||
import { useSortBy, useFilters, useTable, usePagination } from "react-table";
|
||||
|
||||
export interface TableProps {
|
||||
data: any;
|
||||
pagination: TablePagination;
|
||||
sortBy: TableSortBy[];
|
||||
filters: TableFilter[];
|
||||
onTableEvent: any;
|
||||
}
|
||||
function Table({
|
||||
data,
|
||||
pagination,
|
||||
onTableEvent,
|
||||
sortBy,
|
||||
filters,
|
||||
}: TableProps) {
|
||||
const [editId, setEditId] = useState(0);
|
||||
const [columns, tableData] = useMemo(() => {
|
||||
const columns = [
|
||||
{
|
||||
Header: intl.formatMessage({ id: "column.name" }),
|
||||
accessor: "name",
|
||||
sortable: true,
|
||||
Filter: TextFilter,
|
||||
},
|
||||
{
|
||||
Header: intl.formatMessage({ id: "column.max-domains" }),
|
||||
accessor: "maxDomains",
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
Header: intl.formatMessage({ id: "column.wildcard-support" }),
|
||||
accessor: "isWildcardSupported",
|
||||
Cell: BooleanFormatter(),
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
accessor: "id",
|
||||
className: "w-80",
|
||||
Cell: ActionsFormatter([
|
||||
{
|
||||
title: intl.formatMessage({
|
||||
id: "action.edit",
|
||||
}),
|
||||
onClick: (e: any, { id }: any) => setEditId(id),
|
||||
icon: <FiEdit />,
|
||||
disabled: (data: any) => data.isReadonly,
|
||||
},
|
||||
]),
|
||||
},
|
||||
];
|
||||
return [columns, data];
|
||||
}, [data]);
|
||||
|
||||
const tableInstance = useTable(
|
||||
{
|
||||
columns,
|
||||
data: tableData,
|
||||
initialState: {
|
||||
pageIndex: Math.floor(pagination.offset / pagination.limit),
|
||||
pageSize: pagination.limit,
|
||||
sortBy,
|
||||
filters,
|
||||
},
|
||||
// Tell the usePagination
|
||||
// hook that we'll handle our own data fetching
|
||||
// This means we'll also have to provide our own
|
||||
// pageCount.
|
||||
pageCount: Math.ceil(pagination.total / pagination.limit),
|
||||
manualPagination: true,
|
||||
// Sorting options
|
||||
manualSortBy: true,
|
||||
disableMultiSort: true,
|
||||
disableSortRemove: true,
|
||||
autoResetSortBy: false,
|
||||
// Filter options
|
||||
manualFilters: true,
|
||||
autoResetFilters: false,
|
||||
},
|
||||
useFilters,
|
||||
useSortBy,
|
||||
usePagination,
|
||||
);
|
||||
|
||||
const gotoPage = tableInstance.gotoPage;
|
||||
|
||||
useEffect(() => {
|
||||
onTableEvent({
|
||||
type: tableEvents.PAGE_CHANGED,
|
||||
payload: tableInstance.state.pageIndex,
|
||||
});
|
||||
}, [onTableEvent, tableInstance.state.pageIndex]);
|
||||
|
||||
useEffect(() => {
|
||||
onTableEvent({
|
||||
type: tableEvents.PAGE_SIZE_CHANGED,
|
||||
payload: tableInstance.state.pageSize,
|
||||
});
|
||||
gotoPage(0);
|
||||
}, [gotoPage, onTableEvent, tableInstance.state.pageSize]);
|
||||
|
||||
useEffect(() => {
|
||||
if (pagination.total) {
|
||||
onTableEvent({
|
||||
type: tableEvents.TOTAL_COUNT_CHANGED,
|
||||
payload: pagination.total,
|
||||
});
|
||||
}
|
||||
}, [pagination.total, onTableEvent]);
|
||||
|
||||
useEffect(() => {
|
||||
onTableEvent({
|
||||
type: tableEvents.SORT_CHANGED,
|
||||
payload: tableInstance.state.sortBy,
|
||||
});
|
||||
}, [onTableEvent, tableInstance.state.sortBy]);
|
||||
|
||||
useEffect(() => {
|
||||
onTableEvent({
|
||||
type: tableEvents.FILTERS_CHANGED,
|
||||
payload: tableInstance.state.filters,
|
||||
});
|
||||
}, [onTableEvent, tableInstance.state.filters]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<TableLayout pagination={pagination} {...tableInstance} />
|
||||
{editId ? (
|
||||
<CertificateAuthorityEditModal
|
||||
isOpen
|
||||
editId={editId}
|
||||
onClose={() => setEditId(0)}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Table;
|
74
frontend/src/pages/CertificateAuthorities/TableWrapper.tsx
Normal file
74
frontend/src/pages/CertificateAuthorities/TableWrapper.tsx
Normal file
@ -0,0 +1,74 @@
|
||||
import { useEffect, useReducer, useState } from "react";
|
||||
|
||||
import { Alert, AlertIcon } from "@chakra-ui/react";
|
||||
import { SpinnerPage, tableEventReducer } from "components";
|
||||
import { useCertificateAuthorities } from "hooks";
|
||||
|
||||
import Table from "./Table";
|
||||
|
||||
const initialState = {
|
||||
offset: 0,
|
||||
limit: 10,
|
||||
sortBy: [
|
||||
{
|
||||
id: "name",
|
||||
desc: false,
|
||||
},
|
||||
],
|
||||
filters: [],
|
||||
};
|
||||
|
||||
function TableWrapper() {
|
||||
const [{ offset, limit, sortBy, filters }, dispatch] = useReducer(
|
||||
tableEventReducer,
|
||||
initialState,
|
||||
);
|
||||
|
||||
const [tableData, setTableData] = useState(null);
|
||||
const { isFetching, isLoading, isError, error, data } =
|
||||
useCertificateAuthorities(offset, limit, sortBy, filters);
|
||||
|
||||
useEffect(() => {
|
||||
setTableData(data as any);
|
||||
}, [data]);
|
||||
|
||||
if (isFetching || isLoading || !tableData) {
|
||||
return <SpinnerPage />;
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return (
|
||||
<Alert status="error">
|
||||
<AlertIcon />
|
||||
{error?.message || "Unknown error"}
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof data?.total === "undefined") {
|
||||
return (
|
||||
<Alert status="error">
|
||||
<AlertIcon />
|
||||
There was an error fetching the data.
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
const pagination = {
|
||||
offset: data?.offset,
|
||||
limit: data?.limit,
|
||||
total: data?.total,
|
||||
};
|
||||
|
||||
return (
|
||||
<Table
|
||||
data={data?.items || []}
|
||||
pagination={pagination}
|
||||
sortBy={sortBy}
|
||||
filters={filters}
|
||||
onTableEvent={dispatch}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default TableWrapper;
|
35
frontend/src/pages/CertificateAuthorities/index.tsx
Normal file
35
frontend/src/pages/CertificateAuthorities/index.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import { Heading, HStack } from "@chakra-ui/react";
|
||||
import { HelpDrawer, PrettyButton } from "components";
|
||||
import { intl } from "locale";
|
||||
import { CertificateAuthorityCreateModal } from "modals";
|
||||
|
||||
import TableWrapper from "./TableWrapper";
|
||||
|
||||
function CertificateAuthorities() {
|
||||
const [createShown, setCreateShown] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<HStack mx={6} my={4} justifyContent="space-between">
|
||||
<Heading mb={2}>
|
||||
{intl.formatMessage({ id: "certificate-authorities.title" })}
|
||||
</Heading>
|
||||
<HStack>
|
||||
<HelpDrawer section="CertificateAuthorities" />
|
||||
<PrettyButton size="sm" onClick={() => setCreateShown(true)}>
|
||||
{intl.formatMessage({ id: "certificate-authority.create" })}
|
||||
</PrettyButton>
|
||||
</HStack>
|
||||
</HStack>
|
||||
<TableWrapper />
|
||||
<CertificateAuthorityCreateModal
|
||||
isOpen={createShown}
|
||||
onClose={() => setCreateShown(false)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default CertificateAuthorities;
|
Reference in New Issue
Block a user