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

feat(mui): add a loading spinner to <Show> component #6131

Closed
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions .changeset/lucky-balloons-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@refinedev/mui": minor
---

feat(mui): add loading spinner to `<Show>` component [#5668](https://github.com/refinedev/refine/issues/5668)

This change introduces a loading spinner to the `<Show>` component in the `@refinedev/mui` package. The spinner provides a visual indication that data is being loaded, improving the user experience by giving clear feedback during loading states.

Resolves [#5668](https://github.com/refinedev/refine/issues/5668)
8 changes: 8 additions & 0 deletions packages/mui/src/components/crud/show/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ const renderShow = (
describe("Show", () => {
crudShowTests.bind(this)(Show);

it("should display loading spinner when isLoading is true", async () => {
const { queryByRole } = renderShow(<Show isLoading />);

await waitFor(() => {
expect(queryByRole("progressbar")).not.toBeNull();
});
});

it("depending on the accessControlProvider it should get the buttons successfully", async () => {
const { getByText, getAllByText, queryByTestId } = renderShow(
<Show
Expand Down
13 changes: 12 additions & 1 deletion packages/mui/src/components/crud/show/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from "@components";
import type { ShowProps } from "../types";
import { RefinePageHeaderClassNames } from "@refinedev/ui-types";
import { CircularProgress } from "@mui/material";
BatuhanW marked this conversation as resolved.
Show resolved Hide resolved

/**
* `<Show>` provides us a layout for displaying the page.
Expand Down Expand Up @@ -212,7 +213,17 @@ export const Show: React.FC<ShowProps> = ({
}
{...(headerProps ?? {})}
/>
<CardContent {...(contentProps ?? {})}>{children}</CardContent>
<CardContent {...(contentProps ?? {})}>
{isLoading ? (
<Box display="flex" justifyContent="center">
<CircularProgress
sx={{ border: (theme) => theme.palette.primary.main }}
/>
</Box>
) : (
children
)}
</CardContent>
<CardActions sx={{ padding: "16px" }} {...(footerButtonProps ?? {})}>
{footerButtons
? typeof footerButtons === "function"
Expand Down