Skip to content

Commit

Permalink
chore(core): handle empty extensions (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
andypf authored Feb 19, 2025
1 parent 348b6b6 commit 48a8e60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
7 changes: 5 additions & 2 deletions apps/aurora-portal/scripts/extensions/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ type Error = {
const generateExtensionsImportFiles = (extensionImports: ExtensionImports[] = []): void => {
const clientImports: string[] = []
const serverImports: string[] = []
const clientExports = [`export const clientExtensions = [`]
const serverExports = [`export const extensionRouters = {`]
const clientExports: string[] = []
const serverExports: string[] = []

clientExports.push(`export const clientExtensions = [`)
serverExports.push(`export const extensionRouters = {`)

for (const imports of extensionImports) {
if (imports?.clientImports?.length) {
Expand Down
27 changes: 18 additions & 9 deletions apps/aurora-portal/src/client/Shell/AppContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Suspense } from "react"
import React, { Suspense } from "react"

import { Breadcrumb } from "./Breadcrumb"
import { Home } from "./Home"
Expand All @@ -11,23 +11,32 @@ import { Route, Switch } from "wouter"
import { MainNavigation } from "./Navigation/MainNavigation"
import { useAuth } from "./AuthProvider"
import { ErrorBoundary } from "react-error-boundary"

type RouterScopes = keyof typeof trpcClient
import { lazy, ReactNode } from "react"
import { lazy } from "react"
import { TrpcClient } from "../trpcClient"
import { clientExtensions } from "../generated/extensions"

type RouterScopes = keyof typeof trpcClient

interface ExtensionProps {
client: TrpcClient
client: TrpcClient[RouterScopes]
getTokenFunc: () => string
}

type Extension = (props: ExtensionProps) => ReactNode
interface Extension {
id: string
name: string
navigation: {
label: string
scope: string[]
}
App: Promise<{ default: React.ComponentType<ExtensionProps> }>
Logo?: Promise<{ default: React.ComponentType }>
}

const extensions = clientExtensions.map((ext) => ({
const extensions = clientExtensions.map((ext: Extension) => ({
...ext,
App: lazy(() => ext.App) as Extension,
Logo: ext.Logo ? lazy(() => ext.Logo) : null,
App: lazy(() => ext.App),
Logo: lazy(() => ext.Logo || Promise.resolve({ default: () => null })),
}))

export function AppContent() {
Expand Down
1 change: 1 addition & 0 deletions apps/aurora-portal/src/server/routers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { identityRouters } from "./Identity/routers"
import { computeRouters } from "./Compute/routers"
import { extensionRouters } from "./generated/extensions"

import { auroraRouter, mergeRouters } from "./trpc"

const coreRouter = mergeRouters(auroraRouter(identityRouters), auroraRouter(computeRouters))
Expand Down

0 comments on commit 48a8e60

Please sign in to comment.