major refactor of the dashboard and react-openapi integration #1
@@ -24,6 +24,10 @@ export const ConfigContext = React.createContext<AppConfig | null>(null);
|
|||||||
function Dashboard({ basePath }: { basePath: string }) {
|
function Dashboard({ basePath }: { basePath: string }) {
|
||||||
const config = React.useContext(ConfigContext);
|
const config = React.useContext(ConfigContext);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const resources = config?.resources || [];
|
||||||
|
const visibleResources = resources.filter((res) => !res.hidden);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Typography variant="h4" gutterBottom>
|
<Typography variant="h4" gutterBottom>
|
||||||
@@ -41,7 +45,7 @@ function Dashboard({ basePath }: { basePath: string }) {
|
|||||||
mt: 4,
|
mt: 4,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{config?.resources.map((res) => (
|
{visibleResources.map((res) => (
|
||||||
<Paper
|
<Paper
|
||||||
key={res.name}
|
key={res.name}
|
||||||
sx={{
|
sx={{
|
||||||
@@ -69,6 +73,9 @@ function AdminApp({ basePath }: { basePath: string }) {
|
|||||||
const config = React.useContext(ConfigContext);
|
const config = React.useContext(ConfigContext);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const resources = config?.resources || [];
|
||||||
|
const visibleResources = resources.filter((res) => !res.hidden);
|
||||||
|
|
||||||
if (!currentUser) {
|
if (!currentUser) {
|
||||||
return (
|
return (
|
||||||
<AuthPage
|
<AuthPage
|
||||||
@@ -89,7 +96,7 @@ function AdminApp({ basePath }: { basePath: string }) {
|
|||||||
username={currentUser.username}
|
username={currentUser.username}
|
||||||
onLogout={logout}
|
onLogout={logout}
|
||||||
onSelectResource={(name) => navigate(`/admin/${name}`)}
|
onSelectResource={(name) => navigate(`/admin/${name}`)}
|
||||||
resources={config?.resources || []}
|
resources={visibleResources}
|
||||||
>
|
>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<Dashboard basePath={basePath} />} />
|
<Route path="/" element={<Dashboard basePath={basePath} />} />
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export interface ResourceConfig {
|
|||||||
primaryKey: string;
|
primaryKey: string;
|
||||||
fields: Record<string, ResourceField>;
|
fields: Record<string, ResourceField>;
|
||||||
pagination?: boolean;
|
pagination?: boolean;
|
||||||
|
hidden?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppConfig {
|
export interface AppConfig {
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ export interface FieldOverride {
|
|||||||
export interface ResourceOverride {
|
export interface ResourceOverride {
|
||||||
fields?: Record<string, FieldOverride>;
|
fields?: Record<string, FieldOverride>;
|
||||||
pagination?: boolean;
|
pagination?: boolean;
|
||||||
|
hidden?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ export async function loadConfigFromOpenApi(baseUrl: string, configuration: Reco
|
|||||||
primaryKey: "id", // Strict default, no heuristics
|
primaryKey: "id", // Strict default, no heuristics
|
||||||
fields,
|
fields,
|
||||||
pagination: resourceOverride.pagination,
|
pagination: resourceOverride.pagination,
|
||||||
|
hidden: resourceOverride.hidden,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user