From f5b15aa4aefd1b749d86fc940ba2554bc0a796fb Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Wed, 24 May 2023 17:49:50 +0200 Subject: [PATCH] Add support for admin configuration through props instead of elements --- examples/with-config/README.md | 50 +++++ examples/with-config/index.html | 125 +++++++++++ examples/with-config/package.json | 24 +++ examples/with-config/public/favicon.ico | Bin 0 -> 15086 bytes examples/with-config/public/manifest.json | 15 ++ examples/with-config/src/App.tsx | 58 +++++ examples/with-config/src/README.md | 8 + examples/with-config/src/authProvider.ts | 41 ++++ examples/with-config/src/data.json | 121 +++++++++++ examples/with-config/src/dataProvider.ts | 4 + examples/with-config/src/help.txt | 3 + examples/with-config/src/index.tsx | 9 + examples/with-config/src/users.json | 18 ++ examples/with-config/src/vite-env.d.ts | 1 + examples/with-config/tsconfig.json | 26 +++ examples/with-config/vite.config.ts | 42 ++++ packages/ra-core/src/core/CoreAdmin.tsx | 6 + .../ra-core/src/core/CoreAdminRoutes.spec.tsx | 5 - packages/ra-core/src/core/CoreAdminRoutes.tsx | 22 +- packages/ra-core/src/core/CoreAdminUI.tsx | 14 +- packages/ra-core/src/core/Resource.tsx | 121 ++++++++--- .../core/useConfigureAdminRouterFromProps.tsx | 200 ++++++++++++++++++ packages/ra-core/src/types.ts | 21 ++ packages/react-admin/src/Admin.tsx | 6 + yarn.lock | 28 ++- 25 files changed, 925 insertions(+), 43 deletions(-) create mode 100644 examples/with-config/README.md create mode 100644 examples/with-config/index.html create mode 100644 examples/with-config/package.json create mode 100644 examples/with-config/public/favicon.ico create mode 100644 examples/with-config/public/manifest.json create mode 100644 examples/with-config/src/App.tsx create mode 100644 examples/with-config/src/README.md create mode 100644 examples/with-config/src/authProvider.ts create mode 100644 examples/with-config/src/data.json create mode 100644 examples/with-config/src/dataProvider.ts create mode 100644 examples/with-config/src/help.txt create mode 100644 examples/with-config/src/index.tsx create mode 100644 examples/with-config/src/users.json create mode 100644 examples/with-config/src/vite-env.d.ts create mode 100644 examples/with-config/tsconfig.json create mode 100644 examples/with-config/vite.config.ts create mode 100644 packages/ra-core/src/core/useConfigureAdminRouterFromProps.tsx diff --git a/examples/with-config/README.md b/examples/with-config/README.md new file mode 100644 index 00000000000..6231eacdcfa --- /dev/null +++ b/examples/with-config/README.md @@ -0,0 +1,50 @@ +# with-config + +## Installation + +Install the application dependencies by running: + +```sh +npm install +# or +yarn install +``` + +## Development + +Start the application in development mode by running: + +```sh +npm run dev +# or +yarn dev +``` + +## Production + +Build the application in production mode by running: + +```sh +npm run build +# or +yarn build +``` + +## DataProvider + +The included data provider use [FakeREST](https://github.com/marmelab/fakerest) to simulate a backend. +You'll find a `data.json` file in the `src` directory that includes some fake data for testing purposes. + +It includes two resources, posts and comments. +Posts have the following properties: `id`, `title` and `content`. +Comments have the following properties: `id`, `post_id` and `content`. + +## Authentication + +The included auth provider should only be used for development and test purposes. +You'll find a `users.json` file in the `src` directory that includes the users you can use. + +You can sign in to the application with the following usernames and password: +- janedoe / password +- johndoe / password + diff --git a/examples/with-config/index.html b/examples/with-config/index.html new file mode 100644 index 00000000000..26018ebc157 --- /dev/null +++ b/examples/with-config/index.html @@ -0,0 +1,125 @@ + + + + + + + + + with-config + + + + + + + +
+
+
Loading...
+
+
+ + + diff --git a/examples/with-config/package.json b/examples/with-config/package.json new file mode 100644 index 00000000000..06bf10a48c1 --- /dev/null +++ b/examples/with-config/package.json @@ -0,0 +1,24 @@ +{ + "name": "with-config", + "private": true, + "scripts": { + "dev": "vite", + "build": "vite build", + "serve": "vite preview", + "type-check": "tsc --noEmit" + }, + "dependencies": { + "ra-data-fakerest": "^4.9.2", + "react": "^18.2.0", + "react-admin": "^4.9.0", + "react-dom": "^18.2.0" + }, + "devDependencies": { + "@types/node": "^18.16.1", + "@types/react": "^18.0.22", + "@types/react-dom": "^18.0.7", + "@vitejs/plugin-react": "^2.2.0", + "typescript": "^4.6.4", + "vite": "^3.2.0" + } +} diff --git a/examples/with-config/public/favicon.ico b/examples/with-config/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..f9222554e6c30f98dc616b5b1f8df05f1cbc9350 GIT binary patch literal 15086 zcmeHO34Bi168|D0_M&#Bv6ZS{OY2#(kwge;i>>x8ym+XksMZ>yG_Q{a&rYbF)FY&J zQM=ef36co4FCmuL!gT(Voa@WCB>5r<>2rU-$^GuV=bV`{XU@!=nTbwkrL)#mtES_- zoo+=%ovx-%r?az5d@i8VMe(}=e8+ch8=dY4Zcv%qa2H)S2E3Q6Lc&e|FA>dPIK*%; ziveg3UN?FFOB|?z}4iED<|1o>Bu45+XLZcRT|O`&-KYUbSn|m=5h}WSiF1sBj?-hvB$*2HvJ6iqXinZKRL4qdhrV zTWK`ld%aw?Ep-r{Mj>_@$E2ezM#Efp@Ot> z$`p#Zaf4pGc%f_%z2x5yV`J&$zP(JhEBW>D7JT7Hj!>Hl<&vy}dHRj@59kjL2oOAv zA3dU;HEWoqAN1AFpO5x$+$inuT)$3UHUFXEw&%G`^y)#+o<7yS?^?H(g67So-xe*R zV>@>e`kXsVHXuC;3u);@910B=ZO zpnQwDd4q{rd#xx#P#E`3EI6y{YKOecqVS(gyouU+@O{Prtr2s$E;L7qA(C z5o~An1O=r#{ow1jEt-+%hh>C!;2*%#t_=Bf>Zs|A#XnABxp`%?6#dYjZOWIUL%aqr zUc?K1_ygUq0P~7xz%#D&@aA zsw7S5(T!I5`-_|h^IlP~V)A4P80SM#r%t6i{W4%G{$QOp@%h@E3}FtCcdQZYqdwpr z)@keVWrFF_xwF)^V)-O{DXsSF`Ln0AdfHT)K6Hrq1@H|N%=&IPZCEg$u3x+;cwfGJ zNlW~GOyc_}IZEk{`6>F(9z7!d6yB+RX{8_b*VO)1x&yrHThCc!7Lz!C;siBkS<%O> zXh`nvoZUuZIT+(~=t0e=Q+-~C{^a~0j1PZ##gxfFO%LwfqdrcKM*fnTFXRMs(}16$ zJ3Z|_)a=B8O&h5m>|CM`f_sM2&-mdxVjp9_!^eSs75q%ATi)E{#r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>)WX6y0UkeZZ}B5ASLl1x31B?bGmPV$FzQGQ`)}bo zPkU=?a<;XVnyf({4cQhI7aP&GLV59fR?e0CzV!eJGUvJ8Y<&6Om6xZ3FbR{`zBWAR9^6A7|^5#o7PtD(j@y3O)+j8tQ!G f{zYZYai-D-WlzywAN1w-b@$Kf?q5TFVCnN;r_I_P literal 0 HcmV?d00001 diff --git a/examples/with-config/public/manifest.json b/examples/with-config/public/manifest.json new file mode 100644 index 00000000000..0b29eca21ce --- /dev/null +++ b/examples/with-config/public/manifest.json @@ -0,0 +1,15 @@ +{ + "short_name": "with-config", + "name": "{{name}}", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + } + ], + "start_url": "./index.html", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/examples/with-config/src/App.tsx b/examples/with-config/src/App.tsx new file mode 100644 index 00000000000..7eb96a1c0a4 --- /dev/null +++ b/examples/with-config/src/App.tsx @@ -0,0 +1,58 @@ +import { + Admin, + ListGuesser, + EditGuesser, + ShowGuesser, + CardContentInner, + Button, +} from 'react-admin'; +import { Link } from 'react-router-dom'; +import { dataProvider } from './dataProvider'; +import { authProvider } from './authProvider'; + +export const App = () => ( + ({ + posts: { + edit: EditGuesser, + list: ListGuesser, + routes: [ + { + path: 'all/*', + element: , + }, + { + path: '*', + element: ( + + Posts Dashboard +
+