df-ae-forms-package 1.0.80 → 1.0.82
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 +1 -0
- package/dist/index.esm.js +161 -257
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +161 -257
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5971,9 +5971,47 @@ const DfFormSection = ({ id, properties, mode = 'edit', formData = {}, onValueCh
|
|
|
5971
5971
|
|
|
5972
5972
|
// Dynamic imports to avoid circular dependencies
|
|
5973
5973
|
const DfFormTable$1 = React.lazy(() => Promise.resolve().then(function () { return dfFormTable; }));
|
|
5974
|
-
const DfFormPreview = ({ formComponents = [], currentDevice = 'desktop', isPreviewMode = false, initialFormData = [], onSubmit, onFormDataChange, formTitle, formDescription, formTemplateId,
|
|
5974
|
+
const DfFormPreview = ({ formComponents: rawFormComponents = [], currentDevice = 'desktop', isPreviewMode = false, initialFormData = [], onSubmit, onFormDataChange, formTitle, formDescription, formTemplateId,
|
|
5975
5975
|
// Add component management props for edit mode
|
|
5976
5976
|
onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, selectedComponent, workOrderNumber, assetNumber, isStandalone, user, onCreateIssue, onUpdateIssue }) => {
|
|
5977
|
+
// Ensure all components have IDs (matching main website approach)
|
|
5978
|
+
const formComponents = React.useMemo(() => {
|
|
5979
|
+
const ensureIds = (components) => {
|
|
5980
|
+
return components.map(comp => {
|
|
5981
|
+
// Reuse existing ID or generate one
|
|
5982
|
+
const id = comp.id || `generated-${Math.random().toString(36).substr(2, 9)}`;
|
|
5983
|
+
const newComp = { ...comp, id };
|
|
5984
|
+
// Recursively handle nested components
|
|
5985
|
+
if (newComp.children && Array.isArray(newComp.children)) {
|
|
5986
|
+
newComp.children = ensureIds(newComp.children);
|
|
5987
|
+
}
|
|
5988
|
+
if (newComp.cells && Array.isArray(newComp.cells)) {
|
|
5989
|
+
newComp.cells = newComp.cells.map((row) => {
|
|
5990
|
+
if (Array.isArray(row)) {
|
|
5991
|
+
return row.map((cell) => ({
|
|
5992
|
+
...cell,
|
|
5993
|
+
components: cell.components ? ensureIds(cell.components) : []
|
|
5994
|
+
}));
|
|
5995
|
+
}
|
|
5996
|
+
// Handle flat 1D cell (not wrapped in row array)
|
|
5997
|
+
const cell = row;
|
|
5998
|
+
return {
|
|
5999
|
+
...cell,
|
|
6000
|
+
components: cell.components ? ensureIds(cell.components) : []
|
|
6001
|
+
};
|
|
6002
|
+
});
|
|
6003
|
+
}
|
|
6004
|
+
if (newComp.entries && Array.isArray(newComp.entries)) {
|
|
6005
|
+
newComp.entries = newComp.entries.map((entry) => ({
|
|
6006
|
+
...entry,
|
|
6007
|
+
components: entry.components ? ensureIds(entry.components) : []
|
|
6008
|
+
}));
|
|
6009
|
+
}
|
|
6010
|
+
return newComp;
|
|
6011
|
+
});
|
|
6012
|
+
};
|
|
6013
|
+
return ensureIds(rawFormComponents || []);
|
|
6014
|
+
}, [rawFormComponents]);
|
|
5977
6015
|
// Form state
|
|
5978
6016
|
const [formValues, setFormValues] = React.useState({});
|
|
5979
6017
|
const [validationErrors, setValidationErrors] = React.useState({});
|
|
@@ -6019,24 +6057,16 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6019
6057
|
}
|
|
6020
6058
|
}
|
|
6021
6059
|
}
|
|
6022
|
-
// Handle nested components in table cells
|
|
6060
|
+
// Handle nested components in table cells (2D array: row → cell → components)
|
|
6023
6061
|
if (component.cells && Array.isArray(component.cells)) {
|
|
6024
|
-
component.cells.forEach((
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
rowOrCell.forEach((cell, _cellIndex) => {
|
|
6062
|
+
component.cells.forEach((row) => {
|
|
6063
|
+
if (Array.isArray(row)) {
|
|
6064
|
+
row.forEach((cell) => {
|
|
6028
6065
|
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
6029
6066
|
initializeComponentValues(cell.components, values);
|
|
6030
6067
|
}
|
|
6031
6068
|
});
|
|
6032
6069
|
}
|
|
6033
|
-
// Handle 1D array (flat) structure
|
|
6034
|
-
else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
|
|
6035
|
-
const cell = rowOrCell;
|
|
6036
|
-
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
6037
|
-
initializeComponentValues(cell.components, values);
|
|
6038
|
-
}
|
|
6039
|
-
}
|
|
6040
6070
|
});
|
|
6041
6071
|
}
|
|
6042
6072
|
// Handle nested components in datagrid entries
|
|
@@ -6082,7 +6112,6 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6082
6112
|
const initialValues = {};
|
|
6083
6113
|
const initialNotes = {};
|
|
6084
6114
|
const initialAttachments = {};
|
|
6085
|
-
const seenIds = new Set();
|
|
6086
6115
|
// Helper to extract notes and attachments recursively
|
|
6087
6116
|
const extractNotesAndAttachments = (components) => {
|
|
6088
6117
|
components.forEach(comp => {
|
|
@@ -6119,92 +6148,16 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6119
6148
|
});
|
|
6120
6149
|
});
|
|
6121
6150
|
};
|
|
6122
|
-
//
|
|
6123
|
-
const getValidatedComponents = (components) => {
|
|
6124
|
-
return components.map((component, index) => {
|
|
6125
|
-
let validatedComponent = { ...component };
|
|
6126
|
-
// Ensure component has an ID
|
|
6127
|
-
if (!validatedComponent.id || typeof validatedComponent.id !== 'string' || validatedComponent.id.trim() === '') {
|
|
6128
|
-
// Determine a base name for the ID
|
|
6129
|
-
const name = validatedComponent.name || 'component';
|
|
6130
|
-
const label = validatedComponent.basic?.label || '';
|
|
6131
|
-
const safeLabel = label.replace(/[^a-zA-Z0-9]/g, '').toLowerCase().substring(0, 10);
|
|
6132
|
-
// Generate a unique ID
|
|
6133
|
-
validatedComponent.id = `${name}-${safeLabel || 'gen'}-${Date.now()}-${Math.random().toString(36).substr(2, 6)}-${index}`;
|
|
6134
|
-
console.warn(`[DfFormPreview] Assigned missing ID: ${validatedComponent.id}`);
|
|
6135
|
-
}
|
|
6136
|
-
else {
|
|
6137
|
-
// Check for duplicates
|
|
6138
|
-
if (seenIds.has(validatedComponent.id)) {
|
|
6139
|
-
console.error(`[DfFormPreview] Duplicate component ID detected: ${validatedComponent.id}`);
|
|
6140
|
-
// Generate a unique ID for duplicate
|
|
6141
|
-
validatedComponent.id = `${validatedComponent.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
6142
|
-
console.warn(`[DfFormPreview] Generated new unique ID: ${validatedComponent.id}`);
|
|
6143
|
-
}
|
|
6144
|
-
}
|
|
6145
|
-
seenIds.add(validatedComponent.id);
|
|
6146
|
-
// Recursively validate nested components
|
|
6147
|
-
if (validatedComponent.children && Array.isArray(validatedComponent.children)) {
|
|
6148
|
-
validatedComponent.children = getValidatedComponents(validatedComponent.children);
|
|
6149
|
-
}
|
|
6150
|
-
if (validatedComponent.cells && Array.isArray(validatedComponent.cells)) {
|
|
6151
|
-
validatedComponent.cells = validatedComponent.cells.map((rowOrCell) => {
|
|
6152
|
-
if (Array.isArray(rowOrCell)) {
|
|
6153
|
-
// Standard 2D: rowOrCell is an array of cells
|
|
6154
|
-
return rowOrCell.map((cell) => {
|
|
6155
|
-
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
6156
|
-
return { ...cell, components: getValidatedComponents(cell.components) };
|
|
6157
|
-
}
|
|
6158
|
-
return cell;
|
|
6159
|
-
});
|
|
6160
|
-
}
|
|
6161
|
-
else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
|
|
6162
|
-
// Flat 1D: rowOrCell IS the cell object
|
|
6163
|
-
const cell = rowOrCell;
|
|
6164
|
-
if (cell.components && Array.isArray(cell.components)) {
|
|
6165
|
-
return { ...cell, components: getValidatedComponents(cell.components) };
|
|
6166
|
-
}
|
|
6167
|
-
return cell;
|
|
6168
|
-
}
|
|
6169
|
-
return rowOrCell;
|
|
6170
|
-
});
|
|
6171
|
-
}
|
|
6172
|
-
if (validatedComponent.entries && Array.isArray(validatedComponent.entries)) {
|
|
6173
|
-
validatedComponent.entries = validatedComponent.entries.map((entry) => {
|
|
6174
|
-
if (entry && entry.components && Array.isArray(entry.components)) {
|
|
6175
|
-
return {
|
|
6176
|
-
...entry,
|
|
6177
|
-
components: getValidatedComponents(entry.components)
|
|
6178
|
-
};
|
|
6179
|
-
}
|
|
6180
|
-
return entry;
|
|
6181
|
-
});
|
|
6182
|
-
}
|
|
6183
|
-
return validatedComponent;
|
|
6184
|
-
});
|
|
6185
|
-
};
|
|
6186
|
-
// Initialize validated components
|
|
6187
|
-
let validatedFormComponents = formComponents;
|
|
6188
|
-
if (formComponents && formComponents.length > 0) {
|
|
6189
|
-
validatedFormComponents = getValidatedComponents(formComponents);
|
|
6190
|
-
// Notifying parent of changed components if they were mutated (IDs added/fixed)
|
|
6191
|
-
if (JSON.stringify(validatedFormComponents) !== JSON.stringify(formComponents)) {
|
|
6192
|
-
onFormDataChange?.(validatedFormComponents);
|
|
6193
|
-
}
|
|
6194
|
-
}
|
|
6195
|
-
let validatedInitialFormData = initialFormData;
|
|
6196
|
-
if (initialFormData && initialFormData.length > 0) {
|
|
6197
|
-
validatedInitialFormData = getValidatedComponents(initialFormData);
|
|
6198
|
-
}
|
|
6151
|
+
// IDs are already ensured by the useMemo at the top - no need for getValidatedComponents
|
|
6199
6152
|
// Initialize form values from initial data
|
|
6200
|
-
if (
|
|
6201
|
-
initializeComponentValues(
|
|
6153
|
+
if (initialFormData && initialFormData.length > 0) {
|
|
6154
|
+
initializeComponentValues(initialFormData, initialValues);
|
|
6202
6155
|
}
|
|
6203
6156
|
// Initialize form values from form components (for submitted data or pre-filled forms)
|
|
6204
6157
|
// CRITICAL: This must run AFTER initialFormData to pick up any values embedded in the components themselves
|
|
6205
|
-
if (
|
|
6206
|
-
initializeComponentValues(
|
|
6207
|
-
extractNotesAndAttachments(
|
|
6158
|
+
if (formComponents && formComponents.length > 0) {
|
|
6159
|
+
initializeComponentValues(formComponents, initialValues);
|
|
6160
|
+
extractNotesAndAttachments(formComponents);
|
|
6208
6161
|
}
|
|
6209
6162
|
// Set the state
|
|
6210
6163
|
setFormValues(prev => {
|
|
@@ -6247,21 +6200,20 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6247
6200
|
visibility[component.basic.label] = true;
|
|
6248
6201
|
}
|
|
6249
6202
|
}
|
|
6250
|
-
// Handle nested components in table cells
|
|
6203
|
+
// Handle nested components in table cells (2D: row → cell → components)
|
|
6251
6204
|
if (component.cells && Array.isArray(component.cells)) {
|
|
6252
|
-
component.cells.forEach((
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
if (cell.components && Array.isArray(cell.components)) {
|
|
6205
|
+
component.cells.forEach((row) => {
|
|
6206
|
+
if (Array.isArray(row)) {
|
|
6207
|
+
row.forEach((cell) => {
|
|
6208
|
+
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
6257
6209
|
evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
|
|
6258
6210
|
}
|
|
6259
6211
|
});
|
|
6260
6212
|
}
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
const cell =
|
|
6264
|
-
if (cell.components && Array.isArray(cell.components)) {
|
|
6213
|
+
else {
|
|
6214
|
+
// Handle flat 1D cell
|
|
6215
|
+
const cell = row;
|
|
6216
|
+
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
6265
6217
|
evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
|
|
6266
6218
|
}
|
|
6267
6219
|
}
|
|
@@ -6388,13 +6340,24 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6388
6340
|
if (component.name === 'table' && component.cells) {
|
|
6389
6341
|
return {
|
|
6390
6342
|
...component,
|
|
6391
|
-
cells: component.cells.map((row) =>
|
|
6343
|
+
cells: component.cells.map((row) => {
|
|
6344
|
+
if (Array.isArray(row)) {
|
|
6345
|
+
return row.map((cell) => {
|
|
6346
|
+
const updatedCell = { ...cell };
|
|
6347
|
+
if (updatedCell.components) {
|
|
6348
|
+
updatedCell.components = updateComponentValue(updatedCell.components);
|
|
6349
|
+
}
|
|
6350
|
+
return updatedCell;
|
|
6351
|
+
});
|
|
6352
|
+
}
|
|
6353
|
+
// Handle flat 1D cell
|
|
6354
|
+
const cell = row;
|
|
6392
6355
|
const updatedCell = { ...cell };
|
|
6393
6356
|
if (updatedCell.components) {
|
|
6394
6357
|
updatedCell.components = updateComponentValue(updatedCell.components);
|
|
6395
6358
|
}
|
|
6396
6359
|
return updatedCell;
|
|
6397
|
-
})
|
|
6360
|
+
})
|
|
6398
6361
|
};
|
|
6399
6362
|
}
|
|
6400
6363
|
if (component.name === 'datagrid' && component.entries) {
|
|
@@ -6466,8 +6429,19 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6466
6429
|
// Check nested components in table cells
|
|
6467
6430
|
if (comp.name === 'table' && comp.cells) {
|
|
6468
6431
|
for (const row of comp.cells) {
|
|
6469
|
-
|
|
6470
|
-
|
|
6432
|
+
if (Array.isArray(row)) {
|
|
6433
|
+
for (const cell of row) {
|
|
6434
|
+
if (cell && cell.components) {
|
|
6435
|
+
const found = findComponentById(cell.components, fieldId);
|
|
6436
|
+
if (found)
|
|
6437
|
+
return found;
|
|
6438
|
+
}
|
|
6439
|
+
}
|
|
6440
|
+
}
|
|
6441
|
+
else {
|
|
6442
|
+
// Handle flat 1D cell
|
|
6443
|
+
const cell = row;
|
|
6444
|
+
if (cell && cell.components) {
|
|
6471
6445
|
const found = findComponentById(cell.components, fieldId);
|
|
6472
6446
|
if (found)
|
|
6473
6447
|
return found;
|
|
@@ -7194,86 +7168,48 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
7194
7168
|
} }));
|
|
7195
7169
|
case 'table':
|
|
7196
7170
|
return (jsxRuntime.jsx(React.Suspense, { fallback: jsxRuntime.jsx("div", { children: "Loading table..." }), children: jsxRuntime.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) => {
|
|
7197
|
-
// Handle notes change for table cell components
|
|
7198
7171
|
const updatedComponents = formComponents.map(comp => {
|
|
7199
7172
|
if (comp.id === component.id && comp.cells) {
|
|
7200
|
-
const
|
|
7201
|
-
if (
|
|
7202
|
-
return
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
return cellComp;
|
|
7209
|
-
});
|
|
7210
|
-
return { ...cell, components: updatedCellComponents };
|
|
7211
|
-
}
|
|
7212
|
-
return cell;
|
|
7213
|
-
});
|
|
7214
|
-
}
|
|
7215
|
-
else {
|
|
7216
|
-
const cell = rowOrCell;
|
|
7217
|
-
if (cell.components) {
|
|
7218
|
-
const updatedCellComponents = cell.components.map((cellComp) => {
|
|
7219
|
-
if (cellComp.id === componentId) {
|
|
7220
|
-
return { ...cellComp, basic: { ...cellComp.basic, notes } };
|
|
7221
|
-
}
|
|
7222
|
-
return cellComp;
|
|
7223
|
-
});
|
|
7224
|
-
return { ...cell, components: updatedCellComponents };
|
|
7225
|
-
}
|
|
7226
|
-
return cell;
|
|
7173
|
+
const updateCell = (cell) => {
|
|
7174
|
+
if (cell.components) {
|
|
7175
|
+
return {
|
|
7176
|
+
...cell,
|
|
7177
|
+
components: cell.components.map((cellComp) => cellComp.id === componentId
|
|
7178
|
+
? { ...cellComp, basic: { ...cellComp.basic, notes } }
|
|
7179
|
+
: cellComp)
|
|
7180
|
+
};
|
|
7227
7181
|
}
|
|
7228
|
-
|
|
7182
|
+
return cell;
|
|
7183
|
+
};
|
|
7184
|
+
const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map(updateCell) : updateCell(row));
|
|
7229
7185
|
return { ...comp, cells: updatedCells };
|
|
7230
7186
|
}
|
|
7231
7187
|
return comp;
|
|
7232
7188
|
});
|
|
7233
7189
|
onFormDataChange?.(updatedComponents);
|
|
7234
7190
|
}, onAttachmentChange: (componentId, attachments) => {
|
|
7235
|
-
// Handle attachment change for table cell components
|
|
7236
7191
|
const updatedComponents = formComponents.map(comp => {
|
|
7237
7192
|
if (comp.id === component.id && comp.cells) {
|
|
7238
|
-
const
|
|
7239
|
-
if (
|
|
7240
|
-
return
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
return cellComp;
|
|
7247
|
-
});
|
|
7248
|
-
return { ...cell, components: updatedCellComponents };
|
|
7249
|
-
}
|
|
7250
|
-
return cell;
|
|
7251
|
-
});
|
|
7252
|
-
}
|
|
7253
|
-
else {
|
|
7254
|
-
const cell = rowOrCell;
|
|
7255
|
-
if (cell.components) {
|
|
7256
|
-
const updatedCellComponents = cell.components.map((cellComp) => {
|
|
7257
|
-
if (cellComp.id === componentId) {
|
|
7258
|
-
return { ...cellComp, basic: { ...cellComp.basic, attachments: attachments || [] } };
|
|
7259
|
-
}
|
|
7260
|
-
return cellComp;
|
|
7261
|
-
});
|
|
7262
|
-
return { ...cell, components: updatedCellComponents };
|
|
7263
|
-
}
|
|
7264
|
-
return cell;
|
|
7193
|
+
const updateCell = (cell) => {
|
|
7194
|
+
if (cell.components) {
|
|
7195
|
+
return {
|
|
7196
|
+
...cell,
|
|
7197
|
+
components: cell.components.map((cellComp) => cellComp.id === componentId
|
|
7198
|
+
? { ...cellComp, basic: { ...cellComp.basic, attachments: attachments || [] } }
|
|
7199
|
+
: cellComp)
|
|
7200
|
+
};
|
|
7265
7201
|
}
|
|
7266
|
-
|
|
7202
|
+
return cell;
|
|
7203
|
+
};
|
|
7204
|
+
const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map(updateCell) : updateCell(row));
|
|
7267
7205
|
return { ...comp, cells: updatedCells };
|
|
7268
7206
|
}
|
|
7269
7207
|
return comp;
|
|
7270
7208
|
});
|
|
7271
7209
|
onFormDataChange?.(updatedComponents);
|
|
7272
7210
|
}, renderFormComponent: (field) => {
|
|
7273
|
-
// CRITICAL: Pass the field to renderFormComponent which has access to latest formValues
|
|
7274
|
-
// renderFormComponent uses formValues[field.id] internally, so it will get the correct value
|
|
7275
7211
|
return renderFormComponent(field);
|
|
7276
|
-
} }) }));
|
|
7212
|
+
}, shouldShowComponent: shouldShowComponent }) }));
|
|
7277
7213
|
case 'datagrid':
|
|
7278
7214
|
return (jsxRuntime.jsx(DfFormDataGrid, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, onNotesChange: (componentId, notes) => {
|
|
7279
7215
|
handleComponentNotesChange(componentId, notes);
|
|
@@ -7583,12 +7519,13 @@ const ensureComponentHasId = (component) => {
|
|
|
7583
7519
|
}
|
|
7584
7520
|
return component;
|
|
7585
7521
|
};
|
|
7586
|
-
const SimpleTableComponent = ({ component, mode, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue }) => {
|
|
7522
|
+
const SimpleTableComponent = ({ component, mode, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue, shouldShowComponent }) => {
|
|
7587
7523
|
const formValue = formData[component.id];
|
|
7524
|
+
const isVisible = shouldShowComponent ? shouldShowComponent(component.id) : true;
|
|
7588
7525
|
// Check if component has notes or attachments for submission view
|
|
7589
7526
|
const hasSubmissionData = mode === 'preview' && ((component.basic?.notes && component.basic.notes.trim().length > 0) ||
|
|
7590
7527
|
(component.basic?.attachments && Array.isArray(component.basic.attachments) && component.basic.attachments.length > 0));
|
|
7591
|
-
return (jsxRuntime.jsxs("div", { className:
|
|
7528
|
+
return (jsxRuntime.jsxs("div", { className: `simple-table-component ${(!isVisible && mode !== 'edit') ? 'conditionally-hidden' : ''}`, style: { display: (isVisible || mode === 'edit') ? undefined : 'none' }, children: [renderFormComponent(component), mode === 'test' && !['section', 'table', 'heading', 'file', 'instructions', 'signature', 'location', 'datagrid'].includes(component.name) && (jsxRuntime.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 && (jsxRuntime.jsx(ComponentSubmissionActions, { component: component }))] }));
|
|
7592
7529
|
};
|
|
7593
7530
|
const DraggableTableComponent = ({ component, selectedComponent, mode, onComponentSelect, onComponentDelete, onComponentEdit, renderFormComponent, isOverlay = false, }) => {
|
|
7594
7531
|
const { attributes, listeners, setNodeRef, transform, transition, isDragging, isSorting, } = sortable.useSortable({
|
|
@@ -7609,7 +7546,7 @@ const DraggableTableComponent = ({ component, selectedComponent, mode, onCompone
|
|
|
7609
7546
|
onComponentDelete(component, e);
|
|
7610
7547
|
}, type: "button", title: "Delete Component", children: jsxRuntime.jsx(lucideReact.Trash2, { size: 12 }) })] }))] }));
|
|
7611
7548
|
};
|
|
7612
|
-
const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, tableId, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue }) => {
|
|
7549
|
+
const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, tableId, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue, shouldShowComponent }) => {
|
|
7613
7550
|
const dropZoneId = `table-cell-${tableId}-${cell.row}-${cell.column}`;
|
|
7614
7551
|
const { setNodeRef, isOver } = core.useDroppable({
|
|
7615
7552
|
id: dropZoneId,
|
|
@@ -7644,7 +7581,7 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
|
|
|
7644
7581
|
cell.components.map((component) => {
|
|
7645
7582
|
// Only ensure ID if it's truly missing - don't regenerate existing IDs
|
|
7646
7583
|
const componentWithId = component.id ? component : ensureComponentHasId(component);
|
|
7647
|
-
return (jsxRuntime.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));
|
|
7584
|
+
return (jsxRuntime.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, shouldShowComponent: shouldShowComponent }, componentWithId.id));
|
|
7648
7585
|
}))) : (
|
|
7649
7586
|
// Only show drop zone content in edit mode
|
|
7650
7587
|
mode === 'edit' ? (jsxRuntime.jsx("div", { className: "empty-cell-placeholder", children: jsxRuntime.jsxs("div", { className: "cell-info", children: [jsxRuntime.jsx("span", { className: "drop-zone-text", children: "Drag and Drop a form component" }), jsxRuntime.jsxs("span", { className: "cell-coordinates", children: ["Cell (", cell.row + 1, ", ", cell.column + 1, ")"] })] }) })) : (
|
|
@@ -7655,44 +7592,19 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
|
|
|
7655
7592
|
visibility: 'hidden' // Hide content but maintain space
|
|
7656
7593
|
}, children: "\u00A0" }))) }) }));
|
|
7657
7594
|
};
|
|
7658
|
-
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 }) => {
|
|
7659
|
-
const [isCollapsed, setIsCollapsed] = React.useState(false);
|
|
7660
|
-
//
|
|
7661
|
-
//
|
|
7662
|
-
const normalizedCells = React.useMemo(() => {
|
|
7663
|
-
const raw = properties.cells;
|
|
7664
|
-
if (!raw || !Array.isArray(raw) || raw.length === 0)
|
|
7665
|
-
return [];
|
|
7666
|
-
// DEBUG: Log cell structure to understand API format
|
|
7667
|
-
console.log('[DfFormTable] raw cells (first item):', JSON.stringify(raw[0], null, 2));
|
|
7668
|
-
console.log('[DfFormTable] is first item array?', Array.isArray(raw[0]));
|
|
7669
|
-
console.log('[DfFormTable] total cells:', raw.length);
|
|
7670
|
-
// Check if it's already a 2D array (first element is an array)
|
|
7671
|
-
if (Array.isArray(raw[0])) {
|
|
7672
|
-
console.log('[DfFormTable] Using 2D array format');
|
|
7673
|
-
return raw;
|
|
7674
|
-
}
|
|
7675
|
-
// It's a flat 1D array — reconstruct 2D using each cell's row/column
|
|
7676
|
-
console.log('[DfFormTable] Using 1D flat format, reconstructing 2D grid');
|
|
7677
|
-
const grid = [];
|
|
7678
|
-
raw.forEach((cell) => {
|
|
7679
|
-
const r = typeof cell.row === 'number' ? cell.row : 0;
|
|
7680
|
-
const c = typeof cell.column === 'number' ? cell.column : 0;
|
|
7681
|
-
console.log(`[DfFormTable] Cell at row=${r} col=${c}, components count:`, cell.components?.length ?? 0);
|
|
7682
|
-
if (!grid[r])
|
|
7683
|
-
grid[r] = [];
|
|
7684
|
-
grid[r][c] = cell;
|
|
7685
|
-
});
|
|
7686
|
-
return grid;
|
|
7687
|
-
}, [properties.cells]);
|
|
7595
|
+
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, shouldShowComponent }) => {
|
|
7596
|
+
const [isCollapsed, setIsCollapsed] = React.useState(false);
|
|
7597
|
+
// Cells may be 2D (row arrays) or 1D (flat cells) depending on API format.
|
|
7598
|
+
// The useMemo in DfFormPreview ensures IDs, but structure may still vary.
|
|
7688
7599
|
// Check if table has any components in any cells
|
|
7689
|
-
const hasAnyComponents =
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
//
|
|
7694
|
-
|
|
7695
|
-
|
|
7600
|
+
const hasAnyComponents = properties.cells?.some((row) => {
|
|
7601
|
+
if (Array.isArray(row)) {
|
|
7602
|
+
return row.some((cell) => cell && cell.components && cell.components.length > 0);
|
|
7603
|
+
}
|
|
7604
|
+
// Handle flat 1D cell
|
|
7605
|
+
const cell = row;
|
|
7606
|
+
return cell && cell.components && cell.components.length > 0;
|
|
7607
|
+
}) || false;
|
|
7696
7608
|
const handleTableClick = React.useCallback((event) => {
|
|
7697
7609
|
event.stopPropagation();
|
|
7698
7610
|
onSelect?.();
|
|
@@ -7708,54 +7620,46 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7708
7620
|
};
|
|
7709
7621
|
const handleComponentDelete = React.useCallback((component, event) => {
|
|
7710
7622
|
event.stopPropagation();
|
|
7711
|
-
|
|
7712
|
-
|
|
7623
|
+
const updatedCells = properties.cells.map((row) => {
|
|
7624
|
+
if (Array.isArray(row)) {
|
|
7625
|
+
return row.map((cell) => {
|
|
7626
|
+
if (cell && cell.components && cell.components.some((comp) => comp.id === component.id)) {
|
|
7627
|
+
return { ...cell, components: cell.components.filter((comp) => comp.id !== component.id) };
|
|
7628
|
+
}
|
|
7629
|
+
return cell;
|
|
7630
|
+
});
|
|
7631
|
+
}
|
|
7632
|
+
// Handle flat 1D cell
|
|
7633
|
+
const cell = row;
|
|
7713
7634
|
if (cell && cell.components && cell.components.some((comp) => comp.id === component.id)) {
|
|
7714
|
-
|
|
7715
|
-
return {
|
|
7716
|
-
...cell,
|
|
7717
|
-
components: filteredComponents
|
|
7718
|
-
};
|
|
7635
|
+
return { ...cell, components: cell.components.filter((comp) => comp.id !== component.id) };
|
|
7719
7636
|
}
|
|
7720
7637
|
return cell;
|
|
7721
|
-
})
|
|
7722
|
-
|
|
7723
|
-
if (onValueChange) {
|
|
7724
|
-
onValueChange({
|
|
7725
|
-
id,
|
|
7726
|
-
value: { ...properties, cells: updatedCells }
|
|
7727
|
-
});
|
|
7728
|
-
}
|
|
7729
|
-
// Don't call parent delete handler for table cell components
|
|
7730
|
-
// The parent delete handler is for deleting entire fields, not components within table cells
|
|
7638
|
+
});
|
|
7639
|
+
onValueChange?.({ id, value: { ...properties, cells: updatedCells } });
|
|
7731
7640
|
}, [onComponentDelete, properties, onValueChange, id]);
|
|
7732
|
-
//
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
};
|
|
7755
|
-
})
|
|
7756
|
-
: []
|
|
7757
|
-
})));
|
|
7758
|
-
}, [normalizedCells, id]); // Only recalculate if cells or table ID changes
|
|
7641
|
+
// Ensure all table cell components have IDs (matching website ensureTableCellComponentsHaveIds)
|
|
7642
|
+
const ensureCellComponentIds = (cell) => ({
|
|
7643
|
+
...cell,
|
|
7644
|
+
components: (cell?.components || []).map((comp) => {
|
|
7645
|
+
if (!comp.id || comp.id.trim() === '') {
|
|
7646
|
+
return { ...comp, id: `table-cell-${comp.name}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}` };
|
|
7647
|
+
}
|
|
7648
|
+
return comp;
|
|
7649
|
+
})
|
|
7650
|
+
});
|
|
7651
|
+
const ensureTableCellComponentsHaveIds = (cells) => {
|
|
7652
|
+
return cells.map((row) => {
|
|
7653
|
+
if (Array.isArray(row)) {
|
|
7654
|
+
return row.map(ensureCellComponentIds);
|
|
7655
|
+
}
|
|
7656
|
+
// Handle flat 1D cell
|
|
7657
|
+
return ensureCellComponentIds(row);
|
|
7658
|
+
});
|
|
7659
|
+
};
|
|
7660
|
+
const cellsWithIds = properties.cells && properties.cells.length > 0
|
|
7661
|
+
? ensureTableCellComponentsHaveIds(properties.cells)
|
|
7662
|
+
: [];
|
|
7759
7663
|
// CRITICAL FIX: Update the parent component with the cells that have proper IDs
|
|
7760
7664
|
// Skip this in package to prevent flickering - cells are managed by parent
|
|
7761
7665
|
// useEffect(() => {
|
|
@@ -7883,7 +7787,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7883
7787
|
fontSize: '14px',
|
|
7884
7788
|
textAlign: 'center'
|
|
7885
7789
|
}, children: columnName }, `header-${colIndex}`));
|
|
7886
|
-
}) }) })), jsxRuntime.jsx("tbody", { children: cellsWithIds.filter(row => Array.isArray(row) && row.length > 0).map((row, rowIndex) => (jsxRuntime.jsx("tr", { className: "table-row", children: row.filter(cell => cell != null).map((cell) => (jsxRuntime.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
|
+
}) }) })), jsxRuntime.jsx("tbody", { children: cellsWithIds.filter((row) => Array.isArray(row) && row.length > 0).map((row, rowIndex) => (jsxRuntime.jsx("tr", { className: "table-row", children: row.filter((cell) => cell != null).map((cell) => (jsxRuntime.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, shouldShowComponent: shouldShowComponent }, cell.id))) }, rowIndex))) })] })] }))] }));
|
|
7887
7791
|
};
|
|
7888
7792
|
|
|
7889
7793
|
var dfFormTable = /*#__PURE__*/Object.freeze({
|