@eohjsc/react-native-smart-city 0.4.57 → 0.4.59

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eohjsc/react-native-smart-city",
3
3
  "title": "React Native Smart Home",
4
- "version": "0.4.57",
4
+ "version": "0.4.59",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -98,6 +98,10 @@ const ItemQuickAction = memo(
98
98
  on_action?.id,
99
99
  ]);
100
100
 
101
+ if (!config_id) {
102
+ return <View />;
103
+ }
104
+
101
105
  return (
102
106
  <TouchableOpacity
103
107
  accessibilityLabel={`${AccessibilityLabel.ITEM_QUICK_ACTION_PRESS}-${sensor?.id}`}
@@ -4,7 +4,7 @@ export default StyleSheet.create({
4
4
  calendar: {
5
5
  borderTopLeftRadius: 20,
6
6
  borderTopRightRadius: 20,
7
- marginBottom: 50,
7
+ marginBottom: 100,
8
8
  },
9
9
  arrowRight: {
10
10
  transform: [{ rotate: '180deg' }],
@@ -6,7 +6,7 @@ export default StyleSheet.create({
6
6
  justifyContent: 'center',
7
7
  alignItems: 'center',
8
8
  height: 180,
9
- marginBottom: 50,
9
+ marginBottom: 100,
10
10
  },
11
11
  picker: {
12
12
  width: 120,
@@ -10,12 +10,7 @@ import { AUTOMATE_TYPE } from '../../../configs/Constants';
10
10
 
11
11
  const SelectMonitorDevices = ({ route }) => {
12
12
  const t = useTranslations();
13
- const {
14
- automate = {},
15
- isCreateNewAction,
16
- closeScreen,
17
- unit,
18
- } = route?.params || {};
13
+ const { automate = {}, isCreateNewAction, closeScreen } = route?.params || {};
19
14
 
20
15
  const [stations, setStations] = useState([]);
21
16
  const [listStation, setListStation] = useState([]);
@@ -31,7 +26,7 @@ const SelectMonitorDevices = ({ route }) => {
31
26
  configs.params.type = 'event';
32
27
  }
33
28
  await fetchWithCache(
34
- API.UNIT.DEVICE_SENSOR(automate?.unit ? automate?.unit : unit.id),
29
+ API.UNIT.DEVICE_SENSOR(automate?.unit),
35
30
  configs,
36
31
  (response) => {
37
32
  const { success, data } = response;
@@ -50,7 +45,7 @@ const SelectMonitorDevices = ({ route }) => {
50
45
  }
51
46
  );
52
47
  setLoading(false);
53
- }, [automate?.type, automate?.unit, unit.id]);
48
+ }, [automate?.type, automate?.unit]);
54
49
 
55
50
  useEffect(() => {
56
51
  if (!automate?.sensor_id) {
@@ -58,13 +58,13 @@ const SetupConfigCondition = () => {
58
58
  if (item.evaluate_template === 'boolean') {
59
59
  return [
60
60
  {
61
- title: item.evaluate_configuration?.on?.text,
61
+ title: item.evaluate_configuration?.off?.text,
62
62
  condition: 'value_evaluation',
63
63
  config: item.id,
64
64
  value: 0,
65
65
  },
66
66
  {
67
- title: item.evaluate_configuration?.off?.text,
67
+ title: item.evaluate_configuration?.on?.text,
68
68
  condition: 'value_evaluation',
69
69
  config: item.id,
70
70
  value: 1,
@@ -172,8 +172,8 @@ describe('Test SetupConfigCondition', () => {
172
172
  );
173
173
  const texts = modalCustom.findAllByType(Text);
174
174
  expect(texts).toHaveLength(2);
175
- expect(texts[0].props.children).toEqual('Case On');
176
- expect(texts[1].props.children).toEqual('Case Off');
175
+ expect(texts[1].props.children).toEqual('Case On');
176
+ expect(texts[0].props.children).toEqual('Case Off');
177
177
  });
178
178
 
179
179
  const testConditionValue = async (value, message) => {
@@ -56,6 +56,7 @@ const navContextValue = {
56
56
  isFocused: () => false,
57
57
  addListener: jest.fn(() => jest.fn()),
58
58
  };
59
+
59
60
  const wrapComponent = (state, account, route) => (
60
61
  <SCProvider initState={state}>
61
62
  <NavigationContext.Provider
@@ -16,6 +16,12 @@ import Compass from '../../../commons/Device/WindDirection/Compass';
16
16
  import DeviceAlertStatus from '../../../commons/Device/DeviceAlertStatus';
17
17
  import MockAdapter from 'axios-mock-adapter';
18
18
  import api from '../../../utils/Apis/axios';
19
+ import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
20
+
21
+ jest.mock('../../../iot/states', () => ({
22
+ useConfigGlobalState: () => [{}, null],
23
+ getConfigGlobalState: () => 'en',
24
+ }));
19
25
 
20
26
  new MockAdapter(api.axiosInstance);
21
27
 
@@ -102,6 +108,7 @@ describe('Test SensorDisplayItem', () => {
102
108
  const actionGroup = instance.findAllByType(ActionGroup);
103
109
  expect(actionGroup).toHaveLength(1);
104
110
  });
111
+
105
112
  it('render camera', async () => {
106
113
  const item = {
107
114
  id: 10452,
@@ -304,4 +311,106 @@ describe('Test SensorDisplayItem', () => {
304
311
  const flatListItems = instance.findAllByType(DeviceAlertStatus);
305
312
  expect(flatListItems).toHaveLength(1);
306
313
  });
314
+
315
+ const _testCircleMini = async (item, expectProps) => {
316
+ const sensor = {
317
+ name: 'Sensor name',
318
+ is_managed_by_backend: false,
319
+ };
320
+
321
+ await act(async () => {
322
+ tree = await renderer.create(wrapComponent({ item, sensor }));
323
+ });
324
+ const instance = tree.root;
325
+
326
+ const currentRainSensor = instance.findByType(CurrentRainSensor);
327
+ expect(currentRainSensor.props).toEqual(expectProps);
328
+ };
329
+
330
+ it('render circle_mini', async () => {
331
+ const globalStates = require('../../../iot/states');
332
+ globalStates.useConfigGlobalState = () => [{ 99: { value: 1 } }, null];
333
+
334
+ const item = {
335
+ id: 10452,
336
+ order: 0,
337
+ template: 'circle_mini',
338
+ type: 'circle_mini',
339
+ configuration: {
340
+ config: {
341
+ id: 99,
342
+ title: '1',
343
+ color: 'blue',
344
+ },
345
+ },
346
+ is_configuration_ready: true,
347
+ };
348
+
349
+ await _testCircleMini(item, {
350
+ data: [
351
+ {
352
+ id: 99,
353
+ title: '1',
354
+ color: 'blue',
355
+ value: 1,
356
+ evaluate: {
357
+ color: null,
358
+ text: '--',
359
+ },
360
+ },
361
+ ],
362
+ isWidgetOrder: undefined,
363
+ });
364
+ });
365
+
366
+ it('render circle_mini without config value', async () => {
367
+ const globalStates = require('../../../iot/states');
368
+ globalStates.useConfigGlobalState = () => [{ 2: { value: 1 } }, null];
369
+
370
+ const item = {
371
+ id: 10452,
372
+ order: 0,
373
+ template: 'circle_mini',
374
+ type: 'circle_mini',
375
+ configuration: {
376
+ config: {
377
+ id: 99,
378
+ title: '1',
379
+ color: 'blue',
380
+ },
381
+ },
382
+ is_configuration_ready: true,
383
+ };
384
+
385
+ await _testCircleMini(item, {
386
+ data: [
387
+ {
388
+ id: 99,
389
+ title: '1',
390
+ color: 'blue',
391
+ value: null,
392
+ evaluate: null,
393
+ },
394
+ ],
395
+ isWidgetOrder: undefined,
396
+ });
397
+ });
398
+
399
+ it('render circle_mini without config id', async () => {
400
+ const item = {
401
+ id: 10452,
402
+ order: 0,
403
+ template: 'circle_mini',
404
+ type: 'circle_mini',
405
+ configuration: {
406
+ config: null,
407
+ },
408
+ is_configuration_ready: true,
409
+ };
410
+
411
+ await _testCircleMini(item, {
412
+ data: undefined,
413
+ isWidgetOrder: undefined,
414
+ });
415
+ });
307
416
  });
@@ -46,6 +46,13 @@ export const SensorDisplayItem = ({
46
46
 
47
47
  const evaluateValue = useEvaluateValue();
48
48
 
49
+ const checkConfigValue = (configValue) => {
50
+ if (configValue === null || configValue === undefined) {
51
+ return false;
52
+ }
53
+ return true;
54
+ };
55
+
49
56
  const getData = useCallback(() => {
50
57
  if (!item.configuration) {
51
58
  return;
@@ -83,6 +90,34 @@ export const SensorDisplayItem = ({
83
90
  value_evaluation,
84
91
  ]);
85
92
 
93
+ const getDataCircleMini = useCallback(() => {
94
+ if (!item?.configuration?.config?.id) {
95
+ return;
96
+ }
97
+
98
+ const config = item.configuration.config;
99
+ const configValue = configValues[config.id]?.value;
100
+ const configEvaluate = evaluate[config.id] || {};
101
+
102
+ const hasConfigValue = checkConfigValue(configValue);
103
+
104
+ let value = {
105
+ id: config.id,
106
+ value: hasConfigValue ? configValue : null,
107
+ evaluate: hasConfigValue
108
+ ? evaluateValue(configValue, value_evaluation) || configEvaluate
109
+ : null,
110
+ };
111
+
112
+ return [{ ...config, ...value }].filter(Boolean);
113
+ }, [
114
+ configValues,
115
+ evaluate,
116
+ evaluateValue,
117
+ item.configuration,
118
+ value_evaluation,
119
+ ]);
120
+
86
121
  const doAction = useCallback(
87
122
  async (action, data) => {
88
123
  if (processing) {
@@ -156,6 +191,13 @@ export const SensorDisplayItem = ({
156
191
  isWidgetOrder={isWidgetOrder}
157
192
  />
158
193
  );
194
+ case 'circle_mini':
195
+ return (
196
+ <CurrentRainSensor
197
+ data={getDataCircleMini(item)}
198
+ isWidgetOrder={isWidgetOrder}
199
+ />
200
+ );
159
201
  case 'value':
160
202
  switch (type || template) {
161
203
  case 'circle':