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

Fix: notifications with type 'warning' should use the warning color from the MUI palette #8519

Merged
merged 7 commits into from
Dec 20, 2022
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
8 changes: 4 additions & 4 deletions docs/Actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ const ApproveButton = () => {
},
onError: (error) => {
// failure side effects go here
notify(`Comment approval error: ${error.message}`, { type: 'warning' });
notify(`Comment approval error: ${error.message}`, { type: 'error' });
},
}
);
Expand Down Expand Up @@ -410,7 +410,7 @@ const ApproveButton = () => {
notify('Comment approved');
},
onError: (error) => {
notify(`Comment approval error: ${error.message}`, { type: 'warning' });
notify(`Comment approval error: ${error.message}`, { type: 'error' });
},
}
);
Expand Down Expand Up @@ -462,7 +462,7 @@ const ApproveButton = () => {
- notify('Comment approved');
+ notify('Comment approved', { undoable: true });
},
onError: (error) => notify(`Error: ${error.message}`, { type: 'warning' }),
onError: (error) => notify(`Error: ${error.message}`, { type: 'error' }),
}
);
return <Button label="Approve" onClick={() => approve()} disabled={isLoading} />;
Expand Down Expand Up @@ -504,7 +504,7 @@ const ApproveButton = () => {
redirect('/comments');
})
.catch((e) => {
notify('Error: comment not approved', { type: 'warning' })
notify('Error: comment not approved', { type: 'error' })
})
.finally(() => {
setLoading(false);
Expand Down
2 changes: 1 addition & 1 deletion docs/Create.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ The default `onError` function is:

```jsx
(error) => {
notify(typeof error === 'string' ? error : error.message || 'ra.notification.http_error', { type: 'warning' });
notify(typeof error === 'string' ? error : error.message || 'ra.notification.http_error', { type: 'error' });
}
```

Expand Down
6 changes: 3 additions & 3 deletions docs/Datagrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ const CustomResetViewsButton = () => {
notify('Posts updated');
unselectAll();
},
onError: error => notify('Error: posts not updated', { type: 'warning' }),
onError: error => notify('Error: posts not updated', { type: 'error' }),
}
);

Expand Down Expand Up @@ -283,7 +283,7 @@ const CustomResetViewsButton = () => {
notify('Posts updated');
unselectAll();
},
onError: error => notify('Error: posts not updated', { type: 'warning' }),
onError: error => notify('Error: posts not updated', { type: 'error' }),
}
);
const handleClick = () => setOpen(true);
Expand Down Expand Up @@ -349,7 +349,7 @@ const CustomResetViewsButton = () => {
+ notify('Posts updated', { undoable: true }); // the last argument forces the display of 'undo' in the notification
unselectAll();
},
onError: error => notify('Error: posts not updated', { type: 'warning' }),
onError: error => notify('Error: posts not updated', { type: 'error' }),
+ mutationMode: 'undoable'
}
);
Expand Down
2 changes: 1 addition & 1 deletion docs/Edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ The default `onError` function is:

