@applica-software-guru/react-admin 1.5.333 → 1.5.334
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/dist/components/Layout/Sidebar/Drawer.d.ts +4 -2
- package/dist/components/Layout/Sidebar/Drawer.d.ts.map +1 -1
- package/dist/components/ra-inputs/BooleanInput.d.ts.map +1 -1
- package/dist/components/ra-lists/FilterSidebar/ActiveFiltersChips.d.ts.map +1 -1
- package/dist/components/ra-lists/FilterSidebar/FilterSidebar.d.ts +4 -2
- package/dist/components/ra-lists/FilterSidebar/FilterSidebar.d.ts.map +1 -1
- package/dist/components/ra-lists/FilterSidebar/FilterSidebarContext.d.ts.map +1 -1
- package/dist/components/ra-lists/ListToolbar.d.ts.map +1 -1
- package/dist/components/ra-lists/ListView.d.ts.map +1 -1
- package/dist/react-admin.cjs.js +32 -32
- package/dist/react-admin.cjs.js.gz +0 -0
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +2401 -2388
- package/dist/react-admin.es.js.gz +0 -0
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +32 -32
- package/dist/react-admin.umd.js.gz +0 -0
- package/dist/react-admin.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Layout/Sidebar/Drawer.tsx +26 -21
- package/src/components/ra-inputs/BooleanInput.tsx +1 -0
- package/src/components/ra-lists/FilterSidebar/ActiveFiltersChips.tsx +7 -1
- package/src/components/ra-lists/FilterSidebar/FilterSidebar.tsx +30 -36
- package/src/components/ra-lists/FilterSidebar/FilterSidebarContext.tsx +5 -1
- package/src/components/ra-lists/FilterSidebar/SaveFiltersDialog.tsx +1 -1
- package/src/components/ra-lists/ListToolbar.tsx +11 -5
- package/src/components/ra-lists/ListView.tsx +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import React, { useCallback, useMemo } from 'react';
|
|
1
2
|
import { Drawer as MUIDrawer, SxProps, useMediaQuery, useTheme } from '@mui/material';
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
import { isFunction } from 'lodash';
|
|
4
3
|
|
|
5
4
|
type DrawerProps = {
|
|
6
5
|
sx?: SxProps;
|
|
@@ -9,6 +8,7 @@ type DrawerProps = {
|
|
|
9
8
|
children: React.ReactNode;
|
|
10
9
|
open?: boolean;
|
|
11
10
|
onClose?: () => void;
|
|
11
|
+
keepMounted?: boolean;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -20,30 +20,32 @@ type DrawerProps = {
|
|
|
20
20
|
*/
|
|
21
21
|
const MAX_WIDTH = 444;
|
|
22
22
|
|
|
23
|
-
function
|
|
24
|
-
const { sx, anchor = 'right', variant = 'temporary', open = false, onClose } = props;
|
|
23
|
+
function DrawerComp(props: DrawerProps) {
|
|
24
|
+
const { sx, anchor = 'right', variant = 'temporary', open = false, onClose, keepMounted = false } = props;
|
|
25
25
|
const theme = useTheme();
|
|
26
26
|
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
27
27
|
const anchorPosition = isMobile ? 'bottom' : anchor;
|
|
28
28
|
const handleClose = useCallback(() => {
|
|
29
|
-
if (
|
|
30
|
-
onClose();
|
|
31
|
-
}
|
|
29
|
+
if (onClose) onClose();
|
|
32
30
|
}, [onClose]);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
31
|
+
|
|
32
|
+
const sxProps = useMemo(
|
|
33
|
+
() => ({
|
|
34
|
+
backgroundImage: 'none',
|
|
35
|
+
boxShadow: '-10px 4px 42px 0px rgba(0, 0, 0, 0.25)',
|
|
36
|
+
width: {
|
|
37
|
+
sm: '30%'
|
|
38
|
+
},
|
|
39
|
+
maxWidth: {
|
|
40
|
+
sm: MAX_WIDTH
|
|
41
|
+
},
|
|
42
|
+
[theme.breakpoints.down('sm')]: {
|
|
43
|
+
width: '100% !important',
|
|
44
|
+
maxWidth: '100% !important'
|
|
45
|
+
}
|
|
46
|
+
}),
|
|
47
|
+
[theme.breakpoints]
|
|
48
|
+
);
|
|
47
49
|
|
|
48
50
|
return (
|
|
49
51
|
<MUIDrawer
|
|
@@ -53,10 +55,13 @@ function Drawer(props: DrawerProps) {
|
|
|
53
55
|
open={open}
|
|
54
56
|
PaperProps={{ sx: { ...sxProps, ...sx } }}
|
|
55
57
|
variant={variant}
|
|
58
|
+
keepMounted={keepMounted}
|
|
56
59
|
>
|
|
57
60
|
{props.children}
|
|
58
61
|
</MUIDrawer>
|
|
59
62
|
);
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
const Drawer = React.memo(DrawerComp);
|
|
66
|
+
|
|
62
67
|
export { Drawer };
|
|
@@ -21,6 +21,7 @@ function BooleanInput({ ...props }: BooleanInputProps): JSX.Element {
|
|
|
21
21
|
},
|
|
22
22
|
'& .MuiSwitch-root': {
|
|
23
23
|
margin: '0 !important',
|
|
24
|
+
marginRight: `6px !important`,
|
|
24
25
|
// @ts-ignore
|
|
25
26
|
marginTop: props.display === 'legend' ? 0 : `${theme.spacing(1)} !important`
|
|
26
27
|
}
|
|
@@ -96,7 +96,13 @@ function ActiveFiltersChips(): ReactElement | null {
|
|
|
96
96
|
const translate = useTranslate();
|
|
97
97
|
|
|
98
98
|
return filterValues && !isEmpty(filterValues) ? (
|
|
99
|
-
<Stack
|
|
99
|
+
<Stack
|
|
100
|
+
sx={{ backgroundColor: theme.palette.background.paper }}
|
|
101
|
+
flexDirection={isMobile ? 'column' : 'row'}
|
|
102
|
+
alignItems={'baseline'}
|
|
103
|
+
gap={2}
|
|
104
|
+
p={isMobile ? 2 : 0}
|
|
105
|
+
>
|
|
100
106
|
<Typography variant="h6" color="secondary" whiteSpace={'nowrap'}>
|
|
101
107
|
{translate('ra.title.active_filters')}
|
|
102
108
|
</Typography>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { LoadingButton } from '@/components/@extended';
|
|
2
2
|
import { Box, Button, Stack } from '@mui/material';
|
|
3
3
|
import { useListContext, useResourceContext, useTranslate } from 'ra-core';
|
|
4
|
-
import React, { ReactElement, useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
import React, { ReactElement, memo, useCallback, useEffect, useMemo, useState } from 'react';
|
|
5
5
|
import { FilterContext, getFilterFormValues } from 'react-admin';
|
|
6
6
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
7
7
|
import { ReloadOutlined } from '@ant-design/icons';
|
|
8
|
-
import {
|
|
8
|
+
import { isEqual, isNull, isUndefined } from 'lodash';
|
|
9
9
|
import { SavedFiltersList } from './SavedFiltersList';
|
|
10
10
|
import { useListViewContext } from '@/components/ra-lists';
|
|
11
11
|
import { Sidebar } from '@/components/Layout/Sidebar';
|
|
@@ -41,30 +41,31 @@ function FiltersInput(props: FiltersInputProps): ReactElement {
|
|
|
41
41
|
|
|
42
42
|
interface FilterSidebarProps {
|
|
43
43
|
filters?: ReactElement | ReactElement[];
|
|
44
|
+
keepMounted?: boolean;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
function
|
|
47
|
-
const { filters } = props;
|
|
47
|
+
function FilterSidebarComp(props: FilterSidebarProps): ReactElement {
|
|
48
|
+
const { filters, keepMounted = false } = props;
|
|
48
49
|
const [loading, setLoading] = useState(false);
|
|
49
50
|
const { setSidebarOpen, sidebarOpen } = useListViewContext();
|
|
50
51
|
const { filterValues, setFilters } = useListContext();
|
|
51
52
|
const translate = useTranslate();
|
|
52
|
-
|
|
53
|
-
defaultValues: filterValues
|
|
54
|
-
});
|
|
55
|
-
const { handleSubmit, getValues, reset, watch } = form;
|
|
56
|
-
const watchValues = watch();
|
|
53
|
+
|
|
57
54
|
// values containes all the filters values and the default ones
|
|
58
55
|
const values = useMemo(() => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return values;
|
|
56
|
+
if (!filters) return {};
|
|
57
|
+
return (Array.isArray(filters) ? filters : [filters]).reduce((acc, filter) => {
|
|
58
|
+
acc[filter.props.source] = filterValues?.[filter.props.source] ?? '';
|
|
59
|
+
return acc;
|
|
60
|
+
}, {} as Record<string, any>);
|
|
66
61
|
}, [filters, filterValues]);
|
|
67
62
|
|
|
63
|
+
const form = useForm({
|
|
64
|
+
defaultValues: filterValues,
|
|
65
|
+
values
|
|
66
|
+
});
|
|
67
|
+
const { handleSubmit, getValues, reset } = form;
|
|
68
|
+
|
|
68
69
|
// Reapply filterValues when the URL changes or a user removes a filter
|
|
69
70
|
useEffect(() => {
|
|
70
71
|
const newValues = getFilterFormValues(getValues(), filterValues);
|
|
@@ -80,13 +81,18 @@ function FilterSidebar(props: FilterSidebarProps): ReactElement {
|
|
|
80
81
|
}, [JSON.stringify(filterValues), filterValues, getValues, reset]);
|
|
81
82
|
|
|
82
83
|
const closeSidebar = useCallback(() => {
|
|
83
|
-
if (
|
|
84
|
-
setSidebarOpen(false);
|
|
85
|
-
}
|
|
84
|
+
if (setSidebarOpen) setSidebarOpen(false);
|
|
86
85
|
}, [setSidebarOpen]);
|
|
87
86
|
|
|
88
87
|
const onSubmit = React.useCallback(
|
|
89
88
|
(data: any) => {
|
|
89
|
+
// remove all empty || null || undefined values
|
|
90
|
+
Object.keys(data).forEach((key) => {
|
|
91
|
+
// if data[key] is empty, null or undefined, delete it. Some values can be boolean. So please handle it
|
|
92
|
+
if (isNull(data[key]) || isUndefined(data[key]) || data[key] === '') {
|
|
93
|
+
delete data[key];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
90
96
|
// @ts-ignore
|
|
91
97
|
setFilters(data);
|
|
92
98
|
closeSidebar();
|
|
@@ -103,19 +109,11 @@ function FilterSidebar(props: FilterSidebarProps): ReactElement {
|
|
|
103
109
|
const toggleLoading = useCallback(() => {
|
|
104
110
|
setLoading((prev) => !prev);
|
|
105
111
|
resetAllFields();
|
|
106
|
-
setTimeout(() =>
|
|
107
|
-
setLoading(false);
|
|
108
|
-
}, 1000);
|
|
112
|
+
setTimeout(() => setLoading(false), 1000);
|
|
109
113
|
}, [resetAllFields]);
|
|
110
114
|
|
|
111
|
-
const isApplyDisabled = useMemo(() => {
|
|
112
|
-
const currentFormValues = getValues();
|
|
113
|
-
return isEmpty(values) || isEqual(currentFormValues, values);
|
|
114
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
115
|
-
}, [values, getValues, watchValues]);
|
|
116
|
-
|
|
117
115
|
return (
|
|
118
|
-
<Sidebar sx={{ height: '100%' }} open={sidebarOpen} onClose={closeSidebar}>
|
|
116
|
+
<Sidebar sx={{ height: '100%' }} open={sidebarOpen} onClose={closeSidebar} keepMounted={keepMounted}>
|
|
119
117
|
<Sidebar.Header>
|
|
120
118
|
<Sidebar.HeaderText primary={translate('ra.action.add_filter')} />
|
|
121
119
|
<Sidebar.HeaderAction>
|
|
@@ -146,13 +144,7 @@ function FilterSidebar(props: FilterSidebarProps): ReactElement {
|
|
|
146
144
|
>
|
|
147
145
|
{translate('ra.action.close')}
|
|
148
146
|
</Button>
|
|
149
|
-
<Button
|
|
150
|
-
fullWidth
|
|
151
|
-
disabled={isApplyDisabled}
|
|
152
|
-
variant="contained"
|
|
153
|
-
color="primary"
|
|
154
|
-
onClick={handleSubmit(onSubmit)}
|
|
155
|
-
>
|
|
147
|
+
<Button fullWidth variant="contained" color="primary" onClick={handleSubmit(onSubmit)}>
|
|
156
148
|
{translate('ra.action.apply_filters')}
|
|
157
149
|
</Button>
|
|
158
150
|
</Stack>
|
|
@@ -161,4 +153,6 @@ function FilterSidebar(props: FilterSidebarProps): ReactElement {
|
|
|
161
153
|
);
|
|
162
154
|
}
|
|
163
155
|
|
|
156
|
+
const FilterSidebar = memo(FilterSidebarComp);
|
|
157
|
+
|
|
164
158
|
export { FilterSidebar };
|
|
@@ -24,7 +24,10 @@ function useGetChipValue({ source, value }: ChipItemProps): JSX.Element | null {
|
|
|
24
24
|
const resource = useResourceContext();
|
|
25
25
|
|
|
26
26
|
const currentSourceFilter = useMemo(() => {
|
|
27
|
-
return filters.find(
|
|
27
|
+
return filters.find(
|
|
28
|
+
(filter) =>
|
|
29
|
+
React.isValidElement(filter) && (filter.props?.source === source || source?.includes(filter.props?.source))
|
|
30
|
+
);
|
|
28
31
|
}, [filters, source]);
|
|
29
32
|
const currentSourceFilterProps = useMemo(
|
|
30
33
|
() => (React.isValidElement(currentSourceFilter) ? currentSourceFilter.props : {}),
|
|
@@ -39,6 +42,7 @@ function useGetChipValue({ source, value }: ChipItemProps): JSX.Element | null {
|
|
|
39
42
|
|
|
40
43
|
const chipProps = {
|
|
41
44
|
...currentSourceFilterProps,
|
|
45
|
+
specificSource: source,
|
|
42
46
|
record: { [source]: value },
|
|
43
47
|
value,
|
|
44
48
|
resource
|
|
@@ -36,7 +36,7 @@ function SelectedFiltersList(): JSX.Element {
|
|
|
36
36
|
<Typography variant="h6" fontWeight={'bold'} color={'secondary'}>
|
|
37
37
|
{translate('ra.title.selected_filters')}
|
|
38
38
|
</Typography>
|
|
39
|
-
<List sx={{ bgcolor: 'background.paper', pt: 0 }}>
|
|
39
|
+
<List sx={{ bgcolor: 'background.paper', pt: 0, overflowY: 'auto', maxHeight: 400 }}>
|
|
40
40
|
{filterValues
|
|
41
41
|
? Object.entries(filterValues).map(([key, value]) => {
|
|
42
42
|
const lastEntry = Object.entries(filterValues).pop();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { ReactElement, memo } from 'react';
|
|
2
2
|
import { styled, useTheme } from '@mui/material/styles';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import { Divider, ToolbarProps, useMediaQuery } from '@mui/material';
|
|
4
|
+
import { Box, Divider, ToolbarProps, useMediaQuery } from '@mui/material';
|
|
5
5
|
import { Exporter, useListContext } from 'ra-core';
|
|
6
6
|
import { FilterContext, FilterForm } from 'react-admin';
|
|
7
7
|
import { ActiveFiltersChips, FilterSidebarContext } from './FilterSidebar';
|
|
@@ -13,16 +13,22 @@ interface ListToolbarPropsExtended extends ListToolbarProps {
|
|
|
13
13
|
|
|
14
14
|
function ListToolbarComp(props: ListToolbarPropsExtended): ReactElement | null {
|
|
15
15
|
const { filters, actions, className, hasFilterSidebar, ...rest } = props;
|
|
16
|
-
const theme = useTheme();
|
|
16
|
+
const theme = useTheme() as any;
|
|
17
17
|
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
18
18
|
const Actions = actions ? React.cloneElement(actions, { ...rest, ...actions.props }) : null;
|
|
19
|
-
const { filterValues } = useListContext();
|
|
19
|
+
const { filterValues, data, isLoading } = useListContext();
|
|
20
|
+
const shouldRenderEmptyList = !isLoading && data && data.length === 0;
|
|
20
21
|
|
|
21
22
|
return Array.isArray(filters) ? (
|
|
22
23
|
<FilterSidebarContext.Provider value={{ hasFilterSidebar }}>
|
|
23
24
|
<FilterContext.Provider value={filters}>
|
|
24
25
|
{isMobile && hasFilterSidebar ? (
|
|
25
|
-
<
|
|
26
|
+
<Box
|
|
27
|
+
sx={{
|
|
28
|
+
border: isMobile ? (shouldRenderEmptyList ? '1px solid' : 0) : 0,
|
|
29
|
+
borderColor: theme.palette.mode === 'dark' ? theme.palette.divider : theme.palette.grey.A800
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
26
32
|
{Actions}
|
|
27
33
|
{!isEmpty(filterValues) ? (
|
|
28
34
|
<div>
|
|
@@ -30,7 +36,7 @@ function ListToolbarComp(props: ListToolbarPropsExtended): ReactElement | null {
|
|
|
30
36
|
<ActiveFiltersChips />
|
|
31
37
|
</div>
|
|
32
38
|
) : null}
|
|
33
|
-
</
|
|
39
|
+
</Box>
|
|
34
40
|
) : (
|
|
35
41
|
<Root className={className}>
|
|
36
42
|
{hasFilterSidebar ? <ActiveFiltersChips /> : <FilterForm />}
|
|
@@ -123,7 +123,8 @@ function ListView<RecordType extends RaRecord = any>(props: ListViewProps): Reac
|
|
|
123
123
|
? {
|
|
124
124
|
'& .MuiPaper-root': {
|
|
125
125
|
backgroundColor: 'transparent',
|
|
126
|
-
border: 'none'
|
|
126
|
+
border: 'none',
|
|
127
|
+
borderRadius: 0
|
|
127
128
|
},
|
|
128
129
|
'& .RaList-actions': {
|
|
129
130
|
border: '1px solid',
|