df-ae-forms-package 1.0.77 → 1.0.78
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.esm.js +30 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +30 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7617,8 +7617,29 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
|
|
|
7617
7617
|
};
|
|
7618
7618
|
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 }) => {
|
|
7619
7619
|
const [isCollapsed, setIsCollapsed] = React.useState(false); // Always start expanded to show drop zones
|
|
7620
|
+
// Normalize cells: API may return a flat 1D array of cells (each with .row/.column)
|
|
7621
|
+
// or a proper 2D array of rows. Always convert to 2D for consistent rendering.
|
|
7622
|
+
const normalizedCells = React.useMemo(() => {
|
|
7623
|
+
const raw = properties.cells;
|
|
7624
|
+
if (!raw || !Array.isArray(raw) || raw.length === 0)
|
|
7625
|
+
return [];
|
|
7626
|
+
// Check if it's already a 2D array (first element is an array)
|
|
7627
|
+
if (Array.isArray(raw[0])) {
|
|
7628
|
+
return raw;
|
|
7629
|
+
}
|
|
7630
|
+
// It's a flat 1D array — reconstruct 2D using each cell's row/column
|
|
7631
|
+
const grid = [];
|
|
7632
|
+
raw.forEach((cell) => {
|
|
7633
|
+
const r = typeof cell.row === 'number' ? cell.row : 0;
|
|
7634
|
+
const c = typeof cell.column === 'number' ? cell.column : 0;
|
|
7635
|
+
if (!grid[r])
|
|
7636
|
+
grid[r] = [];
|
|
7637
|
+
grid[r][c] = cell;
|
|
7638
|
+
});
|
|
7639
|
+
return grid;
|
|
7640
|
+
}, [properties.cells]);
|
|
7620
7641
|
// Check if table has any components in any cells
|
|
7621
|
-
const hasAnyComponents =
|
|
7642
|
+
const hasAnyComponents = normalizedCells.some(row => Array.isArray(row) && row.some(cell => cell && cell.components && cell.components.length > 0)) || false;
|
|
7622
7643
|
// Initialize and update table cells when rows/columns change
|
|
7623
7644
|
// CRITICAL: Skip cell initialization updates to prevent flickering when user types
|
|
7624
7645
|
React.useEffect(() => {
|
|
@@ -7641,9 +7662,9 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7641
7662
|
const handleComponentDelete = React.useCallback((component, event) => {
|
|
7642
7663
|
event.stopPropagation();
|
|
7643
7664
|
// Find and remove the component from the table cell
|
|
7644
|
-
const updatedCells =
|
|
7645
|
-
if (cell.components && cell.components.some(comp => comp.id === component.id)) {
|
|
7646
|
-
const filteredComponents = cell.components.filter(comp => comp.id !== component.id);
|
|
7665
|
+
const updatedCells = normalizedCells.map(row => (Array.isArray(row) ? row : []).map(cell => {
|
|
7666
|
+
if (cell && cell.components && cell.components.some((comp) => comp.id === component.id)) {
|
|
7667
|
+
const filteredComponents = cell.components.filter((comp) => comp.id !== component.id);
|
|
7647
7668
|
return {
|
|
7648
7669
|
...cell,
|
|
7649
7670
|
components: filteredComponents
|
|
@@ -7663,12 +7684,13 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7663
7684
|
}, [onComponentDelete, properties, onValueChange, id]);
|
|
7664
7685
|
// CRITICAL FIX: Ensure all table cell components have proper IDs with table and cell position
|
|
7665
7686
|
// Use useMemo to prevent ID regeneration on every render
|
|
7687
|
+
// Uses normalizedCells so it works whether API returns 1D or 2D cell arrays
|
|
7666
7688
|
const cellsWithIds = React.useMemo(() => {
|
|
7667
|
-
if (!
|
|
7689
|
+
if (!normalizedCells || normalizedCells.length === 0)
|
|
7668
7690
|
return [];
|
|
7669
|
-
return
|
|
7691
|
+
return normalizedCells.map((row, rowIndex) => (Array.isArray(row) ? row : []).map((cell, cellIndex) => ({
|
|
7670
7692
|
...cell,
|
|
7671
|
-
components: (cell.components && Array.isArray(cell.components))
|
|
7693
|
+
components: (cell && cell.components && Array.isArray(cell.components))
|
|
7672
7694
|
? cell.components.map((comp, compIndex) => {
|
|
7673
7695
|
// CRITICAL: Only generate ID if it's missing - never regenerate existing IDs
|
|
7674
7696
|
// This prevents component remounting and losing input state
|
|
@@ -7686,7 +7708,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7686
7708
|
})
|
|
7687
7709
|
: []
|
|
7688
7710
|
})));
|
|
7689
|
-
}, [
|
|
7711
|
+
}, [normalizedCells, id]); // Only recalculate if cells or table ID changes
|
|
7690
7712
|
// CRITICAL FIX: Update the parent component with the cells that have proper IDs
|
|
7691
7713
|
// Skip this in package to prevent flickering - cells are managed by parent
|
|
7692
7714
|
// useEffect(() => {
|