@eohjsc/react-native-smart-city 0.3.14 → 0.3.17
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/commons/ActionGroup/OnOffTemplate/index.js +36 -15
- package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +35 -1
- package/src/commons/ActionGroup/__test__/TimerActionTemplateWithutConfigValue.test.js +4 -1
- package/src/commons/ConnectingProcess/index.js +42 -25
- package/src/commons/SubUnit/Favorites/index.js +1 -1
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +1 -1
- package/src/hooks/IoT/useRemoteControl.js +6 -8
- package/src/iot/RemoteControl/LG.js +6 -6
- package/src/iot/RemoteControl/__test__/LgThinq.test.js +2 -2
- package/src/navigations/UnitStack.js +3 -3
- package/src/screens/AddNewAction/SelectAction.js +2 -1
- package/src/screens/AddNewAction/SelectSensorDevices.js +2 -0
- package/src/screens/Device/components/SensorDisplayItem.js +1 -0
- package/src/screens/Unit/Detail.js +0 -1
- package/src/screens/Unit/{SelectDevices.js → SelectFavoritesDevices.js} +7 -6
- package/src/screens/Unit/{SelectDevicesStyles.js → SelectFavoritesDevicesStyles.js} +0 -0
- package/src/screens/Unit/__test__/{SelectDevices.test.js → SelectFavoritesDevices.test.js} +3 -3
- package/src/screens/Unit/styles.js +1 -10
- package/src/utils/Route/index.js +1 -1
package/package.json
CHANGED
|
@@ -6,6 +6,8 @@ import { useConfigGlobalState } from '../../../iot/states';
|
|
|
6
6
|
import OnOffButtonTemplate from './OnOffButtonTemplate';
|
|
7
7
|
import OnOffSimpleTemplate from './OnOffSimpleTemplate';
|
|
8
8
|
|
|
9
|
+
let temp;
|
|
10
|
+
|
|
9
11
|
const getComponent = (template) => {
|
|
10
12
|
switch (template) {
|
|
11
13
|
case 'on_off_button_action_template': // todo refactor later with backend
|
|
@@ -20,11 +22,28 @@ const getComponent = (template) => {
|
|
|
20
22
|
const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
21
23
|
const { configuration } = actionGroup;
|
|
22
24
|
const { action_data, action_on_data, action_off_data } = configuration;
|
|
23
|
-
const [isOn, setIsOn] = useState(null);
|
|
24
25
|
|
|
25
26
|
// eslint-disable-next-line no-unused-vars
|
|
26
27
|
const [configValues, _] = useConfigGlobalState('configValues');
|
|
27
28
|
|
|
29
|
+
const getIsOnValue = useCallback(() => {
|
|
30
|
+
const { is_on_value, config } = configuration;
|
|
31
|
+
const configValue = configValues[config];
|
|
32
|
+
if (is_on_value && is_on_value.length > 0) {
|
|
33
|
+
return is_on_value.includes(configValue);
|
|
34
|
+
}
|
|
35
|
+
return !!configValue;
|
|
36
|
+
}, [configValues, configuration]);
|
|
37
|
+
|
|
38
|
+
const [isOn, setIsOn] = useState(false);
|
|
39
|
+
const [tempIsOn, setTempIsOn] = useState(getIsOnValue());
|
|
40
|
+
|
|
41
|
+
const updateStatusFromPusher = () => {
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
setTempIsOn(temp);
|
|
44
|
+
}, 2500);
|
|
45
|
+
};
|
|
46
|
+
|
|
28
47
|
const actionName = useCallback(
|
|
29
48
|
(text) => {
|
|
30
49
|
const actionNameType = `${
|
|
@@ -34,7 +53,9 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
34
53
|
},
|
|
35
54
|
[actionGroup?.title, sensor?.name]
|
|
36
55
|
);
|
|
56
|
+
|
|
37
57
|
const triggerAction = useCallback(async () => {
|
|
58
|
+
setTempIsOn((prev) => !prev);
|
|
38
59
|
switch (sensor?.device_type) {
|
|
39
60
|
case DEVICE_TYPE.ZIGBEE:
|
|
40
61
|
if (action_on_data && action_off_data) {
|
|
@@ -53,6 +74,13 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
53
74
|
}
|
|
54
75
|
}
|
|
55
76
|
break;
|
|
77
|
+
case DEVICE_TYPE.LG_THINQ:
|
|
78
|
+
if (action_data) {
|
|
79
|
+
await doAction(action_data, JSON.stringify({ value: !isOn }));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
updateStatusFromPusher();
|
|
83
|
+
break;
|
|
56
84
|
default:
|
|
57
85
|
if (action_data) {
|
|
58
86
|
if (isOn) {
|
|
@@ -88,19 +116,12 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
88
116
|
]);
|
|
89
117
|
|
|
90
118
|
useEffect(() => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
setIsOn(configValue);
|
|
98
|
-
}, [
|
|
99
|
-
configuration.config,
|
|
100
|
-
configValues,
|
|
101
|
-
configuration.is_on_value,
|
|
102
|
-
configuration,
|
|
103
|
-
]);
|
|
119
|
+
setIsOn(getIsOnValue());
|
|
120
|
+
}, [getIsOnValue]);
|
|
121
|
+
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
temp = isOn;
|
|
124
|
+
}, [isOn]);
|
|
104
125
|
|
|
105
126
|
useEffect(() => {
|
|
106
127
|
if (sensor?.device_type === DEVICE_TYPE.LG_THINQ) {
|
|
@@ -118,7 +139,7 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
118
139
|
return (
|
|
119
140
|
<>
|
|
120
141
|
<Component
|
|
121
|
-
isOn={
|
|
142
|
+
isOn={tempIsOn}
|
|
122
143
|
triggerAction={triggerAction}
|
|
123
144
|
actionGroup={actionGroup}
|
|
124
145
|
disabled={!action_data && !action_on_data && !action_off_data}
|
|
@@ -90,7 +90,7 @@ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
|
|
|
90
90
|
|
|
91
91
|
const doActionTime = useCallback(
|
|
92
92
|
(hour, minute) => {
|
|
93
|
-
doAction(configuration.action_data,
|
|
93
|
+
doAction(configuration.action_data, JSON.stringify({ hour, minute }));
|
|
94
94
|
if (sensor.is_managed_by_backend) {
|
|
95
95
|
hour !== undefined &&
|
|
96
96
|
minute !== undefined &&
|
|
@@ -113,7 +113,7 @@ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
|
|
|
113
113
|
|
|
114
114
|
const doActionHour = useCallback(
|
|
115
115
|
(hour) => {
|
|
116
|
-
doAction(configuration.action_data, hour);
|
|
116
|
+
doAction(configuration.action_data, JSON.stringify({ hour }));
|
|
117
117
|
if (
|
|
118
118
|
sensor.is_managed_by_backend &&
|
|
119
119
|
sensor.device_type !== 'GOOGLE_HOME'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable promise/prefer-await-to-callbacks */
|
|
2
|
-
import { TESTID } from '../../../configs/Constants';
|
|
2
|
+
import { DEVICE_TYPE, TESTID } from '../../../configs/Constants';
|
|
3
3
|
import { watchMultiConfigs } from '../../../iot/Monitor';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { View } from 'react-native';
|
|
@@ -149,6 +149,7 @@ describe('Test OnOffTemplate', () => {
|
|
|
149
149
|
await act(async () => {
|
|
150
150
|
tree = await create(wrapComponent(actionGroup, mockDoAction, sensor));
|
|
151
151
|
});
|
|
152
|
+
|
|
152
153
|
const instance = tree.root;
|
|
153
154
|
const template = instance.findByType(OnOffSimpleTemplate);
|
|
154
155
|
expect(template.props.isOn).toEqual(true);
|
|
@@ -230,6 +231,39 @@ describe('Test OnOffTemplate', () => {
|
|
|
230
231
|
expect(mockDoAction).toHaveBeenCalledWith(action_data, false);
|
|
231
232
|
});
|
|
232
233
|
|
|
234
|
+
test('render with template OnOffSimpleActionTemplate with just action_data lg_thinq', async () => {
|
|
235
|
+
actionGroup = {
|
|
236
|
+
template: 'OnOffSimpleActionTemplate',
|
|
237
|
+
configuration: {
|
|
238
|
+
config: 5,
|
|
239
|
+
action_data: action_data,
|
|
240
|
+
icon: 'up',
|
|
241
|
+
is_on_value: [2],
|
|
242
|
+
},
|
|
243
|
+
title: 'Turn on / off',
|
|
244
|
+
};
|
|
245
|
+
const mockDoAction = jest.fn();
|
|
246
|
+
await act(async () => {
|
|
247
|
+
tree = await create(
|
|
248
|
+
wrapComponent(actionGroup, mockDoAction, {
|
|
249
|
+
device_type: DEVICE_TYPE.LG_THINQ,
|
|
250
|
+
})
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
const instance = tree.root;
|
|
254
|
+
const template = instance.findAllByType(OnOffSimpleTemplate);
|
|
255
|
+
expect(template).toHaveLength(1);
|
|
256
|
+
expect(template[0].props.disabled).toBeFalsy();
|
|
257
|
+
|
|
258
|
+
await act(async () => {
|
|
259
|
+
await template[0].props.triggerAction();
|
|
260
|
+
});
|
|
261
|
+
expect(mockDoAction).toHaveBeenCalledWith(
|
|
262
|
+
action_data,
|
|
263
|
+
JSON.stringify({ value: false })
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
|
|
233
267
|
test('render with template OnOffSimpleActionTemplate disabled', async () => {
|
|
234
268
|
actionGroup = {
|
|
235
269
|
template: 'OnOffSimpleActionTemplate',
|
|
@@ -89,6 +89,9 @@ describe('Test TimerActionTemplate without config value', () => {
|
|
|
89
89
|
await dateTimePicker.props.onConfirm();
|
|
90
90
|
});
|
|
91
91
|
expect(dateTimePicker.props.isVisible).toBeFalsy();
|
|
92
|
-
expect(mockDoAction).toHaveBeenCalledWith(
|
|
92
|
+
expect(mockDoAction).toHaveBeenCalledWith(
|
|
93
|
+
action_data,
|
|
94
|
+
JSON.stringify({ hour: 11, minute: 0 })
|
|
95
|
+
);
|
|
93
96
|
});
|
|
94
97
|
});
|
|
@@ -14,6 +14,35 @@ import Connecting from '../Connecting';
|
|
|
14
14
|
import { useSCContextSelector } from '../../context';
|
|
15
15
|
import { ToastBottomHelper } from '../../utils/Utils';
|
|
16
16
|
|
|
17
|
+
const ConnectingSuccess = ({
|
|
18
|
+
unit,
|
|
19
|
+
sensor,
|
|
20
|
+
station,
|
|
21
|
+
unit_name,
|
|
22
|
+
newName,
|
|
23
|
+
setNewName,
|
|
24
|
+
}) => {
|
|
25
|
+
const t = useTranslations();
|
|
26
|
+
return (
|
|
27
|
+
<View style={styles.ConnectingSuccess}>
|
|
28
|
+
<ImageSuccessfully />
|
|
29
|
+
<Text bold style={styles.connectingText}>
|
|
30
|
+
{t('successfully_connected')}
|
|
31
|
+
</Text>
|
|
32
|
+
<Text size={14} style={styles.textHome}>
|
|
33
|
+
{`${unit?.name || unit_name} ${
|
|
34
|
+
station?.name !== undefined ? '- ' + station?.name : ''
|
|
35
|
+
}`}
|
|
36
|
+
</Text>
|
|
37
|
+
<DeviceItem
|
|
38
|
+
icon={sensor?.icon_kit}
|
|
39
|
+
name={newName}
|
|
40
|
+
setNewName={setNewName}
|
|
41
|
+
/>
|
|
42
|
+
</View>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
17
46
|
const ConnectingProcess = ({ route }) => {
|
|
18
47
|
const { navigate, goBack } = useNavigation();
|
|
19
48
|
const t = useTranslations();
|
|
@@ -34,7 +63,7 @@ const ConnectingProcess = ({ route }) => {
|
|
|
34
63
|
const user = useSCContextSelector((state) => state?.auth?.account?.user);
|
|
35
64
|
const [newName, setNewName] = useState('');
|
|
36
65
|
|
|
37
|
-
const
|
|
66
|
+
const connectingDevice = useCallback(async () => {
|
|
38
67
|
setIsLoading(true);
|
|
39
68
|
switch (devicePrefixName) {
|
|
40
69
|
case 'SENSOR': {
|
|
@@ -106,27 +135,6 @@ const ConnectingProcess = ({ route }) => {
|
|
|
106
135
|
unit_id,
|
|
107
136
|
]);
|
|
108
137
|
|
|
109
|
-
const ConnectingSuccess = useCallback(() => {
|
|
110
|
-
return (
|
|
111
|
-
<View style={styles.ConnectingSuccess}>
|
|
112
|
-
<ImageSuccessfully />
|
|
113
|
-
<Text bold style={styles.connectingText}>
|
|
114
|
-
{t('successfully_connected')}
|
|
115
|
-
</Text>
|
|
116
|
-
<Text size={14} style={styles.textHome}>
|
|
117
|
-
{`${unit?.name || unit_name} ${
|
|
118
|
-
station?.name !== undefined ? '- ' + station?.name : ''
|
|
119
|
-
}`}
|
|
120
|
-
</Text>
|
|
121
|
-
<DeviceItem
|
|
122
|
-
icon={sensor?.icon_kit}
|
|
123
|
-
name={newName}
|
|
124
|
-
setNewName={setNewName}
|
|
125
|
-
/>
|
|
126
|
-
</View>
|
|
127
|
-
);
|
|
128
|
-
}, [newName, sensor?.icon_kit, station?.name, t, unit?.name, unit_name]);
|
|
129
|
-
|
|
130
138
|
const handleDone = useCallback(async () => {
|
|
131
139
|
let result, message;
|
|
132
140
|
switch (devicePrefixName) {
|
|
@@ -178,8 +186,8 @@ const ConnectingProcess = ({ route }) => {
|
|
|
178
186
|
]);
|
|
179
187
|
|
|
180
188
|
useEffect(() => {
|
|
181
|
-
|
|
182
|
-
}, [
|
|
189
|
+
connectingDevice();
|
|
190
|
+
}, [connectingDevice]);
|
|
183
191
|
|
|
184
192
|
return (
|
|
185
193
|
<SafeAreaView style={styles.wrap}>
|
|
@@ -188,7 +196,16 @@ const ConnectingProcess = ({ route }) => {
|
|
|
188
196
|
{t('connect_device')}
|
|
189
197
|
</Text>
|
|
190
198
|
{!!isLoading && <Connecting isLoading={isLoading} />}
|
|
191
|
-
{!isLoading &&
|
|
199
|
+
{!isLoading && (
|
|
200
|
+
<ConnectingSuccess
|
|
201
|
+
unit={unit}
|
|
202
|
+
sensor={sensor}
|
|
203
|
+
station={station}
|
|
204
|
+
unit_name={unit_name}
|
|
205
|
+
newName={newName}
|
|
206
|
+
setNewName={setNewName}
|
|
207
|
+
/>
|
|
208
|
+
)}
|
|
192
209
|
</View>
|
|
193
210
|
{!isLoading && (
|
|
194
211
|
<TouchableOpacity style={styles.buttonDone} onPress={handleDone}>
|
|
@@ -113,6 +113,7 @@ describe('Test useRemoteControl', () => {
|
|
|
113
113
|
'bluetooth',
|
|
114
114
|
actionName
|
|
115
115
|
);
|
|
116
|
+
expect(sendCommandOverInternet).toBeCalledTimes(1);
|
|
116
117
|
expect(sendCommandOverGoogleHome).not.toBeCalled();
|
|
117
118
|
expect(sendCommandOverLGThinq).not.toBeCalled();
|
|
118
119
|
});
|
|
@@ -190,7 +191,6 @@ describe('Test useRemoteControl', () => {
|
|
|
190
191
|
act(() => {
|
|
191
192
|
sendRemoteCommand.current(sensor, action, data, userId, actionName);
|
|
192
193
|
});
|
|
193
|
-
expect(sendCommandOverLGThinq).toBeCalledWith(sensor, action, data);
|
|
194
194
|
expect(sendCommandOverBluetooth).not.toBeCalled();
|
|
195
195
|
expect(sendCommandOverGoogleHome).not.toBeCalled();
|
|
196
196
|
expect(sendCommandOverInternet).not.toBeCalled();
|
|
@@ -2,7 +2,6 @@ import { useCallback } from 'react';
|
|
|
2
2
|
import { useSCContextSelector } from '../../context';
|
|
3
3
|
import { sendCommandOverGoogleHome } from '../../iot/RemoteControl/GoogleHome';
|
|
4
4
|
import { sendCommandOverInternet } from '../../iot/RemoteControl/Internet';
|
|
5
|
-
import { sendCommandOverLGThinq } from '../../iot/RemoteControl/LG';
|
|
6
5
|
import {
|
|
7
6
|
sendCommandOverBluetooth,
|
|
8
7
|
SEND_COMMAND_OVER_BLUETOOTH_FAIL,
|
|
@@ -19,6 +18,7 @@ const useRemoteControl = () => {
|
|
|
19
18
|
async (sensor, action, data, userId, actionName) => {
|
|
20
19
|
// No action, raise not authorized
|
|
21
20
|
let result = false;
|
|
21
|
+
|
|
22
22
|
if (!action) {
|
|
23
23
|
ToastBottomHelper.error(
|
|
24
24
|
t('your_account_has_not_been_authorized_to_control')
|
|
@@ -30,6 +30,7 @@ const useRemoteControl = () => {
|
|
|
30
30
|
try {
|
|
31
31
|
result = await sendCommandOverBluetooth(sensor, action, data, userId);
|
|
32
32
|
} catch (err) {
|
|
33
|
+
result = false;
|
|
33
34
|
if (err === SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
|
|
34
35
|
result = await sendCommandOverInternet(
|
|
35
36
|
sensor,
|
|
@@ -45,8 +46,9 @@ const useRemoteControl = () => {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
if (
|
|
48
|
-
action.command_prefer_over_internet ||
|
|
49
|
-
|
|
49
|
+
(action.command_prefer_over_internet ||
|
|
50
|
+
action.command_prefer_over_bluetooth) &&
|
|
51
|
+
!result
|
|
50
52
|
) {
|
|
51
53
|
result = await sendCommandOverInternet(
|
|
52
54
|
sensor,
|
|
@@ -56,7 +58,7 @@ const useRemoteControl = () => {
|
|
|
56
58
|
);
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
if (action.command_prefer_over_googlehome) {
|
|
61
|
+
if (action.command_prefer_over_googlehome && !result) {
|
|
60
62
|
result = await sendCommandOverGoogleHome(
|
|
61
63
|
ggHomeConnections,
|
|
62
64
|
sensor,
|
|
@@ -64,10 +66,6 @@ const useRemoteControl = () => {
|
|
|
64
66
|
data
|
|
65
67
|
);
|
|
66
68
|
}
|
|
67
|
-
|
|
68
|
-
if (action.command_prefer_over_lg) {
|
|
69
|
-
result = await sendCommandOverLGThinq(sensor, action, data);
|
|
70
|
-
}
|
|
71
69
|
return result;
|
|
72
70
|
},
|
|
73
71
|
[ggHomeConnections]
|
|
@@ -94,17 +94,17 @@ export async function updateStateByLgThinq(device_id, data) {
|
|
|
94
94
|
setConfigGlobalState('configValues', { ...configValues });
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export async function fetchDeviceStatusLG(
|
|
97
|
+
export async function fetchDeviceStatusLG(endDevice) {
|
|
98
98
|
// still need some delay
|
|
99
99
|
setTimeout(async () => {
|
|
100
100
|
const { success, data: dataStatus } = await axiosGet(
|
|
101
|
-
API.IOT.LG.DEVICE_STATUS(
|
|
101
|
+
API.IOT.LG.DEVICE_STATUS(endDevice.id),
|
|
102
102
|
{},
|
|
103
103
|
true
|
|
104
104
|
);
|
|
105
105
|
|
|
106
106
|
if (success) {
|
|
107
|
-
updateStateByLgThinq(
|
|
107
|
+
updateStateByLgThinq(endDevice.lg_device_id, dataStatus);
|
|
108
108
|
}
|
|
109
109
|
}, 1000);
|
|
110
110
|
}
|
|
@@ -128,11 +128,11 @@ export const lgThinqConnect = async (options) => {
|
|
|
128
128
|
const option = options[i];
|
|
129
129
|
for (let j = 0; j < option.lg_devices.length; j++) {
|
|
130
130
|
const lgDevice = option.lg_devices[j];
|
|
131
|
-
const
|
|
132
|
-
id: lgDevice.
|
|
131
|
+
const endDevice = {
|
|
132
|
+
id: lgDevice.end_device_id,
|
|
133
133
|
lg_device_id: lgDevice.device_id,
|
|
134
134
|
};
|
|
135
|
-
await fetchDeviceStatusLG(
|
|
135
|
+
await fetchDeviceStatusLG(endDevice);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
};
|
|
@@ -107,7 +107,7 @@ describe('Remote Control LG Thinq', () => {
|
|
|
107
107
|
lg_devices: [
|
|
108
108
|
{
|
|
109
109
|
id: 1,
|
|
110
|
-
|
|
110
|
+
end_device_id: 2,
|
|
111
111
|
device_id: 'DEVICE_ID',
|
|
112
112
|
configs: [
|
|
113
113
|
{
|
|
@@ -188,7 +188,7 @@ describe('Remote Control LG Thinq', () => {
|
|
|
188
188
|
lg_devices: [
|
|
189
189
|
{
|
|
190
190
|
id: 1,
|
|
191
|
-
|
|
191
|
+
end_device_id: 2,
|
|
192
192
|
device_id: 'DEVICE_ID',
|
|
193
193
|
configs: [
|
|
194
194
|
{
|
|
@@ -51,7 +51,7 @@ import EmergencySetting from '../screens/EmergencySetting';
|
|
|
51
51
|
import ConfirmUnitDeletion from '../screens/ConfirmUnitDeletion';
|
|
52
52
|
import InfoMemberUnit from '../screens/Sharing/InfoMemberUnit';
|
|
53
53
|
import EnterPassword from '../screens/EnterPassword';
|
|
54
|
-
import
|
|
54
|
+
import SelectFavoritesDevices from '../screens/Unit/SelectFavoritesDevices';
|
|
55
55
|
import { HanetCameraStack } from './HanetCameraStack';
|
|
56
56
|
import { axiosGet } from '../utils/Apis/axios';
|
|
57
57
|
import { API } from '../configs';
|
|
@@ -402,8 +402,8 @@ export const UnitStack = memo((props) => {
|
|
|
402
402
|
}}
|
|
403
403
|
/>
|
|
404
404
|
<Stack.Screen
|
|
405
|
-
name={Route.
|
|
406
|
-
component={
|
|
405
|
+
name={Route.SelectFavoritesDevices}
|
|
406
|
+
component={SelectFavoritesDevices}
|
|
407
407
|
options={{
|
|
408
408
|
headerShown: false,
|
|
409
409
|
}}
|
|
@@ -41,6 +41,7 @@ const SelectAction = memo(({ route }) => {
|
|
|
41
41
|
isAutomateTab,
|
|
42
42
|
isCreateNewAction,
|
|
43
43
|
isMultiUnits,
|
|
44
|
+
oldType,
|
|
44
45
|
} = route.params;
|
|
45
46
|
const [data, setData] = useState([]);
|
|
46
47
|
const [actions, setActions] = useState([]);
|
|
@@ -257,7 +258,7 @@ const SelectAction = memo(({ route }) => {
|
|
|
257
258
|
navigate(Routes.ScriptDetail, {
|
|
258
259
|
id: automateId,
|
|
259
260
|
name: scriptName,
|
|
260
|
-
type:
|
|
261
|
+
type: oldType,
|
|
261
262
|
havePermission: true,
|
|
262
263
|
unit,
|
|
263
264
|
isMultiUnits,
|
|
@@ -116,6 +116,7 @@ const SelectSensorDevices = memo(({ route }) => {
|
|
|
116
116
|
isAutomateTab,
|
|
117
117
|
isCreateNewAction,
|
|
118
118
|
isMultiUnits,
|
|
119
|
+
oldType,
|
|
119
120
|
});
|
|
120
121
|
}, [
|
|
121
122
|
navigate,
|
|
@@ -131,6 +132,7 @@ const SelectSensorDevices = memo(({ route }) => {
|
|
|
131
132
|
isAutomateTab,
|
|
132
133
|
isCreateNewAction,
|
|
133
134
|
isMultiUnits,
|
|
135
|
+
oldType,
|
|
134
136
|
]);
|
|
135
137
|
|
|
136
138
|
const onPressClose = useCallback(() => {
|
|
@@ -20,9 +20,9 @@ import { SCContext } from '../../context';
|
|
|
20
20
|
import { Action } from '../../context/actionType';
|
|
21
21
|
import { axiosGet, axiosPost } from '../../utils/Apis/axios';
|
|
22
22
|
import { API, Colors } from '../../configs';
|
|
23
|
-
import styles from './
|
|
23
|
+
import styles from './SelectFavoritesDevicesStyles';
|
|
24
24
|
|
|
25
|
-
const
|
|
25
|
+
const SelectFavoritesDevices = memo(({ route }) => {
|
|
26
26
|
const t = useTranslations();
|
|
27
27
|
const { goBack } = useNavigation();
|
|
28
28
|
const { unitId } = route.params;
|
|
@@ -32,7 +32,7 @@ const SelectDevices = memo(({ route }) => {
|
|
|
32
32
|
const [indexStation, setIndexStation] = useState(0);
|
|
33
33
|
const [stations, setStations] = useState([]);
|
|
34
34
|
const [selectedIds, setSelectedIds] = useState([]);
|
|
35
|
-
const [loading, setLoading] = useState(
|
|
35
|
+
const [loading, setLoading] = useState(true);
|
|
36
36
|
|
|
37
37
|
const fetchData = useCallback(async () => {
|
|
38
38
|
setLoading(true);
|
|
@@ -116,7 +116,7 @@ const SelectDevices = memo(({ route }) => {
|
|
|
116
116
|
{t('select_device')}
|
|
117
117
|
</Text>
|
|
118
118
|
|
|
119
|
-
{listStation.length
|
|
119
|
+
{!!listStation.length && (
|
|
120
120
|
<NavBar
|
|
121
121
|
listStation={listStation}
|
|
122
122
|
listMenuItem={listMenuItem}
|
|
@@ -124,7 +124,8 @@ const SelectDevices = memo(({ route }) => {
|
|
|
124
124
|
indexStation={indexStation}
|
|
125
125
|
style={styles.navbar}
|
|
126
126
|
/>
|
|
127
|
-
)
|
|
127
|
+
)}
|
|
128
|
+
{!listStation.length && !loading && (
|
|
128
129
|
<View style={styles.noneData}>
|
|
129
130
|
<Text center>{t('text_unit_add_to_favorites_no_devices')}</Text>
|
|
130
131
|
</View>
|
|
@@ -155,4 +156,4 @@ const SelectDevices = memo(({ route }) => {
|
|
|
155
156
|
);
|
|
156
157
|
});
|
|
157
158
|
|
|
158
|
-
export default
|
|
159
|
+
export default SelectFavoritesDevices;
|
|
File without changes
|
|
@@ -4,7 +4,7 @@ import MockAdapter from 'axios-mock-adapter';
|
|
|
4
4
|
|
|
5
5
|
import { SCProvider } from '../../../context';
|
|
6
6
|
import { mockSCStore } from '../../../context/mockStore';
|
|
7
|
-
import
|
|
7
|
+
import SelectFavoritesDevices from '../SelectFavoritesDevices';
|
|
8
8
|
import Device from '../../AddNewAction/Device';
|
|
9
9
|
import BottomButtonView from '../../../commons/BottomButtonView';
|
|
10
10
|
import { API } from '../../../configs';
|
|
@@ -12,7 +12,7 @@ import api from '../../../utils/Apis/axios';
|
|
|
12
12
|
|
|
13
13
|
const wrapComponent = (route) => (
|
|
14
14
|
<SCProvider initState={mockSCStore({})}>
|
|
15
|
-
<
|
|
15
|
+
<SelectFavoritesDevices route={route} />
|
|
16
16
|
</SCProvider>
|
|
17
17
|
);
|
|
18
18
|
|
|
@@ -35,7 +35,7 @@ jest.mock('react', () => {
|
|
|
35
35
|
};
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
describe('Test
|
|
38
|
+
describe('Test SelectFavoritesDevices', () => {
|
|
39
39
|
let tree, route;
|
|
40
40
|
|
|
41
41
|
beforeAll(() => {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { StyleSheet } from 'react-native';
|
|
2
|
-
import { Colors
|
|
3
|
-
|
|
4
|
-
const marginItem = 12;
|
|
5
|
-
const marginHorizontal = 16;
|
|
6
|
-
const widthItem = (Constants.width - marginHorizontal * 2 - marginItem) / 2;
|
|
7
|
-
const heightItem = (widthItem / 166) * 126;
|
|
2
|
+
import { Colors } from '../../configs';
|
|
8
3
|
|
|
9
4
|
export default StyleSheet.create({
|
|
10
5
|
container: {
|
|
@@ -76,10 +71,6 @@ export default StyleSheet.create({
|
|
|
76
71
|
margin: 0,
|
|
77
72
|
padding: 0,
|
|
78
73
|
},
|
|
79
|
-
wrapItemStyle: {
|
|
80
|
-
height: heightItem,
|
|
81
|
-
marginVertical: 0,
|
|
82
|
-
},
|
|
83
74
|
camera: {
|
|
84
75
|
width: 1,
|
|
85
76
|
height: 1,
|
package/src/utils/Route/index.js
CHANGED
|
@@ -146,7 +146,7 @@ const Routes = {
|
|
|
146
146
|
ItemPasscode: 'ItemPasscode',
|
|
147
147
|
UnitMemberInformation: 'UnitMemberInformation',
|
|
148
148
|
EnterPassword: 'EnterPassword',
|
|
149
|
-
|
|
149
|
+
SelectFavoritesDevices: 'SelectFavoritesDevices',
|
|
150
150
|
};
|
|
151
151
|
|
|
152
152
|
export default Routes;
|