-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
341 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SKIP_PREFLIGHT_CHECK=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# See https://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.eslintcache | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# React-admin tutorial | ||
|
||
This is the application built while following the [tutorial](https://marmelab.com/react-admin/Tutorial.html). | ||
|
||
## How to run | ||
|
||
After having cloned the react-admin repository, run the following commands: | ||
|
||
```sh | ||
make install | ||
|
||
make build | ||
|
||
make run-tutorial | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
<link | ||
rel="stylesheet" | ||
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" | ||
/> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "tutorial", | ||
"version": "4.9.1", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"ra-data-json-server": "^4.9.1", | ||
"ra-data-simple-rest": "^4.9.1", | ||
"react": "^18.2.0", | ||
"react-admin": "^4.9.1", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@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" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"infiniteLoopProtection": true, | ||
"hardReloadOnChange": false, | ||
"view": "browser", | ||
"template": "node", | ||
"container": { | ||
"node": "16" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Admin, Resource } from "react-admin"; | ||
import { fetchUtils } from "ra-core"; | ||
import jsonServerProvider from "ra-data-json-server"; | ||
import PostIcon from "@mui/icons-material/Book"; | ||
import UserIcon from "@mui/icons-material/Group"; | ||
|
||
import { PostList, PostEdit, PostCreate, PostShow } from "./posts"; | ||
import { UserList } from "./users"; | ||
import { Dashboard } from "./Dashboard"; | ||
import { authProvider } from "./authProvider"; | ||
|
||
import simpleRestProvider from "ra-data-simple-rest"; | ||
|
||
// const dataProvider = simpleRestProvider( | ||
// "http://localhost:7001", | ||
// fetchUtils.fetchJson, | ||
// "X-Total-Count" | ||
// ); | ||
|
||
// const dataProvider = jsonServerProvider("http://127.0.0.1:7001"); | ||
|
||
const dataProvider = jsonServerProvider("https://jsonplaceholder.typicode.com"); | ||
|
||
const App = () => ( | ||
<Admin | ||
authProvider={authProvider} | ||
dataProvider={dataProvider} | ||
dashboard={Dashboard} | ||
> | ||
<Resource | ||
name="posts" | ||
list={PostList} | ||
edit={PostEdit} | ||
create={PostCreate} | ||
icon={PostIcon} | ||
show={PostShow} | ||
/> | ||
<Resource | ||
name="users" | ||
list={UserList} | ||
icon={UserIcon} | ||
recordRepresentation="name" | ||
/> | ||
</Admin> | ||
); | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Card, CardContent, CardHeader } from '@mui/material'; | ||
|
||
export const Dashboard = () => ( | ||
<Card> | ||
<CardHeader title="Welcome to the administration" /> | ||
<CardContent>Lorem ipsum sic dolor amet...</CardContent> | ||
</Card> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useRecordContext } from 'react-admin'; | ||
import { Link } from '@mui/material'; | ||
import LaunchIcon from '@mui/icons-material/Launch'; | ||
|
||
const MyUrlField = ({ source }: { source: string }) => { | ||
const record = useRecordContext(); | ||
return record ? ( | ||
<Link href={record[source]} sx={{ textDecoration: 'none' }}> | ||
{record[source]} | ||
<LaunchIcon sx={{ fontSize: 15, ml: 1 }} /> | ||
</Link> | ||
) : null; | ||
}; | ||
|
||
export default MyUrlField; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { AuthProvider } from 'react-admin'; | ||
|
||
export const authProvider: AuthProvider = { | ||
// called when the user attempts to log in | ||
login: ({ username }: { username: string }) => { | ||
localStorage.setItem('username', username); | ||
// accept all username/password combinations | ||
return Promise.resolve(); | ||
}, | ||
// called when the user clicks on the logout button | ||
logout: () => { | ||
localStorage.removeItem('username'); | ||
return Promise.resolve(); | ||
}, | ||
// called when the API returns an error | ||
checkError: ({ status }: { status: number }) => { | ||
if (status === 401 || status === 403) { | ||
localStorage.removeItem('username'); | ||
return Promise.reject(); | ||
} | ||
return Promise.resolve(); | ||
}, | ||
// called when the user navigates to a new location, to check for authentication | ||
checkAuth: () => { | ||
return localStorage.getItem('username') | ||
? Promise.resolve() | ||
: Promise.reject(); | ||
}, | ||
// called when the user navigates to a new location, to check for permissions / roles | ||
getPermissions: () => Promise.resolve(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
margin: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './App'; | ||
import './index.css'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { | ||
List, | ||
Datagrid, | ||
TextField, | ||
ReferenceField, | ||
EditButton, | ||
DeleteButton, | ||
SimpleShowLayout, | ||
Show, | ||
ShowButton, | ||
Edit, | ||
Create, | ||
SimpleForm, | ||
ReferenceInput, | ||
TextInput, | ||
useRecordContext, | ||
} from "react-admin"; | ||
|
||
const postFilters = [ | ||
<TextInput source="q" label="Search" alwaysOn />, | ||
<ReferenceInput source="userId" label="User" reference="users" />, | ||
]; | ||
|
||
export const PostList = () => ( | ||
<List filters={postFilters}> | ||
<Datagrid rowClick="edit"> | ||
<TextField source="id" /> | ||
<TextField source="title" /> | ||
<EditButton label="编辑" /> | ||
<ShowButton label="查看" /> | ||
<DeleteButton label="删除" /> | ||
</Datagrid> | ||
</List> | ||
); | ||
|
||
const PostTitle = () => { | ||
const record = useRecordContext(); | ||
return <span>Post {record ? `"${record.title}"` : ""}</span>; | ||
}; | ||
|
||
export const PostEdit = () => ( | ||
<Edit title={<PostTitle />}> | ||
<SimpleForm> | ||
<TextInput source="id" disabled /> | ||
{/* <ReferenceInput source="userId" reference="users" /> */} | ||
<TextInput source="title" /> | ||
{/* <TextInput source="description" multiline rows={5} /> */} | ||
</SimpleForm> | ||
</Edit> | ||
); | ||
|
||
export const PostCreate = () => ( | ||
<Create> | ||
<SimpleForm> | ||
<ReferenceInput source="userId" reference="users" /> | ||
<TextInput source="title" /> | ||
<TextInput source="body" multiline rows={5} /> | ||
</SimpleForm> | ||
</Create> | ||
); | ||
|
||
export const PostShow = () => ( | ||
<Show> | ||
<SimpleShowLayout> | ||
<TextField source="title" /> | ||
<TextField source="teaser" /> | ||
{/* <RichTextField source="body" /> */} | ||
{/* <DateField label="Publication date" source="published_at" /> */} | ||
</SimpleShowLayout> | ||
</Show> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useMediaQuery } from '@mui/material'; | ||
import { List, SimpleList, Datagrid, TextField, EmailField } from 'react-admin'; | ||
import MyUrlField from './MyUrlField'; | ||
|
||
export const UserList = () => { | ||
const isSmall = useMediaQuery<any>(theme => theme.breakpoints.down('sm')); | ||
return ( | ||
<List> | ||
{isSmall ? ( | ||
<SimpleList | ||
primaryText={record => record.name} | ||
secondaryText={record => record.username} | ||
tertiaryText={record => record.email} | ||
/> | ||
) : ( | ||
<Datagrid rowClick="edit"> | ||
<TextField source="id" /> | ||
<TextField source="name" /> | ||
<EmailField source="email" /> | ||
<TextField source="phone" /> | ||
<MyUrlField source="website" /> | ||
<TextField source="company.name" /> | ||
</Datagrid> | ||
)} | ||
</List> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"allowJs": false, | ||
"skipLibCheck": true, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx" | ||
}, | ||
"include": ["src"], | ||
"references": [{ "path": "./tsconfig.node.json" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": ["vite.config.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.