@eohjsc/react-native-smart-city 0.7.19 → 0.7.21
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/commons/Automate/ButtonAddCondition.js +51 -0
- package/src/commons/Automate/ItemConditionScriptDetail.js +28 -15
- package/src/commons/Automate/ItemConditionScriptDetailStyles.js +9 -0
- package/src/configs/API.js +12 -1
- package/src/configs/AccessibilityLabel.js +6 -0
- package/src/context/actionType.ts +5 -0
- package/src/context/reducer.ts +30 -1
- package/src/navigations/UnitStack.js +8 -0
- package/src/screens/AddNewGateway/ScanDeviceLocal.js +15 -14
- package/src/screens/AddNewGateway/__test__/ScanDeviceLocal.test.js +51 -1
- package/src/screens/AddNewGateway/hooks/useConnectDevice.js +11 -9
- package/src/screens/AllGateway/DeviceInternalDetail/__test__/index.test.js +28 -0
- package/src/screens/AllGateway/DeviceModbusDetail/__test__/index.test.js +1 -1
- package/src/screens/AllGateway/__test__/index.test.js +19 -0
- package/src/screens/AllGateway/hooks/useGateway.js +16 -9
- package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +73 -30
- package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +115 -10
- package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +7 -3
- 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 +19 -0
- package/src/screens/Automate/ScriptDetail/__test__/index.test.js +441 -47
- package/src/screens/Automate/ScriptDetail/index.js +402 -106
- package/src/screens/Automate/ScriptDetail/utils.js +7 -11
- package/src/screens/Automate/SetSchedule/AddEditConditionSchedule.js +173 -0
- package/src/screens/Automate/SetSchedule/__test__/AddEditConditionSchedule.test.js +211 -0
- package/src/utils/I18n/translations/en.js +24 -0
- package/src/utils/I18n/translations/vi.js +24 -1
- package/src/utils/Route/index.js +1 -0
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
useCallback,
|
|
3
|
+
useContext,
|
|
3
4
|
useEffect,
|
|
4
5
|
useMemo,
|
|
5
6
|
useRef,
|
|
6
7
|
useState,
|
|
7
8
|
} from 'react';
|
|
8
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
Image,
|
|
11
|
+
Platform,
|
|
12
|
+
ScrollView,
|
|
13
|
+
Switch,
|
|
14
|
+
TouchableOpacity,
|
|
15
|
+
View,
|
|
16
|
+
} from 'react-native';
|
|
9
17
|
import { PopoverMode } from 'react-native-popover-view';
|
|
10
18
|
import { IconFill, IconOutline } from '@ant-design/icons-react-native';
|
|
11
19
|
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
|
|
@@ -42,6 +50,11 @@ import styles from './Styles/indexStyles';
|
|
|
42
50
|
import ItemConditionScriptDetail from '../../../commons/Automate/ItemConditionScriptDetail';
|
|
43
51
|
import { ModalCustom } from '../../../commons/Modal';
|
|
44
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';
|
|
45
58
|
|
|
46
59
|
const PreventDoubleTouch = withPreventDoubleClick(TouchableOpacity);
|
|
47
60
|
|
|
@@ -49,6 +62,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
49
62
|
const { dispatch, navigate, goBack, getState } = useNavigation();
|
|
50
63
|
const { params = {} } = route;
|
|
51
64
|
const refMenuAction = useRef();
|
|
65
|
+
const { setAction } = useContext(SCContext);
|
|
52
66
|
const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
|
|
53
67
|
usePopover();
|
|
54
68
|
const {
|
|
@@ -70,9 +84,12 @@ const ScriptDetail = ({ route }) => {
|
|
|
70
84
|
const [data, setData] = useState([]);
|
|
71
85
|
const [isShowRename, setIsShowRename] = useState(false);
|
|
72
86
|
const [isShowDelete, setIsShowDelete] = useState(false);
|
|
87
|
+
const [itemDeleteCondition, setItemDeleteCondition] = useState({});
|
|
73
88
|
const [isShowAddAction, setIsShowAddAction] = useState(false);
|
|
74
89
|
const [isShowLocalControl, setIsShowLocalControl] = useState(false);
|
|
75
90
|
const [listChipShared, setListChipShared] = useState([]);
|
|
91
|
+
const [isShowSelectCondition, setIsShowSelectCondition] = useState(false);
|
|
92
|
+
const [numberConditionsUsed, setNumberConditionsUsed] = useState(0);
|
|
76
93
|
const {
|
|
77
94
|
script,
|
|
78
95
|
type,
|
|
@@ -80,9 +97,12 @@ const ScriptDetail = ({ route }) => {
|
|
|
80
97
|
unit,
|
|
81
98
|
can_edit,
|
|
82
99
|
id: automateId,
|
|
83
|
-
|
|
100
|
+
is_need_all_conditions,
|
|
101
|
+
conditions = [{}],
|
|
84
102
|
} = automate;
|
|
85
|
-
const
|
|
103
|
+
const [needAllCondition, setNeedAllCondition] = useState(
|
|
104
|
+
is_need_all_conditions
|
|
105
|
+
);
|
|
86
106
|
const {
|
|
87
107
|
enable,
|
|
88
108
|
chip_local_control,
|
|
@@ -96,7 +116,12 @@ const ScriptDetail = ({ route }) => {
|
|
|
96
116
|
chip_id_local_control,
|
|
97
117
|
});
|
|
98
118
|
const [enableScript, setEnableScript] = useState(enable);
|
|
99
|
-
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
|
+
|
|
100
125
|
const onShowActivityLog = useCallback(() => {
|
|
101
126
|
navigate(Routes.ActivityLog, {
|
|
102
127
|
id: automateId,
|
|
@@ -151,24 +176,77 @@ const ScriptDetail = ({ route }) => {
|
|
|
151
176
|
[closeScreen, dispatch, getState, route.params]
|
|
152
177
|
);
|
|
153
178
|
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
t('only_owner_has_permission_to_edit_this_script')
|
|
158
|
-
);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (!enableScript) {
|
|
162
|
-
ToastBottomHelper.error(t('this_script_has_been_disabled'));
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
179
|
+
const canUpdateCondition = useMemo(() => {
|
|
180
|
+
return can_edit && enableScript;
|
|
181
|
+
}, [can_edit, enableScript]);
|
|
165
182
|
|
|
166
|
-
|
|
167
|
-
|
|
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
|
+
}
|
|
195
|
+
|
|
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
|
+
[
|
|
168
223
|
automate,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
+
);
|
|
172
250
|
|
|
173
251
|
const listMenuItem = useMemo(
|
|
174
252
|
() => [
|
|
@@ -185,32 +263,6 @@ const ScriptDetail = ({ route }) => {
|
|
|
185
263
|
[t, onShowActivityLog]
|
|
186
264
|
);
|
|
187
265
|
|
|
188
|
-
const listMenuItemCondition = useMemo(() => {
|
|
189
|
-
const items = [
|
|
190
|
-
{ text: t('edit_condition'), doAction: () => handleUpdateAutomate() },
|
|
191
|
-
];
|
|
192
|
-
if (unit_id) {
|
|
193
|
-
items.unshift({
|
|
194
|
-
text: t('text_unit'),
|
|
195
|
-
doAction: () =>
|
|
196
|
-
navigate(Routes.UnitDetail, {
|
|
197
|
-
unitId: unit_id,
|
|
198
|
-
}),
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
if (end_device_id) {
|
|
202
|
-
items.unshift({
|
|
203
|
-
text: t('device_display'),
|
|
204
|
-
doAction: () =>
|
|
205
|
-
navigate(Routes.DeviceDetail, {
|
|
206
|
-
unitId: unit_id,
|
|
207
|
-
sensorId: end_device_id,
|
|
208
|
-
}),
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return items;
|
|
212
|
-
}, [t, handleUpdateAutomate, navigate, unit_id, end_device_id]);
|
|
213
|
-
|
|
214
266
|
const handleShowMenuAction = useCallback(() => {
|
|
215
267
|
if (!can_edit) {
|
|
216
268
|
ToastBottomHelper.error(
|
|
@@ -241,6 +293,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
241
293
|
if (success) {
|
|
242
294
|
setAutomate(automateData);
|
|
243
295
|
setEnableScript(automateData.script.enable);
|
|
296
|
+
setNeedAllCondition(automateData.is_need_all_conditions);
|
|
244
297
|
}
|
|
245
298
|
}, [automateId]);
|
|
246
299
|
|
|
@@ -288,13 +341,39 @@ const ScriptDetail = ({ route }) => {
|
|
|
288
341
|
enable: checked,
|
|
289
342
|
}
|
|
290
343
|
);
|
|
291
|
-
|
|
344
|
+
if (success) {
|
|
345
|
+
ToastBottomHelper.success(t('update_successfully'));
|
|
346
|
+
setEnableScript(checked);
|
|
347
|
+
}
|
|
292
348
|
},
|
|
293
|
-
[automateId]
|
|
349
|
+
[automateId, t]
|
|
294
350
|
);
|
|
295
351
|
|
|
296
352
|
useBlockBack(handleGoBack);
|
|
297
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
|
+
|
|
298
377
|
useEffect(() => {
|
|
299
378
|
if (isFocused) {
|
|
300
379
|
fetchAutomate();
|
|
@@ -333,18 +412,60 @@ const ScriptDetail = ({ route }) => {
|
|
|
333
412
|
saveAt && fetchAutomateActions();
|
|
334
413
|
}, [saveAt, fetchAutomateActions]);
|
|
335
414
|
|
|
336
|
-
const handleShowMenuAction1 = useCallback(
|
|
337
|
-
|
|
338
|
-
|
|
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
|
+
);
|
|
339
458
|
|
|
340
459
|
const onCloseLocalControl = () => setIsShowLocalControl(false);
|
|
341
460
|
|
|
461
|
+
const onCloseSelectCondition = () => setIsShowSelectCondition(false);
|
|
462
|
+
|
|
342
463
|
const fetchChipShared = useCallback(async () => {
|
|
343
464
|
const { success, data: listChip } = await axiosGet(
|
|
344
465
|
API.DEV_MODE.GATEWAY.SHARED(),
|
|
345
466
|
{
|
|
346
467
|
params: {
|
|
347
|
-
unit:
|
|
468
|
+
unit: unit,
|
|
348
469
|
},
|
|
349
470
|
},
|
|
350
471
|
true
|
|
@@ -352,12 +473,16 @@ const ScriptDetail = ({ route }) => {
|
|
|
352
473
|
if (success) {
|
|
353
474
|
setListChipShared(listChip);
|
|
354
475
|
}
|
|
355
|
-
}, [
|
|
476
|
+
}, [unit]);
|
|
356
477
|
|
|
357
478
|
const onShowLocalControl = useCallback(async () => {
|
|
358
479
|
setIsShowLocalControl(true);
|
|
359
480
|
}, []);
|
|
360
481
|
|
|
482
|
+
const onShowSelectCondition = useCallback(async () => {
|
|
483
|
+
setIsShowSelectCondition(true);
|
|
484
|
+
}, []);
|
|
485
|
+
|
|
361
486
|
useEffect(() => {
|
|
362
487
|
fetchChipShared();
|
|
363
488
|
}, [fetchChipShared]);
|
|
@@ -377,6 +502,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
377
502
|
);
|
|
378
503
|
setIsShowLocalControl(false);
|
|
379
504
|
if (success) {
|
|
505
|
+
ToastBottomHelper.success(t('local_control_update_success'));
|
|
380
506
|
setLocalControl({
|
|
381
507
|
is_local_control: enable_local_control,
|
|
382
508
|
chip_local_control: item.name,
|
|
@@ -384,7 +510,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
384
510
|
});
|
|
385
511
|
}
|
|
386
512
|
},
|
|
387
|
-
[automateId, local_control.chip_id_local_control]
|
|
513
|
+
[automateId, local_control.chip_id_local_control, t]
|
|
388
514
|
);
|
|
389
515
|
|
|
390
516
|
const renderLocalControl = useMemo(() => {
|
|
@@ -423,6 +549,119 @@ const ScriptDetail = ({ route }) => {
|
|
|
423
549
|
type,
|
|
424
550
|
]);
|
|
425
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
|
+
|
|
426
665
|
return (
|
|
427
666
|
<View style={styles.wrap}>
|
|
428
667
|
<WrapHeaderScrollable
|
|
@@ -441,15 +680,9 @@ const ScriptDetail = ({ route }) => {
|
|
|
441
680
|
</View>
|
|
442
681
|
)}
|
|
443
682
|
{renderLocalControl}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
<ItemConditionScriptDetail
|
|
448
|
-
automate={automate}
|
|
449
|
-
enableScript={enableScript}
|
|
450
|
-
handleShowMenuAction1={handleShowMenuAction1}
|
|
451
|
-
refMenuAction1={refMenuAction1}
|
|
452
|
-
/>
|
|
683
|
+
{selectCondition}
|
|
684
|
+
{renderCondition}
|
|
685
|
+
{renderButtonAddCondition}
|
|
453
686
|
{type === AUTOMATE_TYPE.ONE_TAP && enableScript && (
|
|
454
687
|
<TouchableOpacity
|
|
455
688
|
onPress={handleScriptAction}
|
|
@@ -460,7 +693,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
460
693
|
</TouchableOpacity>
|
|
461
694
|
)}
|
|
462
695
|
|
|
463
|
-
<View style={styles.
|
|
696
|
+
<View style={styles.rowActionList}>
|
|
464
697
|
<Text type="H3" color={Colors.Gray9} semibold>
|
|
465
698
|
{t('actions_list')}
|
|
466
699
|
</Text>
|
|
@@ -472,15 +705,20 @@ const ScriptDetail = ({ route }) => {
|
|
|
472
705
|
AccessibilityLabel.BUTTON_EDIT_SCRIPT_ACTION
|
|
473
706
|
}
|
|
474
707
|
>
|
|
475
|
-
<Text
|
|
476
|
-
{t('edit')}
|
|
477
|
-
</Text>
|
|
708
|
+
<Text highlight>{t('edit')}</Text>
|
|
478
709
|
</TouchableOpacity>
|
|
479
710
|
)}
|
|
480
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>
|
|
481
719
|
{data.map((item, index) => (
|
|
482
720
|
<Item
|
|
483
|
-
key={
|
|
721
|
+
key={`Item${index}`}
|
|
484
722
|
item={item}
|
|
485
723
|
index={index}
|
|
486
724
|
enableScript={enableScript}
|
|
@@ -490,7 +728,8 @@ const ScriptDetail = ({ route }) => {
|
|
|
490
728
|
))}
|
|
491
729
|
{!!can_edit && !!enableScript && (
|
|
492
730
|
<ItemAdd
|
|
493
|
-
|
|
731
|
+
t={t}
|
|
732
|
+
max_actions_per_automation={max_actions_per_automation}
|
|
494
733
|
numberActionAdded={data.length}
|
|
495
734
|
setIsShowAddAction={setIsShowAddAction}
|
|
496
735
|
/>
|
|
@@ -533,6 +772,14 @@ const ScriptDetail = ({ route }) => {
|
|
|
533
772
|
type={type}
|
|
534
773
|
navigate={handleNavigate}
|
|
535
774
|
/>
|
|
775
|
+
<ModalAddCondition
|
|
776
|
+
automate={automate}
|
|
777
|
+
numberActionAdded={data.length}
|
|
778
|
+
isVisible={isShowAddCondition}
|
|
779
|
+
setIsVisible={setIsShowAddCondition}
|
|
780
|
+
type={type}
|
|
781
|
+
navigate={navigate}
|
|
782
|
+
/>
|
|
536
783
|
<RenameScript
|
|
537
784
|
automate={automate}
|
|
538
785
|
setAutomate={setAutomate}
|
|
@@ -544,52 +791,99 @@ const ScriptDetail = ({ route }) => {
|
|
|
544
791
|
setIsVisible={setIsShowDelete}
|
|
545
792
|
isVisible={isShowDelete}
|
|
546
793
|
/>
|
|
794
|
+
<DeleteCondition
|
|
795
|
+
automate={automate}
|
|
796
|
+
setAutomate={setAutomate}
|
|
797
|
+
condition={itemDeleteCondition}
|
|
798
|
+
setIsVisible={setItemDeleteCondition}
|
|
799
|
+
isVisible={Boolean(itemDeleteCondition.id)}
|
|
800
|
+
/>
|
|
547
801
|
<ModalCustom
|
|
802
|
+
key={'ModalLocalControl'}
|
|
548
803
|
isVisible={isShowLocalControl}
|
|
549
804
|
onBackButtonPress={onCloseLocalControl}
|
|
550
805
|
onBackdropPress={onCloseLocalControl}
|
|
551
806
|
>
|
|
552
807
|
<View key={'localControl'} style={styles.popoverStyle}>
|
|
553
|
-
<
|
|
554
|
-
style={styles.textDisable}
|
|
555
|
-
key={'listChip'}
|
|
556
|
-
onPress={() => {
|
|
557
|
-
onPressSelectChip(false, {
|
|
558
|
-
id: local_control.chip_id_local_control,
|
|
559
|
-
name: local_control.chip_local_control,
|
|
560
|
-
});
|
|
561
|
-
}}
|
|
562
|
-
accessibilityLabel={
|
|
563
|
-
AccessibilityLabel.AUTOMATE_DISABLE_LOCAL_CONTROL
|
|
564
|
-
}
|
|
565
|
-
>
|
|
566
|
-
<Text>{t('disable')}</Text>
|
|
567
|
-
{!local_control.is_local_control && (
|
|
568
|
-
<IconOutline style={styles.checked} name={'check'} size={20} />
|
|
569
|
-
)}
|
|
570
|
-
</TouchableOpacity>
|
|
571
|
-
{listChipShared.map((item, index) => (
|
|
808
|
+
<ScrollView>
|
|
572
809
|
<TouchableOpacity
|
|
573
|
-
|
|
574
|
-
|
|
810
|
+
style={styles.textDisable}
|
|
811
|
+
key={'listChip'}
|
|
575
812
|
onPress={() => {
|
|
576
|
-
onPressSelectChip(
|
|
813
|
+
onPressSelectChip(false, {
|
|
814
|
+
id: local_control.chip_id_local_control,
|
|
815
|
+
name: local_control.chip_local_control,
|
|
816
|
+
});
|
|
577
817
|
}}
|
|
578
818
|
accessibilityLabel={
|
|
579
|
-
AccessibilityLabel.
|
|
819
|
+
AccessibilityLabel.AUTOMATE_DISABLE_LOCAL_CONTROL
|
|
580
820
|
}
|
|
581
821
|
>
|
|
582
|
-
<Text>{
|
|
583
|
-
{local_control.
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
style={styles.checked}
|
|
587
|
-
name={'check'}
|
|
588
|
-
size={20}
|
|
589
|
-
/>
|
|
590
|
-
)}
|
|
822
|
+
<Text>{t('disable')}</Text>
|
|
823
|
+
{!local_control.is_local_control && (
|
|
824
|
+
<IconOutline style={styles.checked} name={'check'} size={20} />
|
|
825
|
+
)}
|
|
591
826
|
</TouchableOpacity>
|
|
592
|
-
|
|
827
|
+
{listChipShared.map((item, index) => (
|
|
828
|
+
<TouchableOpacity
|
|
829
|
+
key={'listChip' + index} // Add key fix warning
|
|
830
|
+
style={styles.listChip}
|
|
831
|
+
onPress={() => {
|
|
832
|
+
onPressSelectChip(true, item);
|
|
833
|
+
}}
|
|
834
|
+
accessibilityLabel={
|
|
835
|
+
AccessibilityLabel.AUTOMATE_ENABLE_LOCAL_CONTROL
|
|
836
|
+
}
|
|
837
|
+
>
|
|
838
|
+
<Text>{item.name}</Text>
|
|
839
|
+
{local_control.chip_id_local_control === item.id &&
|
|
840
|
+
local_control.is_local_control && (
|
|
841
|
+
<IconOutline
|
|
842
|
+
style={styles.checked}
|
|
843
|
+
name={'check'}
|
|
844
|
+
size={20}
|
|
845
|
+
/>
|
|
846
|
+
)}
|
|
847
|
+
</TouchableOpacity>
|
|
848
|
+
))}
|
|
849
|
+
</ScrollView>
|
|
850
|
+
</View>
|
|
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>
|
|
593
887
|
</View>
|
|
594
888
|
</ModalCustom>
|
|
595
889
|
</View>
|
|
@@ -771,10 +1065,12 @@ const Item = ({ item, index, enableScript, t, local_control }) => {
|
|
|
771
1065
|
}
|
|
772
1066
|
};
|
|
773
1067
|
|
|
774
|
-
const ItemAdd = ({
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
1068
|
+
const ItemAdd = ({
|
|
1069
|
+
t,
|
|
1070
|
+
max_actions_per_automation,
|
|
1071
|
+
numberActionAdded,
|
|
1072
|
+
setIsShowAddAction,
|
|
1073
|
+
}) => {
|
|
778
1074
|
const paddedIndex = (numberActionAdded + 1).toString().padStart(2, '0');
|
|
779
1075
|
|
|
780
1076
|
const onPressAddAction = useCallback(() => {
|