@infinite-table/infinite-react 0.2.4 → 0.2.5

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/index.d.ts CHANGED
@@ -675,7 +675,7 @@ declare module "components/InfiniteTable/types/InfiniteTableColumn" {
675
675
  draggable?: boolean;
676
676
  resizable?: boolean;
677
677
  comparer?: InfiniteTableColumnComparer<T>;
678
- hiddenWhenGrouped?: boolean;
678
+ defaultHiddenWhenGrouped?: boolean;
679
679
  align?: InfiniteTableColumnAlign;
680
680
  verticalAlign?: InfiniteTableColumnVerticalAlign;
681
681
  columnGroup?: string;
@@ -1136,6 +1136,7 @@ declare module "components/InfiniteTable/types/InfiniteTableProps" {
1136
1136
  defaultWidth?: number;
1137
1137
  defaultFlex?: number;
1138
1138
  defaultPinned?: InfiniteTableColumnPinnedValues;
1139
+ defaultHiddenWhenGrouped?: boolean;
1139
1140
  header?: InfiniteTableColumn<T>['header'];
1140
1141
  comparer?: InfiniteTableColumn<T>['comparer'];
1141
1142
  draggable?: InfiniteTableColumn<T>['draggable'];
@@ -1418,6 +1419,7 @@ declare module "components/InfiniteTable/types/InfiniteTableState" {
1418
1419
  computedColumnGroups: InfiniteTablePropColumnGroupsMap;
1419
1420
  rowHeightCSSVar: string;
1420
1421
  headerHeightCSSVar: string;
1422
+ controlledColumnVisibility: boolean;
1421
1423
  }
1422
1424
  export type InfiniteTableActions<T> = ComponentStateActions<InfiniteTableState<T>>;
1423
1425
  export interface InfiniteTableState<T> extends InfiniteTableMappedState<T>, InfiniteTableDerivedState<T>, InfiniteTableSetupState<T> {
@@ -1666,7 +1668,6 @@ declare module "components/InfiniteTable/utils/getComputedVisibleColumns" {
1666
1668
  index: number;
1667
1669
  };
1668
1670
  };
1669
- export const IS_GROUP_COLUMN_ID: (columnId: string) => boolean;
1670
1671
  export type GetComputedVisibleColumnsResult<T> = {
1671
1672
  computedRemainingSpace: number;
1672
1673
  computedPinnedStartColumnsWidth: number;
package/index.esm.js CHANGED
@@ -856,6 +856,7 @@ var mapPropsToState = (params) => {
856
856
  });
857
857
  const computedColumns = state.columnsWhenGrouping || state.columnsWhenInlineGroupRenderStrategy || state.columns;
858
858
  return {
859
+ controlledColumnVisibility: !!props.columnVisibility,
859
860
  groupRenderStrategy,
860
861
  groupBy,
861
862
  computedColumns,
@@ -1389,6 +1390,7 @@ var getComputedVisibleColumns = ({
1389
1390
  const result2 = __spreadProps(__spreadValues({
1390
1391
  align: colType.align,
1391
1392
  verticalAlign: colType.verticalAlign,
1393
+ defaultHiddenWhenGrouped: colType.defaultHiddenWhenGrouped,
1392
1394
  valueGetter: colType.valueGetter,
1393
1395
  renderValue: colType.renderValue,
1394
1396
  render: colType.render
@@ -4082,7 +4084,7 @@ function useColumnsWhen() {
4082
4084
  }, [pivotTotalColumnPosition]);
4083
4085
  useColumnsWhenInlineGroupRenderStrategy(groupByMap);
4084
4086
  const { toggleGroupRow } = useColumnsWhenGrouping();
4085
- useHideEmptyGroupColumns();
4087
+ useHideColumns();
4086
4088
  return { toggleGroupRow };
4087
4089
  }
4088
4090
  function useColumnsWhenInlineGroupRenderStrategy(groupByMap) {
@@ -4204,9 +4206,10 @@ function useColumnsWhenGrouping() {
4204
4206
  ]);
4205
4207
  return { toggleGroupRow };
4206
4208
  }
4207
- function useHideEmptyGroupColumns() {
4209
+ function useHideColumns() {
4208
4210
  const {
4209
4211
  componentState: {
4212
+ dataArray,
4210
4213
  groupBy,
4211
4214
  groupRowsState,
4212
4215
  originalLazyGroupDataChangeDetect
@@ -4217,18 +4220,19 @@ function useHideEmptyGroupColumns() {
4217
4220
  getComponentState,
4218
4221
  componentActions,
4219
4222
  componentState: {
4223
+ columnTypes,
4224
+ computedColumns,
4220
4225
  columnsWhenGrouping: generatedColumns,
4221
4226
  hideEmptyGroupColumns,
4222
4227
  groupRenderStrategy
4223
4228
  }
4224
4229
  } = useComponentState();
4225
4230
  useEffect9(() => {
4226
- if (groupRenderStrategy !== "multi-column") {
4231
+ if (groupRenderStrategy !== "multi-column" || !hideEmptyGroupColumns) {
4227
4232
  return;
4228
4233
  }
4229
4234
  const groupsLength = groupBy.length;
4230
4235
  let expandedGroupsLevel = 0;
4231
- const { dataArray } = getDataSourceState();
4232
4236
  const len = dataArray.length;
4233
4237
  for (let i = 0; i < len; i++) {
4234
4238
  const data = dataArray[i];
@@ -4238,10 +4242,10 @@ function useHideEmptyGroupColumns() {
4238
4242
  }
4239
4243
  }
4240
4244
  const currentState = getComponentState();
4241
- const { computedColumns } = currentState;
4245
+ const { computedColumns: computedColumns2 } = currentState;
4242
4246
  let updated = false;
4243
4247
  const columnVisibility = __spreadValues({}, currentState.columnVisibility);
4244
- const cols = computedColumns;
4248
+ const cols = computedColumns2;
4245
4249
  groupBy.forEach(({ field, column: groupColumn }, index) => {
4246
4250
  const colId = (groupColumn == null ? void 0 : groupColumn.id) || `group-by-${field}`;
4247
4251
  let col = cols.get(colId);
@@ -4265,9 +4269,36 @@ function useHideEmptyGroupColumns() {
4265
4269
  generatedColumns,
4266
4270
  originalLazyGroupDataChangeDetect,
4267
4271
  groupBy,
4272
+ hideEmptyGroupColumns ? dataArray : null,
4268
4273
  hideEmptyGroupColumns ? groupRowsState : null,
4269
4274
  hideEmptyGroupColumns
4270
4275
  ]);
4276
+ useEffect9(() => {
4277
+ const isGrouped = groupBy.length > 0;
4278
+ const currentState = getComponentState();
4279
+ const { controlledColumnVisibility, columnVisibility } = currentState;
4280
+ if (controlledColumnVisibility) {
4281
+ return;
4282
+ }
4283
+ const newColumnVisibility = __spreadValues({}, columnVisibility);
4284
+ let updated = false;
4285
+ computedColumns.forEach((col, id) => {
4286
+ if (col.defaultHiddenWhenGrouped) {
4287
+ const nowHidden = columnVisibility[id] === false;
4288
+ if (!nowHidden && isGrouped) {
4289
+ updated = true;
4290
+ newColumnVisibility[id] = false;
4291
+ }
4292
+ if (nowHidden && !isGrouped) {
4293
+ updated = true;
4294
+ delete newColumnVisibility[id];
4295
+ }
4296
+ }
4297
+ });
4298
+ if (updated) {
4299
+ componentActions.columnVisibility = newColumnVisibility;
4300
+ }
4301
+ }, [computedColumns, columnTypes, groupBy]);
4271
4302
  }
4272
4303
  function getColumnsWhenGrouping(params) {
4273
4304
  const {
@@ -7739,7 +7770,7 @@ var useLicense = (licenseKey = "") => {
7739
7770
  const valid = useMemo12(() => {
7740
7771
  let valid2 = isValidLicense(licenseKey, {
7741
7772
  publishedAt: 1624970570587,
7742
- version: "0.2.4"
7773
+ version: "0.2.5"
7743
7774
  });
7744
7775
  if (!licenseKey && !valid2 && isInsideSandbox) {
7745
7776
  return true;
package/index.js CHANGED
@@ -873,6 +873,7 @@ var mapPropsToState = (params) => {
873
873
  });
874
874
  const computedColumns = state.columnsWhenGrouping || state.columnsWhenInlineGroupRenderStrategy || state.columns;
875
875
  return {
876
+ controlledColumnVisibility: !!props.columnVisibility,
876
877
  groupRenderStrategy,
877
878
  groupBy,
878
879
  computedColumns,
@@ -1398,6 +1399,7 @@ var getComputedVisibleColumns = ({
1398
1399
  const result2 = __spreadProps(__spreadValues({
1399
1400
  align: colType.align,
1400
1401
  verticalAlign: colType.verticalAlign,
1402
+ defaultHiddenWhenGrouped: colType.defaultHiddenWhenGrouped,
1401
1403
  valueGetter: colType.valueGetter,
1402
1404
  renderValue: colType.renderValue,
1403
1405
  render: colType.render
@@ -4068,7 +4070,7 @@ function useColumnsWhen() {
4068
4070
  }, [pivotTotalColumnPosition]);
4069
4071
  useColumnsWhenInlineGroupRenderStrategy(groupByMap);
4070
4072
  const { toggleGroupRow } = useColumnsWhenGrouping();
4071
- useHideEmptyGroupColumns();
4073
+ useHideColumns();
4072
4074
  return { toggleGroupRow };
4073
4075
  }
4074
4076
  function useColumnsWhenInlineGroupRenderStrategy(groupByMap) {
@@ -4190,9 +4192,10 @@ function useColumnsWhenGrouping() {
4190
4192
  ]);
4191
4193
  return { toggleGroupRow };
4192
4194
  }
4193
- function useHideEmptyGroupColumns() {
4195
+ function useHideColumns() {
4194
4196
  const {
4195
4197
  componentState: {
4198
+ dataArray,
4196
4199
  groupBy,
4197
4200
  groupRowsState,
4198
4201
  originalLazyGroupDataChangeDetect
@@ -4203,18 +4206,19 @@ function useHideEmptyGroupColumns() {
4203
4206
  getComponentState,
4204
4207
  componentActions,
4205
4208
  componentState: {
4209
+ columnTypes,
4210
+ computedColumns,
4206
4211
  columnsWhenGrouping: generatedColumns,
4207
4212
  hideEmptyGroupColumns,
4208
4213
  groupRenderStrategy
4209
4214
  }
4210
4215
  } = useComponentState();
4211
4216
  (0, import_react17.useEffect)(() => {
4212
- if (groupRenderStrategy !== "multi-column") {
4217
+ if (groupRenderStrategy !== "multi-column" || !hideEmptyGroupColumns) {
4213
4218
  return;
4214
4219
  }
4215
4220
  const groupsLength = groupBy.length;
4216
4221
  let expandedGroupsLevel = 0;
4217
- const { dataArray } = getDataSourceState();
4218
4222
  const len = dataArray.length;
4219
4223
  for (let i = 0; i < len; i++) {
4220
4224
  const data = dataArray[i];
@@ -4224,10 +4228,10 @@ function useHideEmptyGroupColumns() {
4224
4228
  }
4225
4229
  }
4226
4230
  const currentState = getComponentState();
4227
- const { computedColumns } = currentState;
4231
+ const { computedColumns: computedColumns2 } = currentState;
4228
4232
  let updated = false;
4229
4233
  const columnVisibility = __spreadValues({}, currentState.columnVisibility);
4230
- const cols = computedColumns;
4234
+ const cols = computedColumns2;
4231
4235
  groupBy.forEach(({ field, column: groupColumn }, index) => {
4232
4236
  const colId = (groupColumn == null ? void 0 : groupColumn.id) || `group-by-${field}`;
4233
4237
  let col = cols.get(colId);
@@ -4251,9 +4255,36 @@ function useHideEmptyGroupColumns() {
4251
4255
  generatedColumns,
4252
4256
  originalLazyGroupDataChangeDetect,
4253
4257
  groupBy,
4258
+ hideEmptyGroupColumns ? dataArray : null,
4254
4259
  hideEmptyGroupColumns ? groupRowsState : null,
4255
4260
  hideEmptyGroupColumns
4256
4261
  ]);
4262
+ (0, import_react17.useEffect)(() => {
4263
+ const isGrouped = groupBy.length > 0;
4264
+ const currentState = getComponentState();
4265
+ const { controlledColumnVisibility, columnVisibility } = currentState;
4266
+ if (controlledColumnVisibility) {
4267
+ return;
4268
+ }
4269
+ const newColumnVisibility = __spreadValues({}, columnVisibility);
4270
+ let updated = false;
4271
+ computedColumns.forEach((col, id) => {
4272
+ if (col.defaultHiddenWhenGrouped) {
4273
+ const nowHidden = columnVisibility[id] === false;
4274
+ if (!nowHidden && isGrouped) {
4275
+ updated = true;
4276
+ newColumnVisibility[id] = false;
4277
+ }
4278
+ if (nowHidden && !isGrouped) {
4279
+ updated = true;
4280
+ delete newColumnVisibility[id];
4281
+ }
4282
+ }
4283
+ });
4284
+ if (updated) {
4285
+ componentActions.columnVisibility = newColumnVisibility;
4286
+ }
4287
+ }, [computedColumns, columnTypes, groupBy]);
4257
4288
  }
4258
4289
  function getColumnsWhenGrouping(params) {
4259
4290
  const {
@@ -7646,7 +7677,7 @@ var useLicense = (licenseKey = "") => {
7646
7677
  const valid = (0, import_react43.useMemo)(() => {
7647
7678
  let valid2 = isValidLicense(licenseKey, {
7648
7679
  publishedAt: 1624970570587,
7649
- version: "0.2.4"
7680
+ version: "0.2.5"
7650
7681
  });
7651
7682
  if (!licenseKey && !valid2 && isInsideSandbox) {
7652
7683
  return true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infinite-table/infinite-react",
3
3
  "description": "Infinite Table for React",
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
5
5
  "main": "index.js",
6
6
  "module": "index.esm.js",
7
7
  "typings": "index.d.ts",
@@ -14,5 +14,5 @@
14
14
  },
15
15
  "license": "Commercial & Open Source",
16
16
  "//": "will be updated at build time",
17
- "publishedAt": 1644430025786
17
+ "publishedAt": 1644855707573
18
18
  }