feat(dashboard,admin-sdk,admin-shared,admin-vite-plugin): Add support for UI extensions (#7383)

* intial work

* update lock

* add routes and fix HMR of configs

* cleanup

* rm imports

* rm debug from plugin

* address feedback

* address feedback
This commit is contained in:
Kasper Fabricius Kristensen
2024-05-23 14:02:19 +02:00
committed by GitHub
parent 521c252dee
commit f1176a0673
50 changed files with 1366 additions and 1098 deletions
@@ -0,0 +1,56 @@
import { RouteObject } from "react-router-dom"
/**
* Used to test if a route is a settings route.
*/
export const settingsRouteRegex = /^\/settings\//
export const createRouteMap = (
routes: { path: string; file: string }[],
ignore?: string
): RouteObject[] => {
const root: RouteObject[] = []
const addRoute = (
pathSegments: string[],
file: string,
currentLevel: RouteObject[]
) => {
if (!pathSegments.length) {
return
}
const [currentSegment, ...remainingSegments] = pathSegments
let route = currentLevel.find((r) => r.path === currentSegment)
if (!route) {
route = { path: currentSegment, children: [] }
currentLevel.push(route)
}
if (remainingSegments.length === 0) {
route.children ||= []
route.children.push({
path: "",
async lazy() {
const { default: Component } = await import(/* @vite-ignore */ file)
return { Component }
},
})
} else {
route.children ||= []
addRoute(remainingSegments, file, route.children)
}
}
routes.forEach(({ path, file }) => {
// Remove the ignore segment from the path if it is provided
const cleanedPath = ignore
? path.replace(ignore, "").replace(/^\/+/, "")
: path.replace(/^\/+/, "")
const pathSegments = cleanedPath.split("/").filter(Boolean)
addRoute(pathSegments, file, root)
})
return root
}