Skip to content

Make initial admin customization easier #2745

@fzaninotto

Description

@fzaninotto

Description

When developers want to customize the admin, it's not super straightforward because the admin is in a dynamic import:

useEffect(() => {
(async () => {
const HydraAdmin = (await import("@api-platform/admin")).HydraAdmin;
setDynamicAdmin(<HydraAdmin entrypoint={window.origin}></HydraAdmin>);
})();
}, []);

In order to customize the admin, the developer has to extract this into another component, then start cusomizing the component.

A better solution would be to extract the admin app by default:

// in pwa/pages/admin/index.tsx
import Head from "next/head";
import { useEffect, useState } from "react";
import styles from "./admin.module.css";

const Admin = () => {
  // Load the admin client-side
  const [DynamicAdmin, setDynamicAdmin] = useState(<p>Loading...</p>);
  useEffect(() => {
    (async () => {
      const App = (await import("../../components/admin/App")).App;
      setDynamicAdmin(<App />);
    })();
  }, []);

  return (
    <div className={styles.admin}>
      <Head>
        <title>API Platform Admin</title>
      </Head>

      {DynamicAdmin}
    </div>
  );
};
export default Admin;

and provide a ready-to-customize App component without lazy loading:

// in pwa/components/admin/App.tsx
import { HydraAdmin } from "@api-platform/admin";

export const App = () => <HydraAdmin entrypoint={window.origin}></HydraAdmin>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions