From 3d49023252b6a16adaae28257ba7832786c6edc1 Mon Sep 17 00:00:00 2001 From: prplwtf Date: Sat, 9 Mar 2024 18:36:16 +0100 Subject: [PATCH] feat `core` `routes`: start work on nestids --- blueprint.sh | 13 ++++++++----- .../blueprint/extends/routers/ServerRouter.tsx | 3 +++ .../scripts/blueprint/extends/routers/routes.ts | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/blueprint.sh b/blueprint.sh index d51c7ce..6096f7e 100644 --- a/blueprint.sh +++ b/blueprint.sh @@ -876,6 +876,8 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD=" if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Component" ]]; then COMPONENTS_ROUTE_COMP="${!child}"; fi # Route admin if [[ $child == "Components_Navigation_Routes_"+([0-9])"_AdminOnly" ]]; then COMPONENTS_ROUTE_ADMI="${!child}"; fi + # Route nests + if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Nests" ]]; then COMPONENTS_ROUTE_NEST="${!child}"; fi done # Route identifier @@ -943,10 +945,9 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD=" exit 1 fi - # Assign value to ROUTE_ADMI if empty - if [[ $COMPONENTS_ROUTE_ADMI != "true" ]]; then - COMPONENTS_ROUTE_ADMI="false" - fi + # Assign value to ROUTE_ADMI and ROUTE_NEST if empty + if [[ $COMPONENTS_ROUTE_ADMI != "true" ]]; then COMPONENTS_ROUTE_ADMI="false"; fi + if [[ $COMPONENTS_ROUTE_NEST != "" ]]; then COMPONENTS_ROUTE_NEST="nests: [$COMPONENTS_ROUTE_NEST]"; fi # Apply routes. @@ -960,7 +961,7 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD=" elif [[ $COMPONENTS_ROUTE_TYPE == "server" ]]; then # Server routes COMPONENTS_IMPORT="import $COMPONENTS_ROUTE_IDEN from '@/blueprint/extensions/$identifier/$COMPONENTS_ROUTE_COMP';" - COMPONENTS_ROUTE="{ path: '$COMPONENTS_ROUTE_PATH', permission: null, name: '$COMPONENTS_ROUTE_NAME', component: $COMPONENTS_ROUTE_IDEN, adminOnly: $COMPONENTS_ROUTE_ADMI }," + COMPONENTS_ROUTE="{ path: '$COMPONENTS_ROUTE_PATH', permission: null, name: '$COMPONENTS_ROUTE_NAME', component: $COMPONENTS_ROUTE_IDEN, adminOnly: $COMPONENTS_ROUTE_ADMI, $COMPONENTS_ROUTE_NEST }," sed -i "s~/\* \[import] \*/~/* [import] */""$COMPONENTS_IMPORT""~g" $ImportConstructor sed -i "s~/\* \[routes] \*/~/* [routes] */""$COMPONENTS_ROUTE""~g" $ServerRouteConstructor @@ -975,6 +976,8 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD=" COMPONENTS_ROUTE_TYPE="" COMPONENTS_ROUTE_COMP="" COMPONENTS_ROUTE_IDEN="" + COMPONENTS_ROUTE_ADMI="" + COMPONENTS_ROUTE_NEST="" done sed -i "s~/\* \[import] \*/~~g" $ImportConstructor diff --git a/resources/scripts/blueprint/extends/routers/ServerRouter.tsx b/resources/scripts/blueprint/extends/routers/ServerRouter.tsx index 6c1f1b5..80ea52a 100644 --- a/resources/scripts/blueprint/extends/routers/ServerRouter.tsx +++ b/resources/scripts/blueprint/extends/routers/ServerRouter.tsx @@ -7,12 +7,14 @@ import Spinner from '@/components/elements/Spinner'; import { NotFound } from '@/components/elements/ScreenBlock'; import { useLocation } from 'react-router'; import { useStoreState } from 'easy-peasy'; +import { ServerContext } from '@/state/server'; import routes from '@/routers/routes'; import blueprintRoutes from './routes'; export const NavigationLinks = () => { const rootAdmin = useStoreState((state) => state.user.data!.rootAdmin); + const serverNest = ServerContext.useStoreState((state) => state.server.data?.nestId); const match = useRouteMatch<{ id: string }>(); const to = (value: string, url = false) => { if (value === '/') { @@ -46,6 +48,7 @@ export const NavigationLinks = () => { {blueprintRoutes.server.length > 0 && blueprintRoutes.server .filter((route) => !!route.name) .filter((route) => route.adminOnly ? rootAdmin : true) + .filter((route) => route.nests && serverNest ? route.nests.includes(serverNest) : true ) .map((route) => route.permission ? ( diff --git a/resources/scripts/blueprint/extends/routers/routes.ts b/resources/scripts/blueprint/extends/routers/routes.ts index 4a8127d..2e73542 100644 --- a/resources/scripts/blueprint/extends/routers/routes.ts +++ b/resources/scripts/blueprint/extends/routers/routes.ts @@ -11,6 +11,7 @@ interface RouteDefinition { } interface ServerRouteDefinition extends RouteDefinition { permission: string | string[] | null; + nests?: number[]; } interface Routes { account: RouteDefinition[];