Skip to content

Commit 5fc6dd1

Browse files
committed
menu short cuts for each system dynamic entity that exists
1 parent d13b4cf commit 5fc6dd1

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

src/routes/+layout.svelte

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
let isAccountAccessExpanded = $state(false);
7171
let isDynamicEntitiesExpanded = $state(false);
7272
let displayMode: "dark" | "light" = $state("dark");
73+
let systemDynamicEntities = $state<any[]>([]);
7374
7475
async function clearCache() {
7576
try {
@@ -111,6 +112,26 @@
111112
}
112113
});
113114
115+
// Fetch system dynamic entities for shortcuts
116+
onMount(async () => {
117+
if (isAuthenticated) {
118+
try {
119+
const response = await fetch("/api/dynamic-entities/system/list", {
120+
credentials: "include",
121+
});
122+
if (response.ok) {
123+
const data = await response.json();
124+
systemDynamicEntities = data.entities || [];
125+
logger.info(
126+
`✅ Loaded ${systemDynamicEntities.length} system dynamic entities`,
127+
);
128+
}
129+
} catch (error) {
130+
logger.error("Failed to fetch system dynamic entities:", error);
131+
}
132+
}
133+
});
134+
114135
let isMyAccountActive = $derived(
115136
page.url.pathname === "/user" || page.url.pathname.startsWith("/user/"),
116137
);
@@ -639,6 +660,39 @@
639660
<span>{subItem.label}</span>
640661
</a>
641662
{/each}
663+
664+
{#if systemDynamicEntities.length > 0}
665+
<div
666+
class="my-2 border-t border-gray-300 dark:border-gray-600"
667+
></div>
668+
{#each systemDynamicEntities as entity}
669+
{@const entityName =
670+
Object.keys(entity).find(
671+
(key) =>
672+
![
673+
"userId",
674+
"dynamicEntityId",
675+
"hasPersonalEntity",
676+
].includes(key),
677+
) || "Unknown"}
678+
<a
679+
href="/dynamic-entities/system/{entity.dynamicEntityId}/crud"
680+
class="btn w-full justify-start gap-3 px-2 pl-6 text-sm hover:preset-tonal"
681+
class:preset-filled-secondary-50-950={page.url
682+
.pathname ===
683+
`/dynamic-entities/system/${entity.dynamicEntityId}/crud`}
684+
class:border-l-2={page.url.pathname ===
685+
`/dynamic-entities/system/${entity.dynamicEntityId}/crud`}
686+
class:border-primary-500={page.url.pathname ===
687+
`/dynamic-entities/system/${entity.dynamicEntityId}/crud`}
688+
title={entityName}
689+
aria-label={entityName}
690+
>
691+
<Database class="size-4" />
692+
<span>{entityName}</span>
693+
</a>
694+
{/each}
695+
{/if}
642696
</Navigation.Menu>
643697
{/if}
644698
</Navigation.Group>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { json } from "@sveltejs/kit";
2+
import type { RequestHandler } from "./$types";
3+
import { obp_requests } from "$lib/obp/requests";
4+
import { SessionOAuthHelper } from "$lib/oauth/sessionHelper";
5+
import { createLogger } from "$lib/utils/logger";
6+
7+
const logger = createLogger("SystemDynamicEntitiesListAPI");
8+
9+
export const GET: RequestHandler = async ({ locals }) => {
10+
const session = locals.session;
11+
12+
if (!session?.data?.user) {
13+
return json({ error: "Unauthorized" }, { status: 401 });
14+
}
15+
16+
const sessionOAuth = SessionOAuthHelper.getSessionOAuth(session);
17+
const accessToken = sessionOAuth?.accessToken;
18+
19+
if (!accessToken) {
20+
logger.warn("No access token available");
21+
return json({ error: "No API access token available" }, { status: 401 });
22+
}
23+
24+
try {
25+
logger.info("Fetching system dynamic entities list");
26+
27+
const endpoint = `/obp/v4.0.0/management/system-dynamic-entities`;
28+
const response = await obp_requests.get(endpoint, accessToken);
29+
30+
const entities = response.dynamic_entities || [];
31+
32+
logger.info(`Retrieved ${entities.length} system dynamic entities`);
33+
return json({ entities });
34+
} catch (err) {
35+
logger.error("Error fetching system dynamic entities:", err);
36+
37+
let errorMessage = "Failed to fetch system dynamic entities";
38+
let obpErrorCode = undefined;
39+
40+
if (err instanceof Error) {
41+
errorMessage = err.message;
42+
if ("obpErrorCode" in err) {
43+
obpErrorCode = (err as any).obpErrorCode;
44+
}
45+
}
46+
47+
const errorResponse: any = { error: errorMessage };
48+
if (obpErrorCode) {
49+
errorResponse.obpErrorCode = obpErrorCode;
50+
}
51+
52+
return json(errorResponse, { status: 500 });
53+
}
54+
};

0 commit comments

Comments
 (0)