generated from Luis/nextjs-python-web-template
Compare commits
3 Commits
a8b472e84d
...
b6b2bfbee5
| Author | SHA1 | Date | |
|---|---|---|---|
| b6b2bfbee5 | |||
| 09f80b1f42 | |||
| 170ada9382 |
@@ -168,6 +168,14 @@ def get_entity_by_roles(
|
|||||||
return entity
|
return entity
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/api/v1/entity_by_role", response_model=List[Entity], tags=[Tags.entities])
|
||||||
|
def get_entity_by_role(
|
||||||
|
role: Role, db: Session = Depends(sql_db.get_db)
|
||||||
|
) -> List[sql_models.Entity]:
|
||||||
|
entity = sql_crud.get_entity_by_role(db, roles=[role])
|
||||||
|
return entity
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/v1/entities", response_model=List[Entity], tags=[Tags.entities])
|
@router.get("/api/v1/entities", response_model=List[Entity], tags=[Tags.entities])
|
||||||
def get_all_entities(
|
def get_all_entities(
|
||||||
skip: int = 0, limit: int = 100, db: Session = Depends(sql_db.get_db)
|
skip: int = 0, limit: int = 100, db: Session = Depends(sql_db.get_db)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ def test_health(api_client: ApiClient) -> None:
|
|||||||
|
|
||||||
def create_entities(num: int = 5, role: str = "entity") -> list[EntityCreate]:
|
def create_entities(num: int = 5, role: str = "entity") -> list[EntityCreate]:
|
||||||
res = []
|
res = []
|
||||||
for i in range(num):
|
for i in range(1, num + 1):
|
||||||
en = EntityCreate(
|
en = EntityCreate(
|
||||||
did=f"did:sov:test:12{i}",
|
did=f"did:sov:test:12{i}",
|
||||||
name=f"C{i}",
|
name=f"C{i}",
|
||||||
@@ -125,8 +125,7 @@ random.seed(77)
|
|||||||
def create_eventmessages(num: int = 4) -> list[EventmessageCreate]:
|
def create_eventmessages(num: int = 4) -> list[EventmessageCreate]:
|
||||||
res = []
|
res = []
|
||||||
starttime = int(time.time())
|
starttime = int(time.time())
|
||||||
for idx in range(num):
|
for i2 in range(1, num + 1):
|
||||||
i2 = idx + 1
|
|
||||||
group_id = i2 % 5 + random.getrandbits(6) + 1
|
group_id = i2 % 5 + random.getrandbits(6) + 1
|
||||||
em_req_send = EventmessageCreate(
|
em_req_send = EventmessageCreate(
|
||||||
timestamp=starttime + i2 * 10,
|
timestamp=starttime + i2 * 10,
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
import Client from "@/app/client/client";
|
|
||||||
import { menuEntityEntries } from "@/components/sidebar";
|
|
||||||
|
|
||||||
export const dynamic = "error";
|
|
||||||
export const dynamicParams = false;
|
|
||||||
/*
|
|
||||||
The generateStaticParams function can be used in combination with dynamic route segments
|
|
||||||
to statically generate routes at build time instead of on-demand at request time.
|
|
||||||
During next dev, generateStaticParams will be called when you navigate to a route.
|
|
||||||
During next build, generateStaticParams runs before the corresponding Layouts or Pages are generated.
|
|
||||||
https://nextjs.org/docs/app/api-reference/functions/generate-static-params
|
|
||||||
*/
|
|
||||||
export function generateStaticParams() {
|
|
||||||
return menuEntityEntries.map((entry) => ({
|
|
||||||
name: entry.label,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Page({ params }: { params: { name: string } }) {
|
|
||||||
return <Client params={params} />;
|
|
||||||
}
|
|
||||||
@@ -26,6 +26,7 @@ import useGetEntityByNameOrDid from "@/components/hooks/useGetEntityByNameOrDid"
|
|||||||
import { useGetAllServices } from "@/api/services/services";
|
import { useGetAllServices } from "@/api/services/services";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
import CloseIcon from "@mui/icons-material/Close";
|
||||||
|
import { useSearchParams } from "next/navigation";
|
||||||
|
|
||||||
interface SnackMessage {
|
interface SnackMessage {
|
||||||
message: string;
|
message: string;
|
||||||
@@ -105,8 +106,10 @@ const AttachButton = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Client({ params }: { params: { name: string } }) {
|
export default function Client() {
|
||||||
const { name } = params;
|
const searchParams = useSearchParams();
|
||||||
|
console.log("params: ", searchParams);
|
||||||
|
const name = searchParams.get("name") ?? "";
|
||||||
|
|
||||||
const { entity: entity } = useGetEntityByNameOrDid(name);
|
const { entity: entity } = useGetEntityByNameOrDid(name);
|
||||||
const {
|
const {
|
||||||
|
|||||||
5
pkgs/ui/src/app/client/page.tsx
Normal file
5
pkgs/ui/src/app/client/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import Client from "@/app/client/client";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
return <Client />;
|
||||||
|
}
|
||||||
@@ -9,7 +9,8 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { useGetAllEntities } from "@/api/entities/entities";
|
import { useGetEntityByRole } from "@/api/entities/entities";
|
||||||
|
import { Role } from "@/api/model/role";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import React, { ReactNode } from "react";
|
import React, { ReactNode } from "react";
|
||||||
|
|
||||||
@@ -34,8 +35,6 @@ type MenuEntry = {
|
|||||||
subMenuEntries?: MenuEntry[];
|
subMenuEntries?: MenuEntry[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export let menuEntityEntries: MenuEntry[] = [];
|
|
||||||
|
|
||||||
export const menuEntries: MenuEntry[] = [
|
export const menuEntries: MenuEntry[] = [
|
||||||
{
|
{
|
||||||
icon: <HomeIcon />,
|
icon: <HomeIcon />,
|
||||||
@@ -72,7 +71,9 @@ interface SidebarProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Sidebar(props: SidebarProps) {
|
export function Sidebar(props: SidebarProps) {
|
||||||
const { data: entityData } = useGetAllEntities();
|
const { data: entityData } = useGetEntityByRole({
|
||||||
|
role: Role.service_prosumer,
|
||||||
|
});
|
||||||
const { show, onClose } = props;
|
const { show, onClose } = props;
|
||||||
const [activeMenuItem, setActiveMenuItem] = React.useState(
|
const [activeMenuItem, setActiveMenuItem] = React.useState(
|
||||||
typeof window !== "undefined" ? window.location.pathname : "",
|
typeof window !== "undefined" ? window.location.pathname : "",
|
||||||
@@ -89,19 +90,22 @@ export function Sidebar(props: SidebarProps) {
|
|||||||
setCollapseMenuOpen(!collapseMenuOpen);
|
setCollapseMenuOpen(!collapseMenuOpen);
|
||||||
};
|
};
|
||||||
|
|
||||||
React.useEffect(() => {
|
const menuEntityEntries: MenuEntry[] = React.useMemo(() => {
|
||||||
if (entityData) {
|
if (entityData) {
|
||||||
menuEntityEntries = Array.isArray(entityData.data)
|
return Array.isArray(entityData.data)
|
||||||
? entityData.data
|
? entityData.data.map((entity) => ({
|
||||||
.filter((entity) => entity.name !== "AP" && entity.name !== "DLG")
|
|
||||||
.map((entity) => ({
|
|
||||||
icon: <PersonIcon />,
|
icon: <PersonIcon />,
|
||||||
label: entity.name,
|
label: entity.name,
|
||||||
to: `/client/${entity.name}`,
|
to: entity.name,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
}, [entityData]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
if (isSmallerScreen) {
|
if (isSmallerScreen) {
|
||||||
setCollapseMenuOpen(false);
|
setCollapseMenuOpen(false);
|
||||||
} else {
|
} else {
|
||||||
@@ -203,12 +207,16 @@ export function Sidebar(props: SidebarProps) {
|
|||||||
>
|
>
|
||||||
<List component="div" disablePadding>
|
<List component="div" disablePadding>
|
||||||
{menuEntityEntries?.map((menuEntry, idx) => (
|
{menuEntityEntries?.map((menuEntry, idx) => (
|
||||||
|
<Link
|
||||||
|
key={"entity-link-" + idx}
|
||||||
|
href={`/client?name=${menuEntry.to}`}
|
||||||
|
style={{ textDecoration: "none", color: "white" }}
|
||||||
|
>
|
||||||
<ListItemButton
|
<ListItemButton
|
||||||
key={idx}
|
key={idx}
|
||||||
sx={{ pl: 4 }}
|
sx={{ pl: 4 }}
|
||||||
className="lg:justify-normal"
|
className="lg:justify-normal"
|
||||||
LinkComponent={Link}
|
LinkComponent={Link}
|
||||||
href={menuEntry.to}
|
|
||||||
disabled={menuEntry.disabled}
|
disabled={menuEntry.disabled}
|
||||||
selected={activeMenuItem === menuEntry.to}
|
selected={activeMenuItem === menuEntry.to}
|
||||||
onClick={() => handleMenuItemClick(menuEntry.to)}
|
onClick={() => handleMenuItemClick(menuEntry.to)}
|
||||||
@@ -227,6 +235,7 @@ export function Sidebar(props: SidebarProps) {
|
|||||||
className="hidden lg:block"
|
className="hidden lg:block"
|
||||||
/>
|
/>
|
||||||
</ListItemButton>
|
</ListItemButton>
|
||||||
|
</Link>
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
</Collapse>
|
</Collapse>
|
||||||
|
|||||||
Reference in New Issue
Block a user