generated from Luis/nextjs-python-web-template
Merge pull request 'Fixed sidebar and did problem' (#72) from Qubasa-main into main
Reviewed-on: #72
This commit was merged in pull request #72.
This commit is contained in:
@@ -168,6 +168,14 @@ def get_entity_by_roles(
|
||||
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])
|
||||
def get_all_entities(
|
||||
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]:
|
||||
res = []
|
||||
for i in range(num):
|
||||
for i in range(1, num + 1):
|
||||
en = EntityCreate(
|
||||
did=f"did:sov:test:12{i}",
|
||||
name=f"C{i}",
|
||||
@@ -125,8 +125,7 @@ random.seed(77)
|
||||
def create_eventmessages(num: int = 4) -> list[EventmessageCreate]:
|
||||
res = []
|
||||
starttime = int(time.time())
|
||||
for idx in range(num):
|
||||
i2 = idx + 1
|
||||
for i2 in range(1, num + 1):
|
||||
group_id = i2 % 5 + random.getrandbits(6) + 1
|
||||
em_req_send = EventmessageCreate(
|
||||
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 axios from "axios";
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
interface SnackMessage {
|
||||
message: string;
|
||||
@@ -105,8 +106,10 @@ const AttachButton = ({
|
||||
);
|
||||
};
|
||||
|
||||
export default function Client({ params }: { params: { name: string } }) {
|
||||
const { name } = params;
|
||||
export default function Client() {
|
||||
const searchParams = useSearchParams();
|
||||
console.log("params: ", searchParams);
|
||||
const name = searchParams.get("name") ?? "";
|
||||
|
||||
const { entity: entity } = useGetEntityByNameOrDid(name);
|
||||
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,
|
||||
useMediaQuery,
|
||||
} 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 React, { ReactNode } from "react";
|
||||
|
||||
@@ -34,8 +35,6 @@ type MenuEntry = {
|
||||
subMenuEntries?: MenuEntry[];
|
||||
};
|
||||
|
||||
export let menuEntityEntries: MenuEntry[] = [];
|
||||
|
||||
export const menuEntries: MenuEntry[] = [
|
||||
{
|
||||
icon: <HomeIcon />,
|
||||
@@ -72,7 +71,9 @@ interface SidebarProps {
|
||||
}
|
||||
|
||||
export function Sidebar(props: SidebarProps) {
|
||||
const { data: entityData } = useGetAllEntities();
|
||||
const { data: entityData } = useGetEntityByRole({
|
||||
role: Role.service_prosumer,
|
||||
});
|
||||
const { show, onClose } = props;
|
||||
const [activeMenuItem, setActiveMenuItem] = React.useState(
|
||||
typeof window !== "undefined" ? window.location.pathname : "",
|
||||
@@ -89,19 +90,22 @@ export function Sidebar(props: SidebarProps) {
|
||||
setCollapseMenuOpen(!collapseMenuOpen);
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
const menuEntityEntries: MenuEntry[] = React.useMemo(() => {
|
||||
if (entityData) {
|
||||
menuEntityEntries = Array.isArray(entityData.data)
|
||||
? entityData.data
|
||||
.filter((entity) => entity.name !== "AP" && entity.name !== "DLG")
|
||||
.map((entity) => ({
|
||||
icon: <PersonIcon />,
|
||||
label: entity.name,
|
||||
to: `/client/${entity.name}`,
|
||||
disabled: false,
|
||||
}))
|
||||
return Array.isArray(entityData.data)
|
||||
? entityData.data.map((entity) => ({
|
||||
icon: <PersonIcon />,
|
||||
label: entity.name,
|
||||
to: entity.name,
|
||||
disabled: false,
|
||||
}))
|
||||
: [];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}, [entityData]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (isSmallerScreen) {
|
||||
setCollapseMenuOpen(false);
|
||||
} else {
|
||||
@@ -203,30 +207,35 @@ export function Sidebar(props: SidebarProps) {
|
||||
>
|
||||
<List component="div" disablePadding>
|
||||
{menuEntityEntries?.map((menuEntry, idx) => (
|
||||
<ListItemButton
|
||||
key={idx}
|
||||
sx={{ pl: 4 }}
|
||||
className="lg:justify-normal"
|
||||
LinkComponent={Link}
|
||||
href={menuEntry.to}
|
||||
disabled={menuEntry.disabled}
|
||||
selected={activeMenuItem === menuEntry.to}
|
||||
onClick={() => handleMenuItemClick(menuEntry.to)}
|
||||
<Link
|
||||
key={"entity-link-" + idx}
|
||||
href={`/client?name=${menuEntry.to}`}
|
||||
style={{ textDecoration: "none", color: "white" }}
|
||||
>
|
||||
<ListItemIcon
|
||||
color="inherit"
|
||||
className="overflow-hidden text-white lg:justify-normal"
|
||||
<ListItemButton
|
||||
key={idx}
|
||||
sx={{ pl: 4 }}
|
||||
className="lg:justify-normal"
|
||||
LinkComponent={Link}
|
||||
disabled={menuEntry.disabled}
|
||||
selected={activeMenuItem === menuEntry.to}
|
||||
onClick={() => handleMenuItemClick(menuEntry.to)}
|
||||
>
|
||||
{menuEntry.icon}
|
||||
</ListItemIcon>
|
||||
<ListItemText
|
||||
primary={menuEntry.label}
|
||||
primaryTypographyProps={{
|
||||
color: "inherit",
|
||||
}}
|
||||
className="hidden lg:block"
|
||||
/>
|
||||
</ListItemButton>
|
||||
<ListItemIcon
|
||||
color="inherit"
|
||||
className="overflow-hidden text-white lg:justify-normal"
|
||||
>
|
||||
{menuEntry.icon}
|
||||
</ListItemIcon>
|
||||
<ListItemText
|
||||
primary={menuEntry.label}
|
||||
primaryTypographyProps={{
|
||||
color: "inherit",
|
||||
}}
|
||||
className="hidden lg:block"
|
||||
/>
|
||||
</ListItemButton>
|
||||
</Link>
|
||||
))}
|
||||
</List>
|
||||
</Collapse>
|
||||
|
||||
Reference in New Issue
Block a user