df-ae-forms-package 1.0.76 → 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.js CHANGED
@@ -6021,14 +6021,22 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6021
6021
  }
6022
6022
  // Handle nested components in table cells
6023
6023
  if (component.cells && Array.isArray(component.cells)) {
6024
- component.cells.forEach((row, _rowIndex) => {
6025
- if (Array.isArray(row)) {
6026
- row.forEach((cell, _cellIndex) => {
6024
+ component.cells.forEach((rowOrCell, _rowIndex) => {
6025
+ // Handle 2D array (standard)
6026
+ if (Array.isArray(rowOrCell)) {
6027
+ rowOrCell.forEach((cell, _cellIndex) => {
6027
6028
  if (cell && cell.components && Array.isArray(cell.components)) {
6028
6029
  initializeComponentValues(cell.components, values);
6029
6030
  }
6030
6031
  });
6031
6032
  }
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
+ }
6032
6040
  });
6033
6041
  }
6034
6042
  // Handle nested components in datagrid entries
@@ -6235,12 +6243,22 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6235
6243
  }
6236
6244
  // Handle nested components in table cells
6237
6245
  if (component.cells && Array.isArray(component.cells)) {
6238
- component.cells.forEach((row) => {
6239
- row.forEach((cell) => {
6246
+ component.cells.forEach((rowOrCell) => {
6247
+ // Handle 2D array (standard)
6248
+ if (Array.isArray(rowOrCell)) {
6249
+ rowOrCell.forEach((cell) => {
6250
+ if (cell.components && Array.isArray(cell.components)) {
6251
+ evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
6252
+ }
6253
+ });
6254
+ }
6255
+ // Handle 1D array (flat) structure
6256
+ else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
6257
+ const cell = rowOrCell;
6240
6258
  if (cell.components && Array.isArray(cell.components)) {
6241
6259
  evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
6242
6260
  }
6243
- });
6261
+ }
6244
6262
  });
6245
6263
  }
6246
6264
  // Handle nested components in datagrid entries
@@ -7599,8 +7617,29 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
7599
7617
  };
7600
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 }) => {
7601
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]);
7602
7641
  // Check if table has any components in any cells
7603
- const hasAnyComponents = properties.cells?.some(row => row.some(cell => cell.components && cell.components.length > 0)) || false;
7642
+ const hasAnyComponents = normalizedCells.some(row => Array.isArray(row) && row.some(cell => cell && cell.components && cell.components.length > 0)) || false;
7604
7643
  // Initialize and update table cells when rows/columns change
7605
7644
  // CRITICAL: Skip cell initialization updates to prevent flickering when user types
7606
7645
  React.useEffect(() => {
@@ -7623,9 +7662,9 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7623
7662
  const handleComponentDelete = React.useCallback((component, event) => {
7624
7663
  event.stopPropagation();
7625
7664
  // Find and remove the component from the table cell
7626
- const updatedCells = properties.cells.map(row => row.map(cell => {
7627
- if (cell.components && cell.components.some(comp => comp.id === component.id)) {
7628
- 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);
7629
7668
  return {
7630
7669
  ...cell,
7631
7670
  components: filteredComponents
@@ -7645,12 +7684,13 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7645
7684
  }, [onComponentDelete, properties, onValueChange, id]);
7646
7685
  // CRITICAL FIX: Ensure all table cell components have proper IDs with table and cell position
7647
7686
  // Use useMemo to prevent ID regeneration on every render
7687
+ // Uses normalizedCells so it works whether API returns 1D or 2D cell arrays
7648
7688
  const cellsWithIds = React.useMemo(() => {
7649
- if (!properties.cells)
7689
+ if (!normalizedCells || normalizedCells.length === 0)
7650
7690
  return [];
7651
- return properties.cells.map((row, rowIndex) => row.map((cell, cellIndex) => ({
7691
+ return normalizedCells.map((row, rowIndex) => (Array.isArray(row) ? row : []).map((cell, cellIndex) => ({
7652
7692
  ...cell,
7653
- components: (cell.components && Array.isArray(cell.components))
7693
+ components: (cell && cell.components && Array.isArray(cell.components))
7654
7694
  ? cell.components.map((comp, compIndex) => {
7655
7695
  // CRITICAL: Only generate ID if it's missing - never regenerate existing IDs
7656
7696
  // This prevents component remounting and losing input state
@@ -7668,7 +7708,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7668
7708
  })
7669
7709
  : []
7670
7710
  })));
7671
- }, [properties.cells, id]); // Only recalculate if cells or table ID changes
7711
+ }, [normalizedCells, id]); // Only recalculate if cells or table ID changes
7672
7712
  // CRITICAL FIX: Update the parent component with the cells that have proper IDs
7673
7713
  // Skip this in package to prevent flickering - cells are managed by parent
7674
7714
  // useEffect(() => {