Skip to content

[CRUD] Refactor page titles to pageTitles and pageTitle props #4930

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

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7201403
Improve/fix themed example page titles
apedroferreira May 6, 2025
ba67ab5
Fix and improve everywhere
apedroferreira May 6, 2025
6a03ca8
Another improvement
apedroferreira May 6, 2025
d63896c
I think this is more proper
apedroferreira May 23, 2025
488f366
Better pinned actions column
apedroferreira May 23, 2025
d1d61ab
Merge remote-tracking branch 'upstream/master' into fix-themed-exampl…
apedroferreira May 23, 2025
4e29d2c
why lisa why
apedroferreira May 23, 2025
a7db5d3
Merge remote-tracking branch 'upstream/master' into fix-themed-exampl…
apedroferreira May 30, 2025
65d05cb
Make it all more consistent
apedroferreira May 30, 2025
ad4bcc0
dedupe weirdness
apedroferreira May 30, 2025
528f26b
Remove redundancy in CRUD form
apedroferreira Jun 2, 2025
a1668b4
nevermind
apedroferreira Jun 2, 2025
60d7fdb
Set CRUD page titles as component props, use PageContainer in CRUD pa…
apedroferreira Jun 3, 2025
fdd935c
Updated playgrounds
apedroferreira Jun 4, 2025
34011f6
Updated examples and CRA
apedroferreira Jun 4, 2025
9d4866d
Fix examples
apedroferreira Jun 4, 2025
dc1f712
Update all demos
apedroferreira Jun 4, 2025
626f54a
Add slots to hide page container
apedroferreira Jun 4, 2025
fbb0c76
Add documentation and demos
apedroferreira Jun 4, 2025
38b12e0
Revert "Fix examples"
apedroferreira Jun 4, 2025
9c30068
Revert "Updated examples and CRA"
apedroferreira Jun 4, 2025
2d44d6d
Put back CRA changes
apedroferreira Jun 4, 2025
c7fdd0b
Merge remote-tracking branch 'upstream/master' into fix-themed-exampl…
apedroferreira Jun 4, 2025
46f1144
Fix demos
apedroferreira Jun 4, 2025
0c470bc
Remove path from last breadcrumb
apedroferreira Jun 4, 2025
4b870ba
Revert all changes to examples
apedroferreira Jun 4, 2025
4524985
Update docs/data/toolpad/core/components/crud/crud.md
apedroferreira Jun 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 35 additions & 48 deletions docs/data/toolpad/core/components/crud/CrudAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createTheme } from '@mui/material/styles';
import StickyNote2Icon from '@mui/icons-material/StickyNote2';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { PageContainer } from '@toolpad/core/PageContainer';
import {
Create,
CrudProvider,
Expand Down Expand Up @@ -223,22 +222,6 @@ function CrudAdvanced(props) {
const createPath = `${rootPath}/new`;
const editPath = `${rootPath}/:noteId/edit`;

const title = React.useMemo(() => {
if (router.pathname === createPath) {
return 'New Note';
}
const editNoteId = matchPath(editPath, router.pathname);
if (editNoteId) {
return `Note ${editNoteId} - Edit`;
}
const showNoteId = matchPath(showPath, router.pathname);
if (showNoteId) {
return `Note ${showNoteId}`;
}

return undefined;
}, [createPath, editPath, router.pathname, showPath]);

const handleRowClick = React.useCallback(
(noteId) => {
router.navigate(`${rootPath}/${String(noteId)}`);
Expand Down Expand Up @@ -282,37 +265,41 @@ function CrudAdvanced(props) {
window={demoWindow}
>
<DashboardLayout defaultSidebarCollapsed>
<PageContainer title={title}>
{/* preview-start */}
<CrudProvider dataSource={notesDataSource} dataSourceCache={notesCache}>
{router.pathname === listPath ? (
<List
initialPageSize={10}
onRowClick={handleRowClick}
onCreateClick={handleCreateClick}
onEditClick={handleEditClick}
/>
) : null}
{router.pathname === createPath ? (
<Create
initialValues={{ title: 'New note' }}
onSubmitSuccess={handleCreate}
resetOnSubmit={false}
/>
) : null}
{router.pathname !== createPath && showNoteId ? (
<Show
id={showNoteId}
onEditClick={handleEditClick}
onDelete={handleDelete}
/>
) : null}
{editNoteId ? (
<Edit id={editNoteId} onSubmitSuccess={handleEdit} />
) : null}
</CrudProvider>
{/* preview-end */}
</PageContainer>
{/* preview-start */}
<CrudProvider dataSource={notesDataSource} dataSourceCache={notesCache}>
{router.pathname === listPath ? (
<List
initialPageSize={10}
onRowClick={handleRowClick}
onCreateClick={handleCreateClick}
onEditClick={handleEditClick}
/>
) : null}
{router.pathname === createPath ? (
<Create
initialValues={{ title: 'New note' }}
onSubmitSuccess={handleCreate}
resetOnSubmit={false}
pageTitle="New Note"
/>
) : null}
{router.pathname !== createPath && showNoteId ? (
<Show
id={showNoteId}
onEditClick={handleEditClick}
onDelete={handleDelete}
pageTitle={`Note ${showNoteId}`}
/>
) : null}
{editNoteId ? (
<Edit
id={editNoteId}
onSubmitSuccess={handleEdit}
pageTitle={`Note ${editNoteId} - Edit`}
/>
) : null}
</CrudProvider>
{/* preview-end */}
</DashboardLayout>
</AppProvider>
</DemoProvider>
Expand Down
89 changes: 38 additions & 51 deletions docs/data/toolpad/core/components/crud/CrudAdvanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createTheme } from '@mui/material/styles';
import StickyNote2Icon from '@mui/icons-material/StickyNote2';
import { AppProvider, type Navigation } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { PageContainer } from '@toolpad/core/PageContainer';
import {
Create,
CrudProvider,
Expand Down Expand Up @@ -244,22 +243,6 @@ export default function CrudAdvanced(props: DemoProps) {
const createPath = `${rootPath}/new`;
const editPath = `${rootPath}/:noteId/edit`;

const title = React.useMemo(() => {
if (router.pathname === createPath) {
return 'New Note';
}
const editNoteId = matchPath(editPath, router.pathname);
if (editNoteId) {
return `Note ${editNoteId} - Edit`;
}
const showNoteId = matchPath(showPath, router.pathname);
if (showNoteId) {
return `Note ${showNoteId}`;
}

return undefined;
}, [createPath, editPath, router.pathname, showPath]);

const handleRowClick = React.useCallback(
(noteId: string | number) => {
router.navigate(`${rootPath}/${String(noteId)}`);
Expand Down Expand Up @@ -303,40 +286,44 @@ export default function CrudAdvanced(props: DemoProps) {
window={demoWindow}
>
<DashboardLayout defaultSidebarCollapsed>
<PageContainer title={title}>
{/* preview-start */}
<CrudProvider<Note>
dataSource={notesDataSource}
dataSourceCache={notesCache}
>
{router.pathname === listPath ? (
<List<Note>
initialPageSize={10}
onRowClick={handleRowClick}
onCreateClick={handleCreateClick}
onEditClick={handleEditClick}
/>
) : null}
{router.pathname === createPath ? (
<Create<Note>
initialValues={{ title: 'New note' }}
onSubmitSuccess={handleCreate}
resetOnSubmit={false}
/>
) : null}
{router.pathname !== createPath && showNoteId ? (
<Show<Note>
id={showNoteId}
onEditClick={handleEditClick}
onDelete={handleDelete}
/>
) : null}
{editNoteId ? (
<Edit<Note> id={editNoteId} onSubmitSuccess={handleEdit} />
) : null}
</CrudProvider>
{/* preview-end */}
</PageContainer>
{/* preview-start */}
<CrudProvider<Note>
dataSource={notesDataSource}
dataSourceCache={notesCache}
>
{router.pathname === listPath ? (
<List<Note>
initialPageSize={10}
onRowClick={handleRowClick}
onCreateClick={handleCreateClick}
onEditClick={handleEditClick}
/>
) : null}
{router.pathname === createPath ? (
<Create<Note>
initialValues={{ title: 'New note' }}
onSubmitSuccess={handleCreate}
resetOnSubmit={false}
pageTitle="New Note"
/>
) : null}
{router.pathname !== createPath && showNoteId ? (
<Show<Note>
id={showNoteId}
onEditClick={handleEditClick}
onDelete={handleDelete}
pageTitle={`Note ${showNoteId}`}
/>
) : null}
{editNoteId ? (
<Edit<Note>
id={editNoteId}
onSubmitSuccess={handleEdit}
pageTitle={`Note ${editNoteId} - Edit`}
/>
) : null}
</CrudProvider>
{/* preview-end */}
</DashboardLayout>
</AppProvider>
</DemoProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@
initialValues={{ title: 'New note' }}
onSubmitSuccess={handleCreate}
resetOnSubmit={false}
pageTitle="New Note"
/>
) : null}
{router.pathname !== createPath && showNoteId ? (
<Show<Note>
id={showNoteId}
onEditClick={handleEditClick}
onDelete={handleDelete}
pageTitle={`Note ${showNoteId}`}
/>
) : null}
{editNoteId ? (
<Edit<Note> id={editNoteId} onSubmitSuccess={handleEdit} />
<Edit<Note>
id={editNoteId}
onSubmitSuccess={handleEdit}
pageTitle={`Note ${editNoteId} - Edit`}
/>
) : null}
</CrudProvider>
43 changes: 16 additions & 27 deletions docs/data/toolpad/core/components/crud/CrudBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createTheme } from '@mui/material/styles';
import StickyNote2Icon from '@mui/icons-material/StickyNote2';
import { AppProvider } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { PageContainer } from '@toolpad/core/PageContainer';
import { Crud, DataSourceCache } from '@toolpad/core/Crud';
import { DemoProvider, useDemoRouter } from '@toolpad/core/internal';

Expand Down Expand Up @@ -211,21 +210,8 @@ function CrudBasic(props) {
// Remove this const when copying and pasting into your project.
const demoWindow = window !== undefined ? window() : undefined;

const title = React.useMemo(() => {
if (router.pathname === '/notes/new') {
return 'New Note';
}
const editNoteId = matchPath('/notes/:noteId/edit', router.pathname);
if (editNoteId) {
return `Note ${editNoteId} - Edit`;
}
const showNoteId = matchPath('/notes/:noteId', router.pathname);
if (showNoteId) {
return `Note ${showNoteId}`;
}

return undefined;
}, [router.pathname]);
const showNoteId = matchPath('/notes/:noteId', router.pathname);
const editNoteId = matchPath('/notes/:noteId/edit', router.pathname);

return (
// Remove this provider when copying and pasting into your project.
Expand All @@ -237,17 +223,20 @@ function CrudBasic(props) {
window={demoWindow}
>
<DashboardLayout defaultSidebarCollapsed>
<PageContainer title={title}>
{/* preview-start */}
<Crud
dataSource={notesDataSource}
dataSourceCache={notesCache}
rootPath="/notes"
initialPageSize={10}
defaultValues={{ title: 'New note' }}
/>
{/* preview-end */}
</PageContainer>
{/* preview-start */}
<Crud
dataSource={notesDataSource}
dataSourceCache={notesCache}
rootPath="/notes"
initialPageSize={10}
defaultValues={{ title: 'New note' }}
pageTitles={{
create: 'New Note',
edit: `Note ${editNoteId} - Edit`,
show: `Note ${showNoteId}`,
}}
/>
{/* preview-end */}
</DashboardLayout>
</AppProvider>
</DemoProvider>
Expand Down
43 changes: 16 additions & 27 deletions docs/data/toolpad/core/components/crud/CrudBasic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createTheme } from '@mui/material/styles';
import StickyNote2Icon from '@mui/icons-material/StickyNote2';
import { AppProvider, type Navigation } from '@toolpad/core/AppProvider';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { PageContainer } from '@toolpad/core/PageContainer';
import { Crud, DataModel, DataSource, DataSourceCache } from '@toolpad/core/Crud';
import { DemoProvider, useDemoRouter } from '@toolpad/core/internal';

Expand Down Expand Up @@ -230,21 +229,8 @@ export default function CrudBasic(props: DemoProps) {
// Remove this const when copying and pasting into your project.
const demoWindow = window !== undefined ? window() : undefined;

const title = React.useMemo(() => {
if (router.pathname === '/notes/new') {
return 'New Note';
}
const editNoteId = matchPath('/notes/:noteId/edit', router.pathname);
if (editNoteId) {
return `Note ${editNoteId} - Edit`;
}
const showNoteId = matchPath('/notes/:noteId', router.pathname);
if (showNoteId) {
return `Note ${showNoteId}`;
}

return undefined;
}, [router.pathname]);
const showNoteId = matchPath('/notes/:noteId', router.pathname);
const editNoteId = matchPath('/notes/:noteId/edit', router.pathname);

return (
// Remove this provider when copying and pasting into your project.
Expand All @@ -256,17 +242,20 @@ export default function CrudBasic(props: DemoProps) {
window={demoWindow}
>
<DashboardLayout defaultSidebarCollapsed>
<PageContainer title={title}>
{/* preview-start */}
<Crud<Note>
dataSource={notesDataSource}
dataSourceCache={notesCache}
rootPath="/notes"
initialPageSize={10}
defaultValues={{ title: 'New note' }}
/>
{/* preview-end */}
</PageContainer>
{/* preview-start */}
<Crud<Note>
dataSource={notesDataSource}
dataSourceCache={notesCache}
rootPath="/notes"
initialPageSize={10}
defaultValues={{ title: 'New note' }}
pageTitles={{
create: 'New Note',
edit: `Note ${editNoteId} - Edit`,
show: `Note ${showNoteId}`,
}}
/>
{/* preview-end */}
</DashboardLayout>
</AppProvider>
</DemoProvider>
Expand Down
5 changes: 5 additions & 0 deletions docs/data/toolpad/core/components/crud/CrudBasic.tsx.preview
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
rootPath="/notes"
initialPageSize={10}
defaultValues={{ title: 'New note' }}
pageTitles={{
create: 'New Note',
edit: `Note ${editNoteId} - Edit`,
show: `Note ${showNoteId}`,
}}
/>
Loading