@admin-layout/gluestack-ui-mobile 12.2.4-alpha.0 → 12.2.4-alpha.103
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/CHANGELOG.md +104 -8
- package/lib/components/ErrorBounday.js.map +1 -1
- package/lib/components/Fallback.js +11 -11
- package/lib/components/Fallback.js.map +1 -1
- package/lib/components/InputToolBar/InputToolBar.d.ts +8 -0
- package/lib/components/InputToolBar/InputToolBar.js +219 -0
- package/lib/components/InputToolBar/InputToolBar.js.map +1 -0
- package/lib/components/InputToolBar/defaults.d.ts +14 -0
- package/lib/components/InputToolBar/defaults.js +60 -0
- package/lib/components/InputToolBar/defaults.js.map +1 -0
- package/lib/components/InputToolBar/index.d.ts +4 -0
- package/lib/components/InputToolBar/index.js +3 -0
- package/lib/components/InputToolBar/index.js.map +1 -0
- package/lib/components/InputToolBar/types.d.ts +153 -0
- package/lib/components/InputToolBar/types.js +2 -0
- package/lib/components/InputToolBar/types.js.map +1 -0
- package/lib/components/Layout/components/BasicLayout.js +1 -5
- package/lib/components/Layout/components/BasicLayout.js.map +1 -1
- package/lib/components/Layout/components/BottomTabBar.js +2 -2
- package/lib/components/Layout/components/BottomTabBar.js.map +1 -1
- package/lib/components/Layout/components/Sample.js.map +1 -1
- package/lib/components/Layout/components/SideBar.js +5 -6
- package/lib/components/Layout/components/SideBar.js.map +1 -1
- package/lib/components/NavigationComponent.js +1 -1
- package/lib/components/NavigationComponent.js.map +1 -1
- package/lib/components/ToastAlert.d.ts +1 -1
- package/lib/components/ToastAlert.js +2 -2
- package/lib/components/ToastAlert.js.map +1 -1
- package/lib/components/UnAuthenticatedComponent.js +1 -1
- package/lib/components/UnAuthenticatedComponent.js.map +1 -1
- package/lib/components/WithConfiguration.d.ts +1 -6
- package/lib/components/WithConfiguration.js +1 -4
- package/lib/components/WithConfiguration.js.map +1 -1
- package/lib/components/WithPermission.d.ts +1 -11
- package/lib/components/WithPermission.js +0 -8
- package/lib/components/WithPermission.js.map +1 -1
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/lib/components/index.js.map +1 -1
- package/lib/components/usePermissionAutoFetch.d.ts +4 -56
- package/lib/components/usePermissionAutoFetch.js +7 -20
- package/lib/components/usePermissionAutoFetch.js.map +1 -1
- package/lib/components/useSetting.d.ts +11 -6
- package/lib/components/useSetting.js +10 -75
- package/lib/components/useSetting.js.map +1 -1
- package/lib/containers/layout/BasicLayout.js +3 -3
- package/lib/containers/layout/BasicLayout.js.map +1 -1
- package/lib/containers/layout/DrawerBottomNavigationConfig.d.ts +63 -303
- package/lib/containers/layout/DrawerConfig.d.ts +42 -206
- package/lib/containers/layout/ProLayout.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/tailwind-base-config.d.ts +2 -1
- package/lib/utils/generateMobileNavigations.js +36 -30
- package/lib/utils/generateMobileNavigations.js.map +1 -1
- package/package.json +5 -5
- package/src/components/ErrorBounday.tsx +19 -19
- package/src/components/Fallback.tsx +54 -58
- package/src/components/InputToolBar/InputToolBar.tsx +666 -0
- package/src/components/InputToolBar/README.md +239 -0
- package/src/components/InputToolBar/defaults.ts +72 -0
- package/src/components/InputToolBar/index.ts +18 -0
- package/src/components/InputToolBar/types.ts +166 -0
- package/src/components/Layout/components/BasicLayout.tsx +2 -6
- package/src/components/Layout/components/BottomTabBar.tsx +98 -99
- package/src/components/Layout/components/Sample.tsx +1 -1
- package/src/components/Layout/components/SideBar.tsx +10 -14
- package/src/components/NavigationComponent.tsx +3 -1
- package/src/components/ToastAlert.tsx +11 -11
- package/src/components/UnAuthenticatedComponent.tsx +16 -26
- package/src/components/WithConfiguration.tsx +1 -5
- package/src/components/WithPermission.tsx +0 -9
- package/src/components/index.ts +1 -0
- package/src/components/usePermissionAutoFetch.tsx +7 -22
- package/src/components/useSetting.tsx +22 -100
- package/src/containers/layout/BasicLayout.tsx +3 -3
- package/src/containers/layout/ProLayout.tsx +1 -1
- package/src/index.ts +1 -2
- package/src/utils/generateMobileNavigations.ts +43 -34
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {Box,Pressable,Center,Text, SafeAreaView} from '@gluestack-ui/themed';
|
|
2
|
+
import { Box, Pressable, Center, Text, SafeAreaView } from '@gluestack-ui/themed';
|
|
3
3
|
import { useSelector } from 'react-redux';
|
|
4
4
|
import { useRoute } from '@react-navigation/native';
|
|
5
5
|
import { navigationRef } from '@common-stack/client-react';
|
|
6
6
|
|
|
7
|
-
export const BottomTabBar = ({ state, descriptors, navigation
|
|
8
|
-
const tabBarProps = props?.customTabBarProps??{};
|
|
7
|
+
export const BottomTabBar = ({ state, descriptors, navigation, ...props }: any) => {
|
|
8
|
+
const tabBarProps = props?.customTabBarProps ?? {};
|
|
9
9
|
const settings = useSelector<any>((state) => state.settings) as any;
|
|
10
10
|
//const currentRoute: any = useRoute();
|
|
11
11
|
const currentRoute: any = navigationRef.isReady() ? navigationRef?.getCurrentRoute() : null;
|
|
@@ -23,118 +23,117 @@ export const BottomTabBar = ({ state, descriptors, navigation,...props }: any) =
|
|
|
23
23
|
(b.options.priority ? b.options.priority : b.options.title),
|
|
24
24
|
);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (!isFocused && !event.defaultPrevented) {
|
|
35
|
-
// The `merge: true` option makes sure that the params inside the tab screen are preserved
|
|
36
|
-
navigation.navigate({
|
|
37
|
-
name: route.route.name,
|
|
38
|
-
merge: true,
|
|
39
|
-
orgName: currentRoute?.params?.orgName || platformState?.orgName,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}, []);
|
|
26
|
+
const onPress = React.useCallback((route, navigation, isFocused) => {
|
|
27
|
+
if (route?.route) {
|
|
28
|
+
const event = navigation.emit({
|
|
29
|
+
type: 'tabPress',
|
|
30
|
+
target: route.route.key,
|
|
31
|
+
canPreventDefault: true,
|
|
32
|
+
});
|
|
44
33
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
navigation.
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
if (!isFocused && !event.defaultPrevented) {
|
|
35
|
+
// The `merge: true` option makes sure that the params inside the tab screen are preserved
|
|
36
|
+
navigation.navigate({
|
|
37
|
+
name: route.route.name,
|
|
38
|
+
merge: true,
|
|
39
|
+
orgName: currentRoute?.params?.orgName || platformState?.orgName,
|
|
50
40
|
});
|
|
51
41
|
}
|
|
52
|
-
}
|
|
42
|
+
}
|
|
43
|
+
}, []);
|
|
53
44
|
|
|
45
|
+
const onLongPress = React.useCallback((route, navigation, isFocused) => {
|
|
46
|
+
if (route?.route) {
|
|
47
|
+
navigation.emit({
|
|
48
|
+
type: 'tabLongPress',
|
|
49
|
+
target: route.route.key,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}, []);
|
|
54
53
|
|
|
55
54
|
return (
|
|
56
55
|
<SafeAreaView>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
56
|
+
<Box
|
|
57
|
+
flexDirection="row"
|
|
58
|
+
width="100%"
|
|
59
|
+
alignSelf="center"
|
|
60
|
+
bg={'$white'}
|
|
61
|
+
borderTopWidth={'$1'}
|
|
62
|
+
borderTopColor={'#d3d3d3'}
|
|
63
|
+
py={'$4'}
|
|
64
|
+
{...tabBarProps}
|
|
65
|
+
>
|
|
66
|
+
{appRoutes.map((route: any, index: any) => {
|
|
67
|
+
const options = route.options;
|
|
68
|
+
const label =
|
|
69
|
+
options.tabBarLabel !== undefined
|
|
70
|
+
? options.tabBarLabel
|
|
71
|
+
: options.title !== undefined
|
|
73
72
|
? options.title
|
|
74
73
|
: route.route.name;
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
const isFocused = state.index === route.index;
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
// const onPress = () => {
|
|
78
|
+
// const event = navigation.emit({
|
|
79
|
+
// type: 'tabPress',
|
|
80
|
+
// target: route.route.key,
|
|
81
|
+
// canPreventDefault: true,
|
|
82
|
+
// });
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
// if (!isFocused && !event.defaultPrevented) {
|
|
85
|
+
// // The `merge: true` option makes sure that the params inside the tab screen are preserved
|
|
86
|
+
// navigation.navigate({
|
|
87
|
+
// name: route.route.name,
|
|
88
|
+
// merge: true,
|
|
89
|
+
// orgName: currentRoute?.params?.orgName || platformState?.orgName,
|
|
90
|
+
// });
|
|
91
|
+
// }
|
|
92
|
+
// };
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
// const onLongPress = () => {
|
|
95
|
+
// navigation.emit({
|
|
96
|
+
// type: 'tabLongPress',
|
|
97
|
+
// target: route.route.key,
|
|
98
|
+
// });
|
|
99
|
+
// };
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
101
|
+
return (
|
|
102
|
+
<Pressable
|
|
103
|
+
key={index}
|
|
104
|
+
opacity={isFocused ? '$100' : '$50'}
|
|
105
|
+
// pb="$8"
|
|
106
|
+
// pt={"$3"}
|
|
107
|
+
flex={1}
|
|
108
|
+
onPress={() => onPress(route, navigation, isFocused)}
|
|
109
|
+
onLongPress={() => onLongPress(route, navigation, isFocused)}
|
|
110
|
+
testID={options.tabBarTestID}
|
|
111
|
+
accessibilityState={isFocused ? { selected: true } : {}}
|
|
112
|
+
accessibilityLabel={options.tabBarAccessibilityLabel}
|
|
113
|
+
>
|
|
114
|
+
<Center>
|
|
115
|
+
{options?.tabBarIcon
|
|
116
|
+
? options.tabBarIcon({
|
|
117
|
+
color: isFocused
|
|
118
|
+
? options.tabBarActiveTintColor
|
|
119
|
+
: options.tabBarInactiveTintColor,
|
|
120
|
+
size: 24,
|
|
121
|
+
})
|
|
122
|
+
: null}
|
|
124
123
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
124
|
+
<Text
|
|
125
|
+
color={isFocused ? options.tabBarActiveTintColor : options.tabBarInactiveTintColor}
|
|
126
|
+
style={{ fontSize: 12 }}
|
|
127
|
+
>
|
|
128
|
+
{label}
|
|
129
|
+
</Text>
|
|
130
|
+
</Center>
|
|
131
|
+
</Pressable>
|
|
132
|
+
);
|
|
133
|
+
})}
|
|
134
|
+
</Box>
|
|
136
135
|
</SafeAreaView>
|
|
137
136
|
);
|
|
138
137
|
};
|
|
139
138
|
|
|
140
|
-
export default BottomTabBar;
|
|
139
|
+
export default BottomTabBar;
|
|
@@ -2,8 +2,7 @@ import React, { useState } from 'react';
|
|
|
2
2
|
import { HStack, Icon, Text, Box, StatusBar, Divider, Button, FlatList, SafeAreaView } from '@gluestack-ui/themed';
|
|
3
3
|
import { StyleSheet, TouchableOpacity } from 'react-native';
|
|
4
4
|
import { Ionicons } from '@expo/vector-icons';
|
|
5
|
-
import { Link } from 'react-router-native';
|
|
6
|
-
import { useHistory } from 'react-router-native';
|
|
5
|
+
import { Link, useNavigate } from 'react-router-native';
|
|
7
6
|
import { config } from '../../../config';
|
|
8
7
|
import { MenuDataItem } from '../typings';
|
|
9
8
|
import { COLOR } from '../../../utils/ThemeColor';
|
|
@@ -18,7 +17,7 @@ export interface SideBarProps {
|
|
|
18
17
|
const SideBar: React.FC<SideBarProps> = ({ menuData, matchUrl, navTheme, drawerRef }) => {
|
|
19
18
|
const [icon, setIcon] = useState('chevron-down-outline');
|
|
20
19
|
const [isToggle, setToggle] = useState(false);
|
|
21
|
-
const
|
|
20
|
+
const navigate = useNavigate();
|
|
22
21
|
|
|
23
22
|
const toggle = () => {
|
|
24
23
|
if (isToggle) {
|
|
@@ -32,8 +31,8 @@ const SideBar: React.FC<SideBarProps> = ({ menuData, matchUrl, navTheme, drawerR
|
|
|
32
31
|
|
|
33
32
|
const isMenuExist = menuData.length > 0;
|
|
34
33
|
|
|
35
|
-
const openMenuItem = (menu) => {
|
|
36
|
-
|
|
34
|
+
const openMenuItem = (menu: any) => {
|
|
35
|
+
navigate(menu.path, { state: menu.name });
|
|
37
36
|
drawerRef.current.closeDrawer();
|
|
38
37
|
};
|
|
39
38
|
|
|
@@ -42,19 +41,16 @@ const SideBar: React.FC<SideBarProps> = ({ menuData, matchUrl, navTheme, drawerR
|
|
|
42
41
|
{!!isMenuExist && (
|
|
43
42
|
<FlatList
|
|
44
43
|
data={menuData}
|
|
45
|
-
renderItem={({ item }:any) => {
|
|
44
|
+
renderItem={({ item }: any) => {
|
|
46
45
|
const keys = item?.key.split('.');
|
|
47
|
-
const arrowIcon:any = icon || 'chevron-down-outline';
|
|
46
|
+
const arrowIcon: any = icon || 'chevron-down-outline';
|
|
48
47
|
return item?.routes ? (
|
|
49
|
-
<Box p={
|
|
48
|
+
<Box p={'$3'}>
|
|
50
49
|
<TouchableOpacity onPress={() => toggle()}>
|
|
51
50
|
<HStack>
|
|
52
|
-
<Ionicons
|
|
53
|
-
color={isToggle ? '#fff' : '#a1a1a1'}
|
|
54
|
-
name="document-outline"
|
|
55
|
-
/>
|
|
51
|
+
<Ionicons color={isToggle ? '#fff' : '#a1a1a1'} name="document-outline" />
|
|
56
52
|
<Text style={{ color: isToggle ? '#fff' : '#a1a1a1' }}>{item.name}</Text>
|
|
57
|
-
<Ionicons
|
|
53
|
+
<Ionicons name={arrowIcon} />
|
|
58
54
|
</HStack>
|
|
59
55
|
</TouchableOpacity>
|
|
60
56
|
{isToggle
|
|
@@ -69,7 +65,7 @@ const SideBar: React.FC<SideBarProps> = ({ menuData, matchUrl, navTheme, drawerR
|
|
|
69
65
|
</Box>
|
|
70
66
|
) : (
|
|
71
67
|
keys[0] != 'Main' && keys[0] == 'sidebar' && (
|
|
72
|
-
<Box key={item.key} p={
|
|
68
|
+
<Box key={item.key} p={'$3'}>
|
|
73
69
|
<TouchableOpacity style={{ marginBottom: 10 }} onPress={() => openMenuItem(item)}>
|
|
74
70
|
<HStack>
|
|
75
71
|
<Ionicons
|
|
@@ -102,7 +102,9 @@ export const NavigationContainerComponent = ({
|
|
|
102
102
|
independent,
|
|
103
103
|
linking,
|
|
104
104
|
}: INavigationContainerComponentProps): ReactElement => {
|
|
105
|
-
const routeNameRef = useRef() as MutableRefObject<
|
|
105
|
+
const routeNameRef = useRef<INavigationContainerRef | undefined>(undefined) as MutableRefObject<
|
|
106
|
+
INavigationContainerRef | undefined
|
|
107
|
+
>;
|
|
106
108
|
const dispatch = useDispatch();
|
|
107
109
|
const platformState = useSelector((state) => (state as any).platform);
|
|
108
110
|
const { setLocationChange } = useLocationChange();
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
Toast,
|
|
5
|
-
VStack,
|
|
6
|
-
ToastTitle,
|
|
7
|
-
ToastDescription,
|
|
8
|
-
Pressable,
|
|
9
|
-
Icon,
|
|
10
|
-
CloseIcon,
|
|
11
|
-
} from '@gluestack-ui/themed';
|
|
3
|
+
import { Toast, VStack, ToastTitle, ToastDescription, Pressable, Icon, CloseIcon } from '@gluestack-ui/themed';
|
|
12
4
|
|
|
13
5
|
interface IToast {
|
|
14
6
|
id: string;
|
|
@@ -17,7 +9,7 @@ interface IToast {
|
|
|
17
9
|
description?: string;
|
|
18
10
|
isClosable?: boolean;
|
|
19
11
|
toast?: any;
|
|
20
|
-
variant?:any
|
|
12
|
+
variant?: any;
|
|
21
13
|
}
|
|
22
14
|
|
|
23
15
|
// variants:
|
|
@@ -25,7 +17,15 @@ interface IToast {
|
|
|
25
17
|
// solid,
|
|
26
18
|
// outline
|
|
27
19
|
|
|
28
|
-
export const ToastAlert = ({
|
|
20
|
+
export const ToastAlert = ({
|
|
21
|
+
id,
|
|
22
|
+
status = 'info',
|
|
23
|
+
title = '',
|
|
24
|
+
description = '',
|
|
25
|
+
variant = 'solid',
|
|
26
|
+
isClosable,
|
|
27
|
+
toast = null,
|
|
28
|
+
}: IToast) => {
|
|
29
29
|
const toastId = 'toast-' + id;
|
|
30
30
|
const actionType = status || 'info';
|
|
31
31
|
return (
|
|
@@ -1,38 +1,28 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Box,
|
|
4
|
-
Button,
|
|
5
|
-
Heading,
|
|
6
|
-
Text,
|
|
7
|
-
HStack,
|
|
8
|
-
Pressable,
|
|
9
|
-
Divider,
|
|
10
|
-
ButtonText,
|
|
11
|
-
SafeAreaView,
|
|
12
|
-
} from '@gluestack-ui/themed';
|
|
2
|
+
import { Box, Button, Heading, Text, HStack, Pressable, Divider, ButtonText, SafeAreaView } from '@gluestack-ui/themed';
|
|
13
3
|
import { useNavigation } from '@react-navigation/native';
|
|
14
4
|
import { Ionicons } from '@expo/vector-icons';
|
|
15
5
|
import { Linking } from 'react-native';
|
|
16
6
|
|
|
17
|
-
|
|
7
|
+
const UnAuthenticatedComponent = () => {
|
|
18
8
|
const navigation = useNavigation<any>();
|
|
19
9
|
return (
|
|
20
10
|
<SafeAreaView flex={1}>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
<Box flex={1} borderTopWidth={'$1'} borderTopColor={'$trueGray200'}>
|
|
12
|
+
{/* <Box h={'$1'} bg={Colors.primaryBgColor} /> */}
|
|
13
|
+
<Box flex={1} p={'$6'} bg="$white" justifyContent={'center'}>
|
|
14
|
+
<Heading mt={'$2'}>Login</Heading>
|
|
15
|
+
<Text fontSize="$md" mt={'$2'}>
|
|
16
|
+
Log in to continue.
|
|
17
|
+
</Text>
|
|
18
|
+
<Button bg={'$blue500'} size="lg" my={'$3'} onPress={() => navigation.navigate('MainStack.Login')}>
|
|
19
|
+
<ButtonText color="$white">Login</ButtonText>
|
|
20
|
+
</Button>
|
|
21
|
+
<Divider my={'$3'} />
|
|
22
|
+
</Box>
|
|
32
23
|
</Box>
|
|
33
|
-
</
|
|
34
|
-
</SafeAreaView>
|
|
24
|
+
</SafeAreaView>
|
|
35
25
|
);
|
|
36
26
|
};
|
|
37
27
|
|
|
38
|
-
export default UnAuthenticatedComponent;
|
|
28
|
+
export default UnAuthenticatedComponent;
|
|
@@ -16,7 +16,7 @@ export interface IWithConfigurationProps {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export const WithConfiguration = (props: IWithConfigurationProps) => {
|
|
19
|
-
const { configKey, children, permissionKeys, resourceName, permissionTypes } = props;
|
|
19
|
+
const { configKey, children, permissionKeys, resourceName, permissionTypes = [PermissionType.Allow] } = props;
|
|
20
20
|
|
|
21
21
|
const {
|
|
22
22
|
data,
|
|
@@ -65,8 +65,4 @@ export const WithConfiguration = (props: IWithConfigurationProps) => {
|
|
|
65
65
|
);
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
WithConfiguration.defaultProps = {
|
|
69
|
-
permissionTypes: [PermissionType.Allow],
|
|
70
|
-
};
|
|
71
|
-
|
|
72
68
|
export const WithConfigurationContainer = (props: IWithConfigurationProps) => <WithConfiguration {...props} />;
|
|
@@ -68,15 +68,6 @@ export const WithPermission = ({
|
|
|
68
68
|
return null;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
WithPermission.defaultProps = {
|
|
72
|
-
permissionTypes: [PermissionType.Allow],
|
|
73
|
-
behaviour: WithPermissionBehaviour.hide,
|
|
74
|
-
message: "You don't have permission to access this resource, contact owner",
|
|
75
|
-
disabledProps: {
|
|
76
|
-
disabled: true,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
71
|
export const WithPermissionContainer = React.memo((props: IWithPermissionProps) => <WithPermission {...props} />);
|
|
81
72
|
export default WithPermissionContainer;
|
|
82
73
|
// export const WithPermissionContainer = (props: IWithPermissionProps) => <WithPermission {...props} />;
|
package/src/components/index.ts
CHANGED
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { generateUserUri } from '@adminide-stack/core';
|
|
3
|
-
import { useGetContextDataQuery } from 'common/lib/generated/generated.js';
|
|
4
|
-
import { useSetting } from './useSetting';
|
|
1
|
+
import { usePermissionAutoFetch as usePlatformPermissionAutoFetch } from '@adminide-stack/platform-client';
|
|
5
2
|
|
|
6
3
|
interface userPermissionAutoFetchProps {
|
|
7
4
|
configKey?: string;
|
|
8
5
|
}
|
|
9
6
|
export const usePermissionAutoFetch = (options?: userPermissionAutoFetchProps) => {
|
|
10
|
-
const {
|
|
11
|
-
const { orgUri, userId } = (data?.getContextData as IContext) || {};
|
|
7
|
+
const { permissions, loading } = usePlatformPermissionAutoFetch(options);
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
overrides: {
|
|
19
|
-
resource: resource,
|
|
20
|
-
},
|
|
21
|
-
options: {
|
|
22
|
-
forceExist: false,
|
|
23
|
-
authority: ResourceAuthority.Defaultpermissions,
|
|
24
|
-
fragment: ConfigFragmentName.Roles,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return { ...remaining, loading: loading || settingLoading };
|
|
9
|
+
return {
|
|
10
|
+
permissions,
|
|
11
|
+
data: permissions === undefined ? undefined : { resolveConfiguration: permissions },
|
|
12
|
+
loading,
|
|
13
|
+
};
|
|
29
14
|
};
|
|
30
15
|
|
|
31
16
|
// import React from 'react';
|
|
@@ -1,30 +1,25 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import type {
|
|
3
|
-
|
|
4
|
-
IResolveConfigurationQueryVariables,
|
|
2
|
+
IConfigurationsFlattenedKeys,
|
|
5
3
|
IPreferencesInput,
|
|
6
4
|
IPreferencesOpenOptionsInput,
|
|
7
|
-
IUpdateConfigurationMutation,
|
|
8
5
|
IConfigurationOverridesInput,
|
|
9
6
|
} from 'common';
|
|
10
7
|
import { ConfigurationTarget } from 'common';
|
|
11
|
-
import {
|
|
12
|
-
import { omitBy, isNil } from 'lodash-es';
|
|
13
|
-
import { ExecutionResult } from 'graphql';
|
|
14
|
-
import {
|
|
15
|
-
useResolveConfigurationQuery,
|
|
16
|
-
useOpenPreferencesSettingsQuery,
|
|
17
|
-
useUpdateConfigurationMutation,
|
|
18
|
-
} from 'common/lib/generated/generated.js';
|
|
8
|
+
import { useSetting as usePlatformSetting } from '@adminide-stack/platform-client';
|
|
19
9
|
|
|
20
10
|
export interface ISettingsVariable {
|
|
21
11
|
overrides?: IConfigurationOverridesInput;
|
|
22
|
-
configKey:
|
|
12
|
+
configKey: IConfigurationsFlattenedKeys;
|
|
23
13
|
options?: IPreferencesOpenOptionsInput;
|
|
24
14
|
skip?: boolean;
|
|
25
15
|
}
|
|
26
16
|
|
|
27
|
-
interface IResponse
|
|
17
|
+
interface IResponse {
|
|
18
|
+
data?: {
|
|
19
|
+
resolveConfiguration?: unknown;
|
|
20
|
+
};
|
|
21
|
+
loading: boolean;
|
|
22
|
+
error?: unknown;
|
|
28
23
|
preferencesInput?: IPreferencesInput;
|
|
29
24
|
updateConfiguration?: ({
|
|
30
25
|
updateKey,
|
|
@@ -36,7 +31,9 @@ interface IResponse extends QueryResult<IResolveConfigurationQuery, IResolveConf
|
|
|
36
31
|
value: string | boolean | number;
|
|
37
32
|
updateOverrides?: IConfigurationOverridesInput;
|
|
38
33
|
target?: ConfigurationTarget;
|
|
39
|
-
}) => Promise<
|
|
34
|
+
}) => Promise<unknown>;
|
|
35
|
+
refetch?: Function;
|
|
36
|
+
[key: string]: unknown;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
/**
|
|
@@ -45,93 +42,18 @@ interface IResponse extends QueryResult<IResolveConfigurationQuery, IResolveConf
|
|
|
45
42
|
* @param baseOptions
|
|
46
43
|
*/
|
|
47
44
|
export const useSetting = (settingsVariable: ISettingsVariable): IResponse => {
|
|
48
|
-
const {
|
|
49
|
-
const targetResource = overrides?.resource ?? null;
|
|
50
|
-
let prefLoaded = false;
|
|
51
|
-
const {
|
|
52
|
-
data: prefData,
|
|
53
|
-
error: prefError,
|
|
54
|
-
loading: perfLoading,
|
|
55
|
-
refetch: refetchPrefData,
|
|
56
|
-
} = useOpenPreferencesSettingsQuery({
|
|
57
|
-
variables: { resource: targetResource, options },
|
|
58
|
-
fetchPolicy: 'cache-first', // to make `{always: true}` to work
|
|
59
|
-
skip: prefLoaded,
|
|
60
|
-
});
|
|
61
|
-
React.useEffect(() => {
|
|
62
|
-
refetchPrefData({ resource: targetResource, options });
|
|
63
|
-
}, [targetResource]);
|
|
64
|
-
prefLoaded = perfLoading || skip;
|
|
65
|
-
const [updateConfigurationMutation] = useUpdateConfigurationMutation();
|
|
66
|
-
const modifiedOverrides = {
|
|
67
|
-
...overrides,
|
|
68
|
-
resource: targetResource ? prefData?.openPreferencesSettings?.editableSettingsInput ?? null : null,
|
|
69
|
-
};
|
|
70
|
-
const defaultOverrides = omitBy(modifiedOverrides, isNil);
|
|
71
|
-
let {
|
|
72
|
-
data: settingsData,
|
|
73
|
-
error: settingError,
|
|
74
|
-
loading: settingLoading,
|
|
75
|
-
...remaining
|
|
76
|
-
} = useResolveConfigurationQuery({
|
|
77
|
-
variables: {
|
|
78
|
-
input: prefData?.openPreferencesSettings ?? null,
|
|
79
|
-
key: configKey,
|
|
80
|
-
overrides: defaultOverrides,
|
|
81
|
-
},
|
|
82
|
-
fetchPolicy: 'cache-and-network', // to make `{always: true}` to work
|
|
83
|
-
skip: prefLoaded || !!prefError || !prefData?.openPreferencesSettings?.editableSettingsInput,
|
|
84
|
-
});
|
|
85
|
-
React.useEffect(() => {
|
|
86
|
-
remaining?.refetch({
|
|
87
|
-
input: prefData?.openPreferencesSettings ?? null,
|
|
88
|
-
key: configKey,
|
|
89
|
-
overrides: defaultOverrides,
|
|
90
|
-
});
|
|
91
|
-
}, [prefData]);
|
|
92
|
-
|
|
93
|
-
let loading = true;
|
|
94
|
-
if (!settingLoading && !prefLoaded) {
|
|
95
|
-
loading = false;
|
|
96
|
-
}
|
|
97
|
-
const error = settingError || prefError;
|
|
98
|
-
if (error) {
|
|
99
|
-
return {
|
|
100
|
-
error,
|
|
101
|
-
data: undefined,
|
|
102
|
-
loading: false,
|
|
103
|
-
...remaining,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (loading) {
|
|
107
|
-
return {
|
|
108
|
-
error,
|
|
109
|
-
data: undefined,
|
|
110
|
-
loading,
|
|
111
|
-
...remaining,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const updateConfiguration = ({ value, updateKey, updateOverrides, target }) => {
|
|
116
|
-
return updateConfigurationMutation({
|
|
117
|
-
variables: {
|
|
118
|
-
key: updateKey || configKey,
|
|
119
|
-
value,
|
|
120
|
-
target,
|
|
121
|
-
overrides: updateOverrides || defaultOverrides,
|
|
122
|
-
input: prefData?.openPreferencesSettings,
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
};
|
|
45
|
+
const { data, updateConfiguration, ...remaining } = usePlatformSetting(settingsVariable as any);
|
|
126
46
|
|
|
127
47
|
return {
|
|
128
|
-
data:
|
|
129
|
-
loading,
|
|
130
|
-
error,
|
|
48
|
+
data: data === undefined ? undefined : { resolveConfiguration: data },
|
|
131
49
|
...remaining,
|
|
132
|
-
|
|
133
|
-
|
|
50
|
+
updateConfiguration: ({ value, updateKey, updateOverrides, target }) => {
|
|
51
|
+
return updateConfiguration?.({
|
|
52
|
+
value,
|
|
53
|
+
updateKey,
|
|
54
|
+
updateOverrides,
|
|
55
|
+
target,
|
|
56
|
+
});
|
|
134
57
|
},
|
|
135
|
-
|
|
136
|
-
} as any;
|
|
58
|
+
};
|
|
137
59
|
};
|