Skip to content

Commit

Permalink
Merge pull request #10437 from marmelab/react-19
Browse files Browse the repository at this point in the history
Supports react 19
  • Loading branch information
slax57 authored Jan 10, 2025
2 parents 5fc1098 + 6c93dc4 commit 40bda09
Show file tree
Hide file tree
Showing 38 changed files with 752 additions and 363 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/auth.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Authentication', () => {
it('should not login with incorrect credentials', () => {
ListPage.navigate();
ListPage.logout();
LoginPage.login('foo', 'bar');
LoginPage.login('foo', 'bar', true);
cy.contains('Authentication failed, please retry');
});
it('should login with correct credentials', () => {
Expand Down
8 changes: 7 additions & 1 deletion cypress/support/LoginPage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export default url => ({
elements: {
appLoader: '.app-loader',
username: "input[name='username']",
password: "input[name='password']",
submitButton: 'button',
title: '#react-admin-title',
},

navigate() {
Expand All @@ -14,9 +16,13 @@ export default url => ({
cy.get(this.elements.username);
},

login(username = 'login', password = 'password') {
login(username = 'login', password = 'password', shouldFail = false) {
cy.get(this.elements.username).clear().type(username);
cy.get(this.elements.password).clear().type(password);
cy.get(this.elements.submitButton).click();
if (!shouldFail) {
cy.get(this.elements.title);
cy.get(this.elements.appLoader);
}
},
});
4 changes: 2 additions & 2 deletions examples/crm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"type": "module",
"dependencies": {
"@hello-pangea/dnd": "^16.3.0",
"@mui/icons-material": "^5.15.20",
"@mui/material": "^5.15.20",
"@mui/icons-material": "^5.16.12",
"@mui/material": "^5.16.12",
"@nivo/bar": "^0.80.0",
"@nivo/core": "^0.80.0",
"clsx": "^2.1.1",
Expand Down
19 changes: 12 additions & 7 deletions examples/crm/src/contacts/ContactImportDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Box, CircularProgress, Stack, Typography } from '@mui/material';
import Alert from '@mui/material/Alert';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
import MuiLink from '@mui/material/Link';
import {
Alert,
Box,
CircularProgress,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
Link as MuiLink,
Stack,
Typography,
} from '@mui/material';
import {
Button,
FileField,
Expand Down
2 changes: 1 addition & 1 deletion examples/crm/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineConfig(async () => {
// eslint-disable-next-line prettier/prettier
const packageJson = await import(
path.resolve(__dirname, '../../packages', dirName, 'package.json'),
{ assert: { type: 'json' } }
{ with: { type: 'json' } }
);
aliases[packageJson.default.name] = path.resolve(
__dirname,
Expand Down
12 changes: 6 additions & 6 deletions examples/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"private": true,
"type": "module",
"dependencies": {
"@apollo/client": "^3.3.19",
"@mui/icons-material": "^5.15.20",
"@mui/material": "^5.15.20",
"@apollo/client": "^3.12.4",
"@mui/icons-material": "^5.16.12",
"@mui/material": "^5.16.12",
"@types/recharts": "^1.8.10",
"@vitejs/plugin-react": "^2.2.0",
"clsx": "^2.1.1",
Expand All @@ -26,12 +26,12 @@
"ra-input-rich-text": "^5.0.0",
"ra-language-english": "^5.0.0",
"ra-language-french": "^5.0.0",
"react": "^18.3.1",
"react": "^19.0.0",
"react-admin": "^5.0.0",
"react-dom": "^18.3.1",
"react-dom": "^19.0.0",
"react-router": "^6.22.0",
"react-router-dom": "^6.22.0",
"recharts": "^2.1.15"
"recharts": "^2.15.0"
},
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const App = () => {
const darkTheme = themes.find(theme => theme.name === themeName)?.dark;
return (
<Admin
title=""
title="Posters Galore Admin"
dataProvider={dataProviderFactory(
process.env.REACT_APP_DATA_PROVIDER || ''
)}
Expand Down
17 changes: 13 additions & 4 deletions examples/demo/src/categories/CategoryEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
TextInput,
useTranslate,
useRecordContext,
useDefaultTitle,
useGetResourceLabel,
} from 'react-admin';

import ThumbnailField from '../products/ThumbnailField';
Expand Down Expand Up @@ -59,14 +61,21 @@ const CategoryEdit = () => (
);

const CategoryTitle = () => {
const appTitle = useDefaultTitle();
const record = useRecordContext<Category>();
const translate = useTranslate();
const getResourceLabel = useGetResourceLabel();

const pageTitle = translate('ra.page.edit', {
name: getResourceLabel('categories', 1),
recordRepresentation: `"${record?.name}"`,
});

return record ? (
<span>
{translate('resources.categories.name', { smart_count: 1 })} &quot;
{record.name}&quot;
</span>
<>
<title>{`${appTitle} - ${pageTitle}`}</title>
<span>{pageTitle}</span>
</>
) : null;
};

Expand Down
14 changes: 14 additions & 0 deletions examples/demo/src/categories/CategoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
EditButton,
List,
RecordContextProvider,
useDefaultTitle,
useListContext,
} from 'react-admin';
import {
Expand All @@ -17,6 +18,18 @@ import { humanize } from 'inflection';

import LinkToRelatedProducts from './LinkToRelatedProducts';
import { Category } from '../types';
import { usePageTitle } from '../usePageTitle';

const CategoriesTitle = () => {
const title = useDefaultTitle();
const pageTitle = usePageTitle({ view: 'list' });
return (
<>
<title>{`${title} - ${pageTitle}`}</title>
<span>{pageTitle}</span>
</>
);
};

const CategoryList = () => (
<List
Expand All @@ -25,6 +38,7 @@ const CategoryList = () => (
pagination={false}
component="div"
actions={false}
title={<CategoriesTitle />}
>
<CategoryGrid />
</List>
Expand Down
14 changes: 14 additions & 0 deletions examples/demo/src/invoices/InvoiceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
SelectColumnsButton,
ReferenceInput,
FilterButton,
useDefaultTitle,
} from 'react-admin';

import FullNameField from '../visitors/FullNameField';
import AddressField from '../visitors/AddressField';
import InvoiceShow from './InvoiceShow';
import { usePageTitle } from '../usePageTitle';

const listFilters = [
<DateInput source="date_gte" alwaysOn />,
Expand All @@ -33,12 +35,24 @@ const ListActions = () => (
</TopToolbar>
);

const InvoicesTitle = () => {
const title = useDefaultTitle();
const pageTitle = usePageTitle({ view: 'list' });
return (
<>
<title>{`${title} - ${pageTitle}`}</title>
<span>{pageTitle}</span>
</>
);
};

const InvoiceList = () => (
<List
filters={listFilters}
perPage={25}
sort={{ field: 'date', order: 'DESC' }}
actions={<ListActions />}
title={<InvoicesTitle />}
>
<DatagridConfigurable
rowClick="expand"
Expand Down
21 changes: 11 additions & 10 deletions examples/demo/src/orders/OrderEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import {
Toolbar,
useRecordContext,
useTranslate,
useDefaultTitle,
} from 'react-admin';
import { Card, CardContent, Box, Grid, Typography, Link } from '@mui/material';

import { Order, Customer } from '../types';
import { Customer } from '../types';
import Basket from './Basket';
import Totals from './Totals';
import { usePageTitle } from '../usePageTitle';

const OrderEdit = () => (
<Edit title={<OrderTitle />} component="div">
Expand All @@ -27,15 +29,14 @@ const OrderEdit = () => (
);

const OrderTitle = () => {
const translate = useTranslate();
const record = useRecordContext<Order>();
return record ? (
<span>
{translate('resources.orders.title', {
reference: record.reference,
})}
</span>
) : null;
const appTitle = useDefaultTitle();
const pageTitle = usePageTitle({ view: 'edit' });
return (
<>
<title>{`${appTitle} - ${pageTitle}`}</title>
<span>{pageTitle}</span>
</>
);
};

const CustomerDetails = () => {
Expand Down
14 changes: 14 additions & 0 deletions examples/demo/src/orders/OrderList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
SelectColumnsButton,
TextField,
TopToolbar,
useDefaultTitle,
useListContext,
} from 'react-admin';
import { useMediaQuery, Divider, Tabs, Tab, Theme } from '@mui/material';
Expand All @@ -27,6 +28,7 @@ import CustomerReferenceField from '../visitors/CustomerReferenceField';
import AddressField from '../visitors/AddressField';
import MobileGrid from './MobileGrid';
import { Customer } from '../types';
import { usePageTitle } from '../usePageTitle';

const ListActions = () => (
<TopToolbar>
Expand All @@ -36,13 +38,25 @@ const ListActions = () => (
</TopToolbar>
);

const OrdersTitle = () => {
const title = useDefaultTitle();
const pageTitle = usePageTitle({ view: 'list' });
return (
<>
<title>{`${title} - ${pageTitle}`}</title>
<span>{pageTitle}</span>
</>
);
};

const OrderList = () => (
<List
filterDefaultValues={{ status: 'ordered' }}
sort={{ field: 'date', order: 'DESC' }}
perPage={25}
filters={orderFilters}
actions={<ListActions />}
title={<OrdersTitle />}
>
<TabbedDatagrid />
</List>
Expand Down
23 changes: 21 additions & 2 deletions examples/demo/src/products/ProductCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import * as React from 'react';
import { Create, TabbedForm, TextInput, required } from 'react-admin';
import {
Create,
TabbedForm,
TextInput,
required,
useDefaultTitle,
} from 'react-admin';
import { ProductEditDetails } from './ProductEditDetails';
import { usePageTitle } from '../usePageTitle';
const RichTextInput = React.lazy(() =>
import('ra-input-rich-text').then(module => ({
default: module.RichTextInput,
}))
);

const ProductTitle = () => {
const appTitle = useDefaultTitle();
const pageTitle = usePageTitle({ view: 'create' });

return (
<>
<title>{`${appTitle} - ${pageTitle}`}</title>
<span>{pageTitle}</span>
</>
);
};

const ProductCreate = () => (
<Create>
<Create title={<ProductTitle />}>
<TabbedForm defaultValues={{ sales: 0 }}>
<TabbedForm.Tab
label="resources.products.tabs.image"
Expand Down
18 changes: 17 additions & 1 deletion examples/demo/src/products/ProductEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
TextField,
TextInput,
useRecordContext,
useDefaultTitle,
useTranslate,
useGetResourceLabel,
} from 'react-admin';
import PhotoCameraIcon from '@mui/icons-material/PhotoCamera';
import AspectRatioIcon from '@mui/icons-material/AspectRatio';
Expand All @@ -32,8 +35,21 @@ const RichTextInput = React.lazy(() =>
);

const ProductTitle = () => {
const appTitle = useDefaultTitle();
const translate = useTranslate();
const record = useRecordContext<Product>();
return record ? <span>Poster "{record.reference}"</span> : null;
const getResourceLabel = useGetResourceLabel();

const pageTitle = translate('ra.page.edit', {
name: getResourceLabel('products', 1),
recordRepresentation: `"${record?.reference}"`,
});
return record ? (
<>
<title>{`${appTitle} - ${pageTitle}`}</title>
<span>{pageTitle}</span>
</>
) : null;
};

const ProductEdit = () => (
Expand Down
Loading

0 comments on commit 40bda09

Please sign in to comment.