```jsx
(error) => {
notify(typeof error === 'string' ? error : error.message || 'ra.notification.http_error', { type: 'warning' });
notify(typeof error === 'string' ? error : error.message || 'ra.notification.http_error', { type: 'error' });
if (mutationMode === 'undoable' || mutationMode === 'pessimistic') {
refresh();
}
Expand Down
2 changes: 1 addition & 1 deletion docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ const PostList = () => {
const redirect = useRedirect();

const onError = (error) => {
notify(`Could not load list: ${error.message}`, { type: 'warning' });
notify(`Could not load list: ${error.message}`, { type: 'error' });
redirect('/dashboard');
};

Expand Down
4 changes: 2 additions & 2 deletions docs/Show.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const PostShow = props => {
const redirect = useRedirect();

const onError = (error) => {
notify(`Could not load post: ${error.message}`, { type: 'warning' });
notify(`Could not load post: ${error.message}`, { type: 'error' });
redirect('/posts');
refresh();
};
Expand All @@ -205,7 +205,7 @@ The default `onError` function is:

```jsx
(error) => {
notify('ra.notification.item_doesnt_exist', { type: 'warning' });
notify('ra.notification.item_doesnt_exist', { type: 'error' });
redirect('list', resource);
refresh();
}
Expand Down
4 changes: 2 additions & 2 deletions docs/ShowBase.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const PostShow = props => {
const redirect = useRedirect();

const onError = (error) => {
notify(`Could not load post: ${error.message}`, { type: 'warning' });
notify(`Could not load post: ${error.message}`, { type: 'error' });
redirect('/posts');
refresh();
};
Expand All @@ -101,7 +101,7 @@ The default `onError` function is:

```jsx
(error) => {
notify('ra.notification.item_doesnt_exist', { type: 'warning' });
notify('ra.notification.item_doesnt_exist', { type: 'error' });
redirect('list', resource);
refresh();
}
Expand Down
2 changes: 2 additions & 0 deletions docs/useNotify.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ The callback takes 2 arguments:
Here are more examples of `useNotify` calls:

```js
// notify an error
notify(`This is an error`, { type: 'error' });
// notify a warning
notify(`This is a warning`, { type: 'warning' });
// pass translation arguments
Expand Down
2 changes: 1 addition & 1 deletion docs/useRefresh.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const DeleteCommentButton = () => {
notify('Comment deleted');
},
onError: (error) => {
notify(`Comment deletion error: ${error.message}`, { type: 'warning' });
notify(`Comment deletion error: ${error.message}`, { type: 'error' });
},
}
);
Expand Down
4 changes: 2 additions & 2 deletions docs/useShowController.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const PostShow = props => {
const redirect = useRedirect();

const onError = (error) => {
notify(`Could not load post: ${error.message}`, { type: 'warning' });
notify(`Could not load post: ${error.message}`, { type: 'error' });
redirect('/posts');
refresh();
};
Expand Down Expand Up @@ -111,7 +111,7 @@ The default `onError` function is:

```js
(error) => {
notify('ra.notification.item_doesnt_exist', { type: 'warning' });
notify('ra.notification.item_doesnt_exist', { type: 'error' });
redirect('list', resource);
refresh();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/layout/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Login = () => {
? 'ra.auth.sign_in_error'
: error.message,
{
type: 'warning',
type: 'error',
messageArgs: {
_:
typeof error === 'string'
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/reviews/AcceptButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const AcceptButton = () => {
},
onError: () => {
notify('resources.reviews.notification.approved_error', {
type: 'warning',
type: 'error',
});
},
}
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/reviews/BulkAcceptButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const BulkAcceptButton = () => {
},
onError: () => {
notify('resources.reviews.notification.approved_error', {
type: 'warning',
type: 'error',
});
},
}
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/reviews/BulkRejectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const BulkRejectButton = () => {
},
onError: () => {
notify('resources.reviews.notification.approved_error', {
type: 'warning',
type: 'error',
});
},
}
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/reviews/RejectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const RejectButton = () => {
},
onError: () => {
notify('resources.reviews.notification.rejected_error', {
type: 'warning',
type: 'error',
});
},
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/src/posts/ResetViewsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ResetViewsButton = ({ resource, selectedIds }) => {
typeof error === 'string'
? error
: error.message || 'ra.notification.http_error',
{ type: 'warning' }
{ type: 'error' }
),
mutationMode: 'undoable',
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/auth/Authenticated.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('<Authenticated>', () => {
expect(notificationsSpy).toEqual([
{
message: 'ra.auth.auth_check_error',
type: 'warning',
type: 'error',
notificationOptions: {},
},
]);
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/auth/useAuthenticated.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('useAuthenticated', () => {
expect(notificationsSpy).toEqual([
{
message: 'ra.auth.auth_check_error',
type: 'warning',
type: 'error',
notificationOptions: {},
},
]);
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/auth/useCheckAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const useCheckAuth = (): CheckAuth => {
!shouldSkipNotify &&
notify(
getErrorMessage(error, 'ra.auth.auth_check_error'),
{ type: 'warning' }
{ type: 'error' }
);
}
throw error;
Expand Down
6 changes: 3 additions & 3 deletions packages/ra-core/src/auth/useLogoutIfAccessDenied.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let timer;
* dataProvider.getOne('secret', { id: 123 })
* .catch(error => {
* logoutIfAccessDenied(error);
* notify('server error', 'warning');
* notify('server error', { type: 'error' });
* })
* }, []);
* // ...
Expand Down Expand Up @@ -84,15 +84,15 @@ const useLogoutIfAccessDenied = (): LogoutIfAccessDenied => {
e,
'ra.notification.logged_out'
),
{ type: 'warning' }
{ type: 'error' }
);
} else {
notify(
getErrorMessage(
e,
'ra.notification.not_authorized'
),
{ type: 'warning' }
{ type: 'error' }
);
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const useDeleteWithConfirmController = <RecordType extends RaRecord = any>(
? error
: error.message || 'ra.notification.http_error',
{
type: 'warning',
type: 'error',
messageArgs: {
_:
typeof error === 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const useDeleteWithUndoController = <RecordType extends RaRecord = any>(
? error
: error.message || 'ra.notification.http_error',
{
type: 'warning',
type: 'error',
messageArgs: {
_:
typeof error === 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('useCreateController', () => {
expect(notificationsSpy).toEqual([
{
message: 'not good',
type: 'warning',
type: 'error',
notificationOptions: { messageArgs: { _: 'not good' } },
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const useCreateController = <
: error.message ||
'ra.notification.http_error',
{
type: 'warning',
type: 'error',
messageArgs: {
_:
typeof error === 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ describe('useEditController', () => {
expect(notificationsSpy).toEqual([
{
message: 'not good',
type: 'warning',
type: 'error',
notificationOptions: { messageArgs: { _: 'not good' } },
},
]);
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-core/src/controller/edit/useEditController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const useEditController = <
{
onError: () => {
notify('ra.notification.item_doesnt_exist', {
type: 'warning',
type: 'error',
});
redirect('list', resource);
refresh();
Expand Down Expand Up @@ -181,7 +181,7 @@ export const useEditController = <
: error.message ||
'ra.notification.http_error',
{
type: 'warning',
type: 'error',
messageArgs: {
_:
typeof error === 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const useReferenceArrayFieldController = (
? error
: error.message || 'ra.notification.http_error',
{
type: 'warning',
type: 'error',
messageArgs: {
_:
typeof error === 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const useReferenceManyFieldController = (
? error
: error.message || 'ra.notification.http_error',
{
type: 'warning',
type: 'error',
messageArgs: {
_:
typeof error === 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const useReferenceOneFieldController = <
? error
: error.message || 'ra.notification.http_error',
{
type: 'warning',
type: 'error',
messageArgs: {
_:
typeof error === 'string'
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/list/useListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const useListController = <RecordType extends RaRecord = any>(
retry: false,
onError: error =>
notify(error?.message || 'ra.notification.http_error', {
type: 'warning',
type: 'error',
messageArgs: {
_: error?.message,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/show/useShowController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const useShowController = <RecordType extends RaRecord = any>(
{
onError: () => {
notify('ra.notification.item_doesnt_exist', {
type: 'warning',
type: 'error',
});
redirect('list', resource);
refresh();
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/form/useNotifyIsFormInvalid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const useNotifyIsFormInvalid = (control?: Control) => {
submitCountRef.current = submitCount;

if (Object.keys(errors).length > 0) {
notify('ra.message.invalid_form', { type: 'warning' });
notify('ra.message.invalid_form', { type: 'error' });
}
}
}, [errors, submitCount, notify]);
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/i18n/I18nContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const I18nContextProvider = ({
})
.catch(error => {
setInitialized(true);
notify('ra.notification.i18n_error', { type: 'warning' });
notify('ra.notification.i18n_error', { type: 'error' });
console.error(error);
});
} else {
Expand Down
Loading