fix entity list unnecessary parameters

This commit is contained in:
dswbx
2025-01-17 13:43:45 +01:00
parent a723d6f618
commit c19d3b2d75
5 changed files with 48 additions and 18 deletions

View File

@@ -10,9 +10,9 @@ export type IconType =
const styles = { const styles = {
xs: { className: "p-0.5", size: 13 }, xs: { className: "p-0.5", size: 13 },
sm: { className: "p-0.5", size: 16 }, sm: { className: "p-0.5", size: 15 },
md: { className: "p-1", size: 20 }, md: { className: "p-1", size: 18 },
lg: { className: "p-1.5", size: 24 } lg: { className: "p-1.5", size: 22 }
} as const; } as const;
interface IconButtonProps extends ComponentPropsWithoutRef<"button"> { interface IconButtonProps extends ComponentPropsWithoutRef<"button"> {

View File

@@ -0,0 +1,32 @@
import { useEffect, useRef } from "react";
export function useEffectOnce(effect: () => void | (() => void | undefined), deps: any[]): void {
const hasRunRef = useRef(false);
const savedDepsRef = useRef<any[] | undefined>(deps);
useEffect(() => {
const depsChanged = !hasRunRef.current || !areDepsEqual(savedDepsRef.current, deps);
if (depsChanged) {
hasRunRef.current = true;
savedDepsRef.current = deps;
return effect();
}
}, [deps]);
}
function areDepsEqual(prevDeps: any[] | undefined, nextDeps: any[]): boolean {
if (prevDeps && prevDeps.length === 0 && nextDeps.length === 0) {
return true;
}
if (!prevDeps && nextDeps.length === 0) {
return true;
}
if (!prevDeps || !nextDeps || prevDeps.length !== nextDeps.length) {
return false;
}
return prevDeps.every((dep, index) => Object.is(dep, nextDeps[index]));
}

View File

@@ -40,8 +40,8 @@ export function DataEntityList({ params }) {
useBrowserTitle(["Data", entity?.label ?? params.entity]); useBrowserTitle(["Data", entity?.label ?? params.entity]);
const [navigate] = useNavigate(); const [navigate] = useNavigate();
const search = useSearch(searchSchema, { const search = useSearch(searchSchema, {
select: entity?.getSelect(undefined, "table") ?? [], select: undefined,
sort: entity?.getDefaultSort() sort: undefined
}); });
const $q = useApiQuery( const $q = useApiQuery(
@@ -50,7 +50,7 @@ export function DataEntityList({ params }) {
select: search.value.select, select: search.value.select,
limit: search.value.perPage, limit: search.value.perPage,
offset: (search.value.page - 1) * search.value.perPage, offset: (search.value.page - 1) * search.value.perPage,
sort: search.value.sort sort: `${search.value.sort.dir === "asc" ? "" : "-"}${search.value.sort.by}`
}), }),
{ {
enabled: !!entity, enabled: !!entity,
@@ -131,7 +131,7 @@ export function DataEntityList({ params }) {
<EntityTable2 <EntityTable2
data={data ?? null} data={data ?? null}
entity={entity} entity={entity}
/*select={search.value.select}*/ select={search.value.select}
onClickRow={handleClickRow} onClickRow={handleClickRow}
page={search.value.page} page={search.value.page}
sort={search.value.sort} sort={search.value.sort}

View File

@@ -1,17 +1,18 @@
import { IconHome } from "@tabler/icons-react"; import { IconHome } from "@tabler/icons-react";
import { useEffect } from "react"; import { useEffect } from "react";
import { useAuth } from "ui/client"; import { useAuth } from "ui/client";
import { useEffectOnce } from "ui/hooks/use-effect";
import { Empty } from "../components/display/Empty"; import { Empty } from "../components/display/Empty";
import { useBrowserTitle } from "../hooks/use-browser-title"; import { useBrowserTitle } from "../hooks/use-browser-title";
import * as AppShell from "../layouts/AppShell/AppShell"; import * as AppShell from "../layouts/AppShell/AppShell";
import { useNavigate } from "../lib/routes"; import { useNavigate } from "../lib/routes";
export const Root = ({ children }) => { export const Root = ({ children }) => {
const { verify } = useAuth(); const { verify, user } = useAuth();
useEffect(() => { useEffectOnce(() => {
verify(); verify();
}, []); }, [user?.id]);
return ( return (
<AppShell.Root> <AppShell.Root>

View File

@@ -7,12 +7,11 @@ import { StorageLocalAdapter } from "./src/media/storage/adapters/StorageLocalAd
registries.media.register("local", StorageLocalAdapter); registries.media.register("local", StorageLocalAdapter);
const run_example: string | boolean = false; const example = import.meta.env.VITE_EXAMPLE;
//run_example = "ex-admin-rich";
const credentials = run_example const credentials = example
? { ? {
url: `file:.configs/${run_example}.db` url: `file:.configs/${example}.db`
//url: ":memory:" //url: ":memory:"
} }
: { : {
@@ -26,10 +25,8 @@ if (!credentials.url) {
const connection = new LibsqlConnection(createClient(credentials)); const connection = new LibsqlConnection(createClient(credentials));
let initialConfig: any = undefined; let initialConfig: any = undefined;
if (run_example) { if (example) {
const { version, ...config } = JSON.parse( const { version, ...config } = JSON.parse(await readFile(`.configs/${example}.json`, "utf-8"));
await readFile(`.configs/${run_example}.json`, "utf-8")
);
initialConfig = config; initialConfig = config;
} }