-
-
Notifications
You must be signed in to change notification settings - Fork 401
[examples] Update themed example according to latest dependencies #4877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
apedroferreira
merged 7 commits into
mui:master
from
apedroferreira:update-themed-example
Apr 22, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
146baa1
Update themed example according to latest dependencies
apedroferreira 345efda
huh
apedroferreira a51ffdf
weird weird weird
apedroferreira 590ba6a
Merge branch 'master' of github.com:mui/mui-toolpad into update-theme…
bharatkashyap d3bcab0
fix: Use Pickers theme customization
bharatkashyap f2600b4
Dedupe dependencies
apedroferreira e0e38a0
Fix unused theme import
apedroferreira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
92 changes: 13 additions & 79 deletions
92
examples/core/auth-nextjs-themed/app/(dashboard)/employees/[[...segments]]/page.tsx
This file contains hidden or 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,88 +1,22 @@ | ||
| 'use client'; | ||
| import * as React from 'react'; | ||
| import { usePathname, useRouter } from 'next/navigation'; | ||
| import { CrudProvider, List, Create, Edit, Show } from '@toolpad/core/Crud'; | ||
| import { Crud } from '@toolpad/core/Crud'; | ||
| import { employeesDataSource, Employee, employeesCache } from '../../../mocks/employees'; | ||
| import CustomDataGrid from '../../../components/CustomDataGrid'; | ||
|
|
||
| function matchPath(pattern: string, pathname: string): string | null { | ||
| const regex = new RegExp(`^${pattern.replace(/:[^/]+/g, '([^/]+)')}$`); | ||
| const match = pathname.match(regex); | ||
| return match ? match[1] : null; | ||
| } | ||
|
|
||
| export default function EmployeesCrudPage() { | ||
| const pathname = usePathname(); | ||
| const router = useRouter(); | ||
|
|
||
| const rootPath = '/employees'; | ||
| const listPath = rootPath; | ||
| const showPath = `${rootPath}/:employeeId`; | ||
| const createPath = `${rootPath}/new`; | ||
| const editPath = `${rootPath}/:employeeId/edit`; | ||
|
|
||
| const showEmployeeId = matchPath(showPath, pathname); | ||
| const editEmployeeId = matchPath(editPath, pathname); | ||
|
|
||
| const handleRowClick = React.useCallback( | ||
| (employeeId: string | number) => { | ||
| console.log('Clicked on row with ID', employeeId); | ||
| router.push(`${rootPath}/${String(employeeId)}`); | ||
| }, | ||
| [router], | ||
| ); | ||
|
|
||
| const handleCreateClick = React.useCallback(() => { | ||
| router.push(createPath); | ||
| }, [createPath, router]); | ||
|
|
||
| const handleEditClick = React.useCallback( | ||
| (employeeId: string | number) => { | ||
| router.push(`${rootPath}/${String(employeeId)}/edit`); | ||
| }, | ||
| [router], | ||
| ); | ||
|
|
||
| const handleCreate = React.useCallback(() => { | ||
| router.push(listPath); | ||
| }, [listPath, router]); | ||
|
|
||
| const handleEdit = React.useCallback(() => { | ||
| router.push(listPath); | ||
| }, [listPath, router]); | ||
|
|
||
| const handleDelete = React.useCallback(() => { | ||
| router.push(listPath); | ||
| }, [listPath, router]); | ||
|
|
||
| return ( | ||
| <CrudProvider<Employee> dataSource={employeesDataSource} dataSourceCache={employeesCache}> | ||
| {pathname === listPath ? ( | ||
| <List<Employee> | ||
| initialPageSize={20} | ||
| onRowClick={handleRowClick} | ||
| onCreateClick={handleCreateClick} | ||
| onEditClick={handleEditClick} | ||
| slots={{ | ||
| dataGrid: CustomDataGrid, | ||
| }} | ||
| /> | ||
| ) : null} | ||
| {pathname === createPath ? ( | ||
| <Create<Employee> | ||
| initialValues={{ title: 'New Employee' }} | ||
| onSubmitSuccess={handleCreate} | ||
| resetOnSubmit={false} | ||
| /> | ||
| ) : null} | ||
| {pathname !== createPath && showEmployeeId ? ( | ||
| <Show<Employee> id={showEmployeeId} onEditClick={handleEditClick} onDelete={handleDelete} /> | ||
| ) : null} | ||
| {editEmployeeId ? ( | ||
| <div className="employee-edit-container"> | ||
| <Edit<Employee> id={editEmployeeId} onSubmitSuccess={handleEdit} /> | ||
| </div> | ||
| ) : null} | ||
| </CrudProvider> | ||
| <Crud<Employee> | ||
| dataSource={employeesDataSource} | ||
| dataSourceCache={employeesCache} | ||
| rootPath="/employees" | ||
| initialPageSize={20} | ||
| defaultValues={{ title: 'New Employee' }} | ||
| slots={{ | ||
| list: { | ||
| dataGrid: CustomDataGrid, | ||
| }, | ||
| }} | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like I had forgotten this one.