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

[Doc] Fix remaining isLoading should be renamed to isPending #10218

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -1167,8 +1167,8 @@ This is often used by APIs to return facets, aggregations, statistics, or other
// },
// }
const Facets = () => {
const { isLoading, error, meta } = useListContext();
if (isLoading || error) return null;
const { isPending, error, meta } = useListContext();
if (isPending || error) return null;
return (
<Box>
<Typography variant="subtitle2">
Expand Down
4 changes: 2 additions & 2 deletions docs/useListController.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ import { useState } from 'react';
import { useListController } from 'react-admin';

const OfficeList = () => {
const { filterValues, setFilters, data, isLoading } = useListController({ resource: 'offices' });
const { filterValues, setFilters, data, isPending } = useListController({ resource: 'offices' });
const [formValues, setFormValues] = useState(filterValues);

const handleChange = (event) => {
Expand All @@ -285,7 +285,7 @@ const OfficeList = () => {
setFilters(filterFormValues);
};

if (isLoading) return <div>Loading...</div>;
if (isPending) return <div>Loading...</div>;

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/src/customRouteNoLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import * as React from 'react';
import { useGetList } from 'react-admin';

const CustomRouteNoLayout = ({ title = 'Posts' }) => {
const { isLoading, total } = useGetList('posts', {
const { isPending, total } = useGetList('posts', {
pagination: { page: 0, perPage: 10 },
sort: { field: 'id', order: 'ASC' },
});

return (
<div>
<h1>{title}</h1>
{isLoading ? (
{isPending ? (
<p className="app-loader">Loading...</p>
) : (
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export const Meta = ({
const MyReferenceField = (props: { children: React.ReactNode }) => {
const context = useReferenceFieldContext();

if (context.isLoading) {
if (context.isPending) {
return <p>Loading...</p>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const SelectInput = (
Partial<Pick<InputProps, 'source'>> &
ChoicesProps & { source?: string }
) => {
const { allChoices, error, isLoading, source } = useChoicesContext(props);
const { allChoices, error, isPending, source } = useChoicesContext(props);
const { getChoiceValue, getChoiceText } = useChoices(props);
const { field } = useInput({ ...props, source });

Expand All @@ -147,7 +147,7 @@ const SelectInput = (
<div style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}>
<label htmlFor={field.name}>{props.label || field.name}</label>
<select id={field.name} {...field}>
{isLoading && <option value="">Loading...</option>}
{isPending && <option value="">Loading...</option>}
{allChoices.map(choice => (
<option
key={getChoiceValue(choice)}
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-core/src/controller/list/useList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const useList = <RecordType extends RaRecord = any>(
// We do all the data processing (filtering, sorting, paginating) client-side
useEffect(
() => {
if (isLoading || !data) return;
if (isPending || !data) return;
let tempData = data;

// 1. filter
Expand Down Expand Up @@ -236,7 +236,7 @@ export const useList = <RecordType extends RaRecord = any>(
// eslint-disable-next-line react-hooks/exhaustive-deps
JSON.stringify(data),
filterValues,
isLoading,
isPending,
page,
perPage,
setFinalItems,
Expand Down
12 changes: 6 additions & 6 deletions packages/ra-ui-materialui/src/list/List.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ describe('<List />', () => {

it('should render an invite when the list is empty', async () => {
const Dummy = () => {
const { isLoading } = useListContext();
return <div>{isLoading ? 'loading' : 'dummy'}</div>;
const { isPending } = useListContext();
return <div>{isPending ? 'loading' : 'dummy'}</div>;
};
const dataProvider = {
getList: jest.fn(() => Promise.resolve({ data: [], total: 0 })),
Expand All @@ -129,8 +129,8 @@ describe('<List />', () => {

it('should not render an invite when the list is empty with an empty prop set to false', async () => {
const Dummy = () => {
const { isLoading } = useListContext();
return <div>{isLoading ? 'loading' : 'dummy'}</div>;
const { isPending } = useListContext();
return <div>{isPending ? 'loading' : 'dummy'}</div>;
};
const dataProvider = {
getList: jest.fn(() => Promise.resolve({ data: [], total: 0 })),
Expand Down Expand Up @@ -179,8 +179,8 @@ describe('<List />', () => {

it('should not render an invite when a filter is active', async () => {
const Dummy = () => {
const { isLoading } = useListContext();
return <div>{isLoading ? 'loading' : 'dummy'}</div>;
const { isPending } = useListContext();
return <div>{isPending ? 'loading' : 'dummy'}</div>;
};
const dataProvider = {
getList: jest.fn(() => Promise.resolve({ data: [], total: 0 })),
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/list/List.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ export const ErrorInFetch = () => (
);

const Facets = () => {
const { isLoading, error, meta } = useListContext();
if (isLoading || error) return null;
const { isPending, error, meta } = useListContext();
if (isPending || error) return null;
return (
<Box order={-1} width={200} mt={7}>
<Typography variant="subtitle2" gutterBottom>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export const ColumnStyles = () => (
const sort = { field: 'id', order: 'DESC' } as SortPayload;

const MyCustomList = () => {
const { data, total, isLoading } = useGetList('books', {
const { data, total, isPending } = useGetList('books', {
pagination: { page: 1, perPage: 10 },
sort: sort,
});
Expand All @@ -343,7 +343,7 @@ const MyCustomList = () => {
<Datagrid
data={data}
total={total}
isLoading={isLoading}
isPending={isPending}
sort={sort}
bulkActionButtons={false}
>
Expand All @@ -354,11 +354,11 @@ const MyCustomList = () => {
};

const MyCustomListInteractive = () => {
const { data, isLoading } = useGetList('books', {
const { data, isPending } = useGetList('books', {
pagination: { page: 1, perPage: 10 },
sort,
});
const listContext = useList({ data, isLoading });
const listContext = useList({ data, isPending });

return (
<ListContextProvider value={listContext}>
Expand Down
Loading