@applicaster/zapp-react-native-ui-components 14.0.6 → 14.0.7-alpha.9446527193

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.
@@ -4,7 +4,7 @@ import { toNumberWithDefaultZero } from "@applicaster/zapp-react-native-utils/nu
4
4
  import { Button } from "./Button";
5
5
  import {
6
6
  getButtonsCount,
7
- getPluginIdentifier,
7
+ memoizedGetPluginIdentifier,
8
8
  mapSelfAlignment,
9
9
  } from "./utils";
10
10
 
@@ -80,7 +80,11 @@ export const TvActionButtons = ({
80
80
  prefix: independentStyles ? prefixSpecificButton : buttonId(1),
81
81
  value,
82
82
  platformValue,
83
- pluginIdentifier: getPluginIdentifier(configuration, PREFIX, index),
83
+ pluginIdentifier: memoizedGetPluginIdentifier(
84
+ configuration,
85
+ PREFIX,
86
+ index
87
+ ),
84
88
  suffixId: prefixSpecificButton,
85
89
  preferredFocus: index === 0,
86
90
  });
@@ -3,7 +3,7 @@ import { getPluginIdentifier } from "..";
3
3
  describe("getPluginIdentifier", () => {
4
4
  const prefix = "tv_buttons";
5
5
 
6
- it("get first plugin identifier", () => {
6
+ it("returns the first valid plugin identifier", () => {
7
7
  const configuration = {
8
8
  tv_buttons_button_1_other: "value",
9
9
  tv_buttons_button_1_assign_action:
@@ -13,13 +13,12 @@ describe("getPluginIdentifier", () => {
13
13
  };
14
14
 
15
15
  const index = 0;
16
-
17
16
  const result = getPluginIdentifier(configuration, prefix, index);
18
17
 
19
18
  expect(result).toEqual(configuration.tv_buttons_button_1_assign_action);
20
19
  });
21
20
 
22
- it("get second plugin identifier", () => {
21
+ it("returns the second valid plugin identifier", () => {
23
22
  const configuration = {
24
23
  tv_buttons_button_1_other: "value_1",
25
24
  tv_buttons_button_1_assign_action:
@@ -30,24 +29,124 @@ describe("getPluginIdentifier", () => {
30
29
  };
31
30
 
32
31
  const index = 1;
33
-
34
32
  const result = getPluginIdentifier(configuration, prefix, index);
35
33
 
36
34
  expect(result).toEqual(configuration.tv_buttons_button_2_assign_action);
37
35
  });
38
36
 
39
- it("get undefined if no assign_actions at all", () => {
37
+ it("returns undefined when there are no assign_action keys", () => {
40
38
  const configuration = {};
39
+ const index = 0;
40
+
41
+ const result = getPluginIdentifier(configuration, prefix, index);
42
+
43
+ expect(result).toBeUndefined();
44
+ });
45
+
46
+ it("skips undefined values and returns the correct plugin identifier", () => {
47
+ const configuration = {
48
+ tv_buttons_button_1_assign_action: "tv_buttons_button_1_assign_action",
49
+ tv_buttons_button_2_assign_action: undefined,
50
+ tv_buttons_button_3_assign_action: "tv_buttons_button_3_assign_action",
51
+ };
52
+
53
+ const index = 1;
54
+ const result = getPluginIdentifier(configuration, prefix, index);
55
+
56
+ expect(result).toEqual(configuration.tv_buttons_button_3_assign_action);
57
+ });
58
+
59
+ it("handles missing intermediate keys and returns the correct plugin identifier", () => {
60
+ const configuration = {
61
+ tv_buttons_button_1_assign_action: "tv_buttons_button_1_assign_action",
62
+ tv_buttons_button_3_assign_action: "tv_buttons_button_3_assign_action",
63
+ };
64
+
65
+ const index = 1;
66
+ const result = getPluginIdentifier(configuration, prefix, index);
67
+
68
+ expect(result).toEqual(configuration.tv_buttons_button_3_assign_action);
69
+ });
70
+
71
+ it("skips empty string values and returns the first non-empty assign_action", () => {
72
+ const configuration = {
73
+ tv_buttons_button_1_assign_action: "",
74
+ tv_buttons_button_2_assign_action: "tv_buttons_button_2_assign_action",
75
+ };
41
76
 
42
77
  const index = 0;
78
+ const result = getPluginIdentifier(configuration, prefix, index);
79
+
80
+ expect(result).toEqual(configuration.tv_buttons_button_2_assign_action);
81
+ });
82
+
83
+ it("returns undefined for negative index", () => {
84
+ const configuration = {
85
+ tv_buttons_button_1_assign_action: "a",
86
+ tv_buttons_button_2_assign_action: "b",
87
+ };
43
88
 
89
+ const index = -1;
44
90
  const result = getPluginIdentifier(configuration, prefix, index);
45
91
 
46
92
  expect(result).toBeUndefined();
47
93
  });
94
+
95
+ it("returns undefined for out-of-bounds index", () => {
96
+ const configuration = {
97
+ tv_buttons_button_1_assign_action: "a",
98
+ tv_buttons_button_2_assign_action: "b",
99
+ };
100
+
101
+ const index = 5;
102
+ const result = getPluginIdentifier(configuration, prefix, index);
103
+
104
+ expect(result).toBeUndefined();
105
+ });
106
+
107
+ it("ignores keys with wrong prefix or format", () => {
108
+ const configuration = {
109
+ tv_buttons_button_1_assign_action: "a",
110
+ tv_buttons_wrongprefix_2_assign_action: "b",
111
+ tv_buttons_button_x_assign_action: "c",
112
+ };
113
+
114
+ const index = 1;
115
+ const result = getPluginIdentifier(configuration, prefix, index);
116
+
117
+ expect(result).toBeUndefined();
118
+ });
119
+
120
+ it("returns undefined if all assign_actions are null or empty", () => {
121
+ const configuration = {
122
+ tv_buttons_button_1_assign_action: null,
123
+ tv_buttons_button_2_assign_action: undefined,
124
+ tv_buttons_button_3_assign_action: "",
125
+ };
126
+
127
+ const index = 0;
128
+ const result = getPluginIdentifier(configuration, prefix, index);
129
+
130
+ expect(result).toBeUndefined();
131
+ });
132
+
133
+ it("handles non-string values correctly", () => {
134
+ const configuration = {
135
+ tv_buttons_button_1_assign_action: 123,
136
+ tv_buttons_button_2_assign_action: true,
137
+ tv_buttons_button_3_assign_action: { nested: "value" },
138
+ };
139
+
140
+ expect(getPluginIdentifier(configuration, prefix, 0)).toEqual(123);
141
+ expect(getPluginIdentifier(configuration, prefix, 1)).toEqual(true);
142
+
143
+ expect(getPluginIdentifier(configuration, prefix, 2)).toEqual({
144
+ nested: "value",
145
+ });
146
+ });
48
147
  });
49
148
 
50
- describe("getPluginIdentifier - when configuration has same values for different keys", () => {
149
+ describe("getPluginIdentifier - when configuration has duplicate values", () => {
51
150
  const prefix = "tv_buttons";
52
151
 
53
152
  const configuration = {
@@ -55,17 +154,15 @@ describe("getPluginIdentifier - when configuration has same values for different
55
154
  tv_buttons_button_2_assign_action: "navigation_action",
56
155
  };
57
156
 
58
- it("get first plugin identifier", () => {
157
+ it("returns the first plugin identifier when values are identical", () => {
59
158
  const index = 0;
60
-
61
159
  const result = getPluginIdentifier(configuration, prefix, index);
62
160
 
63
161
  expect(result).toEqual(configuration.tv_buttons_button_1_assign_action);
64
162
  });
65
163
 
66
- it("get second plugin identifier", () => {
164
+ it("returns the second plugin identifier when values are identical", () => {
67
165
  const index = 1;
68
-
69
166
  const result = getPluginIdentifier(configuration, prefix, index);
70
167
 
71
168
  expect(result).toEqual(configuration.tv_buttons_button_2_assign_action);
@@ -1,7 +1,7 @@
1
1
  import * as R from "ramda";
2
+ import memoizee from "memoizee";
2
3
 
3
4
  import { isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
4
- import { isNotNil } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
5
5
 
6
6
  export const getButtonsCount = (
7
7
  configuration: Record<string, unknown>,
@@ -21,23 +21,29 @@ export const getPluginIdentifier = (
21
21
  configuration: Record<string, unknown>,
22
22
  prefix: string,
23
23
  index: number
24
- ): string => {
25
- const match = `${prefix}_button_\\d_assign_action`;
26
- const re = new RegExp(match);
27
-
28
- const rejectNils = R.compose(R.path([index]), R.filter(isNotNil));
29
-
30
- return rejectNils(
31
- R.toPairs(configuration)
32
- .filter(([key]) => R.startsWith(`${prefix}_button`, key))
33
- .map(([key, value]) => {
34
- const matched = key.match(re);
24
+ ): string | undefined => {
25
+ const re = new RegExp(`${prefix}_button_\\d_assign_action`);
26
+ let count = 0;
27
+
28
+ for (const [key, value] of Object.entries(configuration)) {
29
+ if (
30
+ key.startsWith(`${prefix}_button`) &&
31
+ re.test(key) &&
32
+ value != null &&
33
+ value !== ""
34
+ ) {
35
+ if (count === index) return value as string;
36
+ count++;
37
+ }
38
+ }
35
39
 
36
- return matched ? value : undefined;
37
- })
38
- );
40
+ return undefined;
39
41
  };
40
42
 
43
+ export const memoizedGetPluginIdentifier = memoizee(getPluginIdentifier, {
44
+ primitive: true,
45
+ });
46
+
41
47
  type Label = {
42
48
  name: string;
43
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "14.0.6",
3
+ "version": "14.0.7-alpha.9446527193",
4
4
  "description": "Applicaster Zapp React Native ui components for the Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "14.0.6",
32
- "@applicaster/zapp-react-native-bridge": "14.0.6",
33
- "@applicaster/zapp-react-native-redux": "14.0.6",
34
- "@applicaster/zapp-react-native-utils": "14.0.6",
31
+ "@applicaster/applicaster-types": "14.0.7-alpha.9446527193",
32
+ "@applicaster/zapp-react-native-bridge": "14.0.7-alpha.9446527193",
33
+ "@applicaster/zapp-react-native-redux": "14.0.7-alpha.9446527193",
34
+ "@applicaster/zapp-react-native-utils": "14.0.7-alpha.9446527193",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",