df-ae-forms-package 1.0.84 → 1.0.85
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/dist/index.d.ts +0 -1
- package/dist/index.esm.js +286 -256
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +286 -256
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -178,19 +178,7 @@ class ConditionalLogicService {
|
|
|
178
178
|
}
|
|
179
179
|
if (comp.name === 'table' && comp.cells) {
|
|
180
180
|
for (const row of comp.cells) {
|
|
181
|
-
|
|
182
|
-
if (Array.isArray(row)) {
|
|
183
|
-
for (const cell of row) {
|
|
184
|
-
if (cell.components) {
|
|
185
|
-
const found = this.findComponent(cell.components, componentId);
|
|
186
|
-
if (found)
|
|
187
|
-
return found;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
// Handle case where cells is a 1D array (row is actually a cell)
|
|
193
|
-
const cell = row;
|
|
181
|
+
for (const cell of row) {
|
|
194
182
|
if (cell.components) {
|
|
195
183
|
const found = this.findComponent(cell.components, componentId);
|
|
196
184
|
if (found)
|
|
@@ -234,14 +222,7 @@ class ConditionalLogicService {
|
|
|
234
222
|
traverse(item.templateComponents);
|
|
235
223
|
if (item.cells) {
|
|
236
224
|
for (const row of item.cells) {
|
|
237
|
-
|
|
238
|
-
for (const cell of row) {
|
|
239
|
-
if (cell.components)
|
|
240
|
-
traverse(cell.components);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
const cell = row;
|
|
225
|
+
for (const cell of row) {
|
|
245
226
|
if (cell.components)
|
|
246
227
|
traverse(cell.components);
|
|
247
228
|
}
|
|
@@ -5144,7 +5125,7 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
|
|
|
5144
5125
|
whiteSpace: 'nowrap',
|
|
5145
5126
|
overflow: 'hidden',
|
|
5146
5127
|
textOverflow: 'ellipsis'
|
|
5147
|
-
}, children: component.basic?.label || `Column ${index + 1}` }, `header-${component.id
|
|
5128
|
+
}, children: component.basic?.label || `Column ${index + 1}` }, `header-${component.id}`))) })), dataEntries.length > 0 ? (dataEntries.map((entry, entryIndex) => (jsxs("div", { className: "table-row", style: {
|
|
5148
5129
|
// Use flex column for column view, grid for row view
|
|
5149
5130
|
display: columnView ? 'flex' : 'grid',
|
|
5150
5131
|
flexDirection: columnView ? 'column' : 'row',
|
|
@@ -5969,47 +5950,9 @@ const DfFormSection = ({ id, properties, mode = 'edit', formData = {}, onValueCh
|
|
|
5969
5950
|
|
|
5970
5951
|
// Dynamic imports to avoid circular dependencies
|
|
5971
5952
|
const DfFormTable$1 = React.lazy(() => Promise.resolve().then(function () { return dfFormTable; }));
|
|
5972
|
-
const DfFormPreview = ({ formComponents
|
|
5953
|
+
const DfFormPreview = ({ formComponents = [], currentDevice = 'desktop', isPreviewMode = false, initialFormData = [], onSubmit, onFormDataChange, formTitle, formDescription, formTemplateId,
|
|
5973
5954
|
// Add component management props for edit mode
|
|
5974
5955
|
onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, selectedComponent, workOrderNumber, assetNumber, isStandalone, user, onCreateIssue, onUpdateIssue }) => {
|
|
5975
|
-
// Ensure all components have IDs (matching main website approach)
|
|
5976
|
-
const formComponents = useMemo(() => {
|
|
5977
|
-
const ensureIds = (components) => {
|
|
5978
|
-
return components.map(comp => {
|
|
5979
|
-
// Reuse existing ID or generate one
|
|
5980
|
-
const id = comp.id || `generated-${Math.random().toString(36).substr(2, 9)}`;
|
|
5981
|
-
const newComp = { ...comp, id };
|
|
5982
|
-
// Recursively handle nested components
|
|
5983
|
-
if (newComp.children && Array.isArray(newComp.children)) {
|
|
5984
|
-
newComp.children = ensureIds(newComp.children);
|
|
5985
|
-
}
|
|
5986
|
-
if (newComp.cells && Array.isArray(newComp.cells)) {
|
|
5987
|
-
newComp.cells = newComp.cells.map((row) => {
|
|
5988
|
-
if (Array.isArray(row)) {
|
|
5989
|
-
return row.map((cell) => ({
|
|
5990
|
-
...cell,
|
|
5991
|
-
components: cell.components ? ensureIds(cell.components) : []
|
|
5992
|
-
}));
|
|
5993
|
-
}
|
|
5994
|
-
// Handle flat 1D cell (not wrapped in row array)
|
|
5995
|
-
const cell = row;
|
|
5996
|
-
return {
|
|
5997
|
-
...cell,
|
|
5998
|
-
components: cell.components ? ensureIds(cell.components) : []
|
|
5999
|
-
};
|
|
6000
|
-
});
|
|
6001
|
-
}
|
|
6002
|
-
if (newComp.entries && Array.isArray(newComp.entries)) {
|
|
6003
|
-
newComp.entries = newComp.entries.map((entry) => ({
|
|
6004
|
-
...entry,
|
|
6005
|
-
components: entry.components ? ensureIds(entry.components) : []
|
|
6006
|
-
}));
|
|
6007
|
-
}
|
|
6008
|
-
return newComp;
|
|
6009
|
-
});
|
|
6010
|
-
};
|
|
6011
|
-
return ensureIds(rawFormComponents || []);
|
|
6012
|
-
}, [rawFormComponents]);
|
|
6013
5956
|
// Form state
|
|
6014
5957
|
const [formValues, setFormValues] = useState({});
|
|
6015
5958
|
const [validationErrors, setValidationErrors] = useState({});
|
|
@@ -6055,11 +5998,11 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6055
5998
|
}
|
|
6056
5999
|
}
|
|
6057
6000
|
}
|
|
6058
|
-
// Handle nested components in table cells
|
|
6001
|
+
// Handle nested components in table cells
|
|
6059
6002
|
if (component.cells && Array.isArray(component.cells)) {
|
|
6060
|
-
component.cells.forEach((row) => {
|
|
6003
|
+
component.cells.forEach((row, _rowIndex) => {
|
|
6061
6004
|
if (Array.isArray(row)) {
|
|
6062
|
-
row.forEach((cell) => {
|
|
6005
|
+
row.forEach((cell, _cellIndex) => {
|
|
6063
6006
|
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
6064
6007
|
initializeComponentValues(cell.components, values);
|
|
6065
6008
|
}
|
|
@@ -6110,6 +6053,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6110
6053
|
const initialValues = {};
|
|
6111
6054
|
const initialNotes = {};
|
|
6112
6055
|
const initialAttachments = {};
|
|
6056
|
+
const seenIds = new Set();
|
|
6113
6057
|
// Helper to extract notes and attachments recursively
|
|
6114
6058
|
const extractNotesAndAttachments = (components) => {
|
|
6115
6059
|
components.forEach(comp => {
|
|
@@ -6125,20 +6069,10 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6125
6069
|
if (comp.children)
|
|
6126
6070
|
extractNotesAndAttachments(comp.children);
|
|
6127
6071
|
if (comp.cells)
|
|
6128
|
-
comp.cells.forEach((row) => {
|
|
6129
|
-
if (
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
extractNotesAndAttachments(cell.components);
|
|
6133
|
-
});
|
|
6134
|
-
}
|
|
6135
|
-
else {
|
|
6136
|
-
// Handle 1D array structure (row is actually a cell)
|
|
6137
|
-
const cell = row;
|
|
6138
|
-
if (cell.components)
|
|
6139
|
-
extractNotesAndAttachments(cell.components);
|
|
6140
|
-
}
|
|
6141
|
-
});
|
|
6072
|
+
comp.cells.forEach((row) => row.forEach((cell) => {
|
|
6073
|
+
if (cell.components)
|
|
6074
|
+
extractNotesAndAttachments(cell.components);
|
|
6075
|
+
}));
|
|
6142
6076
|
if (comp.entries)
|
|
6143
6077
|
comp.entries.forEach((entry) => {
|
|
6144
6078
|
if (entry.components)
|
|
@@ -6146,16 +6080,86 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6146
6080
|
});
|
|
6147
6081
|
});
|
|
6148
6082
|
};
|
|
6149
|
-
//
|
|
6150
|
-
|
|
6083
|
+
// Validate component IDs for uniqueness without mutating original props
|
|
6084
|
+
const getValidatedComponents = (components) => {
|
|
6085
|
+
return components.map((component, index) => {
|
|
6086
|
+
let validatedComponent = { ...component };
|
|
6087
|
+
// Ensure component has an ID
|
|
6088
|
+
if (!validatedComponent.id || typeof validatedComponent.id !== 'string' || validatedComponent.id.trim() === '') {
|
|
6089
|
+
// Determine a base name for the ID
|
|
6090
|
+
const name = validatedComponent.name || 'component';
|
|
6091
|
+
const label = validatedComponent.basic?.label || '';
|
|
6092
|
+
const safeLabel = label.replace(/[^a-zA-Z0-9]/g, '').toLowerCase().substring(0, 10);
|
|
6093
|
+
// Generate a unique ID
|
|
6094
|
+
validatedComponent.id = `${name}-${safeLabel || 'gen'}-${Date.now()}-${Math.random().toString(36).substr(2, 6)}-${index}`;
|
|
6095
|
+
console.warn(`[DfFormPreview] Assigned missing ID: ${validatedComponent.id}`);
|
|
6096
|
+
}
|
|
6097
|
+
else {
|
|
6098
|
+
// Check for duplicates
|
|
6099
|
+
if (seenIds.has(validatedComponent.id)) {
|
|
6100
|
+
console.error(`[DfFormPreview] Duplicate component ID detected: ${validatedComponent.id}`);
|
|
6101
|
+
// Generate a unique ID for duplicate
|
|
6102
|
+
validatedComponent.id = `${validatedComponent.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
6103
|
+
console.warn(`[DfFormPreview] Generated new unique ID: ${validatedComponent.id}`);
|
|
6104
|
+
}
|
|
6105
|
+
}
|
|
6106
|
+
seenIds.add(validatedComponent.id);
|
|
6107
|
+
// Recursively validate nested components
|
|
6108
|
+
if (validatedComponent.children && Array.isArray(validatedComponent.children)) {
|
|
6109
|
+
validatedComponent.children = getValidatedComponents(validatedComponent.children);
|
|
6110
|
+
}
|
|
6111
|
+
if (validatedComponent.cells && Array.isArray(validatedComponent.cells)) {
|
|
6112
|
+
validatedComponent.cells = validatedComponent.cells.map((row) => {
|
|
6113
|
+
if (Array.isArray(row)) {
|
|
6114
|
+
return row.map((cell) => {
|
|
6115
|
+
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
6116
|
+
return {
|
|
6117
|
+
...cell,
|
|
6118
|
+
components: getValidatedComponents(cell.components)
|
|
6119
|
+
};
|
|
6120
|
+
}
|
|
6121
|
+
return cell;
|
|
6122
|
+
});
|
|
6123
|
+
}
|
|
6124
|
+
return row;
|
|
6125
|
+
});
|
|
6126
|
+
}
|
|
6127
|
+
if (validatedComponent.entries && Array.isArray(validatedComponent.entries)) {
|
|
6128
|
+
validatedComponent.entries = validatedComponent.entries.map((entry) => {
|
|
6129
|
+
if (entry && entry.components && Array.isArray(entry.components)) {
|
|
6130
|
+
return {
|
|
6131
|
+
...entry,
|
|
6132
|
+
components: getValidatedComponents(entry.components)
|
|
6133
|
+
};
|
|
6134
|
+
}
|
|
6135
|
+
return entry;
|
|
6136
|
+
});
|
|
6137
|
+
}
|
|
6138
|
+
return validatedComponent;
|
|
6139
|
+
});
|
|
6140
|
+
};
|
|
6141
|
+
// Initialize validated components
|
|
6142
|
+
let validatedFormComponents = formComponents;
|
|
6143
|
+
if (formComponents && formComponents.length > 0) {
|
|
6144
|
+
validatedFormComponents = getValidatedComponents(formComponents);
|
|
6145
|
+
// Notifying parent of changed components if they were mutated (IDs added/fixed)
|
|
6146
|
+
if (JSON.stringify(validatedFormComponents) !== JSON.stringify(formComponents)) {
|
|
6147
|
+
onFormDataChange?.(validatedFormComponents);
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
let validatedInitialFormData = initialFormData;
|
|
6151
6151
|
if (initialFormData && initialFormData.length > 0) {
|
|
6152
|
-
|
|
6152
|
+
validatedInitialFormData = getValidatedComponents(initialFormData);
|
|
6153
|
+
}
|
|
6154
|
+
// Initialize form values from initial data
|
|
6155
|
+
if (validatedInitialFormData && validatedInitialFormData.length > 0) {
|
|
6156
|
+
initializeComponentValues(validatedInitialFormData, initialValues);
|
|
6153
6157
|
}
|
|
6154
6158
|
// Initialize form values from form components (for submitted data or pre-filled forms)
|
|
6155
6159
|
// CRITICAL: This must run AFTER initialFormData to pick up any values embedded in the components themselves
|
|
6156
|
-
if (
|
|
6157
|
-
initializeComponentValues(
|
|
6158
|
-
extractNotesAndAttachments(
|
|
6160
|
+
if (validatedFormComponents && validatedFormComponents.length > 0) {
|
|
6161
|
+
initializeComponentValues(validatedFormComponents, initialValues);
|
|
6162
|
+
extractNotesAndAttachments(validatedFormComponents);
|
|
6159
6163
|
}
|
|
6160
6164
|
// Set the state
|
|
6161
6165
|
setFormValues(prev => {
|
|
@@ -6198,23 +6202,14 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6198
6202
|
visibility[component.basic.label] = true;
|
|
6199
6203
|
}
|
|
6200
6204
|
}
|
|
6201
|
-
// Handle nested components in table cells
|
|
6205
|
+
// Handle nested components in table cells
|
|
6202
6206
|
if (component.cells && Array.isArray(component.cells)) {
|
|
6203
6207
|
component.cells.forEach((row) => {
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
6207
|
-
evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
|
|
6208
|
-
}
|
|
6209
|
-
});
|
|
6210
|
-
}
|
|
6211
|
-
else {
|
|
6212
|
-
// Handle flat 1D cell
|
|
6213
|
-
const cell = row;
|
|
6214
|
-
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
6208
|
+
row.forEach((cell) => {
|
|
6209
|
+
if (cell.components && Array.isArray(cell.components)) {
|
|
6215
6210
|
evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
|
|
6216
6211
|
}
|
|
6217
|
-
}
|
|
6212
|
+
});
|
|
6218
6213
|
});
|
|
6219
6214
|
}
|
|
6220
6215
|
// Handle nested components in datagrid entries
|
|
@@ -6280,19 +6275,26 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6280
6275
|
// Debug: Log value changes to identify ID collisions
|
|
6281
6276
|
const existingValue = formValues[change.id];
|
|
6282
6277
|
if (existingValue !== undefined && existingValue !== change.value) ;
|
|
6278
|
+
// CRITICAL: Check if this is a table/datagrid structure update (cells, entries, etc.)
|
|
6279
|
+
// These should NOT be stored in formValues - they update the component structure only
|
|
6280
|
+
const isStructureUpdate = change.value && typeof change.value === 'object' &&
|
|
6281
|
+
('cells' in change.value || ('entries' in change.value && 'name' in change.value));
|
|
6283
6282
|
// Use the service's recursive find to find the component and update BOTH IDs in formValues
|
|
6284
6283
|
const targetComponent = conditionalLogicService.findComponent(formComponents, change.id);
|
|
6285
6284
|
const newFormValues = { ...formValues };
|
|
6286
|
-
|
|
6287
|
-
if (
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
|
|
6285
|
+
// Only update formValues for actual value changes, not structure updates
|
|
6286
|
+
if (!isStructureUpdate) {
|
|
6287
|
+
newFormValues[change.id] = change.value;
|
|
6288
|
+
if (targetComponent) {
|
|
6289
|
+
if (targetComponent.id)
|
|
6290
|
+
newFormValues[targetComponent.id] = change.value;
|
|
6291
|
+
if (targetComponent._id)
|
|
6292
|
+
newFormValues[targetComponent._id] = change.value;
|
|
6293
|
+
if (targetComponent.basic?.label)
|
|
6294
|
+
newFormValues[targetComponent.basic.label] = change.value;
|
|
6295
|
+
}
|
|
6296
|
+
setFormValues(newFormValues);
|
|
6297
|
+
}
|
|
6296
6298
|
// Re-evaluate conditional logic after form value changes
|
|
6297
6299
|
// Use setTimeout to ensure state update has completed
|
|
6298
6300
|
setTimeout(() => {
|
|
@@ -6317,6 +6319,21 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6317
6319
|
const updateComponentValue = (components) => {
|
|
6318
6320
|
return components.map(component => {
|
|
6319
6321
|
if (component.id === change.id) {
|
|
6322
|
+
// CRITICAL: Handle table/datagrid structure updates (cells, entries, etc.)
|
|
6323
|
+
// When a table sends onValueChange with cells data, update the whole component structure
|
|
6324
|
+
if (change.value && typeof change.value === 'object' && 'cells' in change.value) {
|
|
6325
|
+
return {
|
|
6326
|
+
...component,
|
|
6327
|
+
...change.value
|
|
6328
|
+
};
|
|
6329
|
+
}
|
|
6330
|
+
// Handle datagrid structure updates
|
|
6331
|
+
if (change.value && typeof change.value === 'object' && 'entries' in change.value) {
|
|
6332
|
+
return {
|
|
6333
|
+
...component,
|
|
6334
|
+
...change.value
|
|
6335
|
+
};
|
|
6336
|
+
}
|
|
6320
6337
|
if ('defaultValue' in component.basic) {
|
|
6321
6338
|
return {
|
|
6322
6339
|
...component,
|
|
@@ -6338,24 +6355,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6338
6355
|
if (component.name === 'table' && component.cells) {
|
|
6339
6356
|
return {
|
|
6340
6357
|
...component,
|
|
6341
|
-
cells: component.cells.map((row) => {
|
|
6342
|
-
if (Array.isArray(row)) {
|
|
6343
|
-
return row.map((cell) => {
|
|
6344
|
-
const updatedCell = { ...cell };
|
|
6345
|
-
if (updatedCell.components) {
|
|
6346
|
-
updatedCell.components = updateComponentValue(updatedCell.components);
|
|
6347
|
-
}
|
|
6348
|
-
return updatedCell;
|
|
6349
|
-
});
|
|
6350
|
-
}
|
|
6351
|
-
// Handle flat 1D cell
|
|
6352
|
-
const cell = row;
|
|
6358
|
+
cells: component.cells.map((row) => row.map((cell) => {
|
|
6353
6359
|
const updatedCell = { ...cell };
|
|
6354
6360
|
if (updatedCell.components) {
|
|
6355
6361
|
updatedCell.components = updateComponentValue(updatedCell.components);
|
|
6356
6362
|
}
|
|
6357
6363
|
return updatedCell;
|
|
6358
|
-
})
|
|
6364
|
+
}))
|
|
6359
6365
|
};
|
|
6360
6366
|
}
|
|
6361
6367
|
if (component.name === 'datagrid' && component.entries) {
|
|
@@ -6427,19 +6433,8 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6427
6433
|
// Check nested components in table cells
|
|
6428
6434
|
if (comp.name === 'table' && comp.cells) {
|
|
6429
6435
|
for (const row of comp.cells) {
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
if (cell && cell.components) {
|
|
6433
|
-
const found = findComponentById(cell.components, fieldId);
|
|
6434
|
-
if (found)
|
|
6435
|
-
return found;
|
|
6436
|
-
}
|
|
6437
|
-
}
|
|
6438
|
-
}
|
|
6439
|
-
else {
|
|
6440
|
-
// Handle flat 1D cell
|
|
6441
|
-
const cell = row;
|
|
6442
|
-
if (cell && cell.components) {
|
|
6436
|
+
for (const cell of row) {
|
|
6437
|
+
if (cell.components) {
|
|
6443
6438
|
const found = findComponentById(cell.components, fieldId);
|
|
6444
6439
|
if (found)
|
|
6445
6440
|
return found;
|
|
@@ -6970,25 +6965,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6970
6965
|
updatedComponent.children = updateComponentValues(updatedComponent.children);
|
|
6971
6966
|
}
|
|
6972
6967
|
if (updatedComponent.name === 'table' && updatedComponent.cells) {
|
|
6973
|
-
updatedComponent.cells = updatedComponent.cells.map((
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
if (updatedCell.components) {
|
|
6978
|
-
updatedCell.components = updateComponentValues(updatedCell.components);
|
|
6979
|
-
}
|
|
6980
|
-
return updatedCell;
|
|
6981
|
-
});
|
|
6968
|
+
updatedComponent.cells = updatedComponent.cells.map((row) => row.map((cell) => {
|
|
6969
|
+
const updatedCell = { ...cell };
|
|
6970
|
+
if (updatedCell.components) {
|
|
6971
|
+
updatedCell.components = updateComponentValues(updatedCell.components);
|
|
6982
6972
|
}
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
const updatedCell = { ...rowOrCell };
|
|
6986
|
-
if (updatedCell.components) {
|
|
6987
|
-
updatedCell.components = updateComponentValues(updatedCell.components);
|
|
6988
|
-
}
|
|
6989
|
-
return updatedCell;
|
|
6990
|
-
}
|
|
6991
|
-
});
|
|
6973
|
+
return updatedCell;
|
|
6974
|
+
}));
|
|
6992
6975
|
}
|
|
6993
6976
|
if (updatedComponent.name === 'datagrid' && updatedComponent.entries) {
|
|
6994
6977
|
updatedComponent.entries = updatedComponent.entries.map((entry) => {
|
|
@@ -7166,48 +7149,64 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
7166
7149
|
} }));
|
|
7167
7150
|
case 'table':
|
|
7168
7151
|
return (jsx(React.Suspense, { fallback: jsx("div", { children: "Loading table..." }), children: jsx(DfFormTable$1, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, validationErrors: validationErrors, touchedFields: touchedFields, formSubmitted: formSubmitted, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, workOrderNumber: workOrderNumber, assetNumber: assetNumber, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue, onNotesChange: (componentId, notes) => {
|
|
7152
|
+
// Handle notes change for table cell components
|
|
7169
7153
|
const updatedComponents = formComponents.map(comp => {
|
|
7170
7154
|
if (comp.id === component.id && comp.cells) {
|
|
7171
|
-
const
|
|
7155
|
+
const updatedCells = comp.cells.map((row) => row.map((cell) => {
|
|
7172
7156
|
if (cell.components) {
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7157
|
+
const updatedCellComponents = cell.components.map((cellComp) => {
|
|
7158
|
+
if (cellComp.id === componentId) {
|
|
7159
|
+
return {
|
|
7160
|
+
...cellComp,
|
|
7161
|
+
basic: {
|
|
7162
|
+
...cellComp.basic,
|
|
7163
|
+
notes
|
|
7164
|
+
}
|
|
7165
|
+
};
|
|
7166
|
+
}
|
|
7167
|
+
return cellComp;
|
|
7168
|
+
});
|
|
7169
|
+
return { ...cell, components: updatedCellComponents };
|
|
7179
7170
|
}
|
|
7180
7171
|
return cell;
|
|
7181
|
-
};
|
|
7182
|
-
const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map(updateCell) : updateCell(row));
|
|
7172
|
+
}));
|
|
7183
7173
|
return { ...comp, cells: updatedCells };
|
|
7184
7174
|
}
|
|
7185
7175
|
return comp;
|
|
7186
7176
|
});
|
|
7187
7177
|
onFormDataChange?.(updatedComponents);
|
|
7188
7178
|
}, onAttachmentChange: (componentId, attachments) => {
|
|
7179
|
+
// Handle attachment change for table cell components
|
|
7189
7180
|
const updatedComponents = formComponents.map(comp => {
|
|
7190
7181
|
if (comp.id === component.id && comp.cells) {
|
|
7191
|
-
const
|
|
7182
|
+
const updatedCells = comp.cells.map((row) => row.map((cell) => {
|
|
7192
7183
|
if (cell.components) {
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7184
|
+
const updatedCellComponents = cell.components.map((cellComp) => {
|
|
7185
|
+
if (cellComp.id === componentId) {
|
|
7186
|
+
return {
|
|
7187
|
+
...cellComp,
|
|
7188
|
+
basic: {
|
|
7189
|
+
...cellComp.basic,
|
|
7190
|
+
attachments: attachments || []
|
|
7191
|
+
}
|
|
7192
|
+
};
|
|
7193
|
+
}
|
|
7194
|
+
return cellComp;
|
|
7195
|
+
});
|
|
7196
|
+
return { ...cell, components: updatedCellComponents };
|
|
7199
7197
|
}
|
|
7200
7198
|
return cell;
|
|
7201
|
-
};
|
|
7202
|
-
const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map(updateCell) : updateCell(row));
|
|
7199
|
+
}));
|
|
7203
7200
|
return { ...comp, cells: updatedCells };
|
|
7204
7201
|
}
|
|
7205
7202
|
return comp;
|
|
7206
7203
|
});
|
|
7207
7204
|
onFormDataChange?.(updatedComponents);
|
|
7208
7205
|
}, renderFormComponent: (field) => {
|
|
7206
|
+
// CRITICAL: Pass the field to renderFormComponent which has access to latest formValues
|
|
7207
|
+
// renderFormComponent uses formValues[field.id] internally, so it will get the correct value
|
|
7209
7208
|
return renderFormComponent(field);
|
|
7210
|
-
}
|
|
7209
|
+
} }) }));
|
|
7211
7210
|
case 'datagrid':
|
|
7212
7211
|
return (jsx(DfFormDataGrid, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, onNotesChange: (componentId, notes) => {
|
|
7213
7212
|
handleComponentNotesChange(componentId, notes);
|
|
@@ -7517,13 +7516,12 @@ const ensureComponentHasId = (component) => {
|
|
|
7517
7516
|
}
|
|
7518
7517
|
return component;
|
|
7519
7518
|
};
|
|
7520
|
-
const SimpleTableComponent = ({ component, mode, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue
|
|
7519
|
+
const SimpleTableComponent = ({ component, mode, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue }) => {
|
|
7521
7520
|
const formValue = formData[component.id];
|
|
7522
|
-
const isVisible = shouldShowComponent ? shouldShowComponent(component.id) : true;
|
|
7523
7521
|
// Check if component has notes or attachments for submission view
|
|
7524
7522
|
const hasSubmissionData = mode === 'preview' && ((component.basic?.notes && component.basic.notes.trim().length > 0) ||
|
|
7525
7523
|
(component.basic?.attachments && Array.isArray(component.basic.attachments) && component.basic.attachments.length > 0));
|
|
7526
|
-
return (jsxs("div", { className:
|
|
7524
|
+
return (jsxs("div", { className: "simple-table-component", children: [renderFormComponent(component), !['section', 'table', 'heading', 'file', 'instructions', 'signature', 'location', 'datagrid'].includes(component.name) && (jsx(ComponentActionFeatures, { component: component, mode: "test", formTemplateId: formTemplateId, formValue: formValue, formData: formData, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, onNotesChange: onNotesChange ? (notes) => onNotesChange(component.id, notes) : undefined, onAttachmentChange: onAttachmentChange ? (attachments) => onAttachmentChange(component.id, attachments) : undefined, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue })), hasSubmissionData && (jsx(ComponentSubmissionActions, { component: component }))] }));
|
|
7527
7525
|
};
|
|
7528
7526
|
const DraggableTableComponent = ({ component, selectedComponent, mode, onComponentSelect, onComponentDelete, onComponentEdit, renderFormComponent, isOverlay = false, }) => {
|
|
7529
7527
|
const { attributes, listeners, setNodeRef, transform, transition, isDragging, isSorting, } = useSortable({
|
|
@@ -7544,7 +7542,7 @@ const DraggableTableComponent = ({ component, selectedComponent, mode, onCompone
|
|
|
7544
7542
|
onComponentDelete(component, e);
|
|
7545
7543
|
}, type: "button", title: "Delete Component", children: jsx(Trash2, { size: 12 }) })] }))] }));
|
|
7546
7544
|
};
|
|
7547
|
-
const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, tableId, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue
|
|
7545
|
+
const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, tableId, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue }) => {
|
|
7548
7546
|
const dropZoneId = `table-cell-${tableId}-${cell.row}-${cell.column}`;
|
|
7549
7547
|
const { setNodeRef, isOver } = useDroppable({
|
|
7550
7548
|
id: dropZoneId,
|
|
@@ -7579,7 +7577,7 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
|
|
|
7579
7577
|
cell.components.map((component) => {
|
|
7580
7578
|
// Only ensure ID if it's truly missing - don't regenerate existing IDs
|
|
7581
7579
|
const componentWithId = component.id ? component : ensureComponentHasId(component);
|
|
7582
|
-
return (jsx(SimpleTableComponent, { component: componentWithId, mode: mode, renderFormComponent: renderFormComponent, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue
|
|
7580
|
+
return (jsx(SimpleTableComponent, { component: componentWithId, mode: mode, renderFormComponent: renderFormComponent, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue }, componentWithId.id));
|
|
7583
7581
|
}))) : (
|
|
7584
7582
|
// Only show drop zone content in edit mode
|
|
7585
7583
|
mode === 'edit' ? (jsx("div", { className: "empty-cell-placeholder", children: jsxs("div", { className: "cell-info", children: [jsx("span", { className: "drop-zone-text", children: "Drag and Drop a form component" }), jsxs("span", { className: "cell-coordinates", children: ["Cell (", cell.row + 1, ", ", cell.column + 1, ")"] })] }) })) : (
|
|
@@ -7590,21 +7588,49 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
|
|
|
7590
7588
|
visibility: 'hidden' // Hide content but maintain space
|
|
7591
7589
|
}, children: "\u00A0" }))) }) }));
|
|
7592
7590
|
};
|
|
7593
|
-
const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationErrors = {}, touchedFields = {}, formSubmitted = false, onValueChange, onSelect, isSelected = false, className = '', onTableSelect, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue
|
|
7594
|
-
const [isCollapsed, setIsCollapsed] = useState(false);
|
|
7595
|
-
// NOTE: Unlike the main website, the package does NOT have a cell initialization useEffect.
|
|
7596
|
-
// In the main website, onValueChange handles component structure updates (updating cells).
|
|
7597
|
-
// In the package, onValueChange maps to onFormValueChange which only handles simple form values.
|
|
7598
|
-
// The cells are already properly structured from the API and processed by the useMemo in DfFormPreview.
|
|
7591
|
+
const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationErrors = {}, touchedFields = {}, formSubmitted = false, onValueChange, onSelect, isSelected = false, className = '', onTableSelect, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue }) => {
|
|
7592
|
+
const [isCollapsed, setIsCollapsed] = useState(false); // Always start expanded to show drop zones
|
|
7599
7593
|
// Check if table has any components in any cells
|
|
7600
|
-
const hasAnyComponents = properties.cells?.some(
|
|
7601
|
-
|
|
7602
|
-
|
|
7603
|
-
|
|
7604
|
-
//
|
|
7605
|
-
const
|
|
7606
|
-
|
|
7607
|
-
|
|
7594
|
+
const hasAnyComponents = properties.cells?.some(row => row.some(cell => cell.components && cell.components.length > 0)) || false;
|
|
7595
|
+
// Initialize and update table cells when rows/columns change
|
|
7596
|
+
// Only trigger when cells are truly missing or structure doesn't match rows/columns
|
|
7597
|
+
useEffect(() => {
|
|
7598
|
+
// Get rows and columns from table properties (where they're actually stored)
|
|
7599
|
+
const currentRows = Number(properties.table?.rows || properties.basic?.rows || 3);
|
|
7600
|
+
const currentColumns = Number(properties.table?.columns || properties.basic?.columns || 3);
|
|
7601
|
+
const currentCells = properties.cells || [];
|
|
7602
|
+
// Check if we need to update the table structure
|
|
7603
|
+
// Only update if cells are empty or row/column count doesn't match
|
|
7604
|
+
const needsUpdate = currentCells.length === 0 ||
|
|
7605
|
+
currentCells.length !== currentRows ||
|
|
7606
|
+
(currentCells.length > 0 && currentCells[0].length !== currentColumns);
|
|
7607
|
+
if (needsUpdate) {
|
|
7608
|
+
const newCells = [];
|
|
7609
|
+
for (let row = 0; row < currentRows; row++) {
|
|
7610
|
+
const rowCells = [];
|
|
7611
|
+
for (let col = 0; col < currentColumns; col++) {
|
|
7612
|
+
const cellId = `cell-${row}-${col}`;
|
|
7613
|
+
// Try to preserve existing components if the cell exists
|
|
7614
|
+
let existingComponents = [];
|
|
7615
|
+
if (currentCells[row] && currentCells[row][col]) {
|
|
7616
|
+
existingComponents = (currentCells[row][col].components || []).map(ensureComponentHasId);
|
|
7617
|
+
}
|
|
7618
|
+
rowCells.push({
|
|
7619
|
+
id: cellId,
|
|
7620
|
+
row,
|
|
7621
|
+
column: col,
|
|
7622
|
+
components: existingComponents,
|
|
7623
|
+
styles: {}
|
|
7624
|
+
});
|
|
7625
|
+
}
|
|
7626
|
+
newCells.push(rowCells);
|
|
7627
|
+
}
|
|
7628
|
+
onValueChange?.({
|
|
7629
|
+
id,
|
|
7630
|
+
value: { ...properties, cells: newCells }
|
|
7631
|
+
});
|
|
7632
|
+
}
|
|
7633
|
+
}, [properties.table?.rows, properties.table?.columns, properties.basic?.rows, properties.basic?.columns, properties.cells?.length, id, onValueChange]); // Watch rows/columns changes and cells length for initial init
|
|
7608
7634
|
const handleTableClick = useCallback((event) => {
|
|
7609
7635
|
event.stopPropagation();
|
|
7610
7636
|
onSelect?.();
|
|
@@ -7620,60 +7646,66 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7620
7646
|
};
|
|
7621
7647
|
const handleComponentDelete = useCallback((component, event) => {
|
|
7622
7648
|
event.stopPropagation();
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
}
|
|
7631
|
-
}
|
|
7632
|
-
// Handle flat 1D cell
|
|
7633
|
-
const cell = row;
|
|
7634
|
-
if (cell && cell.components && cell.components.some((comp) => comp.id === component.id)) {
|
|
7635
|
-
return { ...cell, components: cell.components.filter((comp) => comp.id !== component.id) };
|
|
7649
|
+
// Find and remove the component from the table cell
|
|
7650
|
+
const updatedCells = properties.cells.map(row => row.map(cell => {
|
|
7651
|
+
if (cell.components && cell.components.some(comp => comp.id === component.id)) {
|
|
7652
|
+
const filteredComponents = cell.components.filter(comp => comp.id !== component.id);
|
|
7653
|
+
return {
|
|
7654
|
+
...cell,
|
|
7655
|
+
components: filteredComponents
|
|
7656
|
+
};
|
|
7636
7657
|
}
|
|
7637
7658
|
return cell;
|
|
7638
|
-
});
|
|
7639
|
-
|
|
7659
|
+
}));
|
|
7660
|
+
// Update the table with the modified cells
|
|
7661
|
+
if (onValueChange) {
|
|
7662
|
+
onValueChange({
|
|
7663
|
+
id,
|
|
7664
|
+
value: { ...properties, cells: updatedCells }
|
|
7665
|
+
});
|
|
7666
|
+
}
|
|
7667
|
+
// Don't call parent delete handler for table cell components
|
|
7668
|
+
// The parent delete handler is for deleting entire fields, not components within table cells
|
|
7640
7669
|
}, [onComponentDelete, properties, onValueChange, id]);
|
|
7641
|
-
// Ensure all table cell components have IDs
|
|
7642
|
-
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
//
|
|
7667
|
-
// CRITICAL:
|
|
7668
|
-
//
|
|
7669
|
-
|
|
7670
|
+
// CRITICAL FIX: Ensure all table cell components have proper IDs with table and cell position
|
|
7671
|
+
// Use useMemo to prevent ID regeneration on every render
|
|
7672
|
+
const cellsWithIds = useMemo(() => {
|
|
7673
|
+
if (!properties.cells)
|
|
7674
|
+
return [];
|
|
7675
|
+
return properties.cells.map((row, rowIndex) => row.map((cell, cellIndex) => ({
|
|
7676
|
+
...cell,
|
|
7677
|
+
components: (cell.components && Array.isArray(cell.components))
|
|
7678
|
+
? cell.components.map((comp, compIndex) => {
|
|
7679
|
+
// CRITICAL: Only generate ID if it's missing - never regenerate existing IDs
|
|
7680
|
+
// This prevents component remounting and losing input state
|
|
7681
|
+
if (comp.id && typeof comp.id === 'string' && comp.id.trim() !== '') {
|
|
7682
|
+
// ID already exists - keep it as is
|
|
7683
|
+
return comp;
|
|
7684
|
+
}
|
|
7685
|
+
// Generate unique ID that includes table ID, row, cell, and component index
|
|
7686
|
+
// This ensures no conflicts with other components
|
|
7687
|
+
const uniqueId = `${comp.name || 'component'}-table-${id}-row-${rowIndex}-cell-${cellIndex}-comp-${compIndex}`;
|
|
7688
|
+
return {
|
|
7689
|
+
...comp,
|
|
7690
|
+
id: uniqueId
|
|
7691
|
+
};
|
|
7692
|
+
})
|
|
7693
|
+
: []
|
|
7694
|
+
})));
|
|
7695
|
+
}, [properties.cells, id]); // Only recalculate if cells or table ID changes
|
|
7696
|
+
// CRITICAL FIX: Update the parent component with the cells that have proper IDs
|
|
7697
|
+
// Skip this in package to prevent flickering - cells are managed by parent
|
|
7698
|
+
// useEffect(() => {
|
|
7699
|
+
// // Disabled to prevent flickering when user types
|
|
7700
|
+
// }, [])
|
|
7701
|
+
// Fallback renderer for when no renderFormComponent is provided by parent
|
|
7702
|
+
// Always defined to avoid conditional hook calls (React hooks rule)
|
|
7703
|
+
const fallbackRenderComponent = useCallback((field) => {
|
|
7670
7704
|
// CRITICAL: Only ensure ID if it's missing - don't regenerate existing IDs
|
|
7671
|
-
// This prevents component remounting and losing input state
|
|
7672
7705
|
const componentWithId = field.id ? field : ensureComponentHasId(field);
|
|
7673
7706
|
// Get form value - directly access formData from closure (matches main app)
|
|
7674
7707
|
const formValue = formData[componentWithId.id] || ('defaultValue' in componentWithId.basic ? componentWithId.basic.defaultValue || '' : '');
|
|
7675
7708
|
// CRITICAL: Ensure formValue is always a string for number inputs
|
|
7676
|
-
// This prevents validation errors when formValue is a number type
|
|
7677
7709
|
let normalizedFormValue = formValue;
|
|
7678
7710
|
if (componentWithId.name === 'number-input' && typeof formValue === 'number') {
|
|
7679
7711
|
normalizedFormValue = String(formValue);
|
|
@@ -7705,21 +7737,18 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7705
7737
|
case 'textarea':
|
|
7706
7738
|
return jsx(DfFormTextarea, { ...commonProps, properties: componentWithId, readonly: false, disabled: false });
|
|
7707
7739
|
case 'select':
|
|
7708
|
-
// Map basic.options to top-level options for select component
|
|
7709
7740
|
const selectProps = {
|
|
7710
7741
|
...componentWithId,
|
|
7711
7742
|
options: componentWithId.basic?.options || []
|
|
7712
7743
|
};
|
|
7713
7744
|
return jsx(DfFormSelect, { ...commonProps, properties: selectProps, disabled: false });
|
|
7714
7745
|
case 'checkbox':
|
|
7715
|
-
// Map basic.options to top-level options for checkbox component
|
|
7716
7746
|
const checkboxProps = {
|
|
7717
7747
|
...componentWithId,
|
|
7718
7748
|
options: componentWithId.basic?.options || []
|
|
7719
7749
|
};
|
|
7720
7750
|
return jsx(DfFormCheckbox, { ...commonProps, properties: checkboxProps, formValue: [], disabled: false });
|
|
7721
7751
|
case 'radio':
|
|
7722
|
-
// Map basic.options to top-level options for radio component
|
|
7723
7752
|
const radioProps = {
|
|
7724
7753
|
...componentWithId,
|
|
7725
7754
|
options: componentWithId.basic?.options || []
|
|
@@ -7741,7 +7770,6 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7741
7770
|
case 'datagrid':
|
|
7742
7771
|
return (jsx(DfFormDataGrid, { ...commonProps, properties: componentWithId, formData: formData, mode: mode, onNotesChange: () => { }, onAttachmentChange: () => { } }));
|
|
7743
7772
|
case 'segment':
|
|
7744
|
-
// Map basic.options for segment
|
|
7745
7773
|
const segmentProps = {
|
|
7746
7774
|
...componentWithId,
|
|
7747
7775
|
options: componentWithId.basic?.options || []
|
|
@@ -7750,7 +7778,9 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7750
7778
|
default:
|
|
7751
7779
|
return jsxs("div", { className: "unknown-component", children: ["Unknown component: ", componentWithId.name] });
|
|
7752
7780
|
}
|
|
7753
|
-
}, [
|
|
7781
|
+
}, [mode, formData, onValueChange]);
|
|
7782
|
+
// Use parent-provided renderFormComponent if available, otherwise use fallback
|
|
7783
|
+
const renderComponent = renderFormComponent || fallbackRenderComponent;
|
|
7754
7784
|
const tableStyle = {
|
|
7755
7785
|
backgroundColor: properties.styles?.backgroundColor || 'var(--df-color-fb-container)',
|
|
7756
7786
|
borderColor: properties.styles?.borderColor || 'var(--df-color-fb-border)',
|
|
@@ -7771,22 +7801,22 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7771
7801
|
if (!hasAnyComponents && mode === 'preview') {
|
|
7772
7802
|
return null;
|
|
7773
7803
|
}
|
|
7774
|
-
return (jsxs("div", { className: `form-group df-form-table ${isSelected ? 'selected' : ''} ${mode === 'preview' ? 'preview-mode' : mode === 'test' ? 'test-mode' : ''} ${className}`, onClick: handleTableClick, style: tableStyle, children: [jsx("div", { className: "table-header", children: jsx("div", { className: "table-title", onClick: toggleCollapse, children: jsxs("div", { className: "title-content", children: [isCollapsed ? jsx(ChevronRight, { size: 16 }) : jsx(ChevronDown, { size: 16 }), jsx(Table, { size: 16 }), jsx("span", { className: "table-label", children: properties.basic?.label || 'Table' }), properties.validation?.required && (jsx("span", { className: "required-indicator", children: "*" }))] }) }) }), properties.basic?.description && !isCollapsed && (jsx("div", { className: "table-description", children: properties.basic.description })), !isCollapsed && (
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7804
|
+
return (jsxs("div", { className: `form-group df-form-table ${isSelected ? 'selected' : ''} ${mode === 'preview' ? 'preview-mode' : mode === 'test' ? 'test-mode' : ''} ${className}`, onClick: handleTableClick, style: tableStyle, children: [jsx("div", { className: "table-header", children: jsx("div", { className: "table-title", onClick: toggleCollapse, children: jsxs("div", { className: "title-content", children: [isCollapsed ? jsx(ChevronRight, { size: 16 }) : jsx(ChevronDown, { size: 16 }), jsx(Table, { size: 16 }), jsx("span", { className: "table-label", children: properties.basic?.label || 'Table' }), properties.validation?.required && (jsx("span", { className: "required-indicator", children: "*" }))] }) }) }), properties.basic?.description && !isCollapsed && (jsx("div", { className: "table-description", children: properties.basic.description })), !isCollapsed && (jsxs("div", { className: "table-content", children: [(() => {
|
|
7805
|
+
return null;
|
|
7806
|
+
})(), jsxs("table", { style: tableElementStyle, children: [properties.table?.displayAsTable && (mode === 'edit' || properties.table?.showColumns) && (jsx("thead", { children: jsx("tr", { className: "table-header-row", children: Array.from({ length: properties.table?.columns || properties.basic?.columns || 3 }, (_, colIndex) => {
|
|
7807
|
+
// Parse column names from the comma-separated string
|
|
7808
|
+
const columnNames = properties.table?.columnNames?.split(',').map(name => name.trim()) || [];
|
|
7809
|
+
const columnName = columnNames[colIndex] || `Column ${colIndex + 1}`;
|
|
7810
|
+
return (jsx("th", { className: "table-header-cell", style: {
|
|
7811
|
+
backgroundColor: properties.styles.headerBackgroundColor || (mode === 'preview' || mode === 'test') ? 'var(--df-color-fb-container)' : 'var(--df-color-fb-container)',
|
|
7812
|
+
color: properties.styles.headerTextColor || 'var(--df-color-text-dark)',
|
|
7813
|
+
padding: '12px',
|
|
7814
|
+
border: (mode === 'preview' || mode === 'test') ? '1px solid var(--df-color-fb-border)' : '1px solid var(--df-color-fb-border)',
|
|
7815
|
+
fontWeight: '600',
|
|
7816
|
+
fontSize: '14px',
|
|
7817
|
+
textAlign: 'center'
|
|
7818
|
+
}, children: columnName }, `header-${colIndex}`));
|
|
7819
|
+
}) }) })), jsx("tbody", { children: cellsWithIds.map((row, rowIndex) => (jsx("tr", { className: "table-row", children: row.map((cell) => (jsx(TableCellComponent, { cell: cell, mode: mode, onComponentSelect: onComponentSelect || (() => { }), onComponentDelete: handleComponentDelete, onComponentEdit: onComponentEdit, selectedComponent: selectedComponent || null, renderFormComponent: renderComponent, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, tableId: id, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue }, cell.id))) }, rowIndex))) })] })] }))] }));
|
|
7790
7820
|
};
|
|
7791
7821
|
|
|
7792
7822
|
var dfFormTable = /*#__PURE__*/Object.freeze({
|