@eohjsc/react-native-smart-city 0.5.9 → 0.6.1
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/README.md +44 -6
- package/package.json +1 -1
- package/src/commons/Device/HorizontalBarChart.js +1 -1
- package/src/commons/Device/PowerConsumptionChart.js +159 -0
- package/src/commons/Device/ProgressBar/__test__/ProgressBar.test.js +2 -3
- package/src/commons/Device/ProgressBar/index.js +36 -38
- package/src/commons/Device/ProgressBar/styles.js +18 -24
- package/src/commons/Form/CurrencyInput.js +2 -0
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +6 -61
- package/src/commons/Widgets/IFrame/IFrame.js +54 -0
- package/src/commons/Widgets/IFrame/IFrameStyles.js +35 -0
- package/src/commons/Widgets/IFrame/__tests__/IFrame.test.js +74 -0
- package/src/commons/Widgets/IFrame/index.js +0 -0
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +163 -0
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfigStyles.js +9 -0
- package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +284 -0
- package/src/commons/Widgets/IFrameWithConfig/index.js +0 -0
- package/src/commons/Widgets/Widget.js +0 -0
- package/src/commons/Widgets/index.js +0 -0
- package/src/configs/AccessibilityLabel.js +3 -0
- package/src/configs/Constants.js +5 -0
- package/src/hooks/Common/useDevicesStatus.js +23 -23
- package/src/screens/Device/__test__/sensorDisplayItem.test.js +3 -3
- package/src/screens/Device/components/SensorDisplayItem.js +23 -5
- package/src/screens/Device/components/__test__/VisualChart.test.js +2 -9
- package/src/screens/PlayBackCamera/Styles/index.js +2 -4
- package/src/screens/PlayBackCamera/Timer.js +65 -47
- package/src/screens/PlayBackCamera/__test__/index.test.js +27 -19
- package/src/screens/PlayBackCamera/index.js +114 -111
- package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +10 -23
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +57 -3
- package/src/screens/UnitSummary/components/PowerConsumption/index.js +21 -30
- package/src/commons/Device/HistoryChart.js +0 -225
- package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +0 -289
- package/src/screens/Device/__test__/DetailHistoryChart.test.js +0 -69
- package/src/screens/Device/components/DetailHistoryChart.js +0 -118
package/README.md
CHANGED
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
|
|
22
22
|
1. StackNavigator
|
|
23
23
|
|
|
24
|
+
- You can see the screens or components that the library is supporting in the folder `/@eohjsc/react-native-smart-city/index.js`
|
|
25
|
+
|
|
24
26
|
```javascript
|
|
25
27
|
import {
|
|
26
28
|
UnitStack,
|
|
@@ -38,12 +40,9 @@ import {
|
|
|
38
40
|
import Config from 'react-native-config';
|
|
39
41
|
import { createStackNavigator } from '@react-navigation/stack';
|
|
40
42
|
|
|
41
|
-
// TODO: What to do with the module?
|
|
42
43
|
const Stack = createStackNavigator();
|
|
43
44
|
|
|
44
45
|
const YourStack = () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
46
|
useEffect(() => {
|
|
48
47
|
const config = {
|
|
49
48
|
apiRoot: Config.API_ROOT,
|
|
@@ -58,8 +57,8 @@ const YourStack = () => {
|
|
|
58
57
|
language,
|
|
59
58
|
setCurrentSensorDisplay,
|
|
60
59
|
appName: Config.APP_NAME,
|
|
61
|
-
packageName: Config.APP_PACKAGE_NAME,
|
|
62
|
-
versionCode: Config.APP_VERSION_CODE,
|
|
60
|
+
packageName: Config.APP_PACKAGE_NAME, // Your package name is required
|
|
61
|
+
versionCode: Config.APP_VERSION_CODE, // Your app version is required
|
|
63
62
|
};
|
|
64
63
|
initSCConfig(config);
|
|
65
64
|
}, [language, setCurrentSensorDisplay]);
|
|
@@ -132,7 +131,46 @@ const MyScreen = () => {
|
|
|
132
131
|
};
|
|
133
132
|
```
|
|
134
133
|
|
|
135
|
-
3.
|
|
134
|
+
3. Use navigate to the screens included in the '@eohjsc/react-native-smart-city' library
|
|
135
|
+
|
|
136
|
+
- You can see the list of screens, currently supported by the library in the folder `/@eohjsc/react-native-smart-city/src/navigations/`
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
import { useNavigation } from '@react-navigation/native';
|
|
140
|
+
const { navigate } = useNavigation();
|
|
141
|
+
const automate_id = 1;
|
|
142
|
+
const unit_id = 1;
|
|
143
|
+
const sensor_id = 1;
|
|
144
|
+
|
|
145
|
+
const handleNavigateScriptDetail = () => {
|
|
146
|
+
navigate('UnitStack', {
|
|
147
|
+
screen: 'ScriptDetail',
|
|
148
|
+
params: {
|
|
149
|
+
id: automate_id,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const handleNavigateDeviceDetail = () => {
|
|
155
|
+
navigate('UnitStack', {
|
|
156
|
+
screen: 'DeviceDetail',
|
|
157
|
+
params: {
|
|
158
|
+
unitId: unit_id,
|
|
159
|
+
sensorId: sensor_id,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
<TouchableOpacity onPress={handleNavigateScriptDetail}>
|
|
165
|
+
<Text>{'Navigate to the "ScriptDetail" screen'}</Text>
|
|
166
|
+
</TouchableOpacity>;
|
|
167
|
+
|
|
168
|
+
<TouchableOpacity onPress={handleNavigateDeviceDetail}>
|
|
169
|
+
<Text>{'Navigate to the "DeviceDetail" screen'}</Text>
|
|
170
|
+
</TouchableOpacity>;
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
4. Trigger quick action
|
|
136
174
|
|
|
137
175
|
```javascript
|
|
138
176
|
import React from 'react';
|
package/package.json
CHANGED
|
@@ -123,7 +123,7 @@ const HorizontalBarChart = memo(({ datas, config }) => {
|
|
|
123
123
|
y: item.y,
|
|
124
124
|
};
|
|
125
125
|
});
|
|
126
|
-
const dataX = (datas[0]
|
|
126
|
+
const dataX = (datas[0]?.data || []).map((item) => item.x);
|
|
127
127
|
const maxY = getMaxValueIndex(dataY);
|
|
128
128
|
if (!isEmpty(maxY.max)) {
|
|
129
129
|
dataY.splice(maxY._index, 1, { ...maxY.max, color: Colors.Primary });
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import React, { memo, useCallback, useState, useMemo, useEffect } from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
5
|
+
|
|
6
|
+
import { Colors } from '../../configs';
|
|
7
|
+
import Text from '../Text';
|
|
8
|
+
import Button from '../Button';
|
|
9
|
+
import CurrencyInput from '../Form/CurrencyInput';
|
|
10
|
+
import DateTimeRangeChange from '../DateTimeRangeChange';
|
|
11
|
+
import HorizontalBarChart from './HorizontalBarChart';
|
|
12
|
+
import ChartAggregationOption from '../ChartAggregationOption';
|
|
13
|
+
import { formatMoney } from '../../utils/Utils';
|
|
14
|
+
import AccessibilityLabel from '../../configs/AccessibilityLabel';
|
|
15
|
+
|
|
16
|
+
const PowerConsumptionChart = memo(
|
|
17
|
+
({
|
|
18
|
+
datas,
|
|
19
|
+
chartConfig,
|
|
20
|
+
setChartConfig,
|
|
21
|
+
style,
|
|
22
|
+
groupBy,
|
|
23
|
+
setGroupBy,
|
|
24
|
+
onChangeDate,
|
|
25
|
+
}) => {
|
|
26
|
+
const t = useTranslations();
|
|
27
|
+
const [price, setPrice] = useState(null);
|
|
28
|
+
|
|
29
|
+
const onCalculateCost = useCallback(() => {
|
|
30
|
+
setChartConfig((config) => ({
|
|
31
|
+
...config,
|
|
32
|
+
price,
|
|
33
|
+
}));
|
|
34
|
+
}, [setChartConfig, price]);
|
|
35
|
+
|
|
36
|
+
const totalPrice = useMemo(() => {
|
|
37
|
+
const { price: chartPrice } = chartConfig;
|
|
38
|
+
if (chartPrice === '' || isNaN(chartPrice)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const sum = datas[0].data.reduce((a, b) => a + b.y, 0);
|
|
42
|
+
const roundedSum = sum * chartPrice;
|
|
43
|
+
return roundedSum.toFixed();
|
|
44
|
+
}, [datas, chartConfig]);
|
|
45
|
+
|
|
46
|
+
const renderChart = useMemo(() => {
|
|
47
|
+
return <HorizontalBarChart datas={datas} config={chartConfig} />;
|
|
48
|
+
}, [chartConfig, datas]);
|
|
49
|
+
|
|
50
|
+
const [value, setValue] = useState([
|
|
51
|
+
moment().subtract(6, 'days'),
|
|
52
|
+
moment(),
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
onChangeDate(value[0], value[1]);
|
|
57
|
+
}, [onChangeDate, value]);
|
|
58
|
+
|
|
59
|
+
const selectStart = (date) => {
|
|
60
|
+
setValue((state) => [date, state[1]]);
|
|
61
|
+
};
|
|
62
|
+
const selectEnd = (date) => {
|
|
63
|
+
setValue((state) => [state[0], date]);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<View style={style}>
|
|
68
|
+
<View style={styles.historyView}>
|
|
69
|
+
<View style={styles.titleHistory}>
|
|
70
|
+
<Text size={20} semibold color={Colors.Gray9}>
|
|
71
|
+
{t('history')}
|
|
72
|
+
</Text>
|
|
73
|
+
|
|
74
|
+
<ChartAggregationOption groupBy={groupBy} setGroupBy={setGroupBy} />
|
|
75
|
+
</View>
|
|
76
|
+
{groupBy === 'date' && (
|
|
77
|
+
<DateTimeRangeChange
|
|
78
|
+
startTime={value[0]}
|
|
79
|
+
endTime={value[1]}
|
|
80
|
+
selectStart={selectStart}
|
|
81
|
+
selectEnd={selectEnd}
|
|
82
|
+
/>
|
|
83
|
+
)}
|
|
84
|
+
</View>
|
|
85
|
+
|
|
86
|
+
<View style={styles.wrapCalculateCost}>
|
|
87
|
+
<Text type="H4">
|
|
88
|
+
{t('input_price_to_calculate_electricity_cost')}
|
|
89
|
+
</Text>
|
|
90
|
+
<View style={styles.row}>
|
|
91
|
+
<CurrencyInput
|
|
92
|
+
value={price}
|
|
93
|
+
onChange={setPrice}
|
|
94
|
+
minValue={0}
|
|
95
|
+
maxValue={100000000}
|
|
96
|
+
placeholder={'0'}
|
|
97
|
+
onSubmitEditing={onCalculateCost}
|
|
98
|
+
/>
|
|
99
|
+
<Button
|
|
100
|
+
type="primary"
|
|
101
|
+
title={t('calculate_cost')}
|
|
102
|
+
onPress={onCalculateCost}
|
|
103
|
+
style={styles.buttonCalculate}
|
|
104
|
+
textSemiBold={false}
|
|
105
|
+
accessibilityLabel={AccessibilityLabel.BUTTON_CALCULATE_COST}
|
|
106
|
+
/>
|
|
107
|
+
</View>
|
|
108
|
+
</View>
|
|
109
|
+
|
|
110
|
+
{renderChart}
|
|
111
|
+
{!!chartConfig.price && (
|
|
112
|
+
<Text type="H4">
|
|
113
|
+
{t('total_power_price')}{' '}
|
|
114
|
+
<Text bold accessibilityLabel={AccessibilityLabel.TOTAL_PRICE}>
|
|
115
|
+
{formatMoney(totalPrice)}
|
|
116
|
+
</Text>
|
|
117
|
+
</Text>
|
|
118
|
+
)}
|
|
119
|
+
</View>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
export default PowerConsumptionChart;
|
|
125
|
+
|
|
126
|
+
const styles = StyleSheet.create({
|
|
127
|
+
historyView: {
|
|
128
|
+
paddingTop: 16,
|
|
129
|
+
},
|
|
130
|
+
titleHistory: {
|
|
131
|
+
flexDirection: 'row',
|
|
132
|
+
alignItems: 'center',
|
|
133
|
+
justifyContent: 'space-between',
|
|
134
|
+
},
|
|
135
|
+
chartInfo: {
|
|
136
|
+
flexDirection: 'row',
|
|
137
|
+
justifyContent: 'center',
|
|
138
|
+
alignItems: 'center',
|
|
139
|
+
},
|
|
140
|
+
chartContainer: {
|
|
141
|
+
marginLeft: -8,
|
|
142
|
+
},
|
|
143
|
+
chart: {
|
|
144
|
+
height: 300,
|
|
145
|
+
},
|
|
146
|
+
wrapCalculateCost: {
|
|
147
|
+
marginTop: 12,
|
|
148
|
+
},
|
|
149
|
+
row: {
|
|
150
|
+
flexDirection: 'row',
|
|
151
|
+
alignItems: 'center',
|
|
152
|
+
marginTop: 8,
|
|
153
|
+
},
|
|
154
|
+
buttonCalculate: {
|
|
155
|
+
width: null,
|
|
156
|
+
flex: null,
|
|
157
|
+
paddingHorizontal: 12,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
@@ -18,8 +18,7 @@ describe('Test ProgressBar', () => {
|
|
|
18
18
|
it('render ProgressBar', async () => {
|
|
19
19
|
const item = {
|
|
20
20
|
label: 'Value bar',
|
|
21
|
-
configuration: { max_value: 100 },
|
|
22
|
-
value: 8,
|
|
21
|
+
configuration: { min_value: 0, max_value: 100 },
|
|
23
22
|
};
|
|
24
23
|
const data = [{ value: 10, unit: 'oC' }];
|
|
25
24
|
await act(async () => {
|
|
@@ -28,6 +27,6 @@ describe('Test ProgressBar', () => {
|
|
|
28
27
|
const instance = tree.root;
|
|
29
28
|
const texts = instance.findAllByType(Text);
|
|
30
29
|
expect(texts[0].props.children).toBe('Value bar');
|
|
31
|
-
expect(texts[1].props.children).toEqual('
|
|
30
|
+
expect(texts[1].props.children).toEqual('0 oC');
|
|
32
31
|
});
|
|
33
32
|
});
|
|
@@ -3,53 +3,51 @@ import { View } from 'react-native';
|
|
|
3
3
|
import * as Progress from 'react-native-progress';
|
|
4
4
|
|
|
5
5
|
import { Colors } from '../../../configs';
|
|
6
|
-
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
7
6
|
import Text from '../../Text';
|
|
8
7
|
import styles from './styles';
|
|
9
8
|
|
|
10
9
|
const ProgressBar = memo(({ data = [], item, isWidgetOrder }) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let { value = 0, measure, unit } = data.length ? data[0] : {};
|
|
21
|
-
const isNotValue = ['', null, undefined, NaN].includes(value);
|
|
22
|
-
|
|
23
|
-
if (isNotValue) {
|
|
24
|
-
value = minValue;
|
|
25
|
-
}
|
|
10
|
+
const {
|
|
11
|
+
configuration: { max_value, min_value },
|
|
12
|
+
label,
|
|
13
|
+
} = item;
|
|
14
|
+
const { value = 0, unit } = data.length ? data[0] : {};
|
|
15
|
+
const isNotValue = useMemo(
|
|
16
|
+
() => ['', null, undefined, NaN].includes(value),
|
|
17
|
+
[value]
|
|
18
|
+
);
|
|
26
19
|
|
|
27
|
-
const
|
|
28
|
-
const
|
|
20
|
+
const displayedValue = isNotValue ? min_value : value;
|
|
21
|
+
const distance = max_value - min_value;
|
|
22
|
+
const percent = (displayedValue - min_value) / distance;
|
|
29
23
|
|
|
30
24
|
return (
|
|
31
|
-
|
|
32
|
-
<Text
|
|
33
|
-
{
|
|
25
|
+
<>
|
|
26
|
+
<Text type="H3" semibold color={Colors.Gray9} style={styles.textLabel}>
|
|
27
|
+
{label}
|
|
34
28
|
</Text>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
<View style={isWidgetOrder ? styles.wrapOrderItem : styles.container}>
|
|
30
|
+
<View style={styles.boxProgress}>
|
|
31
|
+
<View style={styles.boxMaxMinValue}>
|
|
32
|
+
<Text style={styles.textMaxMinValue}>{`${min_value} ${unit}`}</Text>
|
|
33
|
+
<Text style={styles.textMaxMinValue}>{`${max_value} ${unit}`}</Text>
|
|
34
|
+
</View>
|
|
35
|
+
<Progress.Bar
|
|
36
|
+
style={styles.progressBar}
|
|
37
|
+
width={null}
|
|
38
|
+
height={40}
|
|
39
|
+
progress={percent}
|
|
40
|
+
unfilledColor={Colors.Blue15}
|
|
41
|
+
/>
|
|
42
|
+
</View>
|
|
43
|
+
<View>
|
|
44
|
+
<Text
|
|
45
|
+
bold
|
|
46
|
+
style={styles.textValue}
|
|
47
|
+
>{`${displayedValue} ${unit}`}</Text>
|
|
48
|
+
</View>
|
|
51
49
|
</View>
|
|
52
|
-
|
|
50
|
+
</>
|
|
53
51
|
);
|
|
54
52
|
});
|
|
55
53
|
|
|
@@ -4,44 +4,38 @@ import { Colors } from '../../../configs';
|
|
|
4
4
|
|
|
5
5
|
export default StyleSheet.create({
|
|
6
6
|
container: {
|
|
7
|
+
display: 'flex',
|
|
8
|
+
flexDirection: 'row',
|
|
9
|
+
},
|
|
10
|
+
boxProgress: {
|
|
7
11
|
flex: 1,
|
|
8
|
-
flexDirection: 'column',
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
marginBottom: 12,
|
|
12
|
+
flexDirection: 'column',
|
|
13
|
+
padding: 15,
|
|
14
|
+
},
|
|
15
|
+
boxMaxMinValue: {
|
|
16
|
+
flexDirection: 'row',
|
|
17
|
+
justifyContent: 'space-between',
|
|
15
18
|
},
|
|
16
19
|
wrapOrderItem: {
|
|
17
20
|
flex: 1,
|
|
18
|
-
padding:
|
|
19
|
-
flexDirection: '
|
|
21
|
+
padding: 15,
|
|
22
|
+
flexDirection: 'row',
|
|
20
23
|
},
|
|
21
24
|
textLabel: {
|
|
22
|
-
marginLeft:
|
|
25
|
+
marginLeft: 15,
|
|
23
26
|
paddingTop: 8,
|
|
24
27
|
},
|
|
25
|
-
|
|
26
|
-
marginTop: 20,
|
|
28
|
+
textMaxMinValue: {
|
|
27
29
|
marginBottom: 2,
|
|
28
30
|
textAlign: 'left',
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
},
|
|
32
|
+
textValue: {
|
|
33
|
+
paddingTop: 48,
|
|
34
|
+
marginRight: 8,
|
|
31
35
|
},
|
|
32
36
|
progressBar: {
|
|
33
|
-
flex: 1,
|
|
34
37
|
color: Colors.Blue16,
|
|
35
38
|
borderWidth: 0,
|
|
36
39
|
borderRadius: 10,
|
|
37
40
|
},
|
|
38
|
-
wrapProgressBar: {
|
|
39
|
-
flex: 1,
|
|
40
|
-
flexDirection: 'row',
|
|
41
|
-
justifyContent: 'flex-start',
|
|
42
|
-
alignItems: 'center',
|
|
43
|
-
},
|
|
44
|
-
textValue: {
|
|
45
|
-
marginLeft: 8,
|
|
46
|
-
},
|
|
47
41
|
});
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import AndroidKeyboardAdjust from 'react-native-android-keyboard-adjust';
|
|
16
16
|
import Text from '../Text';
|
|
17
17
|
import { Colors } from '../../configs';
|
|
18
|
+
import AccessibilityLabel from '../../configs/AccessibilityLabel';
|
|
18
19
|
|
|
19
20
|
const formatNumber = (input, options) => {
|
|
20
21
|
const {
|
|
@@ -151,6 +152,7 @@ const CurrencyInput = ({
|
|
|
151
152
|
onSubmitEditing={onSubmitEditing}
|
|
152
153
|
style={styles.input}
|
|
153
154
|
maxLength={10}
|
|
155
|
+
accessibilityLabel={AccessibilityLabel.INPUT_CALCULATE_COST}
|
|
154
156
|
/>
|
|
155
157
|
<Text
|
|
156
158
|
semibold
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
2
|
import moment from 'moment';
|
|
3
3
|
|
|
4
4
|
import { API } from '../../../configs';
|
|
5
|
-
import HistoryChart from '../../../commons/Device/HistoryChart';
|
|
6
5
|
import { axiosGet } from '../../../utils/Apis/axios';
|
|
7
6
|
import { getPusher } from '../../../utils/Pusher';
|
|
8
7
|
|
|
@@ -39,11 +38,12 @@ export const useFetchConfigHistory = (
|
|
|
39
38
|
});
|
|
40
39
|
|
|
41
40
|
const timezone = moment().utcOffset();
|
|
42
|
-
startDate = startDate.subtract(timezone, 'minutes');
|
|
43
|
-
endDate = endDate.subtract(timezone, 'minutes');
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const date_from = moment(startDate).subtract(timezone, 'minutes');
|
|
43
|
+
const date_to = moment(endDate).subtract(timezone, 'minutes');
|
|
44
|
+
|
|
45
|
+
params.append('date_from', date_from.format('YYYY-MM-DDTHH:mm:ss'));
|
|
46
|
+
params.append('date_to', date_to.format('YYYY-MM-DDTHH:mm:ss'));
|
|
47
47
|
|
|
48
48
|
const { success, data } = await axiosGet(endpoint, {
|
|
49
49
|
params,
|
|
@@ -122,58 +122,3 @@ export const updateConfigChart = async (
|
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
};
|
|
125
|
-
|
|
126
|
-
let timeoutId;
|
|
127
|
-
|
|
128
|
-
const ConfigHistoryChart = ({ configs }) => {
|
|
129
|
-
const [chartData, setChartData] = useState(configs);
|
|
130
|
-
const [startDate, setStartDate] = useState(
|
|
131
|
-
moment().subtract(1, 'days').valueOf()
|
|
132
|
-
);
|
|
133
|
-
const [endDate, setEndDate] = useState(moment().valueOf());
|
|
134
|
-
|
|
135
|
-
useEffect(() => {
|
|
136
|
-
const fetchData = async () => {
|
|
137
|
-
let params = new URLSearchParams();
|
|
138
|
-
let configuration = configs.filter((item) => item.id);
|
|
139
|
-
configuration.map((item) => {
|
|
140
|
-
params.append('configs', item.id);
|
|
141
|
-
});
|
|
142
|
-
params.append(
|
|
143
|
-
'date_from',
|
|
144
|
-
moment(startDate).utc().format('YYYY-MM-DD HH:mm:ss')
|
|
145
|
-
);
|
|
146
|
-
params.append(
|
|
147
|
-
'date_to',
|
|
148
|
-
moment(endDate).utc().format('YYYY-MM-DD HH:mm:ss')
|
|
149
|
-
);
|
|
150
|
-
const { success, data } = await axiosGet(
|
|
151
|
-
API.CONFIG.DISPLAY_HISTORY_V3(),
|
|
152
|
-
{
|
|
153
|
-
params,
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
updateConfigChart(success, data, configuration, setChartData);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
timeoutId = setTimeout(fetchData, 200);
|
|
160
|
-
return () => {
|
|
161
|
-
clearTimeout(timeoutId);
|
|
162
|
-
};
|
|
163
|
-
}, [startDate, endDate, configs]);
|
|
164
|
-
|
|
165
|
-
if (!chartData.length) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return (
|
|
170
|
-
<HistoryChart
|
|
171
|
-
configuration={{ type: 'line_chart', date_format: 'DD.MM' }}
|
|
172
|
-
datas={chartData}
|
|
173
|
-
setStartDate={setStartDate}
|
|
174
|
-
setEndDate={setEndDate}
|
|
175
|
-
/>
|
|
176
|
-
);
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
export default ConfigHistoryChart;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { styles } from './IFrameStyles';
|
|
4
|
+
import IconComponent from '../../IconComponent';
|
|
5
|
+
import WebView from 'react-native-webview';
|
|
6
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
7
|
+
|
|
8
|
+
const IFrame = memo(
|
|
9
|
+
({ item = {}, widgetStyle, isWidgetBox, isSetting, isEditing }) => {
|
|
10
|
+
const ref = useRef();
|
|
11
|
+
const [urlWithEnv, setUrlWithEnv] = useState();
|
|
12
|
+
|
|
13
|
+
const { configuration } = item;
|
|
14
|
+
const { url } = configuration || {};
|
|
15
|
+
|
|
16
|
+
const reload = useCallback(() => {
|
|
17
|
+
ref.current.reload();
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!url) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!url.includes('?')) {
|
|
25
|
+
setUrlWithEnv(
|
|
26
|
+
`${url}?eraOrigin=${window.location.origin}&eraWidget=${item?.id}`
|
|
27
|
+
);
|
|
28
|
+
} else {
|
|
29
|
+
setUrlWithEnv(
|
|
30
|
+
`${url}&eraOrigin=${window.location.origin}&eraWidget=${item?.id}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}, [item?.id, url]);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<View>
|
|
37
|
+
<TouchableOpacity
|
|
38
|
+
style={isEditing ? styles.reloadButtonEditing : styles.reloadButton}
|
|
39
|
+
onClick={reload}
|
|
40
|
+
>
|
|
41
|
+
<IconComponent icon="ReloadOutlined" />
|
|
42
|
+
</TouchableOpacity>
|
|
43
|
+
<WebView
|
|
44
|
+
source={{ uri: urlWithEnv }}
|
|
45
|
+
style={styles.iframe}
|
|
46
|
+
ref={ref}
|
|
47
|
+
title={item?.title}
|
|
48
|
+
/>
|
|
49
|
+
</View>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export default IFrame;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors } from '../../../configs';
|
|
3
|
+
|
|
4
|
+
export const styles = StyleSheet.create({
|
|
5
|
+
iframe: {
|
|
6
|
+
display: 'flex',
|
|
7
|
+
width: '100%',
|
|
8
|
+
height: '100%',
|
|
9
|
+
paddingHorizontal: 16,
|
|
10
|
+
},
|
|
11
|
+
reloadButton: {
|
|
12
|
+
position: 'absolute',
|
|
13
|
+
right: 16,
|
|
14
|
+
top: 5,
|
|
15
|
+
border: '1px solid #E6E6E6',
|
|
16
|
+
backgroundColor: Colors.White,
|
|
17
|
+
},
|
|
18
|
+
reloadButtonEditing: {
|
|
19
|
+
position: 'absolute',
|
|
20
|
+
right: 77,
|
|
21
|
+
top: 0,
|
|
22
|
+
width: 36,
|
|
23
|
+
marginLeft: 2,
|
|
24
|
+
paddingTop: 5,
|
|
25
|
+
paddingBottom: 5,
|
|
26
|
+
justifyContent: 'center',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
borderRadius: 4,
|
|
29
|
+
backgroundColor: Colors.White,
|
|
30
|
+
border: '1px solid #E6E6E6',
|
|
31
|
+
},
|
|
32
|
+
settingWidget: {
|
|
33
|
+
width: 256,
|
|
34
|
+
},
|
|
35
|
+
});
|