pagination and empty state fix
This commit is contained in:
1 parent
4e678a4ce7
commit
bd6aa0fa3a
13 files changed
+39
-47
No files matched your search
@@ -100,7 +100,7 @@ export const BasePage = ({
|
|||||||
interface BasePageWithStatesProps extends StackProps {
|
interface BasePageWithStatesProps extends StackProps {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: any;
|
error: any;
|
||||||
items: any[];
|
totalCount: number;
|
||||||
bullets: string[] | unknown;
|
bullets: string[] | unknown;
|
||||||
page: string;
|
page: string;
|
||||||
actionButtonText: string;
|
actionButtonText: string;
|
||||||
@@ -111,7 +111,7 @@ interface BasePageWithStatesProps extends StackProps {
|
|||||||
export const BasePageWithStates = ({
|
export const BasePageWithStates = ({
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
items,
|
totalCount,
|
||||||
page,
|
page,
|
||||||
bullets,
|
bullets,
|
||||||
actionButtonText,
|
actionButtonText,
|
||||||
@@ -119,9 +119,9 @@ export const BasePageWithStates = ({
|
|||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}: BasePageWithStatesProps) => {
|
}: BasePageWithStatesProps) => {
|
||||||
const showLoading = loading && (!items || items.length === 0);
|
const showLoading = loading && totalCount === 0;
|
||||||
|
|
||||||
if (!loading && isEmpty(items)) {
|
if (!loading && totalCount === 0) {
|
||||||
return (
|
return (
|
||||||
<EmptyFallback
|
<EmptyFallback
|
||||||
bullets={bullets}
|
bullets={bullets}
|
||||||
@@ -146,23 +146,17 @@ export const BasePageWithStates = ({
|
|||||||
interface MonitorBasePageWithStatesProps extends StackProps {
|
interface MonitorBasePageWithStatesProps extends StackProps {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: any;
|
error: any;
|
||||||
items: any[];
|
totalCount: number;
|
||||||
page: string;
|
page: string;
|
||||||
actionLink?: string;
|
actionLink?: string;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
priorityFallback?: React.ReactNode;
|
priorityFallback?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isEmpty = (items: any[]) => {
|
|
||||||
if (!items) return true;
|
|
||||||
if (Array.isArray(items) && items.length === 0) return true;
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const MonitorBasePageWithStates = ({
|
export const MonitorBasePageWithStates = ({
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
items,
|
totalCount,
|
||||||
page,
|
page,
|
||||||
actionLink,
|
actionLink,
|
||||||
children,
|
children,
|
||||||
@@ -171,7 +165,7 @@ export const MonitorBasePageWithStates = ({
|
|||||||
}: MonitorBasePageWithStatesProps) => {
|
}: MonitorBasePageWithStatesProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const showLoading = loading && (!items || items.length === 0);
|
const showLoading = loading && totalCount === 0;
|
||||||
|
|
||||||
if (priorityFallback) {
|
if (priorityFallback) {
|
||||||
return (
|
return (
|
||||||
@@ -185,7 +179,7 @@ export const MonitorBasePageWithStates = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loading && isEmpty(items)) {
|
if (!loading && totalCount === 0) {
|
||||||
return (
|
return (
|
||||||
<EmptyMonitorFallback
|
<EmptyMonitorFallback
|
||||||
page={page}
|
page={page}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import TablePagination from "@mui/material/TablePagination";
|
|||||||
import type { TablePaginationOwnProps } from "@mui/material/TablePagination";
|
import type { TablePaginationOwnProps } from "@mui/material/TablePagination";
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useState, Fragment } from "react";
|
import { useState, Fragment, useEffect } from "react";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
|
|
||||||
@@ -454,12 +454,26 @@ function HasMoreTablePaginationActions(props: HasMoreTablePaginationActionsProps
|
|||||||
interface PaginationProps extends TablePaginationOwnProps {
|
interface PaginationProps extends TablePaginationOwnProps {
|
||||||
component?: React.ElementType;
|
component?: React.ElementType;
|
||||||
hasMore?: boolean;
|
hasMore?: boolean;
|
||||||
|
itemsOnPage?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Pagination = ({ ...props }: PaginationProps) => {
|
export const Pagination = ({ ...props }: PaginationProps) => {
|
||||||
const { hasMore, ...rest } = props;
|
const { hasMore, itemsOnPage, ...rest } = props;
|
||||||
const isSmall = useMediaQuery((theme: any) => theme.breakpoints.down("sm"));
|
const isSmall = useMediaQuery((theme: any) => theme.breakpoints.down("sm"));
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
typeof itemsOnPage === "number" &&
|
||||||
|
itemsOnPage === 0 &&
|
||||||
|
rest.count > 0 &&
|
||||||
|
rest.page > 0 &&
|
||||||
|
rest.onPageChange
|
||||||
|
) {
|
||||||
|
rest.onPageChange(null, rest.page - 1);
|
||||||
|
}
|
||||||
|
}, [itemsOnPage, rest.count, rest.page, rest.onPageChange]);
|
||||||
|
|
||||||
const labelDisplayedRows = ({
|
const labelDisplayedRows = ({
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
|
|||||||
@@ -215,6 +215,7 @@ export const IncidentsTable = ({
|
|||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
onPageChange={handlePageChange}
|
onPageChange={handlePageChange}
|
||||||
onRowsPerPageChange={handleRowsPerPageChange}
|
onRowsPerPageChange={handleRowsPerPageChange}
|
||||||
|
itemsOnPage={incidents.length}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -269,6 +269,7 @@ export const InfraMonitorsTable = ({
|
|||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
onPageChange={handlePageChange}
|
onPageChange={handlePageChange}
|
||||||
onRowsPerPageChange={handleRowsPerPageChange}
|
onRowsPerPageChange={handleRowsPerPageChange}
|
||||||
|
itemsOnPage={monitors.length}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -85,13 +85,6 @@ const InfrastructureMonitors = () => {
|
|||||||
return `/monitors/team/with-checks?${params.toString()}`;
|
return `/monitors/team/with-checks?${params.toString()}`;
|
||||||
}, [page, rowsPerPage, filter, field, sortOrder]);
|
}, [page, rowsPerPage, filter, field, sortOrder]);
|
||||||
|
|
||||||
const {
|
|
||||||
data: monitors,
|
|
||||||
isLoading: monitorsLoading,
|
|
||||||
error,
|
|
||||||
refetch: refetchMonitors,
|
|
||||||
} = useGet<Monitor[]>("/monitors/team?type=hardware", {}, { keepPreviousData: true });
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: monitorsWithChecksData,
|
data: monitorsWithChecksData,
|
||||||
isLoading: monitorsWithChecksLoading,
|
isLoading: monitorsWithChecksLoading,
|
||||||
@@ -104,7 +97,7 @@ const InfrastructureMonitors = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { summary, count } = monitorsWithChecksData ?? {};
|
const { summary, count } = monitorsWithChecksData ?? {};
|
||||||
const isLoading = monitorsLoading || monitorsWithChecksLoading;
|
const isLoading = monitorsWithChecksLoading;
|
||||||
|
|
||||||
// Delete hook
|
// Delete hook
|
||||||
const { deleteFn, loading: isDeleting } = useDelete();
|
const { deleteFn, loading: isDeleting } = useDelete();
|
||||||
@@ -114,7 +107,6 @@ const InfrastructureMonitors = () => {
|
|||||||
await deleteFn(`/monitors/${selectedMonitor.id}`);
|
await deleteFn(`/monitors/${selectedMonitor.id}`);
|
||||||
setSelectedMonitor(null);
|
setSelectedMonitor(null);
|
||||||
refetch();
|
refetch();
|
||||||
refetchMonitors();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
@@ -124,8 +116,8 @@ const InfrastructureMonitors = () => {
|
|||||||
return (
|
return (
|
||||||
<MonitorBasePageWithStates
|
<MonitorBasePageWithStates
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
error={error ?? monitorsWithChecksError}
|
error={monitorsWithChecksError}
|
||||||
items={monitors || []}
|
totalCount={summary?.totalMonitors ?? 0}
|
||||||
page="infrastructure"
|
page="infrastructure"
|
||||||
actionLink="/infrastructure/create"
|
actionLink="/infrastructure/create"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ export const MaintenanceWindowTable = ({
|
|||||||
emptyViewText={t("common.table.empty")}
|
emptyViewText={t("common.table.empty")}
|
||||||
/>
|
/>
|
||||||
<Pagination
|
<Pagination
|
||||||
|
itemsOnPage={maintenanceWindows.length}
|
||||||
component="div"
|
component="div"
|
||||||
count={maintenanceWindowCount}
|
count={maintenanceWindowCount}
|
||||||
page={page}
|
page={page}
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ const MaintenanceWindowPage = () => {
|
|||||||
return (
|
return (
|
||||||
<BasePageWithStates
|
<BasePageWithStates
|
||||||
page={t("pages.maintenanceWindow.fallback.title")}
|
page={t("pages.maintenanceWindow.fallback.title")}
|
||||||
|
totalCount={maintenanceWindowCount}
|
||||||
bullets={
|
bullets={
|
||||||
t("pages.maintenanceWindow.fallback.checks", { returnObjects: true }) as string[]
|
t("pages.maintenanceWindow.fallback.checks", { returnObjects: true }) as string[]
|
||||||
}
|
}
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
error={!!error}
|
error={!!error}
|
||||||
items={maintenanceWindows}
|
|
||||||
actionButtonText={t("pages.maintenanceWindow.fallback.actionButton")}
|
actionButtonText={t("pages.maintenanceWindow.fallback.actionButton")}
|
||||||
actionLink="/maintenance/create"
|
actionLink="/maintenance/create"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ const NotificationsPage = () => {
|
|||||||
}
|
}
|
||||||
loading={isLoading || isValidating}
|
loading={isLoading || isValidating}
|
||||||
error={!!error}
|
error={!!error}
|
||||||
items={notifications ?? []}
|
totalCount={notifications?.length ?? 0}
|
||||||
actionButtonText={t("pages.notifications.fallback.actionButton")}
|
actionButtonText={t("pages.notifications.fallback.actionButton")}
|
||||||
actionLink="/notifications/create"
|
actionLink="/notifications/create"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -248,6 +248,7 @@ export const PageSpeedMonitorsTable = ({
|
|||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
onPageChange={handlePageChange}
|
onPageChange={handlePageChange}
|
||||||
onRowsPerPageChange={handleRowsPerPageChange}
|
onRowsPerPageChange={handleRowsPerPageChange}
|
||||||
|
itemsOnPage={monitors.length}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ const PageSpeedMonitorsPage = () => {
|
|||||||
<MonitorBasePageWithStates
|
<MonitorBasePageWithStates
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
error={monitorsError || settingsError}
|
error={monitorsError || settingsError}
|
||||||
items={monitors || []}
|
totalCount={summary?.totalMonitors ?? 0}
|
||||||
page="pageSpeed"
|
page="pageSpeed"
|
||||||
actionLink="/pagespeed/create"
|
actionLink="/pagespeed/create"
|
||||||
priorityFallback={showApiKeyWarning ? <PageSpeedKeyPriorityFallback /> : undefined}
|
priorityFallback={showApiKeyWarning ? <PageSpeedKeyPriorityFallback /> : undefined}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const StatusPages = () => {
|
|||||||
t("pages.statusPages.fallback.checks", { returnObjects: true }) as string[]
|
t("pages.statusPages.fallback.checks", { returnObjects: true }) as string[]
|
||||||
}
|
}
|
||||||
error={!!error}
|
error={!!error}
|
||||||
items={statusPages ?? []}
|
totalCount={statusPages?.length ?? 0}
|
||||||
actionButtonText={t("pages.statusPages.fallback.actionButton")}
|
actionButtonText={t("pages.statusPages.fallback.actionButton")}
|
||||||
actionLink="/status/create"
|
actionLink="/status/create"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ export const MonitorTable = ({
|
|||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
onPageChange={(_e, newPage) => setPage(newPage)}
|
onPageChange={(_e, newPage) => setPage(newPage)}
|
||||||
onRowsPerPageChange={(e) => setRowsPerPage(Number(e.target.value))}
|
onRowsPerPageChange={(e) => setRowsPerPage(Number(e.target.value))}
|
||||||
|
itemsOnPage={monitors.length}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -85,18 +85,6 @@ const UptimeMonitorsPage = () => {
|
|||||||
return `/monitors/team/with-checks?${params.toString()}`;
|
return `/monitors/team/with-checks?${params.toString()}`;
|
||||||
}, [effectiveTypes, page, rowsPerPage, filter, field, sortOrder]);
|
}, [effectiveTypes, page, rowsPerPage, filter, field, sortOrder]);
|
||||||
|
|
||||||
// Data fetching
|
|
||||||
const {
|
|
||||||
data: monitors,
|
|
||||||
isLoading: monitorsLoading,
|
|
||||||
error,
|
|
||||||
refetch: refetchMonitorsAndSummary,
|
|
||||||
} = useGet<Monitor[]>(
|
|
||||||
"/monitors/team?type=http&type=ping&type=port&type=docker",
|
|
||||||
{},
|
|
||||||
{ keepPreviousData: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: monitorsWithChecksData,
|
data: monitorsWithChecksData,
|
||||||
isLoading: monitorsWithChecksLoading,
|
isLoading: monitorsWithChecksLoading,
|
||||||
@@ -126,20 +114,19 @@ const UptimeMonitorsPage = () => {
|
|||||||
await deleteFn(`/monitors/${selectedMonitor.id}`);
|
await deleteFn(`/monitors/${selectedMonitor.id}`);
|
||||||
setSelectedMonitor(null);
|
setSelectedMonitor(null);
|
||||||
refetch();
|
refetch();
|
||||||
refetchMonitorsAndSummary();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setSelectedMonitor(null);
|
setSelectedMonitor(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isLoading = monitorsLoading || monitorsWithChecksLoading;
|
const isLoading = monitorsWithChecksLoading;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MonitorBasePageWithStates
|
<MonitorBasePageWithStates
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
error={error || monitorsWithChecksError}
|
error={monitorsWithChecksError}
|
||||||
items={monitors || []}
|
totalCount={summary?.totalMonitors ?? 0}
|
||||||
page="uptime"
|
page="uptime"
|
||||||
actionLink="/uptime/create"
|
actionLink="/uptime/create"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in new issue
Block a user