mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-11 16:52:38 +02:00
user mutation atoms
This commit is contained in:
parent
10f3baca0c
commit
864ebeea9c
2 changed files with 3046 additions and 2997 deletions
5981
surfsense_backend/uv.lock
generated
5981
surfsense_backend/uv.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -15,6 +15,7 @@ import {
|
||||||
useReactTable,
|
useReactTable,
|
||||||
type VisibilityState,
|
type VisibilityState,
|
||||||
} from "@tanstack/react-table";
|
} from "@tanstack/react-table";
|
||||||
|
import { useAtomValue } from "jotai";
|
||||||
import {
|
import {
|
||||||
Activity,
|
Activity,
|
||||||
AlertCircle,
|
AlertCircle,
|
||||||
|
|
@ -44,8 +45,13 @@ import {
|
||||||
import { AnimatePresence, motion, type Variants } from "motion/react";
|
import { AnimatePresence, motion, type Variants } from "motion/react";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import React, { useContext, useId, useMemo, useRef, useState } from "react";
|
import React, { useCallback, useContext, useId, useMemo, useRef, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import {
|
||||||
|
createLogMutationAtom,
|
||||||
|
deleteLogMutationAtom,
|
||||||
|
updateLogMutationAtom,
|
||||||
|
} from "@/atoms/logs/log-mutation.atoms";
|
||||||
import { JsonMetadataViewer } from "@/components/json-metadata-viewer";
|
import { JsonMetadataViewer } from "@/components/json-metadata-viewer";
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
|
|
@ -89,6 +95,7 @@ import {
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
import type { CreateLogRequest, UpdateLogRequest } from "@/contracts/types/log.types";
|
||||||
import { type Log, type LogLevel, type LogStatus, useLogs, useLogsSummary } from "@/hooks/use-logs";
|
import { type Log, type LogLevel, type LogStatus, useLogs, useLogsSummary } from "@/hooks/use-logs";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
|
@ -334,13 +341,50 @@ export default function LogsManagePage() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const searchSpaceId = Number(params.search_space_id);
|
const searchSpaceId = Number(params.search_space_id);
|
||||||
|
|
||||||
const {
|
const { mutateAsync: deleteLogMutation } = useAtomValue(deleteLogMutationAtom);
|
||||||
logs,
|
const { mutateAsync: updateLogMutation } = useAtomValue(updateLogMutationAtom);
|
||||||
loading: logsLoading,
|
const { mutateAsync: createLogMutation } = useAtomValue(createLogMutationAtom);
|
||||||
error: logsError,
|
|
||||||
refreshLogs,
|
const createLog = useCallback(
|
||||||
deleteLog,
|
async (data: CreateLogRequest) => {
|
||||||
} = useLogs(searchSpaceId);
|
try {
|
||||||
|
await createLogMutation(data);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to create log:", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[createLogMutation]
|
||||||
|
);
|
||||||
|
|
||||||
|
const updateLog = useCallback(
|
||||||
|
async (logId: number, data: UpdateLogRequest) => {
|
||||||
|
try {
|
||||||
|
await updateLogMutation({ logId, data });
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to update log:", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[updateLogMutation]
|
||||||
|
);
|
||||||
|
|
||||||
|
const deleteLog = useCallback(
|
||||||
|
async (id: number) => {
|
||||||
|
try {
|
||||||
|
await deleteLogMutation({ id });
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to delete log:", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[deleteLogMutation]
|
||||||
|
);
|
||||||
|
|
||||||
|
const { logs, loading: logsLoading, error: logsError, refreshLogs } = useLogs(searchSpaceId);
|
||||||
const {
|
const {
|
||||||
summary,
|
summary,
|
||||||
loading: summaryLoading,
|
loading: summaryLoading,
|
||||||
|
|
@ -408,7 +452,7 @@ export default function LogsManagePage() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const deletePromises = selectedRows.map((row) => deleteLog(row.original.id));
|
const deletePromises = selectedRows.map((row) => deleteLog(row.original.id)); // Already passes { id } via wrapper
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const results = await Promise.all(deletePromises);
|
const results = await Promise.all(deletePromises);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue