@eohjsc/react-native-smart-city 0.4.73 → 0.4.75
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/Device/LastUpdatedText.js +17 -3
- package/src/commons/MenuActionList/index.js +0 -1
- package/src/commons/SubUnit/DeviceTemplate/ConfigAndEvaluation/ConfigAndEvaluation.js +22 -11
- package/src/commons/SubUnit/DeviceTemplate/ConfigValue/ConfigValue.js +20 -12
- package/src/commons/SubUnit/DeviceTemplate/EvaluationOverConfig/EvaluationOverConfig.js +24 -12
- package/src/commons/SubUnit/DeviceTemplate/styles/ConfigValueStyles.js +14 -3
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +29 -1
- package/src/configs/AccessibilityLabel.js +3 -0
- package/src/screens/Device/detail.js +0 -1
package/package.json
CHANGED
|
@@ -4,18 +4,32 @@ import Text from '../Text';
|
|
|
4
4
|
import { Colors } from '../../configs';
|
|
5
5
|
import React, { memo } from 'react';
|
|
6
6
|
import { StyleSheet } from 'react-native';
|
|
7
|
+
import moment from 'moment';
|
|
8
|
+
import AccessibilityLabel from '../../configs/AccessibilityLabel';
|
|
7
9
|
|
|
8
10
|
const styles = StyleSheet.create({
|
|
9
11
|
txtLastUpdate: {
|
|
10
|
-
marginLeft: 8,
|
|
11
12
|
lineHeight: 20,
|
|
12
|
-
marginTop:
|
|
13
|
+
marginTop: 6,
|
|
13
14
|
},
|
|
14
15
|
});
|
|
15
16
|
|
|
16
|
-
const LastUpdatedText = memo(({ lastUpdated, showText }) => {
|
|
17
|
+
const LastUpdatedText = memo(({ lastUpdated, showText, format = null }) => {
|
|
17
18
|
const t = useTranslations();
|
|
18
19
|
|
|
20
|
+
if (format === 'DDMMYYYY') {
|
|
21
|
+
const dayMonthYear = moment(lastUpdated).format('HH:mm DD-MM-YYYY');
|
|
22
|
+
return (
|
|
23
|
+
<Text
|
|
24
|
+
accessibilityLabel={AccessibilityLabel.LAST_UPDATED_TEXT}
|
|
25
|
+
color={Colors.Gray7}
|
|
26
|
+
size={12}
|
|
27
|
+
style={styles.txtLastUpdate}
|
|
28
|
+
>
|
|
29
|
+
{dayMonthYear}
|
|
30
|
+
</Text>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
19
33
|
const lastUpdatedStr = lastUpdated
|
|
20
34
|
? timeDifference(new Date(), lastUpdated)
|
|
21
35
|
: `5 ${t('seconds_ago')}`;
|
|
@@ -4,29 +4,40 @@ import { View } from 'react-native';
|
|
|
4
4
|
import Text from '../../../Text';
|
|
5
5
|
import LastUpdatedText from '../../../Device/LastUpdatedText';
|
|
6
6
|
import { EvaluationConfigWrapper } from '../EvaluationOverConfig/EvaluationOverConfig';
|
|
7
|
+
import IconComponent from '../../../IconComponent';
|
|
8
|
+
import { IconOutline } from '@ant-design/icons-react-native';
|
|
7
9
|
|
|
8
10
|
const ConfigAndEvaluationDisplay = memo(
|
|
9
|
-
({ valueEvaluation, stationItem, configValue }) => {
|
|
11
|
+
({ device, valueEvaluation, stationItem, configValue }) => {
|
|
12
|
+
const { icon_kit, icon } = device || {};
|
|
10
13
|
return (
|
|
11
14
|
<>
|
|
12
15
|
<View>
|
|
13
16
|
<View style={styles.rowTop}>
|
|
14
|
-
<
|
|
15
|
-
|
|
17
|
+
<IconComponent icon={icon_kit || icon} />
|
|
18
|
+
</View>
|
|
19
|
+
<View style={styles.rowTop}>
|
|
20
|
+
<Text bold>{stationItem?.configuration?.config_data?.name}</Text>
|
|
21
|
+
</View>
|
|
22
|
+
<View style={styles.rowBottom}>
|
|
23
|
+
<Text style={styles.textValue} bold>
|
|
24
|
+
{configValue?.value}{' '}
|
|
25
|
+
{stationItem?.configuration?.config_data?.unit}
|
|
16
26
|
</Text>
|
|
17
27
|
</View>
|
|
18
|
-
<Text
|
|
28
|
+
<Text style={styles.textStatus} color={valueEvaluation?.color}>
|
|
19
29
|
{valueEvaluation?.text}
|
|
20
30
|
</Text>
|
|
21
31
|
</View>
|
|
22
|
-
|
|
23
|
-
<Text style={styles.textValue} bold>
|
|
24
|
-
{configValue?.value || '-'}
|
|
25
|
-
</Text>
|
|
26
|
-
<Text type="H4">{stationItem?.configuration?.config_data?.unit}</Text>
|
|
27
|
-
</View>
|
|
32
|
+
|
|
28
33
|
{configValue?.last_updated && (
|
|
29
|
-
<
|
|
34
|
+
<View style={styles.lastUpdate}>
|
|
35
|
+
<LastUpdatedText
|
|
36
|
+
lastUpdated={configValue?.last_updated}
|
|
37
|
+
format={'DDMMYYYY'}
|
|
38
|
+
/>
|
|
39
|
+
<IconOutline style={styles.marginTop10} name="right" size={12} />
|
|
40
|
+
</View>
|
|
30
41
|
)}
|
|
31
42
|
</>
|
|
32
43
|
);
|
|
@@ -5,6 +5,8 @@ import Text from '../../../Text';
|
|
|
5
5
|
import { useConfigGlobalState } from '../../../../iot/states';
|
|
6
6
|
import { useWatchConfigs } from '../../../../hooks/IoT';
|
|
7
7
|
import LastUpdatedText from '../../../Device/LastUpdatedText';
|
|
8
|
+
import IconComponent from '../../../IconComponent';
|
|
9
|
+
import { IconOutline } from '@ant-design/icons-react-native';
|
|
8
10
|
|
|
9
11
|
const ConfigValue = ({ device, stationItem }) => {
|
|
10
12
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -13,27 +15,33 @@ const ConfigValue = ({ device, stationItem }) => {
|
|
|
13
15
|
const configIds = useMemo(() => {
|
|
14
16
|
return [stationItem.configuration?.config];
|
|
15
17
|
}, [stationItem.configuration?.config]);
|
|
16
|
-
|
|
18
|
+
const { icon_kit, icon } = device || {};
|
|
17
19
|
useWatchConfigs(configIds);
|
|
18
20
|
|
|
19
21
|
return (
|
|
20
22
|
<>
|
|
21
23
|
<View>
|
|
22
24
|
<View style={styles.rowTop}>
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
+
<IconComponent icon={icon_kit || icon} />
|
|
26
|
+
</View>
|
|
27
|
+
<View style={styles.rowTop}>
|
|
28
|
+
<Text bold>{stationItem?.configuration?.config_data?.name}</Text>
|
|
29
|
+
</View>
|
|
30
|
+
<View style={styles.rowBottom}>
|
|
31
|
+
<Text style={styles.textValue} bold>
|
|
32
|
+
{configValue?.value} {stationItem?.configuration?.config_data?.unit}
|
|
25
33
|
</Text>
|
|
26
34
|
</View>
|
|
35
|
+
{configValue?.last_updated && (
|
|
36
|
+
<View style={styles.lastUpdate}>
|
|
37
|
+
<LastUpdatedText
|
|
38
|
+
lastUpdated={configValue?.last_updated}
|
|
39
|
+
format={'DDMMYYYY'}
|
|
40
|
+
/>
|
|
41
|
+
<IconOutline style={styles.marginTop10} name="right" size={12} />
|
|
42
|
+
</View>
|
|
43
|
+
)}
|
|
27
44
|
</View>
|
|
28
|
-
<View style={styles.rowBottom}>
|
|
29
|
-
<Text style={styles.textValue} bold>
|
|
30
|
-
{configValue?.value || '-'}
|
|
31
|
-
</Text>
|
|
32
|
-
<Text type="H4">{stationItem?.configuration?.config_data?.unit}</Text>
|
|
33
|
-
</View>
|
|
34
|
-
{configValue?.last_updated && (
|
|
35
|
-
<LastUpdatedText lastUpdated={configValue?.last_updated} />
|
|
36
|
-
)}
|
|
37
45
|
</>
|
|
38
46
|
);
|
|
39
47
|
};
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
} from '../../../../screens/Device/hooks/useEvaluateValue';
|
|
10
10
|
import { useWatchConfigs } from '../../../../hooks/IoT';
|
|
11
11
|
import LastUpdatedText from '../../../Device/LastUpdatedText';
|
|
12
|
+
import IconComponent from '../../../IconComponent';
|
|
13
|
+
import { IconOutline } from '@ant-design/icons-react-native';
|
|
12
14
|
|
|
13
15
|
export const EvaluationConfigWrapper = memo(
|
|
14
16
|
({ device, stationItem, Child }) => {
|
|
@@ -31,9 +33,9 @@ export const EvaluationConfigWrapper = memo(
|
|
|
31
33
|
configValue?.value,
|
|
32
34
|
valueEvaluationObject
|
|
33
35
|
);
|
|
34
|
-
|
|
35
36
|
return (
|
|
36
37
|
<Child
|
|
38
|
+
device={device}
|
|
37
39
|
valueEvaluation={valueEvaluation}
|
|
38
40
|
stationItem={stationItem}
|
|
39
41
|
configValue={configValue}
|
|
@@ -43,24 +45,34 @@ export const EvaluationConfigWrapper = memo(
|
|
|
43
45
|
);
|
|
44
46
|
|
|
45
47
|
const EvaluationOverConfigDisplay = memo(
|
|
46
|
-
({ valueEvaluation, stationItem, configValue }) => {
|
|
48
|
+
({ device, valueEvaluation, stationItem, configValue }) => {
|
|
49
|
+
const { icon_kit, icon } = device || {};
|
|
47
50
|
return (
|
|
48
51
|
<>
|
|
49
52
|
<View>
|
|
50
53
|
<View style={styles.rowTop}>
|
|
51
|
-
<
|
|
52
|
-
|
|
54
|
+
<IconComponent icon={icon_kit || icon} />
|
|
55
|
+
</View>
|
|
56
|
+
<View style={styles.rowTop}>
|
|
57
|
+
<Text bold>{stationItem?.configuration?.config_data?.name}</Text>
|
|
58
|
+
</View>
|
|
59
|
+
|
|
60
|
+
<View style={styles.rowBottom}>
|
|
61
|
+
<Text style={styles.textValue} bold color={valueEvaluation?.color}>
|
|
62
|
+
{valueEvaluation?.text}
|
|
53
63
|
</Text>
|
|
54
64
|
</View>
|
|
65
|
+
|
|
66
|
+
{configValue?.last_updated && (
|
|
67
|
+
<View style={styles.lastUpdate}>
|
|
68
|
+
<LastUpdatedText
|
|
69
|
+
lastUpdated={configValue?.last_updated}
|
|
70
|
+
format={'DDMMYYYY'}
|
|
71
|
+
/>
|
|
72
|
+
<IconOutline style={styles.marginTop10} name="right" size={12} />
|
|
73
|
+
</View>
|
|
74
|
+
)}
|
|
55
75
|
</View>
|
|
56
|
-
<View style={styles.rowBottom}>
|
|
57
|
-
<Text style={styles.textValue} bold color={valueEvaluation?.color}>
|
|
58
|
-
{valueEvaluation?.text}
|
|
59
|
-
</Text>
|
|
60
|
-
</View>
|
|
61
|
-
{configValue?.last_updated && (
|
|
62
|
-
<LastUpdatedText lastUpdated={configValue?.last_updated} />
|
|
63
|
-
)}
|
|
64
76
|
</>
|
|
65
77
|
);
|
|
66
78
|
}
|
|
@@ -16,8 +16,19 @@ export default StyleSheet.create({
|
|
|
16
16
|
alignItems: 'center',
|
|
17
17
|
},
|
|
18
18
|
textValue: {
|
|
19
|
-
|
|
20
|
-
lineHeight:
|
|
21
|
-
|
|
19
|
+
marginTop: 6,
|
|
20
|
+
lineHeight: 16,
|
|
21
|
+
},
|
|
22
|
+
textStatus: {
|
|
23
|
+
marginTop: 6,
|
|
24
|
+
fontSize: 12,
|
|
25
|
+
},
|
|
26
|
+
lastUpdate: {
|
|
27
|
+
flexDirection: 'row',
|
|
28
|
+
justifyContent: 'space-between',
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
},
|
|
31
|
+
marginTop10: {
|
|
32
|
+
marginTop: 10,
|
|
22
33
|
},
|
|
23
34
|
});
|
|
@@ -13,6 +13,7 @@ import ItemDevice from '../../Device/ItemDevice';
|
|
|
13
13
|
import { DeviceTemplate } from '../DeviceTemplate/DeviceTemplate';
|
|
14
14
|
import ItemHanetDevice from '../../Device/Hanet/ItemHanetDevice';
|
|
15
15
|
import { watchMultiConfigs } from '../../../iot/Monitor';
|
|
16
|
+
import Text from '../../Text';
|
|
16
17
|
|
|
17
18
|
jest.mock('../../../iot/Monitor');
|
|
18
19
|
|
|
@@ -37,6 +38,9 @@ jest.mock('@react-navigation/native', () => {
|
|
|
37
38
|
useFocusEffect: jest.fn((handler) => handler()),
|
|
38
39
|
};
|
|
39
40
|
});
|
|
41
|
+
jest.mock('../../../iot/states', () => ({
|
|
42
|
+
useConfigGlobalState: () => [{}, null],
|
|
43
|
+
}));
|
|
40
44
|
|
|
41
45
|
describe('test ShortDetail Subunit', () => {
|
|
42
46
|
let tree, props;
|
|
@@ -189,6 +193,18 @@ describe('test ShortDetail Subunit', () => {
|
|
|
189
193
|
['ConfigAndEvaluation', 'ConfigValue', 'EvaluationOverConfig'].forEach(
|
|
190
194
|
(template) => {
|
|
191
195
|
it(`render with device template ${template}`, async () => {
|
|
196
|
+
const globalStates = require('../../../iot/states');
|
|
197
|
+
globalStates.useConfigGlobalState = () => [
|
|
198
|
+
{
|
|
199
|
+
1: {
|
|
200
|
+
value: 10,
|
|
201
|
+
status: null,
|
|
202
|
+
last_updated: '2023-10-10T04:36:04.010471Z',
|
|
203
|
+
status_of_value: 'NO_CHANGE',
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
null,
|
|
207
|
+
];
|
|
192
208
|
props.station.devices = [
|
|
193
209
|
{
|
|
194
210
|
action: {
|
|
@@ -203,14 +219,18 @@ describe('test ShortDetail Subunit', () => {
|
|
|
203
219
|
icon: '',
|
|
204
220
|
id: 1,
|
|
205
221
|
name: 'People Counting',
|
|
222
|
+
icon_kit: 'https://xxx.png',
|
|
206
223
|
quick_action: null,
|
|
207
|
-
remote_control_options: {},
|
|
208
224
|
station: {},
|
|
209
225
|
status: null,
|
|
210
226
|
status2: null,
|
|
211
227
|
station_items: [
|
|
212
228
|
{
|
|
213
229
|
template: template,
|
|
230
|
+
configuration: {
|
|
231
|
+
config: 1,
|
|
232
|
+
config_data: { id: 29520, name: 'Moving', unit: '' },
|
|
233
|
+
},
|
|
214
234
|
},
|
|
215
235
|
],
|
|
216
236
|
},
|
|
@@ -222,6 +242,14 @@ describe('test ShortDetail Subunit', () => {
|
|
|
222
242
|
const instance = tree.root;
|
|
223
243
|
const itemDevices = instance.findAllByType(DeviceTemplate);
|
|
224
244
|
expect(itemDevices.length).toBe(1);
|
|
245
|
+
|
|
246
|
+
const lastUpdate = instance.findAll(
|
|
247
|
+
(el) =>
|
|
248
|
+
el.props.accessibilityLabel ===
|
|
249
|
+
`${AccessibilityLabel.LAST_UPDATED_TEXT}` && el.type === Text
|
|
250
|
+
);
|
|
251
|
+
expect(lastUpdate).toHaveLength(1);
|
|
252
|
+
expect(lastUpdate[0].props.children).toEqual('05:36 10-10-2023');
|
|
225
253
|
});
|
|
226
254
|
}
|
|
227
255
|
);
|