Skip to content

Commit

Permalink
Many things! (#8)
Browse files Browse the repository at this point in the history
* some fixes and also breadcrumbs

* need to wire up the headers, but it should all work

* better sidebar + headers

* README
  • Loading branch information
rambleraptor authored Dec 15, 2024
1 parent 5259dda commit be588ce
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 384 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# aep-explorer

AEP Explorer is a tool designed to create a resource-oriented UI based off an OpenAPI schema.

The tool can be run online or deployed locally depending on CORS settings.

# Running
```
npm install
Expand Down
17 changes: 9 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "./App.css";
import { useState } from "react";
import { StateContext } from "./state/StateContext";
import { HeadersContext, StateContext } from "./state/StateContext";
import { OpenAPI, ResourceSchema } from "./state/openapi";
import SpecSpecifierPage from "./app/spec_specifier/page";
import { createBrowserRouter, RouteObject, RouterProvider } from "react-router-dom";
import Page from "./app/explorer/page";
import Layout from "./app/explorer/page";
import ResourceList from "./app/explorer/resource_list";
import CreateForm from "./app/explorer/form";
import InfoPage from "./app/explorer/info";
Expand All @@ -13,15 +13,15 @@ import UpdateForm from "./app/explorer/update_form";
function createRoutes(resources: ResourceSchema[]): RouteObject[] {
let routes = [{
path: "/",
element: <Page />,
element: <Layout />,
children: [
{
path: "/",
element: <SpecSpecifierPage />,
},
{
path: "/_explorer",
element: <Page />,
element: <div />,
},
].concat(resources.map((resource) => {
return [
Expand All @@ -44,16 +44,17 @@ function createRoutes(resources: ResourceSchema[]): RouteObject[] {
]
}).flat(1))
}];
console.log("my routes");
console.log(routes);
return routes;
}

function App() {
const [state, setState] = useState(new OpenAPI({}));
const [headers, setHeaders] = useState("");
return (
<StateContext.Provider value={{ spec: state, setSpec: setState }}>
<RouterProvider router={createBrowserRouter(createRoutes(state.resources()))} />
<StateContext.Provider value={{ spec: state, setSpec: setState}}>
<HeadersContext.Provider value={{ headers: headers, setHeaders: setHeaders}}>
<RouterProvider router={createBrowserRouter(createRoutes(state.resources()))} />
</HeadersContext.Provider>
</StateContext.Provider>
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/app/explorer/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMemo, } from "react";
import { useForm } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import { toast } from "@/hooks/use-toast";
import { useHeaders } from "@/state/StateContext";

type CreateFormProps = {
resource: ResourceSchema
Expand All @@ -14,10 +15,12 @@ export default function CreateForm(props: CreateFormProps) {
const form = useForm();
const navigate = useNavigate();

const {headers, setHeaders} = useHeaders();

const onSubmit = ((value) => {
// Value is the properly formed JSON body.
// Just need to submit it and navigate back to the list page.
props.resource.create(value).then(() => {
props.resource.create(value, headers).then(() => {
toast({description: `Created ${value.id}`});
navigate(-1);
})
Expand Down
11 changes: 9 additions & 2 deletions src/app/explorer/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { AppSidebar } from "@/components/app-sidebar";
import AppBreadcrumb from "@/components/breadcrumb";
import {} from "@/components/ui/breadcrumb";
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
import { SidebarInset, SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
import { Toaster } from "@/components/ui/toaster";
import { useSpec } from "@/state/StateContext";
import { Separator } from "@radix-ui/react-separator";
import { Outlet } from "react-router-dom";

export default function Page() {
export default function Layout() {
const { spec, setSpec } = useSpec();
return (
<SidebarProvider>
<AppSidebar />
<SidebarInset>
<header className="flex h-16 shrink-0 items-center gap-2 border-b px-4">
<SidebarTrigger className="-ml-1" />
<Separator orientation="vertical" className="mr-2 h-4" />
<AppBreadcrumb />
</header>
<Outlet />
<div className="flex flex-1 flex-col gap-4 p-4 pt-0">
<div className="grid auto-rows-min gap-4 md:grid-cols-3">
Expand Down
6 changes: 4 additions & 2 deletions src/app/explorer/resource_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TableRow,
} from "@/components/ui/table";
import { ColumnDef } from "@tanstack/react-table"
import { useSpec } from "@/state/StateContext";
import { useHeaders, useSpec } from "@/state/StateContext";
import { useCallback, useEffect, useState } from "react";
import { Link, useNavigate, useParams } from "react-router-dom";
import { DataTable } from "@/components/ui/data-table";
Expand Down Expand Up @@ -83,6 +83,8 @@ export default function ResourceList(props: ResourceListProps) {
resources: [],
});

const {headers, setHeaders} = useHeaders();

function deleteResource(r: object) {
const result = state?.resources.find((result: ResourceInstance) => result.id === r.id);
if(result) {
Expand All @@ -94,7 +96,7 @@ export default function ResourceList(props: ResourceListProps) {
}
const refreshList = useCallback(() => {
props.resource
.list()
.list(headers)
.then((resources) => {
if (resources) {
setState({
Expand Down
18 changes: 17 additions & 1 deletion src/components/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
SidebarGroup,
SidebarGroupLabel,
SidebarHeader,
SidebarInput,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarRail,
} from "@/components/ui/sidebar";
import { useSpec } from "@/state/StateContext";
import { useHeaders, useSpec } from "@/state/StateContext";
import { Link } from "react-router-dom";

export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
Expand All @@ -34,8 +35,23 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
))}
</SidebarMenu>
</SidebarGroup>
<p>Headers</p>
<p>key:value, comma-deliniated</p>
<TextBoxComponent />
</SidebarContent>
<SidebarRail />
</Sidebar>
);
}

export function TextBoxComponent() {
const {headers, setHeaders} = useHeaders();

const handleTextChange = (event) => {
setHeaders(event.target.value);
};

return (
<SidebarInput type="text" value={headers!} onChange={handleTextChange} />
);
}
27 changes: 27 additions & 0 deletions src/components/breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useMatches } from "react-router-dom";
import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "./ui/breadcrumb"
import { createRouteObjects } from "@/lib/utils";
import { useSpec } from "@/state/StateContext";

export default function AppBreadcrumb() {
const breadcrumbs = useMatches();
const {spec, setSpec} = useSpec();
console.log(breadcrumbs);
console.log(createRouteObjects(spec?.resources()));

let breadcrumb_elements = [];
for(const i of breadcrumbs) {
breadcrumb_elements.push(<BreadcrumbItem className="hidden md:block">
<BreadcrumbPage>{i.pathname}</BreadcrumbPage>
</BreadcrumbItem>);
breadcrumb_elements.push(<BreadcrumbSeparator className="hidden md:block" />);
}

return (
<Breadcrumb>
<BreadcrumbList>
{breadcrumb_elements}
</BreadcrumbList>
</Breadcrumb>
);
}
74 changes: 0 additions & 74 deletions src/components/nav-main.tsx

This file was deleted.

82 changes: 0 additions & 82 deletions src/components/nav-projects.tsx

This file was deleted.

Loading

0 comments on commit be588ce

Please sign in to comment.