@eohjsc/react-native-smart-city 0.7.4 → 0.7.7

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.7.4",
4
+ "version": "0.7.7",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -1,5 +1,5 @@
1
- import React, { useCallback, useMemo, useRef } from 'react';
2
- import { View, TouchableOpacity, Platform } from 'react-native';
1
+ import React, { useMemo } from 'react';
2
+ import { View, TouchableOpacity } from 'react-native';
3
3
  import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
4
4
  import Text from '../Text';
5
5
  import { Colors } from '../../configs';
@@ -8,28 +8,19 @@ import { AccessibilityLabel, AUTOMATES } from '../../configs/Constants';
8
8
  import { useTranslations } from '../../hooks/Common/useTranslations';
9
9
  import { generateAutomationConditionText } from '../../screens/Automate/ScriptDetail/utils';
10
10
  import { useGetEvaluateValue } from '../../screens/Device/hooks/useEvaluateValue';
11
- import MenuActionMore from '../MenuActionMore';
12
- import { usePopover } from '../../hooks/Common';
13
- import Routes from '../../utils/Route';
14
- import { useNavigation } from '@react-navigation/native';
15
- import { PopoverMode } from 'react-native-popover-view';
16
11
 
17
12
  const ItemConditionScriptDetail = ({
18
13
  automate,
19
- onPress,
20
14
  enableScript = true,
15
+ handleShowMenuAction1,
16
+ refMenuAction1,
21
17
  }) => {
22
18
  const t = useTranslations();
23
- const refMenuAction = useRef();
24
- const { navigate } = useNavigation();
25
- const { type, config, unit, value_change } = automate;
26
- const { end_device_id, unit_id } = value_change || {};
19
+ const { type, config, unit } = automate;
27
20
  /* istanbul ignore next */
28
21
  const item = AUTOMATES[type] || {};
29
22
  const { icon: Icon, title } = item;
30
23
  const valueEvaluations = useGetEvaluateValue(config, unit);
31
- const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
32
- usePopover();
33
24
 
34
25
  const textCondition = useMemo(
35
26
  () => generateAutomationConditionText(automate, valueEvaluations, t),
@@ -43,25 +34,6 @@ const ItemConditionScriptDetail = ({
43
34
  return t('quick_button_create_at_dashboard');
44
35
  }, [textCondition, t]);
45
36
 
46
- const handleShowMenuAction = useCallback(() => {
47
- showPopoverWithRef(refMenuAction);
48
- }, [showPopoverWithRef]);
49
-
50
- const listMenuItem = useMemo(() => {
51
- const items = [{ text: t('edit_condition'), doAction: onPress }];
52
- if (value_change) {
53
- items.unshift({
54
- text: t('device_display'),
55
- doAction: () =>
56
- navigate(Routes.DeviceDetail, {
57
- unitId: unit_id,
58
- sensorId: end_device_id,
59
- }),
60
- });
61
- }
62
- return items;
63
- }, [value_change, t, onPress, navigate, unit_id, end_device_id]);
64
-
65
37
  return (
66
38
  <View style={styles.wrap}>
67
39
  <View style={styles.col}>
@@ -81,27 +53,13 @@ const ItemConditionScriptDetail = ({
81
53
  </View>
82
54
  <View>
83
55
  <TouchableOpacity
84
- onPress={handleShowMenuAction}
85
- ref={refMenuAction}
56
+ onPress={handleShowMenuAction1}
57
+ ref={refMenuAction1}
86
58
  accessibilityLabel={AccessibilityLabel.ICON_MENU_POPUP}
87
59
  >
88
60
  <MaterialIcons name="more-vert" size={27} color={Colors.Black} />
89
61
  </TouchableOpacity>
90
62
  </View>
91
- <MenuActionMore
92
- isVisible={showingPopover}
93
- hideMore={hidePopover}
94
- listMenuItem={listMenuItem}
95
- childRef={childRef}
96
- onItemClick={(object) => object.doAction()}
97
- isTextCenter={false}
98
- wrapStyle={styles.wrapStyle}
99
- mode={
100
- /* istanbul ignore next */
101
- Platform.OS === 'ios' ? PopoverMode.JS_MODAL : PopoverMode.RN_MODAL
102
- }
103
- accessibilityLabel={AccessibilityLabel.MENU_ACTION_LIST_TOUCHABLE}
104
- />
105
63
  </View>
106
64
  );
107
65
  };
@@ -699,6 +699,7 @@ export default {
699
699
  'GATEWAY_INFO_BUTTON_GOTO_CONNECTION_METHODS',
700
700
  GATEWAY_INFO_BUTTON_DELETE_GATEWAY: 'GATEWAY_INFO_BUTTON_DELETE_GATEWAY',
701
701
  MENU_POPPER_MORE: 'MENU_POPPER_MORE',
702
+ MENU_POPPER_MORE_2: 'MENU_POPPER_MORE_2',
702
703
  GATEWAY_CONNECTION_METHODS_TEXT: 'GATEWAY_CONNECTION_METHODS_TEXT',
703
704
  //Notification
704
705
  CUSTOM_TEXT: 'CUSTOM_TEXT',
@@ -178,11 +178,25 @@ describe('Test ScriptDetail', () => {
178
178
  tree = await create(wrapComponent(route));
179
179
  });
180
180
  const instance = tree.root;
181
- const itemAutomate = instance.findByType(ItemConditionScriptDetail);
181
+ const button = instance.find(
182
+ (el) =>
183
+ el.props.accessibilityLabel === AccessibilityLabel.ICON_MENU_POPUP &&
184
+ el.type === TouchableOpacity
185
+ );
186
+ await act(async () => {
187
+ await button.props.onPress();
188
+ });
189
+
190
+ const menuActionMore = instance.find(
191
+ (el) =>
192
+ el.props.accessibilityLabel === AccessibilityLabel.MENU_POPPER_MORE_2
193
+ );
182
194
 
183
195
  await act(async () => {
184
- await itemAutomate.props.onPress();
196
+ menuActionMore.props.onItemClick({ doAction: jest.fn() });
197
+ menuActionMore.props.listMenuItem[1].doAction();
185
198
  });
199
+
186
200
  expect(spyToastError).toBeCalledWith(
187
201
  getTranslate('en', 'only_owner_has_permission_to_edit_this_script')
188
202
  );
@@ -516,8 +530,7 @@ describe('Test ScriptDetail', () => {
516
530
  });
517
531
  const menuActionMore = instance.find(
518
532
  (el) =>
519
- el.props.accessibilityLabel ===
520
- AccessibilityLabel.MENU_ACTION_LIST_TOUCHABLE
533
+ el.props.accessibilityLabel === AccessibilityLabel.MENU_POPPER_MORE_2
521
534
  );
522
535
  await act(async () => {
523
536
  menuActionMore.props.onItemClick({ doAction: jest.fn() });
@@ -43,6 +43,12 @@ const ScriptDetail = ({ route }) => {
43
43
  const refMenuAction = useRef();
44
44
  const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
45
45
  usePopover();
46
+ const {
47
+ childRef: childRef1,
48
+ showingPopover: showingPopover1,
49
+ showPopoverWithRef: showPopoverWithRef1,
50
+ hidePopover: hidePopover1,
51
+ } = usePopover();
46
52
  const t = useTranslations();
47
53
  const {
48
54
  saveAt,
@@ -57,9 +63,19 @@ const ScriptDetail = ({ route }) => {
57
63
  const [isShowDelete, setIsShowDelete] = useState(false);
58
64
  const [isShowAddAction, setIsShowAddAction] = useState(false);
59
65
 
60
- const { script, type, name, unit, can_edit, id: automateId } = automate;
66
+ const {
67
+ script,
68
+ type,
69
+ name,
70
+ unit,
71
+ can_edit,
72
+ id: automateId,
73
+ value_change,
74
+ } = automate;
75
+ const { end_device_id, unit_id } = value_change || {};
61
76
  const { enable } = script || {};
62
77
  const [enableScript, setEnableScript] = useState(enable);
78
+ const refMenuAction1 = useRef();
63
79
  const onShowActivityLog = useCallback(() => {
64
80
  navigate(Routes.ActivityLog, {
65
81
  id: automateId,
@@ -75,6 +91,23 @@ const ScriptDetail = ({ route }) => {
75
91
  });
76
92
  }, [navigate, automateId, type, unit]);
77
93
 
94
+ const handleUpdateAutomate = useCallback(async () => {
95
+ if (!can_edit) {
96
+ ToastBottomHelper.error(
97
+ t('only_owner_has_permission_to_edit_this_script')
98
+ );
99
+ return;
100
+ }
101
+ if (!enableScript) {
102
+ ToastBottomHelper.error(t('this_script_has_been_disabled'));
103
+ return;
104
+ }
105
+ navigate(Routes.AddUnknownTypeSmart, {
106
+ automate,
107
+ closeScreen: route.name,
108
+ });
109
+ }, [automate, can_edit, enableScript, navigate, route.name, t]);
110
+
78
111
  const listMenuItem = useMemo(
79
112
  () => [
80
113
  { text: t('rename'), doAction: () => setIsShowRename(true) },
@@ -90,6 +123,23 @@ const ScriptDetail = ({ route }) => {
90
123
  [t, onShowActivityLog]
91
124
  );
92
125
 
126
+ const listMenuItemCondition = useMemo(() => {
127
+ const items = [
128
+ { text: t('edit_condition'), doAction: () => handleUpdateAutomate() },
129
+ ];
130
+ if (value_change) {
131
+ items.unshift({
132
+ text: t('device_display'),
133
+ doAction: () =>
134
+ navigate(Routes.DeviceDetail, {
135
+ unitId: unit_id,
136
+ sensorId: end_device_id,
137
+ }),
138
+ });
139
+ }
140
+ return items;
141
+ }, [t, handleUpdateAutomate, value_change, navigate, unit_id, end_device_id]);
142
+
93
143
  const handleShowMenuAction = useCallback(() => {
94
144
  if (!can_edit) {
95
145
  ToastBottomHelper.error(
@@ -142,23 +192,6 @@ const ScriptDetail = ({ route }) => {
142
192
  }
143
193
  }, [automateId, t]);
144
194
 
145
- const handleUpdateAutomate = useCallback(async () => {
146
- if (!can_edit) {
147
- ToastBottomHelper.error(
148
- t('only_owner_has_permission_to_edit_this_script')
149
- );
150
- return;
151
- }
152
- if (!enableScript) {
153
- ToastBottomHelper.error(t('this_script_has_been_disabled'));
154
- return;
155
- }
156
- navigate(Routes.AddUnknownTypeSmart, {
157
- automate,
158
- closeScreen: route.name,
159
- });
160
- }, [automate, can_edit, enableScript, navigate, route.name, t]);
161
-
162
195
  const handleGoBack = useCallback(async () => {
163
196
  if (closeScreen === Routes.UnitDetail) {
164
197
  navigate(closeScreen, { unitId: unit });
@@ -224,6 +257,10 @@ const ScriptDetail = ({ route }) => {
224
257
  saveAt && fetchAutomateActions();
225
258
  }, [saveAt, fetchAutomateActions]);
226
259
 
260
+ const handleShowMenuAction1 = useCallback(() => {
261
+ showPopoverWithRef1(refMenuAction1);
262
+ }, [showPopoverWithRef1, refMenuAction1]);
263
+
227
264
  return (
228
265
  <View style={styles.wrap}>
229
266
  <WrapHeaderScrollable
@@ -247,7 +284,8 @@ const ScriptDetail = ({ route }) => {
247
284
  <ItemConditionScriptDetail
248
285
  automate={automate}
249
286
  enableScript={enableScript}
250
- onPress={handleUpdateAutomate}
287
+ handleShowMenuAction1={handleShowMenuAction1}
288
+ refMenuAction1={refMenuAction1}
251
289
  />
252
290
  {type === AUTOMATE_TYPE.ONE_TAP && enableScript && (
253
291
  <TouchableOpacity
@@ -304,10 +342,25 @@ const ScriptDetail = ({ route }) => {
304
342
  isTextCenter={false}
305
343
  wrapStyle={styles.wrapStyle}
306
344
  mode={
345
+ /* istanbul ignore next */
307
346
  Platform.OS === 'ios' ? PopoverMode.JS_MODAL : PopoverMode.RN_MODAL
308
347
  }
309
348
  accessibilityLabel={AccessibilityLabel.MENU_POPPER_MORE}
310
349
  />
350
+ <MenuActionMore
351
+ isVisible={showingPopover1}
352
+ hideMore={hidePopover1}
353
+ listMenuItem={listMenuItemCondition}
354
+ childRef={childRef1}
355
+ onItemClick={onItemClick}
356
+ isTextCenter={false}
357
+ wrapStyle={styles.wrapStyle}
358
+ mode={
359
+ /* istanbul ignore next */
360
+ Platform.OS === 'ios' ? PopoverMode.JS_MODAL : PopoverMode.RN_MODAL
361
+ }
362
+ accessibilityLabel={AccessibilityLabel.MENU_POPPER_MORE_2}
363
+ />
311
364
  <AddActionScript
312
365
  automate={automate}
313
366
  numberActionAdded={data.length}