forked from mui/toolpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support delete in data providers (mui#2978)
- Loading branch information
Showing
26 changed files
with
336 additions
and
47 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
Binary file added
BIN
+326 KB
...ublic/static/toolpad/docs/concepts/connecting-to-data/data-providers-delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions
35
examples/with-prisma-data-provider/toolpad/pages/crud/page.yml
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,35 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/mui/mui-toolpad/v0.1.39/docs/schemas/v1/definitions.json#properties/Page | ||
|
||
apiVersion: v1 | ||
kind: page | ||
spec: | ||
title: Prisma data source CRUD example | ||
content: | ||
- component: Text | ||
name: text | ||
layout: | ||
columnSize: 1 | ||
horizontalAlign: start | ||
props: | ||
variant: h2 | ||
value: Users | ||
mode: text | ||
- component: DataGrid | ||
name: usersDataGrid | ||
layout: | ||
columnSize: 1 | ||
props: | ||
rows: null | ||
columns: | ||
- field: id | ||
type: number | ||
width: 77 | ||
- field: name | ||
type: string | ||
width: 120 | ||
- field: email | ||
type: string | ||
width: 335 | ||
height: 336 | ||
rowsSource: dataProvider | ||
dataProviderId: crud.ts:default |
2 changes: 2 additions & 0 deletions
2
examples/with-prisma-data-provider/toolpad/pages/cursorBased/page.yml
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
2 changes: 2 additions & 0 deletions
2
examples/with-prisma-data-provider/toolpad/pages/indexBased/page.yml
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
// Reuse existing PrismaClient instance during development | ||
(globalThis as any).__prisma ??= new PrismaClient(); | ||
const prisma: PrismaClient = (globalThis as any).__prisma; | ||
|
||
export default prisma; |
29 changes: 29 additions & 0 deletions
29
examples/with-prisma-data-provider/toolpad/resources/crud.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,29 @@ | ||
/** | ||
* Toolpad data provider file. | ||
* See: https://mui.com/toolpad/concepts/data-providers/ | ||
*/ | ||
|
||
import { createDataProvider } from '@mui/toolpad/server'; | ||
import prisma from '../prisma'; | ||
|
||
export default createDataProvider({ | ||
async getRecords({ paginationModel: { start, pageSize } }) { | ||
const [userRecords, totalCount] = await Promise.all([ | ||
prisma.user.findMany({ | ||
skip: start, | ||
take: pageSize, | ||
}), | ||
prisma.user.count(), | ||
]); | ||
return { | ||
records: userRecords, | ||
totalCount, | ||
}; | ||
}, | ||
|
||
async deleteRecord(id) { | ||
await prisma.user.delete({ | ||
where: { id: Number(id) }, | ||
}); | ||
}, | ||
}); |
8 changes: 2 additions & 6 deletions
8
examples/with-prisma-data-provider/toolpad/resources/usersByCursor.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
7 changes: 1 addition & 6 deletions
7
examples/with-prisma-data-provider/toolpad/resources/usersByIndex.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
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
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
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.