@linzjs/step-ag-grid 29.11.0 → 29.11.1

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.
@@ -6,7 +6,6 @@ export interface AutoSizeColumnsProps {
6
6
  skipHeader?: boolean;
7
7
  colIds?: Set<string> | string[];
8
8
  userSizedColIds?: Set<string>;
9
- includeFlex?: boolean;
10
9
  }
11
10
  export type AutoSizeColumnsResult = {
12
11
  width: number;
@@ -2814,7 +2814,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2814
2814
  autoSizeColumns({
2815
2815
  skipHeader,
2816
2816
  userSizedColIds: new Set(userSizedColIds.current.keys()),
2817
- includeFlex: true,
2818
2817
  });
2819
2818
  // Auto-size failed retry later
2820
2819
  if (!autoSizeResult) {
@@ -5346,6 +5345,8 @@ const waitForCondition = async (error, condition, timeoutMs) => {
5346
5345
  return false;
5347
5346
  };
5348
5347
 
5348
+ const colStateId = (colState) => colState.colId;
5349
+ const colStateFlexed = (colState) => !!colState.flex;
5349
5350
  /**
5350
5351
  * Context for AgGrid operations.
5351
5352
  * Make sure you wrap AgGrid in this.
@@ -5627,20 +5628,30 @@ const GridContextProvider = (props) => {
5627
5628
  }, [gridApiOp]);
5628
5629
  /**
5629
5630
  * Resize columns to fit container
5631
+ *
5632
+ * This is used to calculate the preferred size of columns.
5633
+ * It sizes the flex columns first and then clears the calculated width.
5634
+ * If you don't clear flex column widths ag-grid gets confused and does random sizing's.
5635
+ * Then we size the flexed columns.
5630
5636
  */
5631
- const autoSizeColumns = React.useCallback(({ skipHeader, colIds, userSizedColIds, includeFlex } = {}) => {
5637
+ const autoSizeColumns = React.useCallback(({ skipHeader, colIds, userSizedColIds } = {}) => {
5632
5638
  if (!gridApi || !gridApi.getColumnState()) {
5633
5639
  return null;
5634
5640
  }
5635
5641
  const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
5636
- const colsToResize = gridApi.getColumnState()?.filter?.((colState) => {
5642
+ const colStates = gridApi.getColumnState();
5643
+ const relevantCols = colStates?.filter((colState) => {
5637
5644
  const colId = colState.colId;
5638
- return ((lodashEs.isEmpty(colIdsSet) || colIdsSet.has(colId)) &&
5639
- !userSizedColIds?.has(colId) &&
5640
- (includeFlex || !colState.flex));
5645
+ return (lodashEs.isEmpty(colIdsSet) || colIdsSet.has(colId)) && !userSizedColIds?.has(colId);
5641
5646
  });
5642
- if (!lodashEs.isEmpty(colsToResize)) {
5643
- gridApi.autoSizeColumns(colsToResize.map((colState) => colState.colId), skipHeader);
5647
+ const [flexColumns, nonFlexColumns] = lodashEs.partition(relevantCols, colStateFlexed);
5648
+ // If we don't reset the flex columns auto size it causes issues with random resizing of flex columns
5649
+ if (!lodashEs.isEmpty(flexColumns)) {
5650
+ gridApi.autoSizeColumns(flexColumns.map(colStateId), skipHeader);
5651
+ gridApi.resetColumnState();
5652
+ }
5653
+ if (!lodashEs.isEmpty(nonFlexColumns)) {
5654
+ gridApi.autoSizeColumns(nonFlexColumns.map(colStateId), skipHeader);
5644
5655
  }
5645
5656
  return {
5646
5657
  width: lodashEs.sumBy(gridApi.getColumnState().filter((col) => !col.hide), 'width'),