Compare commits

...

3 Commits

Author SHA1 Message Date
b6b2bfbee5 Merge pull request 'Fixed sidebar and did problem' (#72) from Qubasa-main into main
Some checks failed
checks-impure / test (push) Successful in 26s
checks / test (push) Successful in 1m14s
assets1 / test (push) Has been cancelled
Reviewed-on: #72
2024-01-25 15:06:37 +01:00
09f80b1f42 Fixed sidebar and did problem
All checks were successful
checks-impure / test (pull_request) Successful in 26s
checks / test (pull_request) Successful in 1m13s
2024-01-25 14:47:52 +01:00
170ada9382 Fixed sidebar and did problem 2024-01-25 14:47:37 +01:00
6 changed files with 65 additions and 62 deletions

View File

@@ -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)

View File

@@ -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,

View File

@@ -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} />;
}

View File

@@ -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 {

View File

@@ -0,0 +1,5 @@
import Client from "@/app/client/client";
export default function Page() {
return <Client />;
}

View File

@@ -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>