-
-
Notifications
You must be signed in to change notification settings - Fork 337
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
1 parent
dccbb8e
commit 6b47e14
Showing
10 changed files
with
142 additions
and
161 deletions.
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
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
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './List'; | ||
export * from './Show'; | ||
export * from './Create'; | ||
|
||
export * from './shared'; |
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 |
---|---|---|
@@ -1,10 +1,22 @@ | ||
import { GridColDef } from '@mui/x-data-grid'; | ||
|
||
export type CRUDFields = GridColDef[]; | ||
import { GridColDef, GridFilterModel, GridPaginationModel, GridSortModel } from '@mui/x-data-grid'; | ||
|
||
export type DataModelId = string | number; | ||
|
||
export interface DataModel { | ||
id: DataModelId; | ||
[key: string]: unknown; | ||
} | ||
|
||
export interface GetManyParams { | ||
paginationModel: GridPaginationModel; | ||
sortModel: GridSortModel; | ||
filterModel: GridFilterModel; | ||
} | ||
|
||
export interface DataSource<D extends DataModel> { | ||
fields: GridColDef[]; | ||
getMany?: (params: GetManyParams) => Promise<{ items: D[]; itemCount: number }>; | ||
getOne?: (id: DataModelId) => Promise<D>; | ||
createOne?: (data: Omit<D, 'id'>) => Promise<D>; | ||
deleteOne?: (id: DataModelId) => Promise<void>; | ||
} |
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,62 @@ | ||
import { DataSource } from '@toolpad/core/CRUD'; | ||
|
||
export interface Order extends Record<string, unknown> { | ||
id: number; | ||
name: string; | ||
status: string; | ||
} | ||
|
||
const ordersDataSource: Required<DataSource<Order>> = { | ||
fields: [ | ||
{ field: 'id', headerName: 'ID' }, | ||
{ field: 'name', headerName: 'Name' }, | ||
{ field: 'status', headerName: 'Status' }, | ||
], | ||
getMany: async ({ paginationModel }) => { | ||
return new Promise<{ items: Order[]; itemCount: number }>((resolve) => { | ||
setTimeout(() => { | ||
resolve({ | ||
items: Array.from({ length: paginationModel.pageSize }, (_, i) => ({ | ||
id: paginationModel.page * paginationModel.pageSize + i + 1, | ||
name: `Order ${paginationModel.page * paginationModel.pageSize + i + 1}`, | ||
status: 'pending', | ||
})).slice(0, paginationModel.pageSize), | ||
itemCount: 300, | ||
}); | ||
}, 1500); | ||
}); | ||
}, | ||
getOne: (orderId) => { | ||
return new Promise<Order>((resolve) => { | ||
setTimeout(() => { | ||
return orderId | ||
? resolve({ | ||
id: Number(orderId), | ||
name: `Order ${orderId}`, | ||
status: 'pending', | ||
}) | ||
: null; | ||
}, 1500); | ||
}); | ||
}, | ||
createOne: () => { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve({ | ||
id: 69, | ||
name: 'Order 69', | ||
status: 'pending', | ||
}); | ||
}, 1500); | ||
}); | ||
}, | ||
deleteOne: () => { | ||
return new Promise<void>((resolve) => { | ||
setTimeout(() => { | ||
resolve(); | ||
}, 1500); | ||
}); | ||
}, | ||
}; | ||
|
||
export default ordersDataSource; |
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 |
---|---|---|
@@ -1,35 +1,7 @@ | ||
import * as React from 'react'; | ||
import { Create } from '@toolpad/core/CRUD'; | ||
|
||
interface Order extends Record<string, unknown> { | ||
id: number; | ||
name: string; | ||
status: string; | ||
} | ||
|
||
const orderFields = [ | ||
{ field: 'id', headerName: 'ID' }, | ||
{ field: 'name', headerName: 'Name' }, | ||
{ field: 'status', headerName: 'Status' }, | ||
]; | ||
import ordersDataSource, { Order } from '../data/orders'; | ||
|
||
export default function OrderPage() { | ||
return ( | ||
<Create<Order> | ||
fields={orderFields} | ||
methods={{ | ||
createOne: () => { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve({ | ||
id: 69, | ||
name: 'Order 69', | ||
status: 'pending', | ||
}); | ||
}, 1500); | ||
}); | ||
}, | ||
}} | ||
/> | ||
); | ||
return <Create<Order> dataSource={ordersDataSource} />; | ||
} |
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
Oops, something went wrong.