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

[RFR] Rename isLoading to loading everywhere #3644

Merged
merged 1 commit into from
Sep 3, 2019
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
6 changes: 4 additions & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,11 @@ export default (type, params) => {
}
```

## ReferenceInputController isLoading injected props renamed to loading
## isLoading injected props renamed to loading

When using custom component with ReferenceInputController, you should rename the component `isLoading` prop to `loading`.
Much of the react-admin controller components that fetch data used to inject an `isLoading` boolean prop, set to true whenever a dataProvider call was pending. this prop was renamed to `loading` everywhere. Use the search and replace feature of your IDE to rename that prop.

For instance:

```diff
- <ReferenceInputController {...props}>
Expand Down
10 changes: 5 additions & 5 deletions examples/demo/src/layout/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const Login = ({ location }) => {
const translate = useTranslate();
const classes = useStyles();
const dispatch = useDispatch();
const isLoading = useSelector(state => state.admin.loading > 0);
const loading = useSelector(state => state.admin.loading > 0);

const login = auth =>
dispatch(
Expand Down Expand Up @@ -116,7 +116,7 @@ const Login = ({ location }) => {
name="username"
component={renderInput}
label={translate('ra.auth.username')}
disabled={isLoading}
disabled={loading}
/>
</div>
<div className={classes.input}>
Expand All @@ -125,7 +125,7 @@ const Login = ({ location }) => {
component={renderInput}
label={translate('ra.auth.password')}
type="password"
disabled={isLoading}
disabled={loading}
/>
</div>
</div>
Expand All @@ -134,11 +134,11 @@ const Login = ({ location }) => {
variant="contained"
type="submit"
color="primary"
disabled={isLoading}
disabled={loading}
className={classes.button}
fullWidth
>
{isLoading && (
{loading && (
<CircularProgress
size={25}
thickness={2}
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/src/reviews/ReviewListMobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const useStyles = makeStyles({
},
});

const ReviewMobileList = ({ basePath, data, ids, isLoading, total }) => {
const ReviewMobileList = ({ basePath, data, ids, loading, total }) => {
const classes = useStyles();
return (
(isLoading || total > 0) && (
(loading || total > 0) && (
<List className={classes.root}>
{ids.map(id => (
<Link
Expand Down
11 changes: 2 additions & 9 deletions examples/simple/src/comments/CommentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,10 @@ const exporter = (records, fetchRelatedRecords) =>
});
});

const CommentPagination = ({
isLoading,
ids,
page,
perPage,
total,
setPage,
}) => {
const CommentPagination = ({ loading, ids, page, perPage, total, setPage }) => {
const translate = useTranslate();
const nbPages = Math.ceil(total / perPage) || 1;
if (!isLoading && (total === 0 || (ids && !ids.length))) {
if (!loading && (total === 0 || (ids && !ids.length))) {
return <PaginationLimit total={total} page={page} ids={ids} />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const defaultFilter = {};
*
* @example
*
* const { isLoading, referenceRecord, resourceLinkPath } = useReferenceManyFieldController({
* const { loaded, referenceRecord, resourceLinkPath } = useReferenceManyFieldController({
* resource
* reference: 'users',
* record: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('<ReferenceArrayInputController />', () => {
translate: x => `*${x}*`,
};

it('should set isLoading to true as long as there are no references fetched and no selected references', () => {
it('should set loading to true as long as there are no references fetched and no selected references', () => {
const children = jest.fn();
shallow(
<ReferenceArrayInputController
Expand All @@ -32,10 +32,10 @@ describe('<ReferenceArrayInputController />', () => {
</ReferenceArrayInputController>
);

assert.equal(children.mock.calls[0][0].isLoading, true);
assert.equal(children.mock.calls[0][0].loading, true);
});

it('should set isLoading to true as long as there are no references fetched and there are no data found for the references already selected', () => {
it('should set loading to true as long as there are no references fetched and there are no data found for the references already selected', () => {
const children = jest.fn();
shallow(
<ReferenceArrayInputController
Expand All @@ -49,10 +49,10 @@ describe('<ReferenceArrayInputController />', () => {
{children}
</ReferenceArrayInputController>
);
assert.equal(children.mock.calls[0][0].isLoading, true);
assert.equal(children.mock.calls[0][0].loading, true);
});

it('should set isLoading to false if the references are being searched but data from at least one selected reference was found', () => {
it('should set loading to false if the references are being searched but data from at least one selected reference was found', () => {
const children = jest.fn();
shallow(
<ReferenceArrayInputController
Expand All @@ -66,7 +66,7 @@ describe('<ReferenceArrayInputController />', () => {
{children}
</ReferenceArrayInputController>
);
assert.equal(children.mock.calls[0][0].isLoading, false);
assert.equal(children.mock.calls[0][0].loading, false);
assert.deepEqual(children.mock.calls[0][0].choices, [{ id: 1 }]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const defaultReferenceSource = (resource: string, source: string) =>
interface ChildrenFuncParams {
choices: Record[];
error?: string;
isLoading: boolean;
loading: boolean;
onChange: (value: any) => void;
setFilter: (filter: any) => void;
setPagination: (pagination: Pagination) => void;
Expand Down Expand Up @@ -288,7 +288,7 @@ export class UnconnectedReferenceArrayInputController extends Component<
return children({
choices: dataStatus.choices,
error: dataStatus.error,
isLoading: dataStatus.waiting,
loading: dataStatus.waiting,
onChange,
setFilter: this.debouncedSetFilter,
setPagination: this.setPagination,
Expand Down
12 changes: 7 additions & 5 deletions packages/ra-core/src/controller/useCreateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { useTranslate } from '../i18n';
import { useVersion } from '.';

export interface CreateControllerProps {
isLoading: boolean;
isSaving: boolean;
loading: boolean;
loaded: boolean;
saving: boolean;
defaultTitle: string;
save: (record: Partial<Record>, redirect: RedirectionSideEffect) => void;
resource: string;
Expand Down Expand Up @@ -77,7 +78,7 @@ const useCreateController = (props: CreateProps): CreateControllerProps => {
const recordToUse = getRecord(location, record);
const version = useVersion();

const [create, { loading: isSaving }] = useCreate(resource);
const [create, { loading: saving }] = useCreate(resource);

const save = useCallback(
(
Expand Down Expand Up @@ -131,8 +132,9 @@ const useCreateController = (props: CreateProps): CreateControllerProps => {
});

return {
isLoading: false,
isSaving,
loading: false,
loaded: true,
saving,
defaultTitle,
save,
resource,
Expand Down
14 changes: 8 additions & 6 deletions packages/ra-core/src/controller/useEditController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export interface EditProps {
}

export interface EditControllerProps {
isLoading: boolean;
isSaving: boolean;
loading: boolean;
loaded: boolean;
saving: boolean;
defaultTitle: string;
save: (data: Record, redirect?: RedirectionSideEffect) => void;
resource: string;
Expand Down Expand Up @@ -62,7 +63,7 @@ const useEditController = (props: EditProps): EditControllerProps => {
const redirect = useRedirect();
const refresh = useRefresh();
const version = useVersion();
const { data: record, loading } = useGetOne(resource, id, {
const { data: record, loading, loaded } = useGetOne(resource, id, {
version, // used to force reload
onFailure: () => {
notify('ra.notification.item_doesnt_exist', 'warning');
Expand All @@ -81,7 +82,7 @@ const useEditController = (props: EditProps): EditControllerProps => {
record,
});

const [update, { loading: isSaving }] = useUpdate(
const [update, { loading: saving }] = useUpdate(
resource,
id,
{}, // set by the caller
Expand Down Expand Up @@ -119,8 +120,9 @@ const useEditController = (props: EditProps): EditControllerProps => {
);

return {
isLoading: loading,
isSaving,
loading,
loaded,
saving,
defaultTitle,
save,
resource,
Expand Down
6 changes: 3 additions & 3 deletions packages/ra-core/src/controller/useListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface ListControllerProps {
hasCreate: boolean;
hideFilter: (filterName: string) => void;
ids: Identifier[];
isLoading: boolean;
loading: boolean;
loaded: boolean;
onSelect: (ids: Identifier[]) => void;
onToggleItem: (id: Identifier) => void;
Expand Down Expand Up @@ -174,7 +174,7 @@ const useListController = (props: ListProps): ListControllerProps => {
filterValues: query.filterValues,
hasCreate,
ids,
isLoading: loading,
loading,
loaded,
onSelect: selectionModifiers.select,
onToggleItem: selectionModifiers.toggle,
Expand Down Expand Up @@ -204,7 +204,7 @@ export const injectedProps = [
'hasCreate',
'hideFilter',
'ids',
'isLoading',
'loading',
'loaded',
'onSelect',
'onToggleItem',
Expand Down
8 changes: 5 additions & 3 deletions packages/ra-core/src/controller/useShowController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export interface ShowProps {
}

export interface ShowControllerProps {
isLoading: boolean;
loading: boolean;
loaded: boolean;
defaultTitle: string;
resource: string;
basePath: string;
Expand Down Expand Up @@ -53,7 +54,7 @@ const useShowController = (props: ShowProps): ShowControllerProps => {
const redirect = useRedirect();
const refresh = useRefresh();
const version = useVersion();
const { data: record, loading } = useGetOne(resource, id, {
const { data: record, loading, loaded } = useGetOne(resource, id, {
version, // used to force reload
onFailure: () => {
notify('ra.notification.item_doesnt_exist', 'warning');
Expand All @@ -73,7 +74,8 @@ const useShowController = (props: ShowProps): ShowControllerProps => {
});

return {
isLoading: loading,
loading,
loaded,
defaultTitle,
resource,
basePath,
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-tree-ui-materialui/src/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const sanitizeRestProps = ({
hasBulkActions,
hasCreate,
hideFilter,
isLoading,
loading,
loaded,
loadedOnce,
perPage,
Expand Down
12 changes: 5 additions & 7 deletions packages/ra-ui-materialui/src/auth/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ const Input = ({

const LoginForm: SFC<Props> = ({ redirectTo }) => {
const dispatch = useDispatch();
const isLoading = useSelector(
(state: ReduxState) => state.admin.loading > 0
);
const loading = useSelector((state: ReduxState) => state.admin.loading > 0);
const translate = useTranslate();
const classes = useStyles({});

Expand Down Expand Up @@ -85,7 +83,7 @@ const LoginForm: SFC<Props> = ({ redirectTo }) => {
name="username"
component={Input}
label={translate('ra.auth.username')}
disabled={isLoading}
disabled={loading}
/>
</div>
<div className={classes.input}>
Expand All @@ -95,7 +93,7 @@ const LoginForm: SFC<Props> = ({ redirectTo }) => {
component={Input}
label={translate('ra.auth.password')}
type="password"
disabled={isLoading}
disabled={loading}
/>
</div>
</div>
Expand All @@ -104,10 +102,10 @@ const LoginForm: SFC<Props> = ({ redirectTo }) => {
variant="contained"
type="submit"
color="primary"
disabled={submitting || isLoading}
disabled={submitting || loading}
className={classes.button}
>
{isLoading && (
{loading && (
<CircularProgress
className={classes.icon}
size={18}
Expand Down
5 changes: 3 additions & 2 deletions packages/ra-ui-materialui/src/detail/Create.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ const sanitizeRestProps = ({
children,
className,
crudCreate,
isLoading,
isSaving,
loading,
loaded,
saving,
resource,
title,
hasCreate,
Expand Down
5 changes: 3 additions & 2 deletions packages/ra-ui-materialui/src/detail/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ const sanitizeRestProps = ({
hasList,
hasShow,
id,
isLoading,
isSaving,
loading,
loaded,
saving,
resource,
title,
version,
Expand Down
7 changes: 4 additions & 3 deletions packages/ra-ui-materialui/src/detail/Show.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ const sanitizeRestProps = ({
className,
id,
data,
isLoading,
loading,
loaded,
resource,
hasCreate,
hasEdit,
Expand All @@ -114,7 +115,6 @@ export const ShowView = ({
defaultTitle,
hasEdit,
hasList,
isLoading,
record,
resource,
title,
Expand Down Expand Up @@ -184,7 +184,8 @@ ShowView.propTypes = {
defaultTitle: PropTypes.any,
hasEdit: PropTypes.bool,
hasList: PropTypes.bool,
isLoading: PropTypes.bool,
loading: PropTypes.bool,
loaded: PropTypes.bool,
record: PropTypes.object,
resource: PropTypes.string,
title: PropTypes.any,
Expand Down
Loading