@eohjsc/react-native-smart-city 0.7.23 → 0.7.25
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/index.js +2 -0
- package/package.json +1 -1
- package/src/commons/Dashboard/MyDashboardDevice/__test__/index.test.js +171 -0
- package/src/commons/Dashboard/MyDashboardDevice/index.js +218 -0
- package/src/commons/Dashboard/MyDashboardDevice/styles.js +60 -0
- package/src/commons/Device/ItemDevice.js +12 -3
- package/src/commons/Device/ItemDeviceWrapper.js +10 -2
- package/src/commons/SubUnit/DeviceTemplate/DeviceTemplate.js +8 -3
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +7 -1
- package/src/configs/API.js +7 -0
- package/src/configs/AccessibilityLabel.js +2 -0
- package/src/context/actionType.ts +4 -0
- package/src/context/mockStore.ts +5 -0
- package/src/context/reducer.ts +30 -0
- package/src/iot/mqtt.js +163 -47
- package/src/navigations/UnitStack.js +14 -0
- package/src/screens/Device/__test__/detail.test.js +42 -1
- package/src/screens/Device/__test__/mqttDetail.test.js +411 -190
- package/src/screens/Device/detail.js +50 -14
- package/src/screens/Device/hooks/useDashboardDevice.js +34 -0
- package/src/utils/FactoryGateway.js +105 -0
- package/src/utils/I18n/translations/en.js +3 -0
- package/src/utils/I18n/translations/vi.js +7 -4
- package/src/utils/Storage.js +18 -2
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
useAlertResolveEmergency,
|
|
22
22
|
useEmergencyButton,
|
|
23
23
|
} from './hooks/useEmergencyButton';
|
|
24
|
+
import { useDashboardDevice } from './hooks/useDashboardDevice';
|
|
24
25
|
import { useFavoriteDevice } from './hooks/useFavoriteDevice';
|
|
25
26
|
import { usePopover } from '../../hooks/Common';
|
|
26
27
|
import { setConfigGlobalState, getConfigGlobalState } from '../../iot/states';
|
|
@@ -172,6 +173,9 @@ const DeviceDetail = ({ route }) => {
|
|
|
172
173
|
[display.items]
|
|
173
174
|
);
|
|
174
175
|
|
|
176
|
+
const { isPinnedDashboard, addToDashboard, removeFromDashboard } =
|
|
177
|
+
useDashboardDevice(device);
|
|
178
|
+
|
|
175
179
|
const { isFavorite, addToFavorites, removeFromFavorites } =
|
|
176
180
|
useFavoriteDevice(device);
|
|
177
181
|
|
|
@@ -333,6 +337,30 @@ const DeviceDetail = ({ route }) => {
|
|
|
333
337
|
|
|
334
338
|
const listMenuItem = useMemo(() => {
|
|
335
339
|
const menuItems = [];
|
|
340
|
+
|
|
341
|
+
if (!isPinnedDashboard) {
|
|
342
|
+
menuItems.push({
|
|
343
|
+
doAction: addToDashboard,
|
|
344
|
+
text: t('add_to_dashboard'),
|
|
345
|
+
});
|
|
346
|
+
} else {
|
|
347
|
+
menuItems.push({
|
|
348
|
+
doAction: removeFromDashboard,
|
|
349
|
+
text: t('remove_from_dashboard'),
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
if (!isFavorite) {
|
|
353
|
+
menuItems.push({
|
|
354
|
+
doAction: addToFavorites,
|
|
355
|
+
text: t('add_to_favorites'),
|
|
356
|
+
});
|
|
357
|
+
} else {
|
|
358
|
+
menuItems.push({
|
|
359
|
+
doAction: removeFromFavorites,
|
|
360
|
+
text: t('remove_from_favorites'),
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
336
364
|
if (display.items.some((i) => getActionComponent(i.template))) {
|
|
337
365
|
menuItems.push({
|
|
338
366
|
route: Routes.ActivityLog,
|
|
@@ -443,17 +471,6 @@ const DeviceDetail = ({ route }) => {
|
|
|
443
471
|
text: t('passcode_list'),
|
|
444
472
|
});
|
|
445
473
|
}
|
|
446
|
-
if (!isFavorite) {
|
|
447
|
-
menuItems.unshift({
|
|
448
|
-
doAction: addToFavorites,
|
|
449
|
-
text: t('add_to_favorites'),
|
|
450
|
-
});
|
|
451
|
-
} else {
|
|
452
|
-
menuItems.unshift({
|
|
453
|
-
doAction: removeFromFavorites,
|
|
454
|
-
text: t('remove_from_favorites'),
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
474
|
return [...menuItems];
|
|
458
475
|
}, [
|
|
459
476
|
display,
|
|
@@ -462,6 +479,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
462
479
|
sideMenu,
|
|
463
480
|
t,
|
|
464
481
|
isShowSetUpSmartLock,
|
|
482
|
+
isPinnedDashboard,
|
|
465
483
|
isFavorite,
|
|
466
484
|
device,
|
|
467
485
|
unit,
|
|
@@ -471,7 +489,9 @@ const DeviceDetail = ({ route }) => {
|
|
|
471
489
|
fetchDataDeviceDetail,
|
|
472
490
|
isMyUnitDeviceScreen,
|
|
473
491
|
emergencyDeviceId,
|
|
492
|
+
addToDashboard,
|
|
474
493
|
addToFavorites,
|
|
494
|
+
removeFromDashboard,
|
|
475
495
|
removeFromFavorites,
|
|
476
496
|
]);
|
|
477
497
|
|
|
@@ -729,6 +749,19 @@ const DeviceDetail = ({ route }) => {
|
|
|
729
749
|
const HeaderRight = useMemo(
|
|
730
750
|
() => (
|
|
731
751
|
<View style={styles.headerRight}>
|
|
752
|
+
<TouchableOpacity
|
|
753
|
+
onPress={isPinnedDashboard ? removeFromDashboard : addToDashboard}
|
|
754
|
+
accessibilityLabel={AccessibilityLabel.HEADER_DEVICE_BUTTON_PIN}
|
|
755
|
+
>
|
|
756
|
+
<View style={styles.buttonStar}>
|
|
757
|
+
{isPinnedDashboard ? (
|
|
758
|
+
<IconFill name="pushpin" size={25} color={Colors.Yellow6} />
|
|
759
|
+
) : (
|
|
760
|
+
<IconOutline name="pushpin" size={25} />
|
|
761
|
+
)}
|
|
762
|
+
</View>
|
|
763
|
+
</TouchableOpacity>
|
|
764
|
+
|
|
732
765
|
<TouchableOpacity
|
|
733
766
|
onPress={isFavorite ? removeFromFavorites : addToFavorites}
|
|
734
767
|
accessibilityLabel={AccessibilityLabel.HEADER_DEVICE_BUTTON_STAR}
|
|
@@ -761,12 +794,15 @@ const DeviceDetail = ({ route }) => {
|
|
|
761
794
|
</View>
|
|
762
795
|
),
|
|
763
796
|
[
|
|
797
|
+
isPinnedDashboard,
|
|
764
798
|
isFavorite,
|
|
765
|
-
removeFromFavorites,
|
|
766
|
-
addToFavorites,
|
|
767
799
|
isShowSetupEmergencyContact,
|
|
768
|
-
|
|
800
|
+
addToDashboard,
|
|
801
|
+
addToFavorites,
|
|
802
|
+
removeFromDashboard,
|
|
803
|
+
removeFromFavorites,
|
|
769
804
|
handleShowMenuAction,
|
|
805
|
+
onPressSetting,
|
|
770
806
|
]
|
|
771
807
|
);
|
|
772
808
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useContext, useCallback } from 'react';
|
|
2
|
+
import { API } from '../../../configs';
|
|
3
|
+
import { SCContext, useSCContextSelector } from '../../../context';
|
|
4
|
+
import { Action } from '../../../context/actionType';
|
|
5
|
+
import { axiosPost } from '../../../utils/Apis/axios';
|
|
6
|
+
|
|
7
|
+
export const useDashboardDevice = (device) => {
|
|
8
|
+
const { setAction } = useContext(SCContext);
|
|
9
|
+
const dashboardDeviceIds = useSCContextSelector(
|
|
10
|
+
(state) => state.unit.dashboardDeviceIds
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const isPinnedDashboard = dashboardDeviceIds.includes(device.id);
|
|
14
|
+
|
|
15
|
+
const addToDashboard = useCallback(async () => {
|
|
16
|
+
const { success } = await axiosPost(API.DEVICE.ADD_TO_DASHBOARD(device.id));
|
|
17
|
+
success && setAction(Action.ADD_DEVICES_TO_DASHBOARD, [device.id]);
|
|
18
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
|
+
}, [device.id]);
|
|
20
|
+
|
|
21
|
+
const removeFromDashboard = useCallback(async () => {
|
|
22
|
+
const { success } = await axiosPost(
|
|
23
|
+
API.DEVICE.REMOVE_FROM_DASHBOARD(device.id)
|
|
24
|
+
);
|
|
25
|
+
success && setAction(Action.REMOVE_DEVICES_FROM_DASHBOARD, [device.id]);
|
|
26
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
+
}, [device.id]);
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
isPinnedDashboard,
|
|
31
|
+
addToDashboard,
|
|
32
|
+
removeFromDashboard,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -423,6 +423,90 @@ export const gatewayDataFactory = {
|
|
|
423
423
|
chip: 7689,
|
|
424
424
|
icon_kit: null,
|
|
425
425
|
},
|
|
426
|
+
{
|
|
427
|
+
// Third Party
|
|
428
|
+
id: 9,
|
|
429
|
+
configs: [
|
|
430
|
+
{
|
|
431
|
+
id: 37,
|
|
432
|
+
status_texts: [],
|
|
433
|
+
is_on: false,
|
|
434
|
+
get_value_unit: '',
|
|
435
|
+
period_configs: [],
|
|
436
|
+
auto_triggers: [],
|
|
437
|
+
spotsensorconnect: null,
|
|
438
|
+
last_maxmin: null,
|
|
439
|
+
user_receive_email: [],
|
|
440
|
+
phone_send_sms: [],
|
|
441
|
+
status_configuration: {},
|
|
442
|
+
is_auto_release: false,
|
|
443
|
+
related_actions: [],
|
|
444
|
+
active: true,
|
|
445
|
+
name: 'LED',
|
|
446
|
+
is_read: true,
|
|
447
|
+
is_write: true,
|
|
448
|
+
range_min: null,
|
|
449
|
+
range_max: null,
|
|
450
|
+
unit: '',
|
|
451
|
+
scale: 1,
|
|
452
|
+
is_main: true,
|
|
453
|
+
is_chart: true,
|
|
454
|
+
is_report: true,
|
|
455
|
+
is_chart_column: false,
|
|
456
|
+
is_hide: false,
|
|
457
|
+
display_type: '',
|
|
458
|
+
is_alarm: false,
|
|
459
|
+
email_flags: false,
|
|
460
|
+
time_is_over: null,
|
|
461
|
+
maintain_time: 5,
|
|
462
|
+
number_send_email: null,
|
|
463
|
+
period_send_email: 15,
|
|
464
|
+
allow_min_value: 0,
|
|
465
|
+
allow_max_value: 0,
|
|
466
|
+
message: 'Thông báo.',
|
|
467
|
+
last_time_send_email: null,
|
|
468
|
+
ai_trans_offset_value: '0.000',
|
|
469
|
+
ai_trans_average_sample: 0,
|
|
470
|
+
last_values: [],
|
|
471
|
+
icon: '',
|
|
472
|
+
scale_write: 1,
|
|
473
|
+
lock: false,
|
|
474
|
+
flag: false,
|
|
475
|
+
index: 0,
|
|
476
|
+
decimal_behind: null,
|
|
477
|
+
active_filter: '',
|
|
478
|
+
high_level: 0,
|
|
479
|
+
low_level: 0,
|
|
480
|
+
value_converter: '',
|
|
481
|
+
ack: false,
|
|
482
|
+
sensor_type: '',
|
|
483
|
+
value_type: 'number',
|
|
484
|
+
enable_log_max_min: true,
|
|
485
|
+
log_value_mode: 1,
|
|
486
|
+
freq_log_data: 600,
|
|
487
|
+
number_days_storage: 180,
|
|
488
|
+
storage_start_date: '2025-01-07',
|
|
489
|
+
release_time: 0,
|
|
490
|
+
sensor: 9,
|
|
491
|
+
end_device: 4,
|
|
492
|
+
last_value: null,
|
|
493
|
+
last_value_log: null,
|
|
494
|
+
},
|
|
495
|
+
],
|
|
496
|
+
active: true,
|
|
497
|
+
name: 'LED',
|
|
498
|
+
mix: true,
|
|
499
|
+
index: 0,
|
|
500
|
+
icon: '',
|
|
501
|
+
is_managed_by_backend: true,
|
|
502
|
+
device_id: '',
|
|
503
|
+
last_updated: null,
|
|
504
|
+
connection_time: 60,
|
|
505
|
+
sent_email: false,
|
|
506
|
+
realtime_monitoring: false,
|
|
507
|
+
chip: 3,
|
|
508
|
+
icon_kit: null,
|
|
509
|
+
},
|
|
426
510
|
],
|
|
427
511
|
id: 7689,
|
|
428
512
|
sn: '57ae596e-ef65-4162-9b6f-4f67f2c86632',
|
|
@@ -523,4 +607,25 @@ export const gatewayDataFactory = {
|
|
|
523
607
|
],
|
|
524
608
|
chip: 7682,
|
|
525
609
|
},
|
|
610
|
+
third_party_gateway: {
|
|
611
|
+
id: 4,
|
|
612
|
+
sensors: [
|
|
613
|
+
{
|
|
614
|
+
id: 5,
|
|
615
|
+
configs: [
|
|
616
|
+
{
|
|
617
|
+
id: 5,
|
|
618
|
+
key: 'led',
|
|
619
|
+
value_type: 'number',
|
|
620
|
+
device: 5,
|
|
621
|
+
config: 37,
|
|
622
|
+
},
|
|
623
|
+
],
|
|
624
|
+
device_uid: '0x00158d00022fd388',
|
|
625
|
+
gateway: 4,
|
|
626
|
+
sensor: 9,
|
|
627
|
+
},
|
|
628
|
+
],
|
|
629
|
+
chip: 7689,
|
|
630
|
+
},
|
|
526
631
|
};
|
|
@@ -42,6 +42,9 @@ export default {
|
|
|
42
42
|
contact_infomation: 'Contact Infomation',
|
|
43
43
|
company_infomation: 'Company Infomation',
|
|
44
44
|
terms_and_condition: 'Terms & Conditions',
|
|
45
|
+
add_to_dashboard: 'Add to Dashboard',
|
|
46
|
+
remove_from_dashboard: 'Remove from Dashboard',
|
|
47
|
+
dashboard_devices: 'Dashboard Devices',
|
|
45
48
|
text_sub_units: 'Sub-units',
|
|
46
49
|
text_my_units: 'My Units',
|
|
47
50
|
text_shared_units: 'Shared Units',
|
|
@@ -117,6 +117,9 @@ export default {
|
|
|
117
117
|
text_good_night: 'Chào buổi tối, {0}',
|
|
118
118
|
text_anonymous: '',
|
|
119
119
|
multi_unit: 'Nhiều đơn vị',
|
|
120
|
+
add_to_dashboard: 'Thêm vào Dashboard',
|
|
121
|
+
remove_from_dashboard: 'Loại khỏi Dashboard',
|
|
122
|
+
dashboard_devices: 'Thiết bị thường dùng',
|
|
120
123
|
text_my_units: 'Địa điểm của tôi',
|
|
121
124
|
text_shared_units: 'Địa điểm được chia sẻ ',
|
|
122
125
|
text_copyright:
|
|
@@ -491,7 +494,7 @@ export default {
|
|
|
491
494
|
to: 'đến',
|
|
492
495
|
condition: 'Điều kiện',
|
|
493
496
|
no_condition: 'Không điều kiện',
|
|
494
|
-
available_condition: 'Số điều
|
|
497
|
+
available_condition: 'Số điều kiện còn lại [{number}]',
|
|
495
498
|
available_action: 'Số hành động còn lại [{number}]',
|
|
496
499
|
shared_unit: 'Khu vực được chia sẻ',
|
|
497
500
|
owner_unit: 'Chủ khu vực',
|
|
@@ -1049,10 +1052,10 @@ export default {
|
|
|
1049
1052
|
update_condition_success: 'Cập nhật điều kiện thành công',
|
|
1050
1053
|
edit_condition_success: 'Chỉnh sửa điều kiện thành công',
|
|
1051
1054
|
delete_condition: 'Xoá điều kiện',
|
|
1052
|
-
are_met: 'Tất cả điều
|
|
1055
|
+
are_met: 'Tất cả điều kiện đều thỏa',
|
|
1053
1056
|
is_met: 'Một trong các điều kiện được thỏa',
|
|
1054
|
-
add_condition: 'Thêm điều
|
|
1055
|
-
add_condition_success: 'Thêm điều
|
|
1057
|
+
add_condition: 'Thêm điều kiện',
|
|
1058
|
+
add_condition_success: 'Thêm điều kiện thành công',
|
|
1056
1059
|
device_display: 'Thiết bị hiển thị',
|
|
1057
1060
|
time_frame: 'Khung thời gian',
|
|
1058
1061
|
ex_time_frame: 'Ví dụ: 8:00 a.m. mỗi ngày.',
|
package/src/utils/Storage.js
CHANGED
|
@@ -9,11 +9,27 @@ export const STORAGE_KEY = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const storeData = async (key, value) => {
|
|
12
|
-
return await AsyncStorage.setItem(
|
|
12
|
+
return await AsyncStorage.setItem(key, value);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export const getData = async (key) => {
|
|
16
|
-
return await AsyncStorage.getItem(
|
|
16
|
+
return await AsyncStorage.getItem(key);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const storeObject = async (key, value) => {
|
|
20
|
+
return await AsyncStorage.setItem(key, JSON.stringify(value));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getObject = async (key, defaultValue) => {
|
|
24
|
+
const value = await AsyncStorage.getItem(key);
|
|
25
|
+
if (value === null) {
|
|
26
|
+
return defaultValue;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(value);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return defaultValue;
|
|
32
|
+
}
|
|
17
33
|
};
|
|
18
34
|
|
|
19
35
|
export const removeMultiple = async (keys) => {
|