Skip to content

Commit

Permalink
Merge pull request #9919 from marmelab/react-19
Browse files Browse the repository at this point in the history
Prepare for react 19
  • Loading branch information
slax57 authored Jun 17, 2024
2 parents c445440 + 1ad36bd commit e2fa925
Show file tree
Hide file tree
Showing 47 changed files with 2,968 additions and 3,169 deletions.
51 changes: 32 additions & 19 deletions .storybook/main.js → .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
const fs = require('fs');
const path = require('path');
import { StorybookConfig } from '@storybook/react-webpack5';
import fs from 'fs';
import path, { dirname, join } from 'path';

const packages = fs.readdirSync(path.resolve(__dirname, '../packages'));
module.exports = {
stories: [`../packages/${process.env.ONLY || '**'}/**/*.stories.@(tsx)`],

const config: StorybookConfig = {
stories: [
path.resolve(
__dirname,
`../packages/${process.env.ONLY || '**'}/**/*.stories.@(tsx)`
),
],
addons: [
{
name: '@storybook/addon-storysource',
options: {
loaderOptions: {
injectStoryParameters: false,
parser: 'typescript',
},
},
},
'@storybook/addon-webpack5-compiler-babel',
'@storybook/addon-actions',
'@storybook/addon-controls',
],
typescript: {
check: false,
checkOptions: {},
reactDocgen: 'none',
reactDocgen: false,
},
babel: async options => {
const { plugins = [] } = options;
Expand Down Expand Up @@ -54,6 +53,16 @@ module.exports = {
};
},
webpackFinal: async (config, { configType }) => {
config.module?.rules?.push({
test: /\.stories\.tsx?$/,
use: [
{
loader: require.resolve('@storybook/source-loader'),
options: { parser: 'typescript' },
},
],
enforce: 'pre',
});
return {
...config,
resolve: {
Expand All @@ -72,10 +81,14 @@ module.exports = {
};
},
framework: {
name: '@storybook/react-webpack5',
name: getAbsolutePath('@storybook/react-webpack5'),
options: {},
},
docs: {
autodocs: false,
},
docs: {},
};

export default config;

function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, 'package.json')));
}
18 changes: 9 additions & 9 deletions examples/crm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
"type": "module",
"dependencies": {
"@hello-pangea/dnd": "^16.3.0",
"@mui/icons-material": "^5.15.15",
"@mui/material": "^5.15.15",
"@mui/icons-material": "^5.15.20",
"@mui/material": "^5.15.20",
"@nivo/bar": "^0.80.0",
"@nivo/core": "^0.80.0",
"clsx": "^2.1.1",
"date-fns": "^3.6.0",
"faker": "~5.4.0",
"lodash": "~4.17.5",
"ra-data-fakerest": "^5.0.0-alpha.0",
"react": "^18.0.0",
"react": "^18.3.1",
"react-admin": "^5.0.0-alpha.0",
"react-dom": "^18.2.0",
"react-dom": "^18.3.1",
"react-error-boundary": "^4.0.3",
"react-router": "^6.22.0",
"react-router-dom": "^6.22.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.1",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@types/faker": "^5.1.7",
"@types/jest": "^29.5.2",
"@types/lodash": "~4.14.168",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.16",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.2.1",
"rollup-plugin-visualizer": "^5.12.0",
"rollup-preserve-directives": "^1.1.1",
Expand Down
83 changes: 42 additions & 41 deletions examples/crm/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import react from '@vitejs/plugin-react';
import { visualizer } from 'rollup-plugin-visualizer';
import preserveDirectives from 'rollup-preserve-directives';


// https://vitejs.dev/config/
export default defineConfig(async () => {
const packages = fs.readdirSync(path.resolve(__dirname, '../../packages'));
Expand All @@ -23,44 +22,46 @@ export default defineConfig(async () => {
);
}
return {
plugins: [
react(),
visualizer({
open: process.env.NODE_ENV !== 'CI',
filename: './dist/stats.html',
}),
],
define: {
'process.env': process.env,
},
server: {
port: 8000,
open: true,
},
base: './',
esbuild: {
keepNames: true,
},
build: {
sourcemap: true,
rollupOptions: {
plugins: [preserveDirectives()],
}
},
resolve: {
preserveSymlinks: true,
alias: [
// allow profiling in production
{ find: /^react-dom$/, replacement: 'react-dom/profiling' },
{
find: 'scheduler/tracing',
replacement: 'scheduler/tracing-profiling',
},
// we need to manually follow the symlinks for local packages to allow deep HMR
...Object.keys(aliases).map(packageName => ({
find: packageName,
replacement: aliases[packageName],
})),
plugins: [
react(),
visualizer({
open: process.env.NODE_ENV !== 'CI',
filename: './dist/stats.html',
}),
],
},
}});
define: {
'process.env': process.env,
},
server: {
port: 8000,
open: true,
},
base: './',
esbuild: {
keepNames: true,
},
build: {
sourcemap: true,
rollupOptions: {
plugins: [preserveDirectives()],
},
},
resolve: {
preserveSymlinks: true,
alias: [
// FIXME: doesn't work with react 19
// allow profiling in production
// { find: /^react-dom$/, replacement: 'react-dom/profiling' },
// {
// find: 'scheduler/tracing',
// replacement: 'scheduler/tracing-profiling',
// },
// we need to manually follow the symlinks for local packages to allow deep HMR
...Object.keys(aliases).map(packageName => ({
find: packageName,
replacement: aliases[packageName],
})),
],
},
};
});
12 changes: 6 additions & 6 deletions examples/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"type": "module",
"dependencies": {
"@apollo/client": "^3.3.19",
"@mui/icons-material": "^5.15.15",
"@mui/material": "^5.15.15",
"@mui/icons-material": "^5.15.20",
"@mui/material": "^5.15.20",
"@types/recharts": "^1.8.10",
"@vitejs/plugin-react": "^2.2.0",
"clsx": "^2.1.1",
Expand All @@ -26,9 +26,9 @@
"ra-input-rich-text": "^5.0.0-alpha.0",
"ra-language-english": "^5.0.0-alpha.0",
"ra-language-french": "^5.0.0-alpha.0",
"react": "^18.0.0",
"react": "^18.3.1",
"react-admin": "^5.0.0-alpha.0",
"react-dom": "^18.2.0",
"react-dom": "^18.3.1",
"react-router": "^6.22.0",
"react-router-dom": "^6.22.0",
"recharts": "^2.1.15"
Expand All @@ -43,8 +43,8 @@
"@types/fetch-mock": "^7.3.2",
"@types/jest": "^29.5.2",
"@types/node": "^20.10.7",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.16",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.2.1",
"rewire": "^5.0.0",
"rollup-plugin-visualizer": "^5.12.0",
Expand Down
7 changes: 6 additions & 1 deletion examples/demo/src/dashboard/PendingReviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ const PendingReviews = () => {
</ListItemAvatar>

<ListItemText
primary={<StarRatingField record={record} />}
primary={
<StarRatingField
record={record}
source="rating"
/>
}
secondary={record.comment}
sx={{
overflowY: 'hidden',
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/invoices/InvoiceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const InvoiceList = () => (
<TextField source="id" />
<DateField source="date" />
<ReferenceField source="customer_id" reference="customers">
<FullNameField />
<FullNameField source="last_name" />
</ReferenceField>
<ReferenceField
source="customer_id"
Expand Down
1 change: 1 addition & 0 deletions examples/demo/src/orders/MobileGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const MobileGrid = () => {
/>
<CardContent sx={{ pt: 0 }}>
<CustomerReferenceField
source="customer_id"
sx={{ display: 'block', mb: 1 }}
/>
<Typography variant="body2" gutterBottom>
Expand Down
6 changes: 3 additions & 3 deletions examples/demo/src/orders/OrderList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const TabbedDatagrid = () => {
>
<DateField source="date" showTime />
<TextField source="reference" />
<CustomerReferenceField />
<CustomerReferenceField source="customer_id" />
<ReferenceField
source="customer_id"
reference="customers"
Expand Down Expand Up @@ -182,7 +182,7 @@ const TabbedDatagrid = () => {
>
<DateField source="date" showTime />
<TextField source="reference" />
<CustomerReferenceField />
<CustomerReferenceField source="customer_id" />
<ReferenceField
source="customer_id"
reference="customers"
Expand Down Expand Up @@ -237,7 +237,7 @@ const TabbedDatagrid = () => {
>
<DateField source="date" showTime />
<TextField source="reference" />
<CustomerReferenceField />
<CustomerReferenceField source="customer_id" />
<ReferenceField
source="customer_id"
reference="customers"
Expand Down
7 changes: 5 additions & 2 deletions examples/demo/src/products/ProductEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ const ProductEdit = () => (
}}
>
<DateField source="date" />
<CustomerReferenceField />
<StarRatingField />
<CustomerReferenceField source="customer_id" />
<StarRatingField
label="resources.reviews.fields.rating"
source="rating"
/>
<TextField source="comment" />
<TextField source="status" />
<EditButton />
Expand Down
8 changes: 4 additions & 4 deletions examples/demo/src/reviews/ReviewEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const ReviewEdit = ({ id, onCancel }: ReviewEditProps) => {
>
<Grid container rowSpacing={1} mb={1}>
<Grid item xs={6}>
<Labeled>
<CustomerReferenceField />
<Labeled source="customer_id">
<CustomerReferenceField source="customer_id" />
</Labeled>
</Grid>
<Grid item xs={6}>
Expand All @@ -55,8 +55,8 @@ const ReviewEdit = ({ id, onCancel }: ReviewEditProps) => {
</Labeled>
</Grid>
<Grid item xs={6}>
<Labeled>
<StarRatingField />
<Labeled label="resources.reviews.fields.rating">
<StarRatingField source="rating" />
</Labeled>
</Grid>
</Grid>
Expand Down
8 changes: 6 additions & 2 deletions examples/demo/src/reviews/ReviewListDesktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ const ReviewListDesktop = ({ selectedRow }: ReviewListDesktopProps) => (
}}
>
<DateField source="date" />
<CustomerReferenceField link={false} />
<CustomerReferenceField source="customer_id" link={false} />
<ProductReferenceField source="product_id" link={false} />
<StarRatingField size="small" />
<StarRatingField
size="small"
label="resources.reviews.fields.rating"
source="rating"
/>
<TextField source="comment" />
<TextField source="status" />
</DatagridConfigurable>
Expand Down
5 changes: 0 additions & 5 deletions examples/demo/src/reviews/StarRatingField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,4 @@ const StarRatingField = ({ size = 'large' }: FieldProps & OwnProps) => {
);
};

StarRatingField.defaultProps = {
label: 'resources.reviews.fields.rating',
source: 'rating',
};

export default StarRatingField;
2 changes: 1 addition & 1 deletion examples/demo/src/visitors/Aside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ const Review = () => {
{record.comment}
</Typography>
<Typography variant="body2" color="textSecondary">
<StarRatingField />
<StarRatingField source="rating" />
</Typography>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/visitors/CustomerLinkField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CustomerLinkField = (_: FieldProps<Customer>) => {
}
return (
<Link to={`/customers/${record.id}`}>
<FullNameField />
<FullNameField source="last_name" />
</Link>
);
};
Expand Down
6 changes: 1 addition & 5 deletions examples/demo/src/visitors/CustomerReferenceField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ const CustomerReferenceField = (
}
) => (
<ReferenceField source="customer_id" reference="customers" {...props}>
<FullNameField />
<FullNameField source="last_name" />
</ReferenceField>
);

CustomerReferenceField.defaultProps = {
source: 'customer_id',
};

export default CustomerReferenceField;
Loading

0 comments on commit e2fa925

Please sign in to comment.