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