@applica-software-guru/react-admin 1.5.316 → 1.5.318

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -107,5 +107,5 @@
107
107
  "type": "module",
108
108
  "types": "dist/index.d.ts",
109
109
  "typings": "dist/index.d.ts",
110
- "version": "1.5.316"
110
+ "version": "1.5.318"
111
111
  }
@@ -1,10 +1,10 @@
1
1
  import { BulkActionsToolbar } from '@/components/ra-lists/BulkActionsToolbar';
2
2
  import { DatagridContextProvider } from '@/components/ra-lists/Datagrid/DatagridContextProvider';
3
- import { Table } from '@mui/material';
3
+ import { Table, Typography } from '@mui/material';
4
4
  import clsx from 'clsx';
5
5
  import difference from 'lodash/difference';
6
6
  import union from 'lodash/union';
7
- import { Identifier, sanitizeListRestProps, useListContext } from 'ra-core';
7
+ import { Identifier, sanitizeListRestProps, useListContext, useTranslate } from 'ra-core';
8
8
  import { FC, cloneElement, createElement, isValidElement, useCallback, useEffect, useMemo, useRef } from 'react';
9
9
  import * as React from 'react';
10
10
  import {
@@ -14,10 +14,11 @@ import {
14
14
  DatagridHeader,
15
15
  DatagridLoading,
16
16
  DatagridRoot,
17
- ListNoResults,
18
17
  PureDatagridBody,
19
18
  DatagridProps as RaDatagridProps
20
19
  } from 'react-admin';
20
+ import { Empty } from '@/components/ra-lists/Empty';
21
+ import { DropboxOutlined } from '@ant-design/icons';
21
22
 
22
23
  const defaultBulkActionButtons = <BulkDeleteButton />;
23
24
 
@@ -106,7 +107,7 @@ const Datagrid = React.forwardRef((props, ref) => {
106
107
  header = DatagridHeader,
107
108
  children,
108
109
  className,
109
- empty = DefaultEmpty,
110
+ empty,
110
111
  expand,
111
112
  bulkActionsToolbar = false,
112
113
  bulkActionButtons = defaultBulkActionButtons,
@@ -123,6 +124,7 @@ const Datagrid = React.forwardRef((props, ref) => {
123
124
  ...rest
124
125
  } = props;
125
126
 
127
+ const translate = useTranslate();
126
128
  const { sort, data, isLoading, onSelect, onToggleItem, selectedIds, setSort, total } = useListContext(props);
127
129
  const hasBulkActions = !!bulkActionButtons !== false;
128
130
  const contextValue = useMemo(() => ({ isRowExpandable, expandSingle }), [isRowExpandable, expandSingle]);
@@ -165,6 +167,17 @@ const Datagrid = React.forwardRef((props, ref) => {
165
167
  [data, isRowSelectable, onSelect, onToggleItem, selectedIds]
166
168
  );
167
169
 
170
+ const DefaultEmpty = (
171
+ <Empty
172
+ icon={<DropboxOutlined style={{ fontSize: '7em', marginBottom: '16px' }} />}
173
+ title={
174
+ <Typography variant="subtitle1" style={{ color: 'inherit' }} gutterBottom>
175
+ {translate('ra.navigation.no_results')}
176
+ </Typography>
177
+ }
178
+ />
179
+ );
180
+
168
181
  if (isLoading === true) {
169
182
  return (
170
183
  <DatagridLoading
@@ -183,11 +196,7 @@ const Datagrid = React.forwardRef((props, ref) => {
183
196
  * the Datagrid displays the empty component.
184
197
  */
185
198
  if (data == null || data.length === 0 || total === 0) {
186
- if (empty) {
187
- return empty;
188
- }
189
-
190
- return null;
199
+ return empty || DefaultEmpty;
191
200
  }
192
201
 
193
202
  /**
@@ -307,7 +316,5 @@ function sanitizeRestProps(props) {
307
316
  }
308
317
  Datagrid.displayName = 'Datagrid';
309
318
 
310
- const DefaultEmpty = <ListNoResults />;
311
-
312
319
  export { Datagrid };
313
320
  export type { DatagridProps };
@@ -1,9 +1,10 @@
1
1
  /* eslint-disable filenames/match-regex */
2
2
  import { DropboxOutlined } from '@ant-design/icons';
3
- import { Typography } from '@mui/material';
4
- import { styled } from '@mui/material/styles';
3
+ import { Box, Typography } from '@mui/material';
4
+ import { SxProps, styled } from '@mui/material/styles';
5
5
  import { useGetResourceLabel, useResourceContext, useResourceDefinition, useTranslate } from 'ra-core';
6
6
  import * as React from 'react';
7
+ import { CreateButton } from '@/components/ra-buttons';
7
8
 
8
9
  type EmptyProps = {
9
10
  /**
@@ -23,6 +24,28 @@ type EmptyProps = {
23
24
  **/
24
25
  className?: string;
25
26
  hasCreate?: boolean;
27
+ /**
28
+ * The icon of the empty page.
29
+ *
30
+ * @example <DropboxOutlined />
31
+ * @example <DropboxOutlined style={{ fontSize: '9em' }} />
32
+ **/
33
+ icon?: React.ReactNode;
34
+ /**
35
+ * The title of the empty page.
36
+ *
37
+ * @example 'No data available'
38
+ * @example translate('ra_text')
39
+ **/
40
+ title?: string | React.ReactNode;
41
+ /**
42
+ * The subtitle of the empty page.
43
+ *
44
+ * @example 'Please add some data'
45
+ * @example translate('ra_text')
46
+ **/
47
+ subtitle?: string | React.ReactNode;
48
+ sx?: SxProps;
26
49
  };
27
50
 
28
51
  const StyledToolbar = styled('div')(({ theme }) => ({
@@ -36,7 +59,16 @@ const StyledToolbar = styled('div')(({ theme }) => ({
36
59
  * @example
37
60
  * <List empty={<Empty actions={<Button label="Add" onClick={add} />} />} />
38
61
  */
39
- function Empty({ actions, className, hasCreate: _hasCreate, ...props }: EmptyProps): JSX.Element {
62
+ function Empty({
63
+ actions,
64
+ className,
65
+ hasCreate: _hasCreate,
66
+ icon = <DropboxOutlined className={EmptyClasses.icon} />,
67
+ title,
68
+ subtitle,
69
+ sx,
70
+ ...props
71
+ }: EmptyProps): JSX.Element {
40
72
  const { hasCreate } = useResourceDefinition(props);
41
73
  const canCreate = _hasCreate ?? hasCreate;
42
74
  const resource = useResourceContext(props);
@@ -53,24 +85,25 @@ function Empty({ actions, className, hasCreate: _hasCreate, ...props }: EmptyPro
53
85
  const inviteMessage = translate('ra.page.invite');
54
86
 
55
87
  return (
56
- <Root className={className}>
57
- <div className={EmptyClasses.message}>
58
- <DropboxOutlined className={EmptyClasses.icon} />
88
+ <Root className={className} sx={sx}>
89
+ <Box className={EmptyClasses.message}>
90
+ {icon}
59
91
  <Typography variant="h4" paragraph>
60
- {translate(`resources.${resource}.empty`, {
61
- _: emptyMessage
62
- })}
92
+ {title ||
93
+ translate(`resources.${resource}.empty`, {
94
+ _: emptyMessage
95
+ })}
63
96
  </Typography>
64
97
  {canCreate ? (
65
98
  <Typography variant="body1">
66
- {translate(`resources.${resource}.invite`, {
67
- _: inviteMessage
68
- })}
99
+ {subtitle ||
100
+ translate(`resources.${resource}.invite`, {
101
+ _: inviteMessage
102
+ })}
69
103
  </Typography>
70
104
  ) : null}
71
- </div>
72
-
73
- <StyledToolbar className={EmptyClasses.toolbar}>{actions}</StyledToolbar>
105
+ </Box>
106
+ <StyledToolbar className={EmptyClasses.toolbar}>{(canCreate ? <CreateButton /> : null) || actions}</StyledToolbar>
74
107
  </Root>
75
108
  );
76
109
  }
@@ -97,12 +130,12 @@ const Root = styled('span', {
97
130
  },
98
131
 
99
132
  [`& .${EmptyClasses.icon}`]: {
100
- fontSize: '9em'
133
+ fontSize: '9em',
134
+ marginBottom: '16px'
101
135
  },
102
136
 
103
137
  [`& .${EmptyClasses.toolbar}`]: {
104
- textAlign: 'center',
105
- marginTop: '2em'
138
+ textAlign: 'center'
106
139
  }
107
140
  }));
108
141
 
@@ -10,13 +10,13 @@ import * as React from 'react';
10
10
  import {
11
11
  ListActions as DefaultActions,
12
12
  Pagination as DefaultPagination,
13
- Empty,
14
13
  SavedQueriesListClasses,
15
14
  Title
16
15
  } from 'react-admin';
17
16
  import { ListToolbar } from './ListToolbar';
18
17
  import { FilterSidebar } from './FilterSidebar';
19
18
  import { MainCard } from '@/components/MainCard';
19
+ import { Empty } from '@/components/ra-lists/Empty';
20
20
 
21
21
  const defaultActions = <DefaultActions />;
22
22
  const defaultPagination = <DefaultPagination />;