@eohjsc/react-native-smart-city 0.3.89 → 0.3.91
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/__test__/NumberUpDownTemplate.test.js +1 -1
- package/src/commons/ActionTemplate/CurtainAction.js +2 -2
- package/src/commons/ActionTemplate/OnOffButtonAction.js +2 -2
- package/src/commons/ActionTemplate/OnOffSimpleAction.js +2 -2
- package/src/commons/ActionTemplate/OnOffSmartLockAction.js +2 -2
- package/src/commons/ActionTemplate/OneButtonAction.js +2 -2
- package/src/commons/ActionTemplate/ThreeButtonAction.js +2 -2
- package/src/commons/ActionTemplate/__test__/CurtainAction.test.js +1 -1
- package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +1 -1
- package/src/commons/ActionTemplate/__test__/OnOffSimpleAction.test.js +1 -1
- package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +1 -1
- package/src/commons/ActionTemplate/__test__/OneButtonAction.test.js +1 -1
- package/src/commons/ActionTemplate/__test__/ThreeButtonAction.test.js +1 -1
- package/src/commons/ActionTemplate/__test__/index.test.js +21 -70
- package/src/commons/ActionTemplate/index.js +19 -55
- package/src/commons/Alert/__test__/Alert.test.js +1 -1
- package/src/commons/Auth/__test__/OtpInputList.test.js +4 -2
- package/src/commons/Auth/__test__/SocialButton.test.js +4 -2
- package/src/commons/BackDefault/__test__/BackDefault.test.js +1 -1
- package/src/commons/Button/__test__/Button.test.js +1 -1
- package/src/commons/ButtonPopup/__test__/ButtonPopup.test.js +1 -1
- package/src/commons/Calendar/__test__/Calendar.test.js +1 -1
- package/src/commons/ChartLoading/__test__/ChartLoading.test.js +1 -1
- package/src/commons/CircleButton/__test__/CircleButton.test.js +1 -1
- package/src/commons/CircleView/__test__/CircleView.test.js +1 -1
- package/src/commons/DateTimeRangeChange/__test__/DateTimeButton.test.js +4 -2
- package/src/commons/DateTimeRangeChange/index.js +31 -48
- package/src/commons/Device/Emergency/__test__/EmergencyButton.test.js +2 -2
- package/src/commons/Device/Emergency/__test__/EmergencyDetail.test.js +1 -1
- package/src/commons/Device/FlatListItems.js +1 -1
- package/src/commons/Device/Hanet/ItemHanetDevice.test.js +2 -2
- package/src/commons/Device/HistoryChart.js +6 -49
- package/src/commons/Device/LinearChart/LinearChart.test.js +1 -1
- package/src/commons/Device/ProgressBar/__test__/ProgressBar.test.js +3 -4
- package/src/commons/Device/ProgressBar/index.js +6 -4
- package/src/commons/Device/ProgressBar/styles.js +9 -6
- package/src/commons/Device/RainningSensor/__test__/CurrentRainSensor.test.js +5 -5
- package/src/commons/Device/SonosSpeaker/__test__/SonosSpeaker.test.js +3 -3
- package/src/commons/Device/WindDirection/Compass/Compass.test.js +2 -2
- package/src/commons/Device/WindSpeed/LinearChart/index.js +1 -1
- package/src/commons/Device/__test__/DeviceAlertStatus.test.js +3 -3
- package/src/commons/Device/__test__/DisconnectedView.test.js +2 -2
- package/src/commons/Device/__test__/FlatListItems.test.js +1 -1
- package/src/commons/Device/__test__/SensorConnectedStatus.test.js +1 -1
- package/src/commons/DisplayChecking/__test__/DisplayChecking.test.js +1 -1
- package/src/commons/Form/__test__/CurrencyInput.test.js +2 -2
- package/src/commons/Form/__test__/TextInput.test.js +2 -2
- package/src/commons/Form/__test__/TextInputPassword.test.js +2 -2
- package/src/commons/FullLoading/__test__/index.test.js +2 -2
- package/src/commons/ImageButton/__test__/ImageButton.test.js +1 -1
- package/src/commons/OneTapTemplate/NumberUpDownActionTemplate.js +2 -2
- package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +4 -4
- package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +4 -4
- package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +2 -2
- package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +1 -1
- package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +2 -2
- package/src/commons/RowItem/__test__/RowItem.test.js +1 -1
- package/src/commons/RowUser/__test__/RowUser.test.js +1 -1
- package/src/commons/Section/Section.test.js +2 -2
- package/src/commons/SelectSubUnit/__test__/SelectSubUnit.test.js +1 -1
- package/src/commons/SelectUnit/__test__/SelectUnit.test.js +3 -3
- package/src/commons/Sharing/__test__/ButtonRemoveMember.test.js +1 -1
- package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +1 -1
- package/src/commons/Sharing/__test__/MemberList.test.js +6 -4
- package/src/commons/Sharing/__test__/RowMember.test.js +2 -2
- package/src/commons/Sharing/__test__/StationDevicePermission.test.js +3 -3
- package/src/commons/Sharing/__test__/WrapHeaderScrollable.test.js +4 -2
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +2 -10
- package/src/commons/SubUnit/OneTap/index.js +3 -1
- package/src/commons/TextButton/__test__/TextButton.test.js +2 -2
- package/src/commons/Today/__test__/Today.test.js +1 -1
- package/src/commons/TouchableScale/__test__/TouchableScale.test.js +1 -1
- package/src/commons/UnitSummary/AirQuality/index.js +2 -2
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +0 -6
- package/src/commons/UnitSummary/__test__/TotalPowerBox.test.js +1 -1
- package/src/commons/UnitSummary/__test__/TotalPowerConsumption.test.js +1 -1
- package/src/commons/ViewButtonBottom/__test__/ViewButtonBottom.test.js +1 -1
- package/src/configs/API.js +9 -32
- package/src/configs/Constants.js +2 -30
- package/src/context/reducer.ts +3 -1
- package/src/hoc/__test__/withRemoteControl.test.js +1 -1
- package/src/navigations/UnitStack.js +23 -13
- package/src/screens/ActivityLog/FilterPopup.js +4 -4
- package/src/screens/ActivityLog/__test__/FilterPopup.test.js +2 -2
- package/src/screens/ActivityLog/__test__/index.test.js +2 -2
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +3 -3
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +5 -5
- package/src/screens/AddNewAction/ChooseAction.js +180 -0
- package/src/screens/AddNewAction/ChooseConfig.js +207 -0
- package/src/screens/AddNewAction/Components/SelectDevices.js +75 -0
- package/src/screens/AddNewAction/Device/__test__/index.test.js +1 -1
- package/src/screens/AddNewAction/NewActionWrapper.js +55 -0
- package/src/screens/AddNewAction/SelectControlDevices.js +107 -0
- package/src/screens/AddNewAction/SelectMonitorDevices.js +142 -0
- package/src/screens/AddNewAction/SetupConfigCondition.js +245 -0
- package/src/screens/AddNewAction/Styles/SetupSensorStyles.js +1 -1
- package/src/screens/AddNewAction/__test__/{SelectAction.test.js → ChooseAction.test.js} +94 -114
- package/src/screens/AddNewAction/__test__/ChooseConfig.test.js +211 -0
- package/src/screens/AddNewAction/__test__/{SelectSensorDevices.test.js → SelectControlDevices.test.js} +32 -83
- package/src/screens/AddNewAction/__test__/SelectMonitorDevices.test.js +92 -0
- package/src/screens/AddNewAction/__test__/SetupSensor.test.js +9 -22
- package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +2 -3
- package/src/screens/AddNewAutoSmart/index.js +13 -33
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/ConnectRouterGuide.test.js +1 -1
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/FirstWarning.test.js +1 -1
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/ZigbeeDeviceConnectGuide.test.js +1 -1
- package/src/screens/AddNewGateway/__test__/ConnectingWifiGuide.test.js +1 -1
- package/src/screens/AddNewGateway/__test__/ScanGatewayQR.test.js +2 -2
- package/src/screens/AddNewGateway/__test__/ScanModbusQR.test.js +3 -3
- package/src/screens/AddNewGateway/__test__/ScanWifiDeviceQR.test.js +2 -2
- package/src/screens/AddNewGateway/__test__/SelectDeviceSubUnit.test.js +3 -3
- package/src/screens/AddNewGateway/__test__/SelectDeviceUnit.test.js +1 -1
- package/src/screens/AddNewGateway/__test__/ShareWifiPassword.test.js +1 -1
- package/src/screens/AddNewOneTap/index.js +16 -7
- package/src/screens/AllCamera/__test__/index.test.js +18 -57
- package/src/screens/AllCamera/index.js +98 -30
- package/src/screens/Automate/MultiUnits.js +2 -2
- package/src/screens/Automate/__test__/MultiUnits.test.js +2 -2
- package/src/screens/Automate/__test__/index.test.js +19 -38
- package/src/screens/Automate/index.js +8 -3
- package/src/screens/Device/__test__/DetailHistoryChart.test.js +2 -2
- package/src/screens/Device/__test__/EmergencyCountdown.test.js +4 -2
- package/src/screens/Device/__test__/sensorDisplayItem.test.js +10 -10
- package/src/screens/Device/components/ChartWrapper.js +3 -3
- package/src/screens/Device/components/VisualChart.js +1 -1
- package/src/screens/Device/components/__test__/VisualChart.test.js +1 -1
- package/src/screens/Device/hooks/useEvaluateValue.js +8 -0
- package/src/screens/DeviceInfo/__test__/index.test.js +16 -18
- package/src/screens/DeviceInfo/index.js +6 -5
- package/src/screens/EditActionsList/__tests__/index.test.js +14 -6
- package/src/screens/Notification/__test__/Notification.test.js +65 -74
- package/src/screens/Notification/index.js +14 -14
- package/src/screens/ScriptDetail/__test__/index.test.js +2 -8
- package/src/screens/ScriptDetail/index.js +9 -88
- package/src/screens/ScriptDetail/utils.js +112 -0
- package/src/screens/SelectUnit/__test__/index.test.js +0 -5
- package/src/screens/SelectUnit/index.js +1 -2
- package/src/screens/Sharing/Components/TitleCheckBox.js +2 -2
- package/src/screens/SmartAccount/SuccessfullyConnected/__test__/SuccessfullyConnected.test.js +3 -3
- package/src/screens/SmartAccount/__test__/Connecting.test.js +1 -1
- package/src/screens/SmartAccount/__test__/SmartAccount.test.js +3 -3
- package/src/screens/SmartIr/__test__/ButtonsBottom.test.js +1 -1
- package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +5 -5
- package/src/screens/SmartIr/__test__/SelectBrand.test.js +2 -2
- package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +2 -2
- package/src/screens/SmartIr/__test__/SmartIr.test.js +2 -2
- package/src/screens/Template/__test__/detail.test.js +10 -2
- package/src/screens/Unit/__test__/Detail.test.js +7 -13
- package/src/screens/Unit/components/__test__/Header.test.js +4 -4
- package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +1 -1
- package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +14 -6
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +1 -1
- package/src/screens/UnitSummary/components/Temperature/index.js +2 -2
- package/src/screens/UnitSummary/components/UvIndex/index.js +2 -2
- package/src/screens/UnitSummary/components/WaterQuality/index.js +2 -2
- package/src/screens/UnitSummary/components/__test__/TotalPowerBox.test.js +1 -1
- package/src/screens/UnitSummary/components/__test__/TotalPowerConsumption.test.js +1 -1
- package/src/screens/UnitSummary/components/__test__/index.test.js +2 -2
- package/src/utils/Apis/axios.js +3 -0
- package/src/utils/I18n/translations/en.json +1 -0
- package/src/utils/I18n/translations/vi.json +1 -0
- package/src/utils/Route/index.js +6 -3
- package/src/screens/AddNewAction/SelectAction.js +0 -570
- package/src/screens/AddNewAction/SelectSensorDevices.js +0 -236
- package/src/screens/AddNewAction/SetupSensor.js +0 -263
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import React, { memo, useContext, useEffect } from 'react';
|
|
2
|
-
import { View } from 'react-native';
|
|
2
|
+
import { AppState, View } from 'react-native';
|
|
3
3
|
import { IconOutline } from '@ant-design/icons-react-native';
|
|
4
4
|
import { createStackNavigator } from '@react-navigation/stack';
|
|
5
5
|
import { BleManager } from 'react-native-ble-plx';
|
|
6
6
|
import NetInfo from '@react-native-community/netinfo';
|
|
7
|
-
import { AppState } from 'react-native';
|
|
8
7
|
import { get } from 'lodash';
|
|
9
8
|
|
|
10
9
|
import Text from '../commons/Text';
|
|
11
10
|
import { useTranslations } from '../hooks/Common/useTranslations';
|
|
12
11
|
import { unwatchAllConfigs } from '../iot/Monitor';
|
|
13
|
-
import { Colors, Device } from '../configs';
|
|
12
|
+
import { API, Colors, Device } from '../configs';
|
|
14
13
|
import Route from '../utils/Route';
|
|
15
14
|
import ActivityLogScreen from '../screens/ActivityLog';
|
|
16
15
|
import { screenOptions } from './utils';
|
|
@@ -43,10 +42,9 @@ import ScriptDetail from '../screens/ScriptDetail';
|
|
|
43
42
|
import EditActionsList from '../screens/EditActionsList';
|
|
44
43
|
import SelectUnit from '../screens/SelectUnit';
|
|
45
44
|
import SetSchedule from '../screens/SetSchedule';
|
|
46
|
-
import
|
|
47
|
-
import SelectAction from '../screens/AddNewAction/SelectAction';
|
|
45
|
+
import SelectMonitorDevices from '../screens/AddNewAction/SelectMonitorDevices';
|
|
48
46
|
import EditSubUnit from '../screens/SubUnit/EditSubUnit';
|
|
49
|
-
import
|
|
47
|
+
import SetupConfigCondition from '../screens/AddNewAction/SetupConfigCondition';
|
|
50
48
|
import EditDevice from '../screens/Device/EditDevice/index';
|
|
51
49
|
import EmergencySetting from '../screens/EmergencySetting';
|
|
52
50
|
import ConfirmUnitDeletion from '../screens/ConfirmUnitDeletion';
|
|
@@ -56,12 +54,14 @@ import AllGateway from '../screens/AllGateway';
|
|
|
56
54
|
import SelectAddToFavorites from '../screens/Unit/SelectAddToFavorites';
|
|
57
55
|
import { HanetCameraStack } from './HanetCameraStack';
|
|
58
56
|
import { axiosGet, fetchWithCache } from '../utils/Apis/axios';
|
|
59
|
-
import { API } from '../configs';
|
|
60
57
|
import SideMenuDetail from '../screens/SideMenuDetail';
|
|
61
58
|
import { styles } from './UnitStackStyles';
|
|
62
59
|
import { useBluetoothConnection } from '../hooks/IoT';
|
|
63
60
|
import { realScanBluetoothDevices } from '../iot/RemoteControl/Bluetooth';
|
|
64
61
|
import { ToastBottomHelper } from '../utils/Utils';
|
|
62
|
+
import ChooseConfig from '../screens/AddNewAction/ChooseConfig';
|
|
63
|
+
import SelectControlDevices from '../screens/AddNewAction/SelectControlDevices';
|
|
64
|
+
import ChooseAction from '../screens/AddNewAction/ChooseAction';
|
|
65
65
|
|
|
66
66
|
const Stack = createStackNavigator();
|
|
67
67
|
|
|
@@ -410,8 +410,13 @@ export const UnitStack = memo((props) => {
|
|
|
410
410
|
}}
|
|
411
411
|
/>
|
|
412
412
|
<Stack.Screen
|
|
413
|
-
name={Route.
|
|
414
|
-
component={
|
|
413
|
+
name={Route.SelectMonitorDevices}
|
|
414
|
+
component={SelectMonitorDevices}
|
|
415
|
+
options={{ headerShown: false }}
|
|
416
|
+
/>
|
|
417
|
+
<Stack.Screen
|
|
418
|
+
name={Route.SelectControlDevices}
|
|
419
|
+
component={SelectControlDevices}
|
|
415
420
|
options={{ headerShown: false }}
|
|
416
421
|
/>
|
|
417
422
|
<Stack.Screen
|
|
@@ -420,13 +425,18 @@ export const UnitStack = memo((props) => {
|
|
|
420
425
|
options={{ headerShown: false }}
|
|
421
426
|
/>
|
|
422
427
|
<Stack.Screen
|
|
423
|
-
name={Route.
|
|
424
|
-
component={
|
|
428
|
+
name={Route.SetupConfigCondition}
|
|
429
|
+
component={SetupConfigCondition}
|
|
430
|
+
options={{ headerShown: false }}
|
|
431
|
+
/>
|
|
432
|
+
<Stack.Screen
|
|
433
|
+
name={Route.ChooseConfig}
|
|
434
|
+
component={ChooseConfig}
|
|
425
435
|
options={{ headerShown: false }}
|
|
426
436
|
/>
|
|
427
437
|
<Stack.Screen
|
|
428
|
-
name={Route.
|
|
429
|
-
component={
|
|
438
|
+
name={Route.ChooseAction}
|
|
439
|
+
component={ChooseAction}
|
|
430
440
|
options={{ headerShown: false }}
|
|
431
441
|
/>
|
|
432
442
|
<Stack.Screen
|
|
@@ -78,7 +78,7 @@ const FilterPopup = ({
|
|
|
78
78
|
[selectedUsers, setSelectedUsers]
|
|
79
79
|
);
|
|
80
80
|
|
|
81
|
-
const
|
|
81
|
+
const selectStart = useCallback(() => {
|
|
82
82
|
onHide();
|
|
83
83
|
acquireLockShowing();
|
|
84
84
|
setStateDatePicker((state) => ({
|
|
@@ -88,7 +88,7 @@ const FilterPopup = ({
|
|
|
88
88
|
}));
|
|
89
89
|
}, [onHide, acquireLockShowing]);
|
|
90
90
|
|
|
91
|
-
const
|
|
91
|
+
const selectEnd = useCallback(() => {
|
|
92
92
|
onHide();
|
|
93
93
|
acquireLockShowing();
|
|
94
94
|
setStateDatePicker((state) => ({
|
|
@@ -208,8 +208,8 @@ const FilterPopup = ({
|
|
|
208
208
|
<DateTimeRangeChange
|
|
209
209
|
startTime={stateDatePicker.startDate}
|
|
210
210
|
endTime={stateDatePicker.endDate}
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
selectStart={selectStart}
|
|
212
|
+
selectEnd={selectEnd}
|
|
213
213
|
formatType="date"
|
|
214
214
|
inline={true}
|
|
215
215
|
/>
|
|
@@ -133,10 +133,10 @@ it('test date picker pick valid and invalid date', async () => {
|
|
|
133
133
|
const _pickDateAndTest = async (timeChange) => {
|
|
134
134
|
await act(async () => {
|
|
135
135
|
if (timeChange === 'start') {
|
|
136
|
-
await dateTimeRangeChange.props.
|
|
136
|
+
await dateTimeRangeChange.props.selectStart();
|
|
137
137
|
await datePicker.props.onConfirm(moment(dateFrom));
|
|
138
138
|
} else {
|
|
139
|
-
await dateTimeRangeChange.props.
|
|
139
|
+
await dateTimeRangeChange.props.selectEnd();
|
|
140
140
|
await datePicker.props.onConfirm(moment(dateTo));
|
|
141
141
|
}
|
|
142
142
|
});
|
|
@@ -118,7 +118,7 @@ describe('Test Activity log', () => {
|
|
|
118
118
|
|
|
119
119
|
// pick start date
|
|
120
120
|
await act(async () => {
|
|
121
|
-
await dateTimeRangeChange.props.
|
|
121
|
+
await dateTimeRangeChange.props.selectStart();
|
|
122
122
|
await filterPopup[0].props.onModalHide();
|
|
123
123
|
});
|
|
124
124
|
expect(filterPopup[0].props.isVisible).toBeFalsy();
|
|
@@ -136,7 +136,7 @@ describe('Test Activity log', () => {
|
|
|
136
136
|
expect(filterPopup[0].props.isVisible).toBeTruthy();
|
|
137
137
|
// pick end date
|
|
138
138
|
await act(async () => {
|
|
139
|
-
await dateTimeRangeChange.props.
|
|
139
|
+
await dateTimeRangeChange.props.selectEnd();
|
|
140
140
|
await filterPopup[0].props.onModalHide();
|
|
141
141
|
});
|
|
142
142
|
expect(filterPopup[0].props.isVisible).toBeFalsy();
|
|
@@ -44,7 +44,7 @@ describe('Test SelectSubUnit', () => {
|
|
|
44
44
|
it('test ViewButtonBottom onRightClick', async () => {
|
|
45
45
|
const route = { params: { addType: 'AddHassiDevice' } };
|
|
46
46
|
await act(async () => {
|
|
47
|
-
tree = renderer.create(wrapComponent(route));
|
|
47
|
+
tree = await renderer.create(wrapComponent(route));
|
|
48
48
|
});
|
|
49
49
|
const instance = tree.root;
|
|
50
50
|
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
@@ -72,7 +72,7 @@ describe('Test SelectSubUnit container', () => {
|
|
|
72
72
|
test(`create SelectSubUnit ${type} container`, async () => {
|
|
73
73
|
const route = { params: { addType: type } };
|
|
74
74
|
await act(async () => {
|
|
75
|
-
tree = renderer.create(wrapComponent(route));
|
|
75
|
+
tree = await renderer.create(wrapComponent(route));
|
|
76
76
|
});
|
|
77
77
|
const instance = tree.root;
|
|
78
78
|
const button = instance.findAllByType(TouchableOpacity);
|
|
@@ -88,7 +88,7 @@ describe('Test SelectSubUnit container', () => {
|
|
|
88
88
|
]);
|
|
89
89
|
|
|
90
90
|
await act(async () => {
|
|
91
|
-
tree = renderer.create(wrapComponent(route));
|
|
91
|
+
tree = await renderer.create(wrapComponent(route));
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
const instance = tree.root;
|
|
@@ -55,7 +55,7 @@ describe('Test SelectUnit container', () => {
|
|
|
55
55
|
test(`create SelectUnit ${type} container`, async () => {
|
|
56
56
|
const route = { params: { addType: type } };
|
|
57
57
|
await act(async () => {
|
|
58
|
-
tree = renderer.create(wrapComponent(route));
|
|
58
|
+
tree = await renderer.create(wrapComponent(route));
|
|
59
59
|
});
|
|
60
60
|
const instance = tree.root;
|
|
61
61
|
const button = instance.findAllByType(TouchableOpacity);
|
|
@@ -89,7 +89,7 @@ describe('Test SelectUnit container', () => {
|
|
|
89
89
|
};
|
|
90
90
|
mock.onGet(API.SHARE.UNITS()).reply(200, response.data);
|
|
91
91
|
await act(async () => {
|
|
92
|
-
tree = renderer.create(wrapComponent(route));
|
|
92
|
+
tree = await renderer.create(wrapComponent(route));
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
const instance = tree.root;
|
|
@@ -165,7 +165,7 @@ describe('test single SelectUnit', () => {
|
|
|
165
165
|
};
|
|
166
166
|
mock.onGet(API.SHARE.UNITS()).reply(200, response.data);
|
|
167
167
|
await act(async () => {
|
|
168
|
-
tree = renderer.create(wrapComponent(route));
|
|
168
|
+
tree = await renderer.create(wrapComponent(route));
|
|
169
169
|
});
|
|
170
170
|
const instance = tree.root;
|
|
171
171
|
const unitName = instance.findAll(
|
|
@@ -201,7 +201,7 @@ describe('test single SelectUnit', () => {
|
|
|
201
201
|
const route = { params: { addType: 'AddSubUnit' } };
|
|
202
202
|
mock.onGet(500);
|
|
203
203
|
await act(async () => {
|
|
204
|
-
tree = renderer.create(wrapComponent(route));
|
|
204
|
+
tree = await renderer.create(wrapComponent(route));
|
|
205
205
|
});
|
|
206
206
|
|
|
207
207
|
const instance = tree.root;
|
|
@@ -224,7 +224,7 @@ describe('test single SelectUnit', () => {
|
|
|
224
224
|
it('click goBack', async () => {
|
|
225
225
|
const route = { params: { addType: 'AddSubUnit' } };
|
|
226
226
|
await act(async () => {
|
|
227
|
-
tree = renderer.create(wrapComponent(route));
|
|
227
|
+
tree = await renderer.create(wrapComponent(route));
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
const instance = tree.root;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { useNavigation } from '@react-navigation/native';
|
|
4
|
+
import moment from 'moment';
|
|
5
|
+
|
|
6
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
7
|
+
import ActionTemplate from '../../commons/ActionTemplate';
|
|
8
|
+
import NumberUpDownActionTemplate from '../../commons/OneTapTemplate/NumberUpDownActionTemplate';
|
|
9
|
+
import OptionsDropdownActionTemplate from '../../commons/OneTapTemplate/OptionsDropdownActionTemplate';
|
|
10
|
+
import StatesGridActionTemplate from '../../commons/OneTapTemplate/StatesGridActionTemplate';
|
|
11
|
+
import { axiosGet, axiosPost } from '../../utils/Apis/axios';
|
|
12
|
+
import { API } from '../../configs';
|
|
13
|
+
import { AUTOMATE_TYPE } from '../../configs/Constants';
|
|
14
|
+
import Routes from '../../utils/Route';
|
|
15
|
+
import NewActionWrapper from './NewActionWrapper';
|
|
16
|
+
|
|
17
|
+
const ChooseAction = ({ route }) => {
|
|
18
|
+
const t = useTranslations();
|
|
19
|
+
const { navigate } = useNavigation();
|
|
20
|
+
const {
|
|
21
|
+
unit,
|
|
22
|
+
device,
|
|
23
|
+
automateId,
|
|
24
|
+
automate = {},
|
|
25
|
+
scriptName,
|
|
26
|
+
type,
|
|
27
|
+
isMultiUnits,
|
|
28
|
+
index = -1,
|
|
29
|
+
} = route?.params || {};
|
|
30
|
+
const [data, setData] = useState([]);
|
|
31
|
+
const [actions, setActions] = useState([]);
|
|
32
|
+
|
|
33
|
+
const fetchData = useCallback(async () => {
|
|
34
|
+
const { success, data: automateData } = await axiosGet(
|
|
35
|
+
API.DEVICE.DISPLAY_ACTIONS(device.id)
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (success) {
|
|
39
|
+
setData(automateData);
|
|
40
|
+
}
|
|
41
|
+
}, [device.id]);
|
|
42
|
+
|
|
43
|
+
const onSave = useCallback(async () => {
|
|
44
|
+
if (automateId) {
|
|
45
|
+
let list_action = [...actions];
|
|
46
|
+
list_action = list_action.map((item) => ({
|
|
47
|
+
action: item.action,
|
|
48
|
+
data: item.data,
|
|
49
|
+
}));
|
|
50
|
+
const { success } = await axiosPost(
|
|
51
|
+
API.AUTOMATE.ADD_SCRIPT_ACTION(automateId),
|
|
52
|
+
{
|
|
53
|
+
list_action,
|
|
54
|
+
unit: unit.id,
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
success &&
|
|
59
|
+
navigate(Routes.ScriptDetail, {
|
|
60
|
+
id: automateId,
|
|
61
|
+
name: scriptName,
|
|
62
|
+
havePermission: true,
|
|
63
|
+
unit,
|
|
64
|
+
saveAt: moment().valueOf(),
|
|
65
|
+
type: type,
|
|
66
|
+
isMultiUnits,
|
|
67
|
+
automate,
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
navigate(Routes.AddNewOneTap, {
|
|
71
|
+
automateData: {
|
|
72
|
+
action: actions[0].action,
|
|
73
|
+
},
|
|
74
|
+
type: AUTOMATE_TYPE.EVENT_ACTION,
|
|
75
|
+
unit,
|
|
76
|
+
isMultiUnits,
|
|
77
|
+
automateId,
|
|
78
|
+
automate: {
|
|
79
|
+
...automate,
|
|
80
|
+
action: actions[0].action,
|
|
81
|
+
},
|
|
82
|
+
scriptName,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}, [
|
|
86
|
+
actions,
|
|
87
|
+
automateId,
|
|
88
|
+
navigate,
|
|
89
|
+
scriptName,
|
|
90
|
+
unit,
|
|
91
|
+
type,
|
|
92
|
+
isMultiUnits,
|
|
93
|
+
automate,
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
const handleOnSelectAction = (action) => {
|
|
97
|
+
let newActions = [...actions];
|
|
98
|
+
|
|
99
|
+
if (index < 0) {
|
|
100
|
+
newActions.push(action);
|
|
101
|
+
} else {
|
|
102
|
+
newActions[index] = action; // todo Bang this case is not happening?
|
|
103
|
+
}
|
|
104
|
+
setActions(newActions);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
fetchData();
|
|
109
|
+
}, [fetchData]);
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<NewActionWrapper
|
|
113
|
+
canNext={actions.length}
|
|
114
|
+
onNext={onSave}
|
|
115
|
+
nextTitle={t('continue')}
|
|
116
|
+
title={t('choose_action')}
|
|
117
|
+
>
|
|
118
|
+
<View>
|
|
119
|
+
{data?.length > 0 &&
|
|
120
|
+
data.map((item) => (
|
|
121
|
+
<RenderActionItem
|
|
122
|
+
device={device}
|
|
123
|
+
item={item}
|
|
124
|
+
key={item.id}
|
|
125
|
+
handleOnSelectAction={handleOnSelectAction}
|
|
126
|
+
/>
|
|
127
|
+
))}
|
|
128
|
+
</View>
|
|
129
|
+
</NewActionWrapper>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const RenderActionItem = ({ device, item, handleOnSelectAction }) => {
|
|
134
|
+
switch (item.template) {
|
|
135
|
+
case 'on_off_button_action_template':
|
|
136
|
+
case 'one_button_action_template':
|
|
137
|
+
case 'three_button_action_template':
|
|
138
|
+
case 'OnOffSimpleActionTemplate':
|
|
139
|
+
case 'curtain_action_template':
|
|
140
|
+
case 'OnOffSmartLockActionTemplate':
|
|
141
|
+
return (
|
|
142
|
+
<ActionTemplate
|
|
143
|
+
device={device}
|
|
144
|
+
item={item}
|
|
145
|
+
onSelectAction={handleOnSelectAction}
|
|
146
|
+
/>
|
|
147
|
+
);
|
|
148
|
+
case 'OptionsDropdownActionTemplate':
|
|
149
|
+
return (
|
|
150
|
+
<OptionsDropdownActionTemplate
|
|
151
|
+
key={item.id}
|
|
152
|
+
device={device}
|
|
153
|
+
item={item}
|
|
154
|
+
onSelectAction={handleOnSelectAction}
|
|
155
|
+
/>
|
|
156
|
+
);
|
|
157
|
+
case 'NumberUpDownActionTemplate':
|
|
158
|
+
return (
|
|
159
|
+
<NumberUpDownActionTemplate
|
|
160
|
+
key={item.id}
|
|
161
|
+
device={device}
|
|
162
|
+
item={item}
|
|
163
|
+
onSelectAction={handleOnSelectAction}
|
|
164
|
+
/>
|
|
165
|
+
);
|
|
166
|
+
case 'StatesGridActionTemplate':
|
|
167
|
+
return (
|
|
168
|
+
<StatesGridActionTemplate
|
|
169
|
+
key={item.id}
|
|
170
|
+
device={device}
|
|
171
|
+
item={item}
|
|
172
|
+
onSelectAction={handleOnSelectAction}
|
|
173
|
+
/>
|
|
174
|
+
);
|
|
175
|
+
default:
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export default ChooseAction;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { Image, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import { useNavigation } from '@react-navigation/native';
|
|
4
|
+
|
|
5
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
6
|
+
import Text from '../../commons/Text';
|
|
7
|
+
import { axiosGet } from '../../utils/Apis/axios';
|
|
8
|
+
import { API, Colors, Images } from '../../configs';
|
|
9
|
+
import Routes from '../../utils/Route';
|
|
10
|
+
import styles from './Styles/SelectActionStyles';
|
|
11
|
+
import { TitleCheckBox } from '../Sharing/Components';
|
|
12
|
+
import { LoadingSelectAction } from './Components';
|
|
13
|
+
import { ToastBottomHelper } from '../../utils/Utils';
|
|
14
|
+
import {
|
|
15
|
+
generateAutomationConditionText,
|
|
16
|
+
generateAutomationDataConditionText,
|
|
17
|
+
getAutomationData,
|
|
18
|
+
} from '../ScriptDetail/utils';
|
|
19
|
+
import { useSCContextSelector } from '../../context';
|
|
20
|
+
import { AUTOMATE_TYPE } from '../../configs/Constants';
|
|
21
|
+
import NewActionWrapper from './NewActionWrapper';
|
|
22
|
+
|
|
23
|
+
const ChooseConfig = ({ route }) => {
|
|
24
|
+
const t = useTranslations();
|
|
25
|
+
const { navigate } = useNavigation();
|
|
26
|
+
const {
|
|
27
|
+
unit,
|
|
28
|
+
device,
|
|
29
|
+
automateId,
|
|
30
|
+
automate = {},
|
|
31
|
+
scriptName,
|
|
32
|
+
type,
|
|
33
|
+
isAutomateTab,
|
|
34
|
+
isMultiUnits,
|
|
35
|
+
newSensorData,
|
|
36
|
+
closeScreen,
|
|
37
|
+
} = route?.params || {};
|
|
38
|
+
|
|
39
|
+
const [sensorData, setSensorData] = useState([]);
|
|
40
|
+
const [checkedItem, setCheckedItem] = useState({ id: automate?.config_id });
|
|
41
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
42
|
+
const valueEvaluations = useSCContextSelector((state) => {
|
|
43
|
+
return state.valueEvaluations;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const fetchData = useCallback(async () => {
|
|
47
|
+
setIsLoading(true);
|
|
48
|
+
const configs = { params: {} };
|
|
49
|
+
if (type === AUTOMATE_TYPE.EVENT) {
|
|
50
|
+
configs.params.type = 'event';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const { success, data: automateData } = await axiosGet(
|
|
54
|
+
API.AUTOMATE.DISPLAY_CONFIGS(device.id),
|
|
55
|
+
configs
|
|
56
|
+
);
|
|
57
|
+
if (success) {
|
|
58
|
+
setSensorData(automateData);
|
|
59
|
+
}
|
|
60
|
+
setIsLoading(false);
|
|
61
|
+
}, [device.id, type]);
|
|
62
|
+
|
|
63
|
+
const onSave = useCallback(() => {
|
|
64
|
+
let itemTemp = sensorData?.find((i) => i.id === checkedItem?.id);
|
|
65
|
+
|
|
66
|
+
const isDefault = automate?.config_id === itemTemp?.id;
|
|
67
|
+
|
|
68
|
+
// todo Bang refactor remove this using same data format for get/push
|
|
69
|
+
if ([null, undefined].includes(itemTemp?.value) && isDefault) {
|
|
70
|
+
itemTemp = getAutomationData(type, automate);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if ([null, undefined].includes(itemTemp?.value)) {
|
|
74
|
+
ToastBottomHelper.error(t('please_choose_condition_before_continue'));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
navigate(Routes.AddNewOneTap, {
|
|
78
|
+
automateData: itemTemp,
|
|
79
|
+
type,
|
|
80
|
+
unit,
|
|
81
|
+
isAutomateTab,
|
|
82
|
+
isMultiUnits,
|
|
83
|
+
automateId,
|
|
84
|
+
automate: {
|
|
85
|
+
...automate,
|
|
86
|
+
...itemTemp,
|
|
87
|
+
},
|
|
88
|
+
scriptName,
|
|
89
|
+
});
|
|
90
|
+
}, [
|
|
91
|
+
sensorData,
|
|
92
|
+
navigate,
|
|
93
|
+
type,
|
|
94
|
+
unit,
|
|
95
|
+
isAutomateTab,
|
|
96
|
+
isMultiUnits,
|
|
97
|
+
automateId,
|
|
98
|
+
automate,
|
|
99
|
+
scriptName,
|
|
100
|
+
checkedItem?.id,
|
|
101
|
+
t,
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
const onChecked = useCallback(
|
|
105
|
+
(_, isChecked, id) => {
|
|
106
|
+
setCheckedItem(isChecked ? sensorData.find((i) => i?.id === id) : {});
|
|
107
|
+
},
|
|
108
|
+
[sensorData]
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const onPressItem = (item) => () => {
|
|
112
|
+
navigate(Routes.SetupConfigCondition, {
|
|
113
|
+
item,
|
|
114
|
+
sensorData,
|
|
115
|
+
isAutomateTab,
|
|
116
|
+
type,
|
|
117
|
+
automate,
|
|
118
|
+
closeScreen,
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const renderCondition = useCallback(
|
|
123
|
+
(item) => {
|
|
124
|
+
return generateAutomationDataConditionText(
|
|
125
|
+
type,
|
|
126
|
+
item,
|
|
127
|
+
item.value_evaluation || {
|
|
128
|
+
// backward compatible
|
|
129
|
+
template: item.evaluate_template,
|
|
130
|
+
configuration: item.evaluate_configuration,
|
|
131
|
+
},
|
|
132
|
+
t
|
|
133
|
+
);
|
|
134
|
+
},
|
|
135
|
+
[t, type]
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
fetchData();
|
|
140
|
+
}, [fetchData]);
|
|
141
|
+
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
newSensorData && setSensorData(newSensorData);
|
|
144
|
+
}, [newSensorData]);
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<NewActionWrapper
|
|
148
|
+
name={t('set_up {name}', { name: device?.name })}
|
|
149
|
+
nextTitle={t('continue')}
|
|
150
|
+
onNext={onSave}
|
|
151
|
+
canNext={checkedItem?.id}
|
|
152
|
+
>
|
|
153
|
+
{isLoading ? (
|
|
154
|
+
<LoadingSelectAction style={styles.container} />
|
|
155
|
+
) : (
|
|
156
|
+
sensorData.map((item) => {
|
|
157
|
+
const hasValue = ![undefined, null].includes(item?.value);
|
|
158
|
+
const isChecked = checkedItem?.id === item?.id;
|
|
159
|
+
const isDefault = automate?.config_id === item?.id;
|
|
160
|
+
return (
|
|
161
|
+
<View style={styles.wrapItem} key={item?.id}>
|
|
162
|
+
<TitleCheckBox
|
|
163
|
+
onPress={onChecked}
|
|
164
|
+
id={item?.id}
|
|
165
|
+
title={item?.name}
|
|
166
|
+
titleStyle={styles.titleStyle}
|
|
167
|
+
wrapStyle={styles.wrapStyleCheckBox}
|
|
168
|
+
isChecked={isChecked}
|
|
169
|
+
/>
|
|
170
|
+
<TouchableOpacity
|
|
171
|
+
onPress={onPressItem(item)}
|
|
172
|
+
style={[styles.wrapCondition, styles.shadowView]}
|
|
173
|
+
accessibilityLabel={`config-${item.id}`}
|
|
174
|
+
>
|
|
175
|
+
<Text type="Body" color={Colors.Gray7}>
|
|
176
|
+
{t('condition')}
|
|
177
|
+
</Text>
|
|
178
|
+
<Text
|
|
179
|
+
numberOfLines={1}
|
|
180
|
+
type="H4"
|
|
181
|
+
semibold={isChecked}
|
|
182
|
+
style={styles.description}
|
|
183
|
+
>
|
|
184
|
+
{hasValue
|
|
185
|
+
? renderCondition(item)
|
|
186
|
+
: isDefault
|
|
187
|
+
? generateAutomationConditionText(
|
|
188
|
+
type,
|
|
189
|
+
automate,
|
|
190
|
+
valueEvaluations[automate?.config_id],
|
|
191
|
+
t
|
|
192
|
+
)
|
|
193
|
+
: t('no_condition')}
|
|
194
|
+
</Text>
|
|
195
|
+
{hasValue && (
|
|
196
|
+
<Image source={Images.arrowBack} style={styles.arrowRight} />
|
|
197
|
+
)}
|
|
198
|
+
</TouchableOpacity>
|
|
199
|
+
</View>
|
|
200
|
+
);
|
|
201
|
+
})
|
|
202
|
+
)}
|
|
203
|
+
</NewActionWrapper>
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export default ChooseConfig;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import styles from '../Styles/SelectSensorDevicesStyles';
|
|
3
|
+
import Text from '../../../commons/Text';
|
|
4
|
+
import NavBar from '../../../commons/NavBar';
|
|
5
|
+
import Device from '../Device';
|
|
6
|
+
import React, { useCallback, useState } from 'react';
|
|
7
|
+
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
8
|
+
import NewActionWrapper from '../NewActionWrapper';
|
|
9
|
+
|
|
10
|
+
const SelectDevices = ({
|
|
11
|
+
onPressContinue,
|
|
12
|
+
listStation,
|
|
13
|
+
listMenuItem,
|
|
14
|
+
title,
|
|
15
|
+
stations,
|
|
16
|
+
defaultSelectedDevice,
|
|
17
|
+
}) => {
|
|
18
|
+
const t = useTranslations();
|
|
19
|
+
|
|
20
|
+
const [selectedDevice, setSelectedDevice] = useState(defaultSelectedDevice);
|
|
21
|
+
const [indexStation, setIndexStation] = useState(0);
|
|
22
|
+
|
|
23
|
+
const onSnapToItem = useCallback((item, index) => {
|
|
24
|
+
setIndexStation(index);
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
const onPressDevice = (sensor) => {
|
|
28
|
+
if (selectedDevice && selectedDevice.id === sensor.id) {
|
|
29
|
+
setSelectedDevice(null);
|
|
30
|
+
} else {
|
|
31
|
+
setSelectedDevice(sensor);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<NewActionWrapper
|
|
37
|
+
nextTitle={t('continue')}
|
|
38
|
+
onNext={() => onPressContinue(selectedDevice, indexStation)}
|
|
39
|
+
canNext={Object.keys(selectedDevice || {}).length}
|
|
40
|
+
name={title}
|
|
41
|
+
>
|
|
42
|
+
{listStation.length ? (
|
|
43
|
+
<NavBar
|
|
44
|
+
listStation={listStation}
|
|
45
|
+
listMenuItem={listMenuItem}
|
|
46
|
+
onSnapToItem={onSnapToItem}
|
|
47
|
+
indexStation={indexStation}
|
|
48
|
+
style={styles.navbar}
|
|
49
|
+
/>
|
|
50
|
+
) : (
|
|
51
|
+
<View style={styles.noneData}>
|
|
52
|
+
<Text center>
|
|
53
|
+
{t('you_do_not_have_the_device_or_have_share_control_device')}
|
|
54
|
+
</Text>
|
|
55
|
+
</View>
|
|
56
|
+
)}
|
|
57
|
+
|
|
58
|
+
<View style={styles.boxDevices}>
|
|
59
|
+
{stations[indexStation]?.sensors &&
|
|
60
|
+
stations[indexStation].sensors.map((sensor) => (
|
|
61
|
+
<Device
|
|
62
|
+
svgMain={sensor.icon || 'sensor'}
|
|
63
|
+
title={sensor.name}
|
|
64
|
+
sensor={sensor}
|
|
65
|
+
isSelectDevice={selectedDevice && selectedDevice.id === sensor.id}
|
|
66
|
+
onPress={onPressDevice}
|
|
67
|
+
key={sensor.id}
|
|
68
|
+
/>
|
|
69
|
+
))}
|
|
70
|
+
</View>
|
|
71
|
+
</NewActionWrapper>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export default SelectDevices;
|
|
@@ -25,7 +25,7 @@ describe('Test SelectDevice', () => {
|
|
|
25
25
|
const sensor = { id: 1, name: 'sensor' };
|
|
26
26
|
const mockFuntion = jest.fn();
|
|
27
27
|
await act(async () => {
|
|
28
|
-
tree = renderer.create(
|
|
28
|
+
tree = await renderer.create(
|
|
29
29
|
wrapComponent(sensor.icon_kit, sensor, sensor.name, true, mockFuntion)
|
|
30
30
|
);
|
|
31
31
|
});
|