@integry/sdk 4.7.28 → 4.7.29

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@integry/sdk",
3
- "version": "4.7.28",
3
+ "version": "4.7.29",
4
4
  "description": "Integry SDK",
5
5
  "main": "dist/umd/index.umd.js",
6
6
  "module": "dist/esm/index.csm.js",
@@ -115,11 +115,67 @@ const ObjectField = (props: ObjectFieldProps) => {
115
115
  tagsTree = null,
116
116
  showMenuOnLeft = false, // Default to false
117
117
  } = props;
118
+
119
+ // Calculate initial state based on field properties
120
+ const calculateInitialObjectHasFields = (f: any) => {
121
+ // Special case for the Blocks field or similar fields
122
+ if (
123
+ field.type === 'TEXTAREA' &&
124
+ (field.data_type === 'OBJECT[]' || field.data_type === 'OBJECT') &&
125
+ (!field.template_fields || field.template_fields.length === 0)
126
+ ) {
127
+ return false;
128
+ }
129
+
130
+ // For other cases, use the original logic
131
+ if (Array.isArray(field.template_fields)) {
132
+ if (field.template_fields.length > 0) {
133
+ return true;
134
+ }
135
+ if (field.type === 'TEXTAREA' || field.type === 'DYNAMIC') {
136
+ return false;
137
+ }
138
+ } else if (field.properties && Object.keys(field.properties).length === 0) {
139
+ return false;
140
+ }
141
+
142
+ return true;
143
+ };
144
+
145
+ const calculateInitialShowAddMoreOption = (f: any) => {
146
+ // Special case for the Blocks field or similar fields
147
+ if (
148
+ field.type === 'TEXTAREA' &&
149
+ (field.data_type === 'OBJECT[]' || field.data_type === 'OBJECT') &&
150
+ (!field.template_fields || field.template_fields.length === 0)
151
+ ) {
152
+ return false;
153
+ }
154
+
155
+ // For other cases, use the original logic
156
+ if (Array.isArray(field.template_fields)) {
157
+ if (field.template_fields.length > 0) {
158
+ return true;
159
+ }
160
+ if (field.type === 'TEXTAREA' || field.type === 'DYNAMIC') {
161
+ return false;
162
+ }
163
+ } else if (field.properties && Object.keys(field.properties).length === 0) {
164
+ return false;
165
+ }
166
+
167
+ return true;
168
+ };
169
+
118
170
  const [objectArray, setObjectArray] = useState<FieldObject[]>(
119
171
  Array.isArray(objectValue) ? objectValue : [{}],
120
172
  ); // Start with one empty object in the array
121
- const [showAddMoreOption, setShowAddMoreOption] = useState(true);
122
- const [objectHasFields, setObjectHasFields] = useState(true);
173
+ const [showAddMoreOption, setShowAddMoreOption] = useState(() =>
174
+ calculateInitialShowAddMoreOption(field),
175
+ );
176
+ const [objectHasFields, setObjectHasFields] = useState(() =>
177
+ calculateInitialObjectHasFields(field),
178
+ );
123
179
 
124
180
  let templateFields = [];
125
181