Clearing of events does not reload anymore

updating workspace name does not result in reload anymore
set event log page size to 10
fix css issues with charts
This commit is contained in:
timothycarambat 2024-05-01 16:13:20 -07:00
parent 894f727903
commit b69bf7cc27
4 changed files with 48 additions and 33 deletions

View File

@ -107,7 +107,7 @@ export function Chartable({ props, workspace }) {
);
case "line":
return (
<div className="bg-zinc-900 p-8 pb-12 rounded-xl text-white h-[500px]">
<div className="bg-zinc-900 p-8 pb-12 rounded-xl text-white h-[500px] w-full">
<h3 className="text-lg font-medium">{title}</h3>
<LineChart
className="h-[400px]"
@ -371,7 +371,7 @@ export function Chartable({ props, workspace }) {
<div className="py-2 px-4 w-full flex gap-x-5 md:max-w-[800px] flex-col">
<div className="flex gap-x-5">
<WorkspaceProfileImage workspace={workspace} />
<div className="relative">
<div className="relative w-full">
<DownloadGraph onClick={handleDownload} />
<div ref={ref}>{renderChart()}</div>
<span
@ -390,7 +390,7 @@ export function Chartable({ props, workspace }) {
return (
<div className="flex justify-center items-end w-full">
<div className="py-2 px-4 w-full flex gap-x-5 md:max-w-[800px] flex-col">
<div className="relative">
<div className="relative w-full">
<DownloadGraph onClick={handleDownload} />
<div ref={ref}>{renderChart()}</div>
</div>

View File

@ -9,6 +9,22 @@ import showToast from "@/utils/toast";
import CTAButton from "@/components/lib/CTAButton";
export default function AdminLogs() {
const query = useQuery();
const [loading, setLoading] = useState(true);
const [logs, setLogs] = useState([]);
const [offset, setOffset] = useState(Number(query.get("offset") || 0));
const [canNext, setCanNext] = useState(false);
useEffect(() => {
async function fetchLogs() {
const { logs: _logs, hasPages = false } = await System.eventLogs(offset);
setLogs(_logs);
setCanNext(hasPages);
setLoading(false);
}
fetchLogs();
}, [offset]);
const handleResetLogs = async () => {
if (
!window.confirm(
@ -19,13 +35,22 @@ export default function AdminLogs() {
const { success, error } = await System.clearEventLogs();
if (success) {
showToast("Event logs cleared successfully.", "success");
setTimeout(() => {
window.location.reload();
}, 1000);
setLogs([]);
setCanNext(false);
setOffset(0);
} else {
showToast(`Failed to clear logs: ${error}`, "error");
}
};
const handlePrevious = () => {
setOffset(Math.max(offset - 1, 0));
};
const handleNext = () => {
setOffset(offset + 1);
};
return (
<div className="w-screen h-screen overflow-hidden bg-sidebar flex">
<Sidebar />
@ -53,37 +78,28 @@ export default function AdminLogs() {
Clear Event Logs
</CTAButton>
</div>
<LogsContainer />
<LogsContainer
loading={loading}
logs={logs}
offset={offset}
canNext={canNext}
handleNext={handleNext}
handlePrevious={handlePrevious}
/>
</div>
</div>
</div>
);
}
function LogsContainer() {
const query = useQuery();
const [loading, setLoading] = useState(true);
const [logs, setLogs] = useState([]);
const [offset, setOffset] = useState(Number(query.get("offset") || 0));
const [canNext, setCanNext] = useState(false);
const handlePrevious = () => {
setOffset(Math.max(offset - 1, 0));
};
const handleNext = () => {
setOffset(offset + 1);
};
useEffect(() => {
async function fetchLogs() {
const { logs: _logs, hasPages = false } = await System.eventLogs(offset);
setLogs(_logs);
setCanNext(hasPages);
setLoading(false);
}
fetchLogs();
}, [offset]);
function LogsContainer({
loading,
logs,
offset,
canNext,
handleNext,
handlePrevious,
}) {
if (loading) {
return (
<Skeleton.default

View File

@ -36,7 +36,6 @@ export default function GeneralInfo({ slug }) {
);
if (!!updatedWorkspace) {
showToast("Workspace updated!", "success", { clear: true });
setTimeout(() => window.location.reload(), 1_500);
} else {
showToast(`Error: ${message}`, "error", { clear: true });
}

View File

@ -913,7 +913,7 @@ function systemEndpoints(app) {
[validatedRequest, flexUserRoleValid([ROLES.admin])],
async (request, response) => {
try {
const { offset = 0, limit = 20 } = reqBody(request);
const { offset = 0, limit = 10 } = reqBody(request);
const logs = await EventLogs.whereWithData({}, limit, offset * limit, {
id: "desc",
});