@eohjsc/react-native-smart-city 0.7.20 → 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/assets/images/Schedule.svg +39 -0
- package/assets/images/ValueChange.svg +49 -0
- package/package.json +1 -1
- package/src/Images/Common/default_end_device.png +0 -0
- package/src/commons/Automate/ButtonAddCondition.js +51 -0
- package/src/commons/Automate/ItemConditionScriptDetail.js +28 -15
- package/src/commons/Automate/ItemConditionScriptDetailStyles.js +9 -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 +16 -1
- package/src/configs/AccessibilityLabel.js +9 -1
- package/src/configs/Images.js +1 -0
- package/src/context/actionType.ts +5 -0
- package/src/context/reducer.ts +30 -1
- package/src/navigations/AddMemberStack.js +3 -3
- package/src/navigations/UnitStack.js +8 -0
- package/src/screens/AddCommon/SelectUnit.js +3 -2
- package/src/screens/AddLocationMaps/__test__/index.test.js +13 -13
- package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +73 -30
- package/src/screens/Automate/AddNewAction/__test__/ChooseConfig.test.js +9 -11
- package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +115 -10
- package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +7 -3
- package/src/screens/Automate/AddNewAutoSmart/__test__/AddAutomationTypeSmart.test.js +31 -0
- package/src/screens/Automate/ScriptDetail/Components/DeleteCondition.js +51 -0
- package/src/screens/Automate/ScriptDetail/Components/ModalAddCondition.js +196 -0
- package/src/screens/Automate/ScriptDetail/Styles/indexStyles.js +18 -0
- package/src/screens/Automate/ScriptDetail/__test__/index.test.js +441 -47
- package/src/screens/Automate/ScriptDetail/index.js +359 -72
- package/src/screens/Automate/ScriptDetail/utils.js +7 -31
- package/src/screens/Automate/SetSchedule/AddEditConditionSchedule.js +173 -0
- package/src/screens/Automate/SetSchedule/__test__/AddEditConditionSchedule.test.js +211 -0
- 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 +22 -1
- package/src/utils/I18n/translations/vi.js +23 -3
- package/src/utils/Route/index.js +1 -0
- 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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
useCallback,
|
|
3
|
+
useContext,
|
|
3
4
|
useEffect,
|
|
4
5
|
useMemo,
|
|
5
6
|
useRef,
|
|
@@ -49,6 +50,11 @@ import styles from './Styles/indexStyles';
|
|
|
49
50
|
import ItemConditionScriptDetail from '../../../commons/Automate/ItemConditionScriptDetail';
|
|
50
51
|
import { ModalCustom } from '../../../commons/Modal';
|
|
51
52
|
import { Card } from '../../../commons/CardShadow';
|
|
53
|
+
import ButtonAddCondition from '../../../commons/Automate/ButtonAddCondition';
|
|
54
|
+
import ModalAddCondition from './Components/ModalAddCondition';
|
|
55
|
+
import DeleteCondition from './Components/DeleteCondition';
|
|
56
|
+
import { SCContext } from '../../../context';
|
|
57
|
+
import { Action } from '../../../context/actionType';
|
|
52
58
|
|
|
53
59
|
const PreventDoubleTouch = withPreventDoubleClick(TouchableOpacity);
|
|
54
60
|
|
|
@@ -56,6 +62,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
56
62
|
const { dispatch, navigate, goBack, getState } = useNavigation();
|
|
57
63
|
const { params = {} } = route;
|
|
58
64
|
const refMenuAction = useRef();
|
|
65
|
+
const { setAction } = useContext(SCContext);
|
|
59
66
|
const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
|
|
60
67
|
usePopover();
|
|
61
68
|
const {
|
|
@@ -77,9 +84,12 @@ const ScriptDetail = ({ route }) => {
|
|
|
77
84
|
const [data, setData] = useState([]);
|
|
78
85
|
const [isShowRename, setIsShowRename] = useState(false);
|
|
79
86
|
const [isShowDelete, setIsShowDelete] = useState(false);
|
|
87
|
+
const [itemDeleteCondition, setItemDeleteCondition] = useState({});
|
|
80
88
|
const [isShowAddAction, setIsShowAddAction] = useState(false);
|
|
81
89
|
const [isShowLocalControl, setIsShowLocalControl] = useState(false);
|
|
82
90
|
const [listChipShared, setListChipShared] = useState([]);
|
|
91
|
+
const [isShowSelectCondition, setIsShowSelectCondition] = useState(false);
|
|
92
|
+
const [numberConditionsUsed, setNumberConditionsUsed] = useState(0);
|
|
83
93
|
const {
|
|
84
94
|
script,
|
|
85
95
|
type,
|
|
@@ -87,9 +97,12 @@ const ScriptDetail = ({ route }) => {
|
|
|
87
97
|
unit,
|
|
88
98
|
can_edit,
|
|
89
99
|
id: automateId,
|
|
90
|
-
|
|
100
|
+
is_need_all_conditions,
|
|
101
|
+
conditions = [{}],
|
|
91
102
|
} = automate;
|
|
92
|
-
const
|
|
103
|
+
const [needAllCondition, setNeedAllCondition] = useState(
|
|
104
|
+
is_need_all_conditions
|
|
105
|
+
);
|
|
93
106
|
const {
|
|
94
107
|
enable,
|
|
95
108
|
chip_local_control,
|
|
@@ -103,7 +116,12 @@ const ScriptDetail = ({ route }) => {
|
|
|
103
116
|
chip_id_local_control,
|
|
104
117
|
});
|
|
105
118
|
const [enableScript, setEnableScript] = useState(enable);
|
|
106
|
-
const
|
|
119
|
+
const [listMenuItemCondition, setListMenuItemCondition] = useState([]);
|
|
120
|
+
const [isShowAddCondition, setIsShowAddCondition] = useState(false);
|
|
121
|
+
const permissions = useBackendPermission();
|
|
122
|
+
const { max_actions_per_automation, max_conditions_per_automation } =
|
|
123
|
+
permissions;
|
|
124
|
+
|
|
107
125
|
const onShowActivityLog = useCallback(() => {
|
|
108
126
|
navigate(Routes.ActivityLog, {
|
|
109
127
|
id: automateId,
|
|
@@ -158,24 +176,77 @@ const ScriptDetail = ({ route }) => {
|
|
|
158
176
|
[closeScreen, dispatch, getState, route.params]
|
|
159
177
|
);
|
|
160
178
|
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
179
|
+
const canUpdateCondition = useMemo(() => {
|
|
180
|
+
return can_edit && enableScript;
|
|
181
|
+
}, [can_edit, enableScript]);
|
|
182
|
+
|
|
183
|
+
const handleEditCondition = useCallback(
|
|
184
|
+
async (item) => {
|
|
185
|
+
if (!canUpdateCondition) {
|
|
186
|
+
if (!can_edit) {
|
|
187
|
+
ToastBottomHelper.error(
|
|
188
|
+
t('only_owner_has_permission_to_edit_this_script')
|
|
189
|
+
);
|
|
190
|
+
} else if (!enableScript) {
|
|
191
|
+
ToastBottomHelper.error(t('this_script_has_been_disabled'));
|
|
192
|
+
}
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
172
195
|
|
|
173
|
-
|
|
174
|
-
|
|
196
|
+
if (item.type === AUTOMATE_TYPE.SCHEDULE) {
|
|
197
|
+
navigate(Routes.AddEditConditionSchedule, {
|
|
198
|
+
automate: automate,
|
|
199
|
+
condition: item,
|
|
200
|
+
isUpdateCondition: true,
|
|
201
|
+
closeScreen: Routes.ScriptDetail,
|
|
202
|
+
});
|
|
203
|
+
} else {
|
|
204
|
+
setAction(Action.IS_CREATE_CONDITION, false);
|
|
205
|
+
setAction(Action.IS_UPDATE_CONDITION, item.id);
|
|
206
|
+
const navParams = {
|
|
207
|
+
automate: automate,
|
|
208
|
+
closeScreen: Routes.ScriptDetail,
|
|
209
|
+
routeName: unit ? null : Routes.SelectControlDevices,
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
if (unit) {
|
|
213
|
+
navigate(Routes.SelectMonitorDevices, navParams);
|
|
214
|
+
} else {
|
|
215
|
+
navigate(Routes.SelectUnit, {
|
|
216
|
+
automate,
|
|
217
|
+
routeName: Routes.SelectMonitorDevices,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
[
|
|
175
223
|
automate,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
224
|
+
canUpdateCondition,
|
|
225
|
+
can_edit,
|
|
226
|
+
enableScript,
|
|
227
|
+
navigate,
|
|
228
|
+
setAction,
|
|
229
|
+
t,
|
|
230
|
+
unit,
|
|
231
|
+
]
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const handleDeleteCondition = useCallback(
|
|
235
|
+
async (item) => {
|
|
236
|
+
if (!canUpdateCondition) {
|
|
237
|
+
if (!can_edit) {
|
|
238
|
+
ToastBottomHelper.error(
|
|
239
|
+
t('only_owner_has_permission_to_edit_this_script')
|
|
240
|
+
);
|
|
241
|
+
} else if (!enableScript) {
|
|
242
|
+
ToastBottomHelper.error(t('this_script_has_been_disabled'));
|
|
243
|
+
}
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
setItemDeleteCondition(item);
|
|
247
|
+
},
|
|
248
|
+
[canUpdateCondition, can_edit, enableScript, t]
|
|
249
|
+
);
|
|
179
250
|
|
|
180
251
|
const listMenuItem = useMemo(
|
|
181
252
|
() => [
|
|
@@ -192,32 +263,6 @@ const ScriptDetail = ({ route }) => {
|
|
|
192
263
|
[t, onShowActivityLog]
|
|
193
264
|
);
|
|
194
265
|
|
|
195
|
-
const listMenuItemCondition = useMemo(() => {
|
|
196
|
-
const items = [
|
|
197
|
-
{ text: t('edit_condition'), doAction: () => handleUpdateAutomate() },
|
|
198
|
-
];
|
|
199
|
-
if (unit_id) {
|
|
200
|
-
items.unshift({
|
|
201
|
-
text: t('text_unit'),
|
|
202
|
-
doAction: () =>
|
|
203
|
-
navigate(Routes.UnitDetail, {
|
|
204
|
-
unitId: unit_id,
|
|
205
|
-
}),
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
if (end_device_id) {
|
|
209
|
-
items.unshift({
|
|
210
|
-
text: t('device_display'),
|
|
211
|
-
doAction: () =>
|
|
212
|
-
navigate(Routes.DeviceDetail, {
|
|
213
|
-
unitId: unit_id,
|
|
214
|
-
sensorId: end_device_id,
|
|
215
|
-
}),
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
return items;
|
|
219
|
-
}, [t, handleUpdateAutomate, navigate, unit_id, end_device_id]);
|
|
220
|
-
|
|
221
266
|
const handleShowMenuAction = useCallback(() => {
|
|
222
267
|
if (!can_edit) {
|
|
223
268
|
ToastBottomHelper.error(
|
|
@@ -248,6 +293,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
248
293
|
if (success) {
|
|
249
294
|
setAutomate(automateData);
|
|
250
295
|
setEnableScript(automateData.script.enable);
|
|
296
|
+
setNeedAllCondition(automateData.is_need_all_conditions);
|
|
251
297
|
}
|
|
252
298
|
}, [automateId]);
|
|
253
299
|
|
|
@@ -295,13 +341,39 @@ const ScriptDetail = ({ route }) => {
|
|
|
295
341
|
enable: checked,
|
|
296
342
|
}
|
|
297
343
|
);
|
|
298
|
-
|
|
344
|
+
if (success) {
|
|
345
|
+
ToastBottomHelper.success(t('update_successfully'));
|
|
346
|
+
setEnableScript(checked);
|
|
347
|
+
}
|
|
299
348
|
},
|
|
300
|
-
[automateId]
|
|
349
|
+
[automateId, t]
|
|
301
350
|
);
|
|
302
351
|
|
|
303
352
|
useBlockBack(handleGoBack);
|
|
304
353
|
|
|
354
|
+
const getConditionUsed = useCallback(async () => {
|
|
355
|
+
if (max_conditions_per_automation > 0) {
|
|
356
|
+
setNumberConditionsUsed(
|
|
357
|
+
max_conditions_per_automation - conditions.length
|
|
358
|
+
);
|
|
359
|
+
} else {
|
|
360
|
+
const { success, data: perms } = await axiosGet(API.AUTH.PERMISSIONS());
|
|
361
|
+
if (success) {
|
|
362
|
+
setNumberConditionsUsed(
|
|
363
|
+
perms.max_conditions_per_automation - conditions.length
|
|
364
|
+
);
|
|
365
|
+
setAction(Action.UPDATE_PERMISSIONS, perms);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
371
|
+
}, [conditions.length, max_conditions_per_automation]); // Add dependency setAction will cause loop
|
|
372
|
+
|
|
373
|
+
useEffect(() => {
|
|
374
|
+
getConditionUsed();
|
|
375
|
+
}, [getConditionUsed]);
|
|
376
|
+
|
|
305
377
|
useEffect(() => {
|
|
306
378
|
if (isFocused) {
|
|
307
379
|
fetchAutomate();
|
|
@@ -340,18 +412,60 @@ const ScriptDetail = ({ route }) => {
|
|
|
340
412
|
saveAt && fetchAutomateActions();
|
|
341
413
|
}, [saveAt, fetchAutomateActions]);
|
|
342
414
|
|
|
343
|
-
const handleShowMenuAction1 = useCallback(
|
|
344
|
-
|
|
345
|
-
|
|
415
|
+
const handleShowMenuAction1 = useCallback(
|
|
416
|
+
(item, refMenuAction1) => {
|
|
417
|
+
const { unit_id: unitCondition, end_device_id } = item;
|
|
418
|
+
const menu = [
|
|
419
|
+
{
|
|
420
|
+
text: t('edit_condition'),
|
|
421
|
+
doAction: () => handleEditCondition(item),
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
text: t('delete_condition'),
|
|
425
|
+
doAction: () => handleDeleteCondition(item),
|
|
426
|
+
},
|
|
427
|
+
];
|
|
428
|
+
if (unitCondition) {
|
|
429
|
+
menu.unshift({
|
|
430
|
+
text: t('go_to_unit'),
|
|
431
|
+
doAction: () =>
|
|
432
|
+
navigate(Routes.UnitDetail, {
|
|
433
|
+
unitId: unitCondition,
|
|
434
|
+
}),
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
if (end_device_id) {
|
|
438
|
+
menu.unshift({
|
|
439
|
+
text: t('device_display'),
|
|
440
|
+
doAction: () =>
|
|
441
|
+
navigate(Routes.DeviceDetail, {
|
|
442
|
+
unitId: unitCondition,
|
|
443
|
+
sensorId: end_device_id,
|
|
444
|
+
}),
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
setListMenuItemCondition(menu);
|
|
448
|
+
showPopoverWithRef1(refMenuAction1);
|
|
449
|
+
},
|
|
450
|
+
[
|
|
451
|
+
t,
|
|
452
|
+
showPopoverWithRef1,
|
|
453
|
+
handleEditCondition,
|
|
454
|
+
handleDeleteCondition,
|
|
455
|
+
navigate,
|
|
456
|
+
]
|
|
457
|
+
);
|
|
346
458
|
|
|
347
459
|
const onCloseLocalControl = () => setIsShowLocalControl(false);
|
|
348
460
|
|
|
461
|
+
const onCloseSelectCondition = () => setIsShowSelectCondition(false);
|
|
462
|
+
|
|
349
463
|
const fetchChipShared = useCallback(async () => {
|
|
350
464
|
const { success, data: listChip } = await axiosGet(
|
|
351
465
|
API.DEV_MODE.GATEWAY.SHARED(),
|
|
352
466
|
{
|
|
353
467
|
params: {
|
|
354
|
-
unit:
|
|
468
|
+
unit: unit,
|
|
355
469
|
},
|
|
356
470
|
},
|
|
357
471
|
true
|
|
@@ -359,12 +473,16 @@ const ScriptDetail = ({ route }) => {
|
|
|
359
473
|
if (success) {
|
|
360
474
|
setListChipShared(listChip);
|
|
361
475
|
}
|
|
362
|
-
}, [
|
|
476
|
+
}, [unit]);
|
|
363
477
|
|
|
364
478
|
const onShowLocalControl = useCallback(async () => {
|
|
365
479
|
setIsShowLocalControl(true);
|
|
366
480
|
}, []);
|
|
367
481
|
|
|
482
|
+
const onShowSelectCondition = useCallback(async () => {
|
|
483
|
+
setIsShowSelectCondition(true);
|
|
484
|
+
}, []);
|
|
485
|
+
|
|
368
486
|
useEffect(() => {
|
|
369
487
|
fetchChipShared();
|
|
370
488
|
}, [fetchChipShared]);
|
|
@@ -384,6 +502,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
384
502
|
);
|
|
385
503
|
setIsShowLocalControl(false);
|
|
386
504
|
if (success) {
|
|
505
|
+
ToastBottomHelper.success(t('local_control_update_success'));
|
|
387
506
|
setLocalControl({
|
|
388
507
|
is_local_control: enable_local_control,
|
|
389
508
|
chip_local_control: item.name,
|
|
@@ -391,7 +510,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
391
510
|
});
|
|
392
511
|
}
|
|
393
512
|
},
|
|
394
|
-
[automateId, local_control.chip_id_local_control]
|
|
513
|
+
[automateId, local_control.chip_id_local_control, t]
|
|
395
514
|
);
|
|
396
515
|
|
|
397
516
|
const renderLocalControl = useMemo(() => {
|
|
@@ -430,6 +549,119 @@ const ScriptDetail = ({ route }) => {
|
|
|
430
549
|
type,
|
|
431
550
|
]);
|
|
432
551
|
|
|
552
|
+
const onPressSelectCondition = useCallback(
|
|
553
|
+
async (value) => {
|
|
554
|
+
setIsShowSelectCondition(false);
|
|
555
|
+
setNeedAllCondition(value);
|
|
556
|
+
const { success } = await axiosPost(
|
|
557
|
+
API.AUTOMATE.NEED_ALL_CONDITIONS(automateId),
|
|
558
|
+
{
|
|
559
|
+
is_need_all_conditions: value,
|
|
560
|
+
}
|
|
561
|
+
);
|
|
562
|
+
if (success) {
|
|
563
|
+
ToastBottomHelper.success(t('update_condition_success'));
|
|
564
|
+
} else {
|
|
565
|
+
ToastBottomHelper.error(t('error_please_try_later'));
|
|
566
|
+
}
|
|
567
|
+
},
|
|
568
|
+
[automateId, t]
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
const selectCondition = useMemo(() => {
|
|
572
|
+
if (type === AUTOMATE_TYPE.ONE_TAP || !max_conditions_per_automation) {
|
|
573
|
+
return (
|
|
574
|
+
<View style={styles.row}>
|
|
575
|
+
<Text type="H3" semibold style={styles.width40}>
|
|
576
|
+
{t('how_to_start')}
|
|
577
|
+
</Text>
|
|
578
|
+
</View>
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
return (
|
|
582
|
+
<>
|
|
583
|
+
<View style={styles.row}>
|
|
584
|
+
<Text type="H3" semibold style={styles.width30}>
|
|
585
|
+
{t('condition')}
|
|
586
|
+
</Text>
|
|
587
|
+
<Card style={styles.card}>
|
|
588
|
+
<TouchableOpacity
|
|
589
|
+
style={styles.boxCondition}
|
|
590
|
+
onPress={onShowSelectCondition}
|
|
591
|
+
accessibilityLabel={AccessibilityLabel.AUTOMATE_CONDITION}
|
|
592
|
+
>
|
|
593
|
+
<Text numberOfLines={1}>
|
|
594
|
+
{t(needAllCondition ? 'are_met' : 'is_met')}
|
|
595
|
+
</Text>
|
|
596
|
+
|
|
597
|
+
<IconOutline name="down" size={15} style={styles.marginLeft5} />
|
|
598
|
+
</TouchableOpacity>
|
|
599
|
+
</Card>
|
|
600
|
+
</View>
|
|
601
|
+
<View>
|
|
602
|
+
<Text
|
|
603
|
+
type="H5"
|
|
604
|
+
accessibilityLabel={AccessibilityLabel.AUTOMATE_NUMBER_CONDITION}
|
|
605
|
+
>
|
|
606
|
+
{t('available_condition', {
|
|
607
|
+
number: numberConditionsUsed,
|
|
608
|
+
})}
|
|
609
|
+
</Text>
|
|
610
|
+
</View>
|
|
611
|
+
</>
|
|
612
|
+
);
|
|
613
|
+
}, [
|
|
614
|
+
max_conditions_per_automation,
|
|
615
|
+
needAllCondition,
|
|
616
|
+
numberConditionsUsed,
|
|
617
|
+
onShowSelectCondition,
|
|
618
|
+
t,
|
|
619
|
+
type,
|
|
620
|
+
]);
|
|
621
|
+
|
|
622
|
+
const renderCondition = useMemo(() => {
|
|
623
|
+
if (max_conditions_per_automation) {
|
|
624
|
+
return conditions.map((item, index) => (
|
|
625
|
+
<ItemConditionScriptDetail
|
|
626
|
+
key={`condition${index}`}
|
|
627
|
+
automate={automate}
|
|
628
|
+
condition={item}
|
|
629
|
+
enableScript={enableScript}
|
|
630
|
+
handleShowMenuAction1={handleShowMenuAction1}
|
|
631
|
+
/>
|
|
632
|
+
));
|
|
633
|
+
} else {
|
|
634
|
+
return (
|
|
635
|
+
<ItemConditionScriptDetail
|
|
636
|
+
automate={automate}
|
|
637
|
+
condition={conditions[0] || {}}
|
|
638
|
+
enableScript={enableScript}
|
|
639
|
+
handleShowMenuAction1={handleShowMenuAction1}
|
|
640
|
+
/>
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
}, [
|
|
644
|
+
automate,
|
|
645
|
+
conditions,
|
|
646
|
+
enableScript,
|
|
647
|
+
handleShowMenuAction1,
|
|
648
|
+
max_conditions_per_automation,
|
|
649
|
+
]);
|
|
650
|
+
|
|
651
|
+
const renderButtonAddCondition = useMemo(() => {
|
|
652
|
+
if (type === AUTOMATE_TYPE.ONE_TAP || !max_conditions_per_automation) {
|
|
653
|
+
return;
|
|
654
|
+
} else {
|
|
655
|
+
return (
|
|
656
|
+
<ButtonAddCondition
|
|
657
|
+
setIsShowAddCondition={setIsShowAddCondition}
|
|
658
|
+
numberConditionsUsed={numberConditionsUsed}
|
|
659
|
+
max_conditions_per_automation={max_conditions_per_automation}
|
|
660
|
+
/>
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
}, [max_conditions_per_automation, numberConditionsUsed, type]);
|
|
664
|
+
|
|
433
665
|
return (
|
|
434
666
|
<View style={styles.wrap}>
|
|
435
667
|
<WrapHeaderScrollable
|
|
@@ -448,15 +680,9 @@ const ScriptDetail = ({ route }) => {
|
|
|
448
680
|
</View>
|
|
449
681
|
)}
|
|
450
682
|
{renderLocalControl}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
<ItemConditionScriptDetail
|
|
455
|
-
automate={automate}
|
|
456
|
-
enableScript={enableScript}
|
|
457
|
-
handleShowMenuAction1={handleShowMenuAction1}
|
|
458
|
-
refMenuAction1={refMenuAction1}
|
|
459
|
-
/>
|
|
683
|
+
{selectCondition}
|
|
684
|
+
{renderCondition}
|
|
685
|
+
{renderButtonAddCondition}
|
|
460
686
|
{type === AUTOMATE_TYPE.ONE_TAP && enableScript && (
|
|
461
687
|
<TouchableOpacity
|
|
462
688
|
onPress={handleScriptAction}
|
|
@@ -467,7 +693,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
467
693
|
</TouchableOpacity>
|
|
468
694
|
)}
|
|
469
695
|
|
|
470
|
-
<View style={styles.
|
|
696
|
+
<View style={styles.rowActionList}>
|
|
471
697
|
<Text type="H3" color={Colors.Gray9} semibold>
|
|
472
698
|
{t('actions_list')}
|
|
473
699
|
</Text>
|
|
@@ -479,15 +705,20 @@ const ScriptDetail = ({ route }) => {
|
|
|
479
705
|
AccessibilityLabel.BUTTON_EDIT_SCRIPT_ACTION
|
|
480
706
|
}
|
|
481
707
|
>
|
|
482
|
-
<Text
|
|
483
|
-
{t('edit')}
|
|
484
|
-
</Text>
|
|
708
|
+
<Text highlight>{t('edit')}</Text>
|
|
485
709
|
</TouchableOpacity>
|
|
486
710
|
)}
|
|
487
711
|
</View>
|
|
712
|
+
<View style={styles.row}>
|
|
713
|
+
<Text>
|
|
714
|
+
{t('available_action', {
|
|
715
|
+
number: max_actions_per_automation - data.length,
|
|
716
|
+
})}
|
|
717
|
+
</Text>
|
|
718
|
+
</View>
|
|
488
719
|
{data.map((item, index) => (
|
|
489
720
|
<Item
|
|
490
|
-
key={
|
|
721
|
+
key={`Item${index}`}
|
|
491
722
|
item={item}
|
|
492
723
|
index={index}
|
|
493
724
|
enableScript={enableScript}
|
|
@@ -497,7 +728,8 @@ const ScriptDetail = ({ route }) => {
|
|
|
497
728
|
))}
|
|
498
729
|
{!!can_edit && !!enableScript && (
|
|
499
730
|
<ItemAdd
|
|
500
|
-
|
|
731
|
+
t={t}
|
|
732
|
+
max_actions_per_automation={max_actions_per_automation}
|
|
501
733
|
numberActionAdded={data.length}
|
|
502
734
|
setIsShowAddAction={setIsShowAddAction}
|
|
503
735
|
/>
|
|
@@ -540,6 +772,14 @@ const ScriptDetail = ({ route }) => {
|
|
|
540
772
|
type={type}
|
|
541
773
|
navigate={handleNavigate}
|
|
542
774
|
/>
|
|
775
|
+
<ModalAddCondition
|
|
776
|
+
automate={automate}
|
|
777
|
+
numberActionAdded={data.length}
|
|
778
|
+
isVisible={isShowAddCondition}
|
|
779
|
+
setIsVisible={setIsShowAddCondition}
|
|
780
|
+
type={type}
|
|
781
|
+
navigate={navigate}
|
|
782
|
+
/>
|
|
543
783
|
<RenameScript
|
|
544
784
|
automate={automate}
|
|
545
785
|
setAutomate={setAutomate}
|
|
@@ -551,7 +791,15 @@ const ScriptDetail = ({ route }) => {
|
|
|
551
791
|
setIsVisible={setIsShowDelete}
|
|
552
792
|
isVisible={isShowDelete}
|
|
553
793
|
/>
|
|
794
|
+
<DeleteCondition
|
|
795
|
+
automate={automate}
|
|
796
|
+
setAutomate={setAutomate}
|
|
797
|
+
condition={itemDeleteCondition}
|
|
798
|
+
setIsVisible={setItemDeleteCondition}
|
|
799
|
+
isVisible={Boolean(itemDeleteCondition.id)}
|
|
800
|
+
/>
|
|
554
801
|
<ModalCustom
|
|
802
|
+
key={'ModalLocalControl'}
|
|
555
803
|
isVisible={isShowLocalControl}
|
|
556
804
|
onBackButtonPress={onCloseLocalControl}
|
|
557
805
|
onBackdropPress={onCloseLocalControl}
|
|
@@ -601,6 +849,43 @@ const ScriptDetail = ({ route }) => {
|
|
|
601
849
|
</ScrollView>
|
|
602
850
|
</View>
|
|
603
851
|
</ModalCustom>
|
|
852
|
+
<ModalCustom
|
|
853
|
+
key={'ModalSelectCondition'}
|
|
854
|
+
isVisible={isShowSelectCondition}
|
|
855
|
+
onBackButtonPress={onCloseSelectCondition}
|
|
856
|
+
onBackdropPress={onCloseSelectCondition}
|
|
857
|
+
>
|
|
858
|
+
<View key={'selectCondition'} style={styles.popoverStyle}>
|
|
859
|
+
<ScrollView>
|
|
860
|
+
<TouchableOpacity
|
|
861
|
+
style={styles.textDisable}
|
|
862
|
+
key={'are_met'}
|
|
863
|
+
onPress={() => {
|
|
864
|
+
onPressSelectCondition(true);
|
|
865
|
+
}}
|
|
866
|
+
accessibilityLabel={AccessibilityLabel.AUTOMATE_SELECT_CONDITION}
|
|
867
|
+
>
|
|
868
|
+
<Text>{t('are_met')}</Text>
|
|
869
|
+
{needAllCondition && (
|
|
870
|
+
<IconOutline style={styles.checked} name={'check'} size={20} />
|
|
871
|
+
)}
|
|
872
|
+
</TouchableOpacity>
|
|
873
|
+
<TouchableOpacity
|
|
874
|
+
style={styles.textDisable}
|
|
875
|
+
key={'is_met'}
|
|
876
|
+
onPress={() => {
|
|
877
|
+
onPressSelectCondition(false);
|
|
878
|
+
}}
|
|
879
|
+
accessibilityLabel={AccessibilityLabel.AUTOMATE_SELECT_CONDITION}
|
|
880
|
+
>
|
|
881
|
+
<Text>{t('is_met')}</Text>
|
|
882
|
+
{!needAllCondition && (
|
|
883
|
+
<IconOutline style={styles.checked} name={'check'} size={20} />
|
|
884
|
+
)}
|
|
885
|
+
</TouchableOpacity>
|
|
886
|
+
</ScrollView>
|
|
887
|
+
</View>
|
|
888
|
+
</ModalCustom>
|
|
604
889
|
</View>
|
|
605
890
|
);
|
|
606
891
|
};
|
|
@@ -780,10 +1065,12 @@ const Item = ({ item, index, enableScript, t, local_control }) => {
|
|
|
780
1065
|
}
|
|
781
1066
|
};
|
|
782
1067
|
|
|
783
|
-
const ItemAdd = ({
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
1068
|
+
const ItemAdd = ({
|
|
1069
|
+
t,
|
|
1070
|
+
max_actions_per_automation,
|
|
1071
|
+
numberActionAdded,
|
|
1072
|
+
setIsShowAddAction,
|
|
1073
|
+
}) => {
|
|
787
1074
|
const paddedIndex = (numberActionAdded + 1).toString().padStart(2, '0');
|
|
788
1075
|
|
|
789
1076
|
const onPressAddAction = useCallback(() => {
|
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
import { AUTOMATE_TYPE } from '../../../configs/Constants';
|
|
2
2
|
import { REPEAT_OPTIONS } from '../SetSchedule/components/RepeatOptionsPopup';
|
|
3
3
|
|
|
4
|
-
export const generateAutomationDataConditionText = (
|
|
5
|
-
type,
|
|
6
|
-
config_name,
|
|
7
|
-
condition,
|
|
8
|
-
valueEvaluation,
|
|
9
|
-
t
|
|
10
|
-
) => {
|
|
11
|
-
condition.config_name = config_name;
|
|
12
|
-
let automate = {};
|
|
13
|
-
if ([AUTOMATE_TYPE.VALUE_CHANGE].includes(type)) {
|
|
14
|
-
automate = { value_change: condition };
|
|
15
|
-
} else if (type === AUTOMATE_TYPE.SCHEDULE) {
|
|
16
|
-
automate = { schedule: condition };
|
|
17
|
-
} else if ([AUTOMATE_TYPE.EVENT].includes(type)) {
|
|
18
|
-
automate = { event: condition };
|
|
19
|
-
}
|
|
20
|
-
automate.type = type;
|
|
21
|
-
return generateAutomationConditionText(automate, valueEvaluation, t);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
4
|
export const getAutomationData = (automate) => {
|
|
25
5
|
const { type, event_sensor, event_action, schedule, event, value_change } =
|
|
26
6
|
automate;
|
|
@@ -35,11 +15,11 @@ export const getAutomationData = (automate) => {
|
|
|
35
15
|
};
|
|
36
16
|
|
|
37
17
|
const generateAutomationConditionValueEvaluation = (
|
|
38
|
-
|
|
18
|
+
conditionItem,
|
|
39
19
|
valueEvaluations,
|
|
40
20
|
t
|
|
41
21
|
) => {
|
|
42
|
-
const {
|
|
22
|
+
const { end_device_name, config_name, value } = conditionItem;
|
|
43
23
|
|
|
44
24
|
const index = value[1];
|
|
45
25
|
const valueEvaluation = valueEvaluations?.find((v) => v.id === value[0]);
|
|
@@ -62,26 +42,22 @@ const generateAutomationConditionValueEvaluation = (
|
|
|
62
42
|
if (config_name) {
|
|
63
43
|
textEvent = config_name;
|
|
64
44
|
} else {
|
|
65
|
-
textEvent =
|
|
45
|
+
textEvent = end_device_name;
|
|
66
46
|
}
|
|
67
47
|
return textEvent;
|
|
68
48
|
};
|
|
69
49
|
|
|
70
50
|
export const generateAutomationConditionText = (
|
|
71
51
|
automate,
|
|
52
|
+
conditionItem,
|
|
72
53
|
valueEvaluations,
|
|
73
54
|
t
|
|
74
55
|
) => {
|
|
75
|
-
const
|
|
76
|
-
if (!automateData) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const { type } = automate;
|
|
56
|
+
const { condition, config_name, value, type } = conditionItem;
|
|
80
57
|
if ([AUTOMATE_TYPE.VALUE_CHANGE].includes(type)) {
|
|
81
|
-
const { condition, config_name, value } = automateData;
|
|
82
58
|
if (condition === 'value_evaluation') {
|
|
83
59
|
return generateAutomationConditionValueEvaluation(
|
|
84
|
-
|
|
60
|
+
conditionItem,
|
|
85
61
|
valueEvaluations,
|
|
86
62
|
t
|
|
87
63
|
);
|
|
@@ -97,7 +73,7 @@ export const generateAutomationConditionText = (
|
|
|
97
73
|
}
|
|
98
74
|
return `${config_name} ${t(text)} ${value}`;
|
|
99
75
|
} else if (type === AUTOMATE_TYPE.SCHEDULE) {
|
|
100
|
-
const { repeat, time_repeat, date_repeat, weekday_repeat } =
|
|
76
|
+
const { repeat, time_repeat, date_repeat, weekday_repeat } = conditionItem;
|
|
101
77
|
const time =
|
|
102
78
|
time_repeat?.length >= 8
|
|
103
79
|
? time_repeat.substring(0, time_repeat?.length - 3)
|