fix: when auth is disabled, the users entity doesn't exist

This commit is contained in:
dswbx
2024-11-21 08:23:16 +01:00
parent 4e7c1e6e9f
commit 0df5c761ec
14 changed files with 212 additions and 74 deletions

View File

@@ -1,6 +1,9 @@
import { Type } from "core/utils";
import { querySchema } from "data";
import { TbDots } from "react-icons/tb";
import { useBkndData } from "ui/client/schema/data/use-bknd-data";
import { Empty } from "ui/components/display/Empty";
import { Message } from "ui/components/display/Message";
import { EntityTable2 } from "ui/modules/data/components/EntityTable2";
import { useBknd } from "../../client";
import { Button } from "../../components/buttons/Button";
@@ -25,22 +28,21 @@ const searchSchema = Type.Composite(
);
export function DataEntityList({ params }) {
console.log("params", params);
const { app } = useBknd();
const entity = app.entity(params.entity as string)!;
const { $data, relations } = useBkndData();
const entity = $data.entity(params.entity as string);
const [navigate] = useNavigate();
const search = useSearch(searchSchema, {
select: entity.getSelect(undefined, "table"),
sort: entity.getDefaultSort()
select: entity?.getSelect(undefined, "table") ?? [],
sort: entity?.getDefaultSort()
});
console.log("search", search.value);
useBrowserTitle(["Data", entity.label]);
useBrowserTitle(["Data", entity?.label ?? params.entity]);
const PER_PAGE_OPTIONS = [5, 10, 25];
//console.log("search", search.value);
function handleClickRow(row: Record<string, any>) {
navigate(routes.data.entity.edit(entity.name, row.id));
if (entity) navigate(routes.data.entity.edit(entity.name, row.id));
}
function handleClickPage(page: number) {
@@ -61,6 +63,10 @@ export function DataEntityList({ params }) {
search.set("perPage", perPage);
}
if (!entity) {
return <Message.NotFound description={`Entity "${params.entity}" doesn't exist.`} />;
}
return (
<>
<AppShell.SectionHeader