diff --git a/app/src/ui/Admin.tsx b/app/src/ui/Admin.tsx index 3bb86eb..5ece794 100644 --- a/app/src/ui/Admin.tsx +++ b/app/src/ui/Admin.tsx @@ -45,7 +45,7 @@ function AdminInternal() { return ( - + diff --git a/app/src/ui/client/schema/actions.ts b/app/src/ui/client/schema/actions.ts index a0829ff..aa64003 100644 --- a/app/src/ui/client/schema/actions.ts +++ b/app/src/ui/client/schema/actions.ts @@ -26,7 +26,7 @@ export function getSchemaActions({ api, setSchema, reloadSchema }: SchemaActions autoClose: 3000, }; - if (res.success === true) { + if (res.success) { console.log("update config", action, module, path, res.body); if (res.body.success) { setSchema((prev) => { diff --git a/app/src/ui/components/wouter/Link.tsx b/app/src/ui/components/wouter/Link.tsx index 94e03c3..2d33f36 100644 --- a/app/src/ui/components/wouter/Link.tsx +++ b/app/src/ui/components/wouter/Link.tsx @@ -42,6 +42,11 @@ const useLocationFromRouter = (router) => { ]; }; +export function isLinkActive(href: string, strict?: boolean) { + const path = window.location.pathname; + return strict ? path === href : path.includes(href); +} + export function Link({ className, native, diff --git a/app/src/ui/layouts/AppShell/AppShell.tsx b/app/src/ui/layouts/AppShell/AppShell.tsx index 5281a44..1853180 100644 --- a/app/src/ui/layouts/AppShell/AppShell.tsx +++ b/app/src/ui/layouts/AppShell/AppShell.tsx @@ -202,7 +202,7 @@ export const SidebarLink = ({ { + return { + notification: "-top-4 -right-4", + }; + }, + }), }, primaryColor: "dark", primaryShade: 9, diff --git a/app/src/ui/lib/routes.ts b/app/src/ui/lib/routes.ts index df89d99..5c2a1b3 100644 --- a/app/src/ui/lib/routes.ts +++ b/app/src/ui/lib/routes.ts @@ -53,6 +53,14 @@ export function withAbsolute(url: string) { return `~/${basepath}/${url}`.replace(/\/+/g, "/"); } +export function useRouteNavigate() { + const [navigate] = useNavigate(); + + return (fn: (r: typeof routes) => string, options?: Parameters[1]) => { + navigate(fn(routes), options); + }; +} + export function useNavigate() { const [location, navigate] = useLocation(); const router = useRouter(); diff --git a/app/src/ui/modules/data/components/schema/create-modal/step.entity.fields.tsx b/app/src/ui/modules/data/components/schema/create-modal/step.entity.fields.tsx index 7322ed8..4d5f11b 100644 --- a/app/src/ui/modules/data/components/schema/create-modal/step.entity.fields.tsx +++ b/app/src/ui/modules/data/components/schema/create-modal/step.entity.fields.tsx @@ -63,9 +63,10 @@ export function StepEntityFields() { }; }); + console.log("valid"); nextStep("create")(); } else { - console.warn("not valid"); + console.warn("not valid", ref.current?.getErrors()); } } diff --git a/app/src/ui/routes/data/_data.root.tsx b/app/src/ui/routes/data/_data.root.tsx index 40aeab8..0b7df51 100644 --- a/app/src/ui/routes/data/_data.root.tsx +++ b/app/src/ui/routes/data/_data.root.tsx @@ -7,18 +7,20 @@ import { IconPhoto, IconPlus, IconSettings, + IconSwitchHorizontal, } from "@tabler/icons-react"; import type { Entity, TEntityType } from "data"; import { TbDatabasePlus } from "react-icons/tb"; import { twMerge } from "tailwind-merge"; import { useBkndData } from "ui/client/schema/data/use-bknd-data"; +import { Button } from "ui/components/buttons/Button"; import { IconButton } from "ui/components/buttons/IconButton"; import { Empty } from "ui/components/display/Empty"; import { Dropdown, type DropdownClickableChild } from "ui/components/overlay/Dropdown"; -import { Link } from "ui/components/wouter/Link"; +import { Link, isLinkActive } from "ui/components/wouter/Link"; import { useBrowserTitle } from "ui/hooks/use-browser-title"; import * as AppShell from "ui/layouts/AppShell/AppShell"; -import { routes, useNavigate } from "ui/lib/routes"; +import { routes, useNavigate, useRouteNavigate } from "ui/lib/routes"; export function DataRoot({ children }) { // @todo: settings routes should be centralized @@ -106,6 +108,7 @@ const EntityLinkList = ({ suggestCreate = false, }: { entities: Entity[]; title?: string; context: "data" | "schema"; suggestCreate?: boolean }) => { const { $data } = useBkndData(); + const navigate = useRouteNavigate(); if (entities.length === 0) { return suggestCreate ? ( { + e.stopPropagation(); + e.preventDefault(); + + switch (context) { + case "schema": + navigate((r) => r.data.entity.list(entity.name)); + break; + case "data": + navigate((r) => r.data.schema.entity(entity.name)); + break; + } + }; + } + return (