index

Admin Contraption Thing

A tool that allows one to create django admin / active admin like interfaces in react.

https://github.com/1egoman/react-admin-contraption/assets/1704236/d127b193-5c19-44ab-803b-68a5e71afb9f

Docs site: https://bread-1.gitbook.io/react-admin-contraption/

Getting started

There is a next.js app in example. Run npm install && npm run dev, then go to the root web page it serves for some example admin implementations.

Note that you may need to also start a fake backend server locally - cd jsonserver && npx json-server -p 3003 db.json should do that.

Example

The core code currently lives in admin/ (a symlink to example/src/admin). Right now, copy this code into a project's src directory (TBD process for now, some sort of package distribution mechanism needs to be thought through here) to add this to a project.

Data Models

The most important concept in this project is a "data model" - this is how you tell the tool how data should be represented.

Code example

fetchPageOfData / fetchItem / etc

These functions must be implemented for each data model and tell it how it can get data from a server somewhere. Each is a very generic interface that can be implemented no matter the underlying technology the project uses - as of april 2023, I've experimented with REST and TRPC, but any data async source should work fine.

I wouldn't be surprised if a set of standardized, bread specific components that use trpc/react server actions/etc were developed that would be largely drop in to standardize the api interface. But, that is for the future!

Including data models in other pages

Data models must be placed in a <DataModels>...</DataModels> component. Here's what I've done to date:

Then, wrap all subsequent pages in this component.

In a next.js app, there's probably a more elegant way to do this. If so, do that instead.

Remote Data Models

It's likely you won't want to write out custom <DataModel /> definitions for all data models in the app. Instead, you can let the server drive data models by taking advantage of "remote data models". Here is an example:

List Page

The list page shows a read only list of all datamodels that are fetched from a server and allows a user to filter, sort, and perform actions on them.

Code example

If in a next.js app, create a src/pages/admin/vehicles/index.tsx file, and return something like the below from a component defined as that file's default export:

Detail Page

The detail page shows a writable version of a given datamodel allowing one to create and update instances on ones data.

Code example

If in a next.js app, create a src/pages/admin/vehicles/[id].tsx file, and return something like the below from a component defined as that file's default export:

Autorendering List / Detail Pages

It's likely that if you are taking advantage of remote data models, you wouldn't want to have to scaffold out a list and detail page for each remote data model, given there is no way to know for sure which models the server will return.

Luckily, there is a "fallback" available - create a file like src/pages/admin/[...path].tsx and put this inside:

Last updated