@eohjsc/react-native-smart-city 0.7.21 → 0.7.22
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 +1 -1
- package/src/Images/Common/default_end_device.png +0 -0
- package/src/commons/Dashboard/MyUnit/index.js +19 -20
- package/src/commons/DevMode/Search.js +1 -1
- package/src/commons/Device/RainningSensor/CurrentRainSensor.js +5 -5
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +1 -3
- package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +1 -1
- package/src/configs/API.js +4 -0
- package/src/configs/AccessibilityLabel.js +3 -1
- package/src/configs/Images.js +1 -0
- package/src/navigations/AddMemberStack.js +3 -3
- package/src/screens/AddCommon/SelectUnit.js +3 -2
- package/src/screens/AddLocationMaps/__test__/index.test.js +13 -13
- package/src/screens/Automate/AddNewAction/__test__/ChooseConfig.test.js +9 -11
- package/src/screens/Automate/AddNewAutoSmart/__test__/AddAutomationTypeSmart.test.js +31 -0
- package/src/screens/Automate/ScriptDetail/utils.js +0 -20
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +69 -13
- package/src/screens/ConfirmUnitDeletion/index.js +14 -14
- package/src/screens/Sharing/Components/ConfigItem.js +34 -0
- package/src/screens/Sharing/Components/DeviceItem.js +77 -0
- package/src/screens/Sharing/Components/ItemChangeRole.js +3 -4
- package/src/screens/Sharing/Components/ShareDeviceSelector.js +255 -0
- package/src/screens/Sharing/Components/Styles/CheckBoxCustomStyles.js +1 -1
- package/src/screens/Sharing/Components/Styles/DeviceItemStyles.js +11 -27
- package/src/screens/Sharing/{Styles/SelectPermissionStyles.js → Components/Styles/ShareDeviceSelectorStyles.js} +3 -11
- package/src/screens/Sharing/Components/SubUnitItem.js +28 -0
- package/src/screens/Sharing/Components/SubUnitTreeView.js +68 -0
- package/src/screens/Sharing/Components/TitleCheckBox.js +23 -41
- package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +7 -7
- package/src/screens/Sharing/Components/__test__/ShareDeviceSelector.test.js +298 -0
- package/src/screens/Sharing/Components/index.js +14 -1
- package/src/screens/Sharing/InfoMemberUnit.js +20 -20
- package/src/screens/Sharing/SelectShareDevice.js +11 -255
- package/src/screens/Sharing/SelectUser.js +12 -12
- package/src/screens/Sharing/UpdateShareDevice.js +45 -301
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +58 -11
- package/src/screens/Sharing/__test__/SelectShareDevice.test.js +51 -160
- package/src/screens/Sharing/__test__/SelectUser.test.js +72 -10
- package/src/screens/Sharing/__test__/UpdateShareDevice.test.js +49 -209
- package/src/utils/I18n/translations/en.js +1 -1
- package/src/utils/I18n/translations/vi.js +2 -2
- package/src/commons/Sharing/StationDevicePermissions.js +0 -204
- package/src/screens/Sharing/Components/CheckBoxConfig.js +0 -44
- package/src/screens/Sharing/Components/CheckBoxSubUnit.js +0 -35
- package/src/screens/Sharing/Components/EndDevice.js +0 -93
- package/src/screens/Sharing/Components/Styles/CheckBoxConfigStyles.js +0 -18
- package/src/screens/Sharing/Components/Styles/TitleCheckBoxStyles.js +0 -21
- package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +0 -31
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { ActivityIndicator, Alert, View } from 'react-native';
|
|
2
|
+
import { ConfigItem, DeviceItem, SubUnitItem, SubUnitTreeView } from '.';
|
|
3
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import { API } from '../../../configs';
|
|
6
|
+
import { AccessibilityLabel } from '../../../configs/Constants';
|
|
7
|
+
import Text from '../../../commons/Text';
|
|
8
|
+
import ViewButtonBottom from '../../../commons/ViewButtonBottom';
|
|
9
|
+
import { axiosGet } from '../../../utils/Apis/axios';
|
|
10
|
+
import styles from './Styles/ShareDeviceSelectorStyles';
|
|
11
|
+
import { useNavigation } from '@react-navigation/native';
|
|
12
|
+
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
13
|
+
|
|
14
|
+
const ShareDeviceSelector = ({
|
|
15
|
+
unitId,
|
|
16
|
+
initialSelectedKeys = [],
|
|
17
|
+
onRightClick,
|
|
18
|
+
rightTitle,
|
|
19
|
+
}) => {
|
|
20
|
+
const [dataSubUnits, setDataSubUnits] = useState([]);
|
|
21
|
+
const [loading, setLoading] = useState(true);
|
|
22
|
+
const t = useTranslations();
|
|
23
|
+
const navigation = useNavigation();
|
|
24
|
+
const [selectedKeys, setSelectedKeys] = useState(initialSelectedKeys);
|
|
25
|
+
|
|
26
|
+
const updateParentSelected = (data, newSelectedKeys) => {
|
|
27
|
+
const updateParentCheck = (nodes) => {
|
|
28
|
+
nodes.forEach((node) => {
|
|
29
|
+
if (!node?.children || node.children.length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
updateParentCheck(node.children);
|
|
33
|
+
|
|
34
|
+
const allChildrenChecked = node.children.every((child) =>
|
|
35
|
+
newSelectedKeys.has(child.key)
|
|
36
|
+
);
|
|
37
|
+
if (allChildrenChecked) {
|
|
38
|
+
newSelectedKeys.add(node.key);
|
|
39
|
+
} else {
|
|
40
|
+
newSelectedKeys.delete(node.key);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
updateParentCheck(data);
|
|
45
|
+
setSelectedKeys([...newSelectedKeys]);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleOnSelect = (item, isChecked) => {
|
|
49
|
+
const getAllChildIds = (node) => {
|
|
50
|
+
let ids = [node.key];
|
|
51
|
+
(node?.children || []).forEach((child) => {
|
|
52
|
+
ids.push(...getAllChildIds(child));
|
|
53
|
+
});
|
|
54
|
+
return ids;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
let newSelectedKeys = new Set(selectedKeys);
|
|
58
|
+
const affectedKeys = getAllChildIds(item);
|
|
59
|
+
|
|
60
|
+
if (isChecked) {
|
|
61
|
+
affectedKeys.forEach((key) => newSelectedKeys.add(key));
|
|
62
|
+
} else {
|
|
63
|
+
affectedKeys.forEach((key) => newSelectedKeys.delete(key));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
updateParentSelected(dataSource, newSelectedKeys);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const renderSubUnitTreeNode = ({ item, childrenRender }) => {
|
|
70
|
+
const level = item.key.split('-').at(0);
|
|
71
|
+
const isChecked = selectedKeys.includes(item.key);
|
|
72
|
+
switch (level) {
|
|
73
|
+
case 'subUnit':
|
|
74
|
+
return (
|
|
75
|
+
<SubUnitItem
|
|
76
|
+
item={item}
|
|
77
|
+
isChecked={isChecked}
|
|
78
|
+
onSelect={handleOnSelect}
|
|
79
|
+
childrenRender={childrenRender}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
case 'device':
|
|
83
|
+
return (
|
|
84
|
+
<DeviceItem
|
|
85
|
+
item={item}
|
|
86
|
+
isChecked={isChecked}
|
|
87
|
+
childrenRender={childrenRender}
|
|
88
|
+
onSelect={handleOnSelect}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
case 'config':
|
|
92
|
+
case 'action':
|
|
93
|
+
return (
|
|
94
|
+
<ConfigItem
|
|
95
|
+
isChecked={isChecked}
|
|
96
|
+
item={item}
|
|
97
|
+
onSelect={handleOnSelect}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const [dataSource, keyDeviceMap] = useMemo(() => {
|
|
104
|
+
let keyMap = {};
|
|
105
|
+
const items = [
|
|
106
|
+
{
|
|
107
|
+
id: 'all',
|
|
108
|
+
key: 'all',
|
|
109
|
+
label: t('text_all_devices'),
|
|
110
|
+
children: dataSubUnits.map((subUnit) => ({
|
|
111
|
+
id: subUnit.id,
|
|
112
|
+
key: `subUnit-${subUnit.id}`,
|
|
113
|
+
label: subUnit.name,
|
|
114
|
+
children: subUnit.devices.map((device) => ({
|
|
115
|
+
id: device.id,
|
|
116
|
+
key: `device-${device.id}`,
|
|
117
|
+
label: device.name,
|
|
118
|
+
item: device,
|
|
119
|
+
children: [
|
|
120
|
+
...device.actions.map((action) => {
|
|
121
|
+
const key = `action-${action.id}`;
|
|
122
|
+
keyMap[key] = device.id;
|
|
123
|
+
return {
|
|
124
|
+
id: action.id,
|
|
125
|
+
key,
|
|
126
|
+
label: action.name,
|
|
127
|
+
isConfig: false,
|
|
128
|
+
};
|
|
129
|
+
}),
|
|
130
|
+
...device.read_configs.map((config) => {
|
|
131
|
+
const key = `config-${config.id}`;
|
|
132
|
+
keyMap[key] = device.id;
|
|
133
|
+
return {
|
|
134
|
+
id: config.id,
|
|
135
|
+
key,
|
|
136
|
+
label: config.name,
|
|
137
|
+
isConfig: true,
|
|
138
|
+
};
|
|
139
|
+
}),
|
|
140
|
+
],
|
|
141
|
+
})),
|
|
142
|
+
})),
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
return [items, keyMap];
|
|
146
|
+
}, [dataSubUnits, t]);
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
if (!initialSelectedKeys.length) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const newSelectedKeys = new Set(initialSelectedKeys);
|
|
153
|
+
updateParentSelected(dataSource, newSelectedKeys);
|
|
154
|
+
}, [initialSelectedKeys, dataSource]);
|
|
155
|
+
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
const getUnitPermission = async () => {
|
|
158
|
+
setLoading(true);
|
|
159
|
+
const { success, data } = await axiosGet(
|
|
160
|
+
API.SHARE.UNIT_PERMISSIONS_v2(unitId)
|
|
161
|
+
);
|
|
162
|
+
success && setDataSubUnits(data);
|
|
163
|
+
setLoading(false);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
getUnitPermission();
|
|
167
|
+
}, [unitId]);
|
|
168
|
+
|
|
169
|
+
const handleOnRightClick = async () => {
|
|
170
|
+
setLoading(true);
|
|
171
|
+
|
|
172
|
+
const readKeys = selectedKeys.filter((key) => key.startsWith('config'));
|
|
173
|
+
const controlKeys = selectedKeys.filter((key) => key.startsWith('action'));
|
|
174
|
+
const endDeviceKeys = selectedKeys.filter((key) =>
|
|
175
|
+
key.startsWith('device')
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const groupByDevice = (keys) =>
|
|
179
|
+
keys.reduce((acc, key) => {
|
|
180
|
+
const [, id] = key.split('-');
|
|
181
|
+
const deviceId = keyDeviceMap[key];
|
|
182
|
+
deviceId && (acc[deviceId] ??= []).push(Number(id));
|
|
183
|
+
return acc;
|
|
184
|
+
}, {});
|
|
185
|
+
const readGroup = groupByDevice(readKeys);
|
|
186
|
+
const controlGroup = groupByDevice(controlKeys);
|
|
187
|
+
|
|
188
|
+
const read_permissions = Object.entries(readGroup).map(
|
|
189
|
+
([deviceId, configIds]) => ({
|
|
190
|
+
id: Number(deviceId),
|
|
191
|
+
values: configIds,
|
|
192
|
+
})
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
const control_permissions = Object.entries(controlGroup).map(
|
|
196
|
+
([deviceId, actionIds]) => ({
|
|
197
|
+
id: Number(deviceId),
|
|
198
|
+
values: actionIds,
|
|
199
|
+
})
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
endDeviceKeys.forEach((key) => {
|
|
203
|
+
const [, deviceId] = key.split('-');
|
|
204
|
+
if (!readGroup[deviceId] && !controlGroup[deviceId]) {
|
|
205
|
+
read_permissions.push({ id: Number(deviceId), values: [] });
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
if (!read_permissions.length && !control_permissions.length) {
|
|
210
|
+
setLoading(false);
|
|
211
|
+
Alert.alert('', t('choose_at_least_one'));
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
read_permissions.sort((a, b) => a.id - b.id);
|
|
216
|
+
control_permissions.sort((a, b) => a.id - b.id);
|
|
217
|
+
|
|
218
|
+
await onRightClick?.({ read_permissions, control_permissions });
|
|
219
|
+
setLoading(false);
|
|
220
|
+
};
|
|
221
|
+
return (
|
|
222
|
+
<View style={styles.wrap}>
|
|
223
|
+
<Text semibold style={styles.title}>
|
|
224
|
+
{t('select_device')}
|
|
225
|
+
</Text>
|
|
226
|
+
<Text style={styles.subtitle}>{t('sharing_select_devices_hint')}</Text>
|
|
227
|
+
<View style={styles.contentContainer}>
|
|
228
|
+
{loading ? (
|
|
229
|
+
<ActivityIndicator />
|
|
230
|
+
) : (
|
|
231
|
+
<SubUnitTreeView
|
|
232
|
+
data={dataSource}
|
|
233
|
+
render={renderSubUnitTreeNode}
|
|
234
|
+
onSelect={handleOnSelect}
|
|
235
|
+
selectedKeys={selectedKeys}
|
|
236
|
+
/>
|
|
237
|
+
)}
|
|
238
|
+
</View>
|
|
239
|
+
<View style={styles.wrapViewButtonStyle}>
|
|
240
|
+
<ViewButtonBottom
|
|
241
|
+
accessibilityLabelPrefix={
|
|
242
|
+
AccessibilityLabel.PREFIX.SHARING_SELECT_PERMISSION
|
|
243
|
+
}
|
|
244
|
+
leftTitle={t('cancel')}
|
|
245
|
+
onLeftClick={() => navigation.goBack()}
|
|
246
|
+
rightTitle={rightTitle}
|
|
247
|
+
rightDisabled={false}
|
|
248
|
+
onRightClick={handleOnRightClick}
|
|
249
|
+
/>
|
|
250
|
+
</View>
|
|
251
|
+
</View>
|
|
252
|
+
);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
export default ShareDeviceSelector;
|
|
@@ -1,27 +1,13 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native';
|
|
2
1
|
import { Colors } from '../../../../configs';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
3
|
import { normalize } from '../../../../configs/Constants';
|
|
4
4
|
|
|
5
5
|
export default StyleSheet.create({
|
|
6
|
-
wrapCheckBoxStyle: {
|
|
7
|
-
marginLeft: normalize(-10),
|
|
8
|
-
},
|
|
9
|
-
titleStyle: {
|
|
10
|
-
fontSize: 16,
|
|
11
|
-
fontWeight: 'normal',
|
|
12
|
-
width: 200,
|
|
13
|
-
},
|
|
14
|
-
wrapStyleTitle: {
|
|
15
|
-
justifyContent: 'space-between',
|
|
16
|
-
},
|
|
17
6
|
wrap: {
|
|
18
7
|
flexDirection: 'row',
|
|
19
8
|
marginHorizontal: normalize(10),
|
|
20
9
|
paddingBottom: 10,
|
|
21
10
|
},
|
|
22
|
-
isRenderSeparated: {
|
|
23
|
-
paddingBottom: normalize(16),
|
|
24
|
-
},
|
|
25
11
|
viewLeft: {
|
|
26
12
|
marginRight: 16,
|
|
27
13
|
width: normalize(24),
|
|
@@ -32,26 +18,24 @@ export default StyleSheet.create({
|
|
|
32
18
|
flex: 1,
|
|
33
19
|
},
|
|
34
20
|
viewRight: {
|
|
21
|
+
flexDirection: 'row',
|
|
22
|
+
alignItems: 'center',
|
|
23
|
+
marginTop: normalize(16),
|
|
24
|
+
},
|
|
25
|
+
wrapTextIcon: {
|
|
35
26
|
flexDirection: 'row',
|
|
36
27
|
alignItems: 'center',
|
|
37
28
|
justifyContent: 'space-between',
|
|
38
|
-
|
|
29
|
+
flex: 1,
|
|
39
30
|
},
|
|
40
31
|
text: {
|
|
41
32
|
color: Colors.Gray9,
|
|
42
33
|
flex: 1,
|
|
43
34
|
},
|
|
44
|
-
|
|
45
|
-
width:
|
|
46
|
-
height: normalize(20),
|
|
35
|
+
expandView: {
|
|
36
|
+
width: 20,
|
|
47
37
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
marginTop: 10,
|
|
51
|
-
},
|
|
52
|
-
viewSeparated: {
|
|
53
|
-
height: 1,
|
|
54
|
-
backgroundColor: Colors.Gray4,
|
|
55
|
-
marginTop: normalize(16),
|
|
38
|
+
wrapChildren: {
|
|
39
|
+
marginTop: normalize(10),
|
|
56
40
|
},
|
|
57
41
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Constants, normalize } from '../../../../configs/Constants';
|
|
2
|
+
|
|
3
|
+
import { Colors } from '../../../../configs';
|
|
1
4
|
import { StyleSheet } from 'react-native';
|
|
2
5
|
import { getStatusBarHeight } from 'react-native-iphone-x-helper';
|
|
3
|
-
import { Colors } from '../../../configs';
|
|
4
|
-
import { Constants, normalize } from '../../../configs/Constants';
|
|
5
6
|
|
|
6
7
|
export default StyleSheet.create({
|
|
7
8
|
wrap: {
|
|
@@ -31,15 +32,6 @@ export default StyleSheet.create({
|
|
|
31
32
|
checkBoxTile: {
|
|
32
33
|
marginLeft: 5,
|
|
33
34
|
},
|
|
34
|
-
wrapDevice: {
|
|
35
|
-
borderRadius: normalize(20),
|
|
36
|
-
borderWidth: 1,
|
|
37
|
-
borderColor: Colors.Gray4,
|
|
38
|
-
backgroundColor: Colors.White,
|
|
39
|
-
},
|
|
40
|
-
viewGroup: {
|
|
41
|
-
marginTop: normalize(8),
|
|
42
|
-
},
|
|
43
35
|
wrapAllDevices: {
|
|
44
36
|
marginBottom: -10,
|
|
45
37
|
marginLeft: 5,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Colors } from '../../../configs';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { StyleSheet } from 'react-native';
|
|
4
|
+
import { TitleCheckBox } from '.';
|
|
5
|
+
import { View } from 'react-native';
|
|
6
|
+
import { normalize } from '../../../configs/Constants';
|
|
7
|
+
|
|
8
|
+
const SubUnitItem = ({ item, isChecked, onSelect, childrenRender }) => {
|
|
9
|
+
return (
|
|
10
|
+
<View style={styles.viewGroup}>
|
|
11
|
+
<TitleCheckBox isChecked={isChecked} item={item} onSelect={onSelect} />
|
|
12
|
+
<View style={styles.wrapDevice}>{childrenRender}</View>
|
|
13
|
+
</View>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default SubUnitItem;
|
|
18
|
+
const styles = StyleSheet.create({
|
|
19
|
+
wrapDevice: {
|
|
20
|
+
borderRadius: normalize(20),
|
|
21
|
+
borderWidth: 1,
|
|
22
|
+
borderColor: Colors.Gray4,
|
|
23
|
+
backgroundColor: Colors.White,
|
|
24
|
+
},
|
|
25
|
+
viewGroup: {
|
|
26
|
+
marginTop: normalize(8),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccessibilityLabel,
|
|
3
|
+
Constants,
|
|
4
|
+
normalize,
|
|
5
|
+
} from '../../../configs/Constants';
|
|
6
|
+
import { FlatList, Text, View } from 'react-native';
|
|
7
|
+
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { StyleSheet } from 'react-native';
|
|
10
|
+
import SubUnitItem from './SubUnitItem';
|
|
11
|
+
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
12
|
+
|
|
13
|
+
const SubUnitTreeNode = ({ dataNode, render }) => {
|
|
14
|
+
return (
|
|
15
|
+
<View>
|
|
16
|
+
{render &&
|
|
17
|
+
render({
|
|
18
|
+
item: dataNode,
|
|
19
|
+
childrenRender: (dataNode?.children || []).map((child) => (
|
|
20
|
+
<SubUnitTreeNode key={child.key} dataNode={child} render={render} />
|
|
21
|
+
)),
|
|
22
|
+
})}
|
|
23
|
+
</View>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const SubUnitTreeView = ({ data, render, selectedKeys, onSelect }) => {
|
|
28
|
+
const t = useTranslations();
|
|
29
|
+
const { key, children: subUnitsData } = data[0];
|
|
30
|
+
return (
|
|
31
|
+
<View>
|
|
32
|
+
<FlatList
|
|
33
|
+
data={subUnitsData}
|
|
34
|
+
renderItem={({ item }) => (
|
|
35
|
+
<SubUnitTreeNode dataNode={item} render={render} />
|
|
36
|
+
)}
|
|
37
|
+
extraData={subUnitsData}
|
|
38
|
+
keyExtractor={(item) => item.key}
|
|
39
|
+
ListHeaderComponent={
|
|
40
|
+
subUnitsData.length && (
|
|
41
|
+
<SubUnitItem
|
|
42
|
+
isChecked={selectedKeys.includes(key)}
|
|
43
|
+
item={data[0]}
|
|
44
|
+
onSelect={onSelect}
|
|
45
|
+
/>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
ListEmptyComponent={() => (
|
|
49
|
+
<Text
|
|
50
|
+
style={styles.textNodata}
|
|
51
|
+
accessibilityLabel={AccessibilityLabel.TEXT_NO_DATA_STATIONS}
|
|
52
|
+
>
|
|
53
|
+
{t('no_data')}
|
|
54
|
+
</Text>
|
|
55
|
+
)}
|
|
56
|
+
/>
|
|
57
|
+
</View>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const styles = StyleSheet.create({
|
|
62
|
+
textNodata: {
|
|
63
|
+
alignSelf: 'center',
|
|
64
|
+
marginTop: normalize(Constants.height * 0.3),
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export default SubUnitTreeView;
|
|
@@ -1,51 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { View, Text } from 'react-native';
|
|
1
|
+
import AccessibilityLabel from '../../../configs/AccessibilityLabel';
|
|
3
2
|
import { CheckBoxCustom } from '.';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { StyleSheet } from 'react-native';
|
|
5
|
+
import { Text } from '../../../commons';
|
|
6
|
+
import { View } from 'react-native';
|
|
6
7
|
|
|
7
|
-
const TitleCheckBox = ({
|
|
8
|
-
|
|
9
|
-
onPress,
|
|
10
|
-
title = '',
|
|
11
|
-
id,
|
|
12
|
-
wrapCheckBoxStyle,
|
|
13
|
-
wrapStyle,
|
|
14
|
-
titleStyle,
|
|
15
|
-
idGroup,
|
|
16
|
-
isConfig,
|
|
17
|
-
isControl,
|
|
18
|
-
}) => {
|
|
19
|
-
const [checked, setChecked] = useState(isChecked);
|
|
8
|
+
const TitleCheckBox = ({ isChecked, item, onSelect, checkBoxStyle }) => {
|
|
9
|
+
const { label, key } = item;
|
|
20
10
|
const handleOnPress = () => {
|
|
21
|
-
|
|
22
|
-
onPress && onPress(idGroup, !checked, id);
|
|
11
|
+
onSelect(item, !isChecked);
|
|
23
12
|
};
|
|
24
|
-
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
isChecked !== checked && setChecked(isChecked);
|
|
27
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
|
-
}, [isChecked]);
|
|
29
|
-
|
|
30
13
|
return (
|
|
31
|
-
<View style={
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<Text onPress={handleOnPress} style={[styles.title, titleStyle]}>
|
|
40
|
-
{title}
|
|
41
|
-
</Text>
|
|
42
|
-
</View>
|
|
43
|
-
<View>
|
|
44
|
-
{isControl && <Text>{t('can_control')}</Text>}
|
|
45
|
-
{isConfig && <Text>{t('view_only')}</Text>}
|
|
46
|
-
</View>
|
|
14
|
+
<View style={styles.wrapRow}>
|
|
15
|
+
<CheckBoxCustom
|
|
16
|
+
isChecked={isChecked}
|
|
17
|
+
onPress={handleOnPress}
|
|
18
|
+
wrapStyle={checkBoxStyle}
|
|
19
|
+
accessibilityLabel={`${AccessibilityLabel.SHARE_DEVICE.CHECK_BOX_CUSTOM}-${key}`}
|
|
20
|
+
/>
|
|
21
|
+
<Text onPress={handleOnPress}>{label}</Text>
|
|
47
22
|
</View>
|
|
48
23
|
);
|
|
49
24
|
};
|
|
50
25
|
|
|
26
|
+
const styles = StyleSheet.create({
|
|
27
|
+
wrapRow: {
|
|
28
|
+
flexDirection: 'row',
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
51
33
|
export default TitleCheckBox;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { create, act } from 'react-test-renderer';
|
|
1
|
+
import { act, create } from 'react-test-renderer';
|
|
3
2
|
|
|
4
|
-
import { SCProvider } from '../../../../context';
|
|
5
|
-
import { mockSCStore } from '../../../../context/mockStore';
|
|
6
3
|
import ItemChangeRole from '../ItemChangeRole';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { SCProvider } from '../../../../context';
|
|
7
6
|
import { TouchableOpacity } from 'react-native';
|
|
7
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
8
8
|
|
|
9
9
|
const mockOnPress = jest.fn();
|
|
10
|
-
const wrapComponent = () => (
|
|
10
|
+
const wrapComponent = (disabled) => (
|
|
11
11
|
<SCProvider initState={mockSCStore({})}>
|
|
12
|
-
<ItemChangeRole onPress={mockOnPress} />
|
|
12
|
+
<ItemChangeRole onPress={mockOnPress} disabled={disabled} />
|
|
13
13
|
</SCProvider>
|
|
14
14
|
);
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ describe('test ItemChangeRole', () => {
|
|
|
17
17
|
it('test ItemChangeRole', async () => {
|
|
18
18
|
let tree;
|
|
19
19
|
await act(async () => {
|
|
20
|
-
tree = await create(wrapComponent());
|
|
20
|
+
tree = await create(wrapComponent(true));
|
|
21
21
|
});
|
|
22
22
|
const instance = tree.root;
|
|
23
23
|
const touchableOpacity = instance.findAllByType(TouchableOpacity);
|