Skip to content
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

[Demo] Fix ReviewList scrolls to top when editing a review #9958

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
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
80 changes: 49 additions & 31 deletions examples/demo/src/reviews/ReviewListDesktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DateField,
Identifier,
TextField,
useCreatePath,
} from 'react-admin';

import ProductReferenceField from '../products/ProductReferenceField';
Expand All @@ -14,6 +15,7 @@ import rowSx from './rowSx';

import BulkAcceptButton from './BulkAcceptButton';
import BulkRejectButton from './BulkRejectButton';
import { useNavigate } from 'react-router';

export interface ReviewListDesktopProps {
selectedRow?: Identifier;
Expand All @@ -27,36 +29,52 @@ const ReviewsBulkActionButtons = () => (
</>
);

const ReviewListDesktop = ({ selectedRow }: ReviewListDesktopProps) => (
<DatagridConfigurable
rowClick="edit"
rowSx={rowSx(selectedRow)}
bulkActionButtons={<ReviewsBulkActionButtons />}
sx={{
'& .RaDatagrid-thead': {
borderLeftColor: 'transparent',
borderLeftWidth: 5,
borderLeftStyle: 'solid',
},
'& .column-comment': {
maxWidth: '18em',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
},
}}
>
<DateField source="date" />
<CustomerReferenceField source="customer_id" link={false} />
<ProductReferenceField source="product_id" link={false} />
<StarRatingField
size="small"
label="resources.reviews.fields.rating"
source="rating"
/>
<TextField source="comment" />
<TextField source="status" />
</DatagridConfigurable>
);
const ReviewListDesktop = ({ selectedRow }: ReviewListDesktopProps) => {
const navigate = useNavigate();
const createPath = useCreatePath();
return (
<DatagridConfigurable
rowClick={(id, resource) => {
// As we display the edit view in a drawer, we don't the default rowClick behavior that will scroll to the top of the page
// So we navigate manually without specifying the _scrollToTop state
navigate(
createPath({
resource,
id,
type: 'edit',
})
);
// Disable the default rowClick behavior
return false;
}}
rowSx={rowSx(selectedRow)}
bulkActionButtons={<ReviewsBulkActionButtons />}
sx={{
'& .RaDatagrid-thead': {
borderLeftColor: 'transparent',
borderLeftWidth: 5,
borderLeftStyle: 'solid',
},
'& .column-comment': {
maxWidth: '18em',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
},
}}
>
<DateField source="date" />
<CustomerReferenceField source="customer_id" link={false} />
<ProductReferenceField source="product_id" link={false} />
<StarRatingField
size="small"
label="resources.reviews.fields.rating"
source="rating"
/>
<TextField source="comment" />
<TextField source="status" />
</DatagridConfigurable>
);
};

export default ReviewListDesktop;
Loading