@infinite-table/infinite-react 0.4.13 → 0.5.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.
- package/.vscode/settings.json +3 -0
- package/API.md +0 -0
- package/build/buildPackageJson.js +43 -0
- package/build/scripts/test.js +37 -0
- package/bundler.config.js +25 -0
- package/globals.d.ts +7 -0
- package/package.json +102 -3
- package/rollup.config.js +15 -0
- package/run-build-deepmap.js +47 -0
- package/run-build.js +45 -0
- package/run-dts-concat.js +21 -0
- package/src/components/CSSVariableWatch.tsx +82 -0
- package/src/components/DataSource/BooleanCollectionState.ts +214 -0
- package/src/components/DataSource/BooleanDeepCollectionState.ts +208 -0
- package/src/components/DataSource/DataSourceContext.ts +20 -0
- package/src/components/DataSource/GroupRowsState.ts +74 -0
- package/src/components/DataSource/Indexer.ts +27 -0
- package/src/components/DataSource/RowSelectionState.ts +763 -0
- package/src/components/DataSource/defaultFilterTypes.ts +64 -0
- package/src/components/DataSource/index.tsx +108 -0
- package/src/components/DataSource/privateHooks/getChangeDetect.ts +7 -0
- package/src/components/DataSource/privateHooks/useLoadData.ts +783 -0
- package/src/components/DataSource/publicHooks/useDataSource.ts +19 -0
- package/src/components/DataSource/publicHooks/useDataSourceActions.ts +14 -0
- package/src/components/DataSource/state/getInitialState.ts +494 -0
- package/src/components/DataSource/state/normalizeSortInfo.ts +35 -0
- package/src/components/DataSource/state/reducer.ts +466 -0
- package/src/components/DataSource/state/rowInfoStatus.ts +27 -0
- package/src/components/DataSource/types.ts +548 -0
- package/src/components/HeadlessTable/HeadlessTableWithPinnedContainers.tsx +142 -0
- package/src/components/HeadlessTable/MappedCells.ts +251 -0
- package/src/components/HeadlessTable/RawTable.tsx +98 -0
- package/src/components/HeadlessTable/ReactHeadlessTableRenderer.tsx +1516 -0
- package/src/components/HeadlessTable/index.tsx +234 -0
- package/src/components/InfiniteTable/InfiniteCls.css.ts +164 -0
- package/src/components/InfiniteTable/InfiniteTableContext.ts +16 -0
- package/src/components/InfiniteTable/api/getImperativeApi.ts +391 -0
- package/src/components/InfiniteTable/api/getSelectionApi.ts +364 -0
- package/src/components/InfiniteTable/api/type.ts +11 -0
- package/src/components/InfiniteTable/components/ActiveCellIndicator.css.ts +51 -0
- package/src/components/InfiniteTable/components/ActiveCellIndicator.tsx +116 -0
- package/src/components/InfiniteTable/components/ActiveRowIndicator.css.ts +56 -0
- package/src/components/InfiniteTable/components/ActiveRowIndicator.tsx +94 -0
- package/src/components/InfiniteTable/components/CheckBox.css.ts +13 -0
- package/src/components/InfiniteTable/components/CheckBox.tsx +96 -0
- package/src/components/InfiniteTable/components/FilterEditors.tsx +52 -0
- package/src/components/InfiniteTable/components/InfiniteTableBody/InfiniteTableBody.tsx +27 -0
- package/src/components/InfiniteTable/components/InfiniteTableBody/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableFooter/InfiniteTableFooter.tsx +31 -0
- package/src/components/InfiniteTable/components/InfiniteTableFooter/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableColumnHeaderFilter.tsx +102 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeader.tsx +163 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderCell.tsx +574 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderGroup.tsx +79 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderTypes.tsx +25 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderWrapper.tsx +185 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/GroupResizeHandle.tsx +159 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/ResizeHandle.css.ts +124 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/columnResizer.ts +166 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/index.tsx +146 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/buildColumnAndGroupTree.ts +240 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/header.css.ts +358 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/useColumnGroupResizeHandle.tsx +114 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/useColumnResizeHandle.tsx +146 -0
- package/src/components/InfiniteTable/components/InfiniteTableLicenseFooter/footer.css.ts +7 -0
- package/src/components/InfiniteTable/components/InfiniteTableLicenseFooter/index.tsx +110 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableCell.tsx +120 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableCellTypes.ts +74 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableColumnCell.tsx +457 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRow.tsx +107 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowClassName.ts +6 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowTypes.ts +32 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowUnvirtualized.tsx +75 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/columnRendering.tsx +263 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/row.css.ts +74 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/useRowDOMProps.ts +199 -0
- package/src/components/InfiniteTable/components/LoadMask.css.ts +34 -0
- package/src/components/InfiniteTable/components/LoadMask.tsx +27 -0
- package/src/components/InfiniteTable/components/ScrollbarPlaceholder.tsx +56 -0
- package/src/components/InfiniteTable/components/cell.css.ts +192 -0
- package/src/components/InfiniteTable/components/icons/ArrowDown.tsx +14 -0
- package/src/components/InfiniteTable/components/icons/ArrowUp.tsx +14 -0
- package/src/components/InfiniteTable/components/icons/ExpanderIcon.css.ts +31 -0
- package/src/components/InfiniteTable/components/icons/ExpanderIcon.tsx +63 -0
- package/src/components/InfiniteTable/components/icons/Icon.tsx +18 -0
- package/src/components/InfiniteTable/components/icons/InfiniteTableIconClassName.ts +1 -0
- package/src/components/InfiniteTable/components/icons/LoadingIcon.css.ts +8 -0
- package/src/components/InfiniteTable/components/icons/LoadingIcon.tsx +45 -0
- package/src/components/InfiniteTable/components/icons/MenuIcon.tsx +50 -0
- package/src/components/InfiniteTable/components/icons/SortIcon.tsx +113 -0
- package/src/components/InfiniteTable/eventHandlers/eventHandlerTypes.ts +57 -0
- package/src/components/InfiniteTable/eventHandlers/index.ts +95 -0
- package/src/components/InfiniteTable/eventHandlers/keyboardNavigation.ts +232 -0
- package/src/components/InfiniteTable/eventHandlers/keyboardSelection.ts +110 -0
- package/src/components/InfiniteTable/eventHandlers/onCellClick.ts +94 -0
- package/src/components/InfiniteTable/eventHandlers/onKeyDown.ts +25 -0
- package/src/components/InfiniteTable/hooks/adjustColumnOrderForAllColumns.ts +70 -0
- package/src/components/InfiniteTable/hooks/reorderColumnsOnDrag.ts +476 -0
- package/src/components/InfiniteTable/hooks/useAutoSizeColumns.ts +206 -0
- package/src/components/InfiniteTable/hooks/useCellClassName.ts +80 -0
- package/src/components/InfiniteTable/hooks/useCellRendering.tsx +217 -0
- package/src/components/InfiniteTable/hooks/useColumnGroups.ts +71 -0
- package/src/components/InfiniteTable/hooks/useColumnMenu.ts +72 -0
- package/src/components/InfiniteTable/hooks/useColumnPointerEvents.ts +258 -0
- package/src/components/InfiniteTable/hooks/useColumnRowspan.ts +43 -0
- package/src/components/InfiniteTable/hooks/useColumnSizeFn.ts +24 -0
- package/src/components/InfiniteTable/hooks/useColumnsWhen.ts +582 -0
- package/src/components/InfiniteTable/hooks/useComputed.ts +186 -0
- package/src/components/InfiniteTable/hooks/useComputedVisibleColumns.ts +219 -0
- package/src/components/InfiniteTable/hooks/useDOMProps.ts +306 -0
- package/src/components/InfiniteTable/hooks/useEffectWithRaf.ts +47 -0
- package/src/components/InfiniteTable/hooks/useInfiniteTable.ts +10 -0
- package/src/components/InfiniteTable/hooks/useInfiniteTableState.ts +11 -0
- package/src/components/InfiniteTable/hooks/useInternalProps.ts +8 -0
- package/src/components/InfiniteTable/hooks/useLicense/LicenseDetails.ts +13 -0
- package/src/components/InfiniteTable/hooks/useLicense/crc32.ts +56 -0
- package/src/components/InfiniteTable/hooks/useLicense/decode.ts +147 -0
- package/src/components/InfiniteTable/hooks/useLicense/useLicense.ts +39 -0
- package/src/components/InfiniteTable/hooks/useRerenderOnKeyChange.ts +21 -0
- package/src/components/InfiniteTable/hooks/useRowHover.ts +18 -0
- package/src/components/InfiniteTable/hooks/useScrollToActiveCell.ts +48 -0
- package/src/components/InfiniteTable/hooks/useScrollToActiveRow.ts +44 -0
- package/src/components/InfiniteTable/hooks/useScrollbars.ts +51 -0
- package/src/components/InfiniteTable/hooks/useToggleGroupRow.ts +56 -0
- package/src/components/InfiniteTable/hooks/useUnpinnedRendering.tsx +165 -0
- package/src/components/InfiniteTable/hooks/useYourBrain.ts +55 -0
- package/src/components/InfiniteTable/index.tsx +352 -0
- package/src/components/InfiniteTable/internalProps.ts +4 -0
- package/src/components/InfiniteTable/state/computeColumnGroupsDepths.ts +29 -0
- package/src/components/InfiniteTable/state/getColumnVisibilityForHideEmptyGroupColumns.ts +127 -0
- package/src/components/InfiniteTable/state/getInitialState.ts +375 -0
- package/src/components/InfiniteTable/theme.css.ts +556 -0
- package/src/components/InfiniteTable/types/InfiniteTableAction.ts +6 -0
- package/src/components/InfiniteTable/types/InfiniteTableActionType.ts +12 -0
- package/src/components/InfiniteTable/types/InfiniteTableColumn.ts +478 -0
- package/src/components/InfiniteTable/types/InfiniteTableComputedValues.ts +43 -0
- package/src/components/InfiniteTable/types/InfiniteTableContextValue.ts +12 -0
- package/src/components/InfiniteTable/types/InfiniteTableInternalProps.ts +3 -0
- package/src/components/InfiniteTable/types/InfiniteTableProps.ts +511 -0
- package/src/components/InfiniteTable/types/InfiniteTableState.ts +195 -0
- package/src/components/InfiniteTable/types/Utility.ts +35 -0
- package/src/components/InfiniteTable/types/index.ts +96 -0
- package/src/components/InfiniteTable/utilities.css.ts +179 -0
- package/src/components/InfiniteTable/utils/MultiRowSelector.ts +111 -0
- package/src/components/InfiniteTable/utils/RenderHookComponentForInfinite.tsx +52 -0
- package/src/components/InfiniteTable/utils/adjustColumnOrderForPinning.ts +33 -0
- package/src/components/InfiniteTable/utils/assignFiltered.ts +29 -0
- package/src/components/InfiniteTable/utils/defaultGetColumContextMenuItems.tsx +108 -0
- package/src/components/InfiniteTable/utils/getColumnComputedType.ts +33 -0
- package/src/components/InfiniteTable/utils/getColumnForGroupBy.tsx +313 -0
- package/src/components/InfiniteTable/utils/getComputedVisibleColumns.ts +773 -0
- package/src/components/InfiniteTable/utils/getContextMenuForColumn.tsx +72 -0
- package/src/components/InfiniteTable/utils/infiniteDOMUtils.ts +189 -0
- package/src/components/InfiniteTable/utils/mapToObject.ts +20 -0
- package/src/components/InfiniteTable/utils/moveXatY.ts +25 -0
- package/src/components/InfiniteTable/utils/objectValuesExcept.ts +9 -0
- package/src/components/InfiniteTable/utils/progressiveSpeedScroller.ts +158 -0
- package/src/components/InfiniteTable/utils/rafFn.ts +13 -0
- package/src/components/InfiniteTable/utils/toCSSVarName.ts +1 -0
- package/src/components/InfiniteTable/utils/toMap.ts +24 -0
- package/src/components/Menu/Menu.tsx +750 -0
- package/src/components/Menu/MenuCls.css.ts +139 -0
- package/src/components/Menu/MenuContext.ts +10 -0
- package/src/components/Menu/MenuContextValue.ts +15 -0
- package/src/components/Menu/MenuProps.ts +98 -0
- package/src/components/Menu/MenuState.ts +56 -0
- package/src/components/Menu/MenuTriangleContext.ts +352 -0
- package/src/components/Menu/childrenToRuntimeItems.tsx +103 -0
- package/src/components/Menu/getMenuState.tsx +119 -0
- package/src/components/Menu/index.tsx +88 -0
- package/src/components/Menu/propToIdentifyMenu.ts +1 -0
- package/src/components/RawList/AvoidReactDiff.tsx +48 -0
- package/src/components/RawList/MappedItems.ts +143 -0
- package/src/components/RawList/ReactVirtualRenderer.tsx +307 -0
- package/src/components/RawList/index.tsx +42 -0
- package/src/components/RawList/types.ts +23 -0
- package/src/components/RawList/useVirtualRenderer.ts +36 -0
- package/src/components/RenderHookComponent.tsx +10 -0
- package/src/components/ResizeObserver/index.tsx +170 -0
- package/src/components/VirtualBrain/MatrixBrain.ts +1621 -0
- package/src/components/VirtualBrain/ScrollListener.ts +39 -0
- package/src/components/VirtualBrain/index.ts +664 -0
- package/src/components/VirtualList/ColumnListWithExternalScrolling.tsx +78 -0
- package/src/components/VirtualList/InfiniteListRootClassName.ts +1 -0
- package/src/components/VirtualList/RowListWithExternalScrolling.tsx +120 -0
- package/src/components/VirtualList/SpacePlaceholder.tsx +32 -0
- package/src/components/VirtualList/VirtualList.css.ts +29 -0
- package/src/components/VirtualList/VirtualList.tsx +141 -0
- package/src/components/VirtualList/VirtualRowList.tsx +34 -0
- package/src/components/VirtualList/types.ts +56 -0
- package/src/components/VirtualList/useCorrectHeightForRowElements.ts +14 -0
- package/src/components/VirtualScrollContainer/VirtualScrollContainer.css.ts +51 -0
- package/src/components/VirtualScrollContainer/getScrollableClassName.ts +30 -0
- package/src/components/VirtualScrollContainer/index.tsx +63 -0
- package/src/components/flexbox/index.ts +562 -0
- package/src/components/hooks/useComponentState/index.tsx +562 -0
- package/src/components/hooks/useComponentState/types.ts +32 -0
- package/src/components/hooks/useEffectOnceWithProperUnmount.ts +33 -0
- package/src/components/hooks/useEffectWithChanges.ts +56 -0
- package/src/components/hooks/useImmutableRef.ts +7 -0
- package/src/components/hooks/useInterceptedMap.ts +71 -0
- package/src/components/hooks/useLatest.tsx +8 -0
- package/src/components/hooks/useLazyLatest.ts +23 -0
- package/src/components/hooks/useMemoShallowObjectMerge.ts +16 -0
- package/src/components/hooks/useMounted.ts +18 -0
- package/src/components/hooks/useOnMount.ts +21 -0
- package/src/components/hooks/useOnScroll.ts +34 -0
- package/src/components/hooks/useOnce.ts +10 -0
- package/src/components/hooks/useOverlay/index.tsx +418 -0
- package/src/components/hooks/usePrevious.ts +8 -0
- package/src/components/hooks/usePropertyOld.ts +168 -0
- package/src/components/hooks/useRerender.ts +12 -0
- package/src/components/hooks/xuseProperty.ts +165 -0
- package/src/components/types/CellPosition.ts +4 -0
- package/src/components/types/NonUndefined.ts +1 -0
- package/src/components/types/RemoveObject.ts +22 -0
- package/src/components/types/Renderable.ts +3 -0
- package/src/components/types/ScrollPosition.ts +7 -0
- package/src/components/types/Setter.ts +2 -0
- package/src/components/types/Size.ts +6 -0
- package/src/components/types/SubscriptionCallback.ts +10 -0
- package/src/components/types/VoidFn.ts +1 -0
- package/src/components/utils/buildSubscriptionCallback.tsx +60 -0
- package/src/components/utils/clamp.ts +3 -0
- package/src/components/utils/debounce.ts +16 -0
- package/src/components/utils/decamelize.ts +11 -0
- package/src/components/utils/discardCallsWithEqualArg.ts +42 -0
- package/src/components/utils/getRenderIndexes.ts +33 -0
- package/src/components/utils/getScrollbarWidth.ts +31 -0
- package/src/components/utils/getVirtualRenderCount.ts +21 -0
- package/src/components/utils/isControlled.ts +12 -0
- package/src/components/utils/isControlledValue.ts +5 -0
- package/src/index.tsx +34 -0
- package/src/test.tsx +18 -0
- package/src/utils/DeepMap/index.ts +588 -0
- package/src/utils/DeepMap/once.ts +16 -0
- package/src/utils/DeepMap/sortAscending.ts +1 -0
- package/src/utils/DeepMap/tsconfig.deepmap.json +17 -0
- package/src/utils/DeepMap/xpackage.json +26 -0
- package/src/utils/debug.ts +40 -0
- package/src/utils/deepClone.ts +38 -0
- package/src/utils/getGlobal.ts +3 -0
- package/src/utils/groupAndPivot/defaultToKey.ts +3 -0
- package/src/utils/groupAndPivot/getGroupKeysForDataItem.ts +19 -0
- package/src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts +361 -0
- package/src/utils/groupAndPivot/index.ts +1229 -0
- package/src/utils/groupAndPivot/types.ts +10 -0
- package/src/utils/join.ts +4 -0
- package/src/utils/mathIntersection.ts +21 -0
- package/src/utils/minified.d.ts +2 -0
- package/src/utils/minified.js +6 -0
- package/src/utils/multisort/index.ts +151 -0
- package/src/utils/multisort/sortTypes.ts +25 -0
- package/src/utils/notes-status.md +92 -0
- package/src/utils/pageGeometry/ConvexPoly.ts +34 -0
- package/src/utils/pageGeometry/Point.ts +51 -0
- package/src/utils/pageGeometry/PolyWithPoints.ts +52 -0
- package/src/utils/pageGeometry/Rectangle.ts +98 -0
- package/src/utils/pageGeometry/Triangle.ts +16 -0
- package/src/utils/pageGeometry/alignment/index.ts +221 -0
- package/src/utils/pageGeometry/polyContainsPoint.ts +182 -0
- package/src/utils/pageGeometry/types.ts +3 -0
- package/src/utils/proxyFnCall.ts +46 -0
- package/src/utils/raf.ts +13 -0
- package/src/utils/selectParent.ts +18 -0
- package/src/utils/shallowEqualObjects.ts +49 -0
- package/src/utils/stripVar.ts +3 -0
- package/src/utils/toUpperFirst.ts +5 -0
- package/todo.md +2 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.dev.json +7 -0
- package/tsconfig.json +30 -0
- package/tsconfig.typebundler.json +13 -0
- package/typedoc.json +4 -0
- package/README.md +0 -104
- package/index.css +0 -857
- package/index.d.ts +0 -2111
- package/index.esm.css +0 -857
- package/index.esm.js +0 -13695
- package/index.js +0 -13565
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useDataSourceContextValue } from '../../DataSource/publicHooks/useDataSource';
|
|
4
|
+
import { MatrixBrainOptions } from '../../VirtualBrain/MatrixBrain';
|
|
5
|
+
import { InfiniteTableComputedColumn } from '../types';
|
|
6
|
+
|
|
7
|
+
export function useColumnRowspan<T>(
|
|
8
|
+
computedVisibleColumns: InfiniteTableComputedColumn<T>[],
|
|
9
|
+
) {
|
|
10
|
+
const { getState: getDataSourceState } = useDataSourceContextValue<T>();
|
|
11
|
+
|
|
12
|
+
const rowspan = useMemo<MatrixBrainOptions['rowspan']>(() => {
|
|
13
|
+
const colsWithRowspan = computedVisibleColumns.filter(
|
|
14
|
+
(col) => typeof col.rowspan === 'function',
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
return colsWithRowspan.length
|
|
18
|
+
? ({ rowIndex, colIndex }) => {
|
|
19
|
+
const dataArray = getDataSourceState().dataArray;
|
|
20
|
+
const rowInfo = dataArray[rowIndex];
|
|
21
|
+
if (!rowInfo) {
|
|
22
|
+
return 1;
|
|
23
|
+
}
|
|
24
|
+
const data = rowInfo.data;
|
|
25
|
+
|
|
26
|
+
const column = computedVisibleColumns[colIndex];
|
|
27
|
+
|
|
28
|
+
if (!column || !column.rowspan) {
|
|
29
|
+
return 1;
|
|
30
|
+
}
|
|
31
|
+
return column.rowspan({
|
|
32
|
+
column,
|
|
33
|
+
data,
|
|
34
|
+
dataArray,
|
|
35
|
+
rowInfo,
|
|
36
|
+
rowIndex,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
: undefined;
|
|
40
|
+
}, [computedVisibleColumns]);
|
|
41
|
+
|
|
42
|
+
return rowspan;
|
|
43
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { dbg } from '../../../utils/debug';
|
|
3
|
+
import { InfiniteTableComputedColumn } from '../types';
|
|
4
|
+
|
|
5
|
+
const debug = dbg('useColumnSizeFn');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns a function that can be used to retrieve the width of a column column, by the column index
|
|
9
|
+
*/
|
|
10
|
+
export function useColumnSizeFn<T>(columns: InfiniteTableComputedColumn<T>[]) {
|
|
11
|
+
const columnSize = useCallback(
|
|
12
|
+
(index: number) => {
|
|
13
|
+
const column = columns[index];
|
|
14
|
+
if (__DEV__ && !column) {
|
|
15
|
+
debug('cannot find column at index', index, columns);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return column ? column.computedWidth : 0;
|
|
19
|
+
},
|
|
20
|
+
[columns],
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return columnSize;
|
|
24
|
+
}
|
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { InfiniteTableColumn, InfiniteTableState } from '..';
|
|
4
|
+
import { shallowEqualObjects } from '../../../utils/shallowEqualObjects';
|
|
5
|
+
import type {
|
|
6
|
+
DataSourceGroupBy,
|
|
7
|
+
DataSourcePivotBy,
|
|
8
|
+
DataSourcePropGroupBy,
|
|
9
|
+
DataSourcePropSelectionMode,
|
|
10
|
+
} from '../../DataSource';
|
|
11
|
+
import { useDataSourceContextValue } from '../../DataSource/publicHooks/useDataSource';
|
|
12
|
+
import { useComponentState } from '../../hooks/useComponentState';
|
|
13
|
+
import { interceptMap } from '../../hooks/useInterceptedMap';
|
|
14
|
+
import { getGroupByMap } from '../state/getInitialState';
|
|
15
|
+
import {
|
|
16
|
+
getColumnVisibilityForHideEmptyGroupColumns,
|
|
17
|
+
getGroupColumnsMapForComputedColumns,
|
|
18
|
+
} from '../state/getColumnVisibilityForHideEmptyGroupColumns';
|
|
19
|
+
|
|
20
|
+
import type {
|
|
21
|
+
InfiniteTableComputedPivotFinalColumn,
|
|
22
|
+
InfiniteTableGeneratedGroupColumn,
|
|
23
|
+
InfiniteTablePivotColumn,
|
|
24
|
+
} from '../types/InfiniteTableColumn';
|
|
25
|
+
import type {
|
|
26
|
+
InfiniteTablePropGroupRenderStrategy,
|
|
27
|
+
InfiniteTableProps,
|
|
28
|
+
} from '../types/InfiniteTableProps';
|
|
29
|
+
import { GroupByMap } from '../types/InfiniteTableState';
|
|
30
|
+
import {
|
|
31
|
+
getColumnForGroupBy,
|
|
32
|
+
getGroupColumnRender,
|
|
33
|
+
getGroupColumnRenderGroupIcon,
|
|
34
|
+
getSingleGroupColumn,
|
|
35
|
+
} from '../utils/getColumnForGroupBy';
|
|
36
|
+
|
|
37
|
+
import { ToggleGroupRowFn, useToggleGroupRow } from './useToggleGroupRow';
|
|
38
|
+
|
|
39
|
+
function useGroupByMap<T>(groupBy: DataSourcePropGroupBy<T>) {
|
|
40
|
+
return useMemo(() => getGroupByMap(groupBy), [groupBy]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function useColumnsWhen<T>() {
|
|
44
|
+
const {
|
|
45
|
+
componentState: { groupBy },
|
|
46
|
+
componentActions: dataSourceActions,
|
|
47
|
+
} = useDataSourceContextValue<T>();
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
componentState: {
|
|
51
|
+
groupRenderStrategy,
|
|
52
|
+
pivotTotalColumnPosition,
|
|
53
|
+
pivotGrandTotalColumnPosition,
|
|
54
|
+
},
|
|
55
|
+
} = useComponentState<InfiniteTableState<T>>();
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
dataSourceActions.generateGroupRows = groupRenderStrategy !== 'inline';
|
|
59
|
+
}, [groupRenderStrategy]);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
dataSourceActions.pivotTotalColumnPosition = pivotTotalColumnPosition;
|
|
63
|
+
}, [pivotTotalColumnPosition]);
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (pivotGrandTotalColumnPosition != undefined) {
|
|
67
|
+
dataSourceActions.pivotGrandTotalColumnPosition =
|
|
68
|
+
pivotGrandTotalColumnPosition;
|
|
69
|
+
}
|
|
70
|
+
}, [pivotGrandTotalColumnPosition]);
|
|
71
|
+
|
|
72
|
+
const groupByMap = useGroupByMap(groupBy);
|
|
73
|
+
|
|
74
|
+
useColumnsWhenInlineGroupRenderStrategy<T>(groupByMap);
|
|
75
|
+
const { toggleGroupRow } = useColumnsWhenGrouping<T>();
|
|
76
|
+
|
|
77
|
+
useHideColumns<T>(groupByMap);
|
|
78
|
+
|
|
79
|
+
return { toggleGroupRow };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function useColumnsWhenInlineGroupRenderStrategy<T>(groupByMap: GroupByMap<T>) {
|
|
83
|
+
const toggleGroupRow = useToggleGroupRow();
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
componentActions,
|
|
87
|
+
componentState: { columns, groupRenderStrategy },
|
|
88
|
+
} = useComponentState<InfiniteTableState<T>>();
|
|
89
|
+
|
|
90
|
+
function computeColumnsWhenInlineGroupRenderStrategy(
|
|
91
|
+
columns: Map<string, InfiniteTableColumn<T>>,
|
|
92
|
+
groupByMap: GroupByMap<T>,
|
|
93
|
+
groupRenderStrategy: InfiniteTablePropGroupRenderStrategy,
|
|
94
|
+
toggleGroupRow: ToggleGroupRowFn,
|
|
95
|
+
) {
|
|
96
|
+
const computedColumns = new Map<string, InfiniteTableColumn<T>>();
|
|
97
|
+
|
|
98
|
+
if (groupRenderStrategy !== 'inline') {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
columns.forEach((column, id) => {
|
|
103
|
+
let base: Partial<InfiniteTableGeneratedGroupColumn<T>> = {};
|
|
104
|
+
const groupByForColumn = groupByMap.get(column.field!);
|
|
105
|
+
if (groupByForColumn && groupRenderStrategy === 'inline') {
|
|
106
|
+
const { groupIndex } = groupByForColumn;
|
|
107
|
+
const field = groupByForColumn.groupBy.field;
|
|
108
|
+
base = {
|
|
109
|
+
groupByField: field as string,
|
|
110
|
+
field: field,
|
|
111
|
+
valueFormatter: ({ rowInfo }) => {
|
|
112
|
+
return rowInfo.isGroupRow
|
|
113
|
+
? rowInfo.groupKeys?.[groupIndex]
|
|
114
|
+
: rowInfo.value;
|
|
115
|
+
},
|
|
116
|
+
rowspan: ({ rowInfo, dataArray }) => {
|
|
117
|
+
if (!rowInfo.isGroupRow) {
|
|
118
|
+
return 1;
|
|
119
|
+
}
|
|
120
|
+
const prevRowInfo = dataArray[rowInfo.indexInAll - 1] || {
|
|
121
|
+
indexInParentGroups: [],
|
|
122
|
+
};
|
|
123
|
+
if (!prevRowInfo || !prevRowInfo.dataSourceHasGrouping) {
|
|
124
|
+
return 1;
|
|
125
|
+
}
|
|
126
|
+
const prevIndexes = prevRowInfo.indexInParentGroups! || [];
|
|
127
|
+
const currentIndexes = rowInfo.indexInParentGroups! || [];
|
|
128
|
+
|
|
129
|
+
let computeSpan = false;
|
|
130
|
+
for (let i = 0; i <= groupIndex; i++) {
|
|
131
|
+
const prev = prevIndexes[i];
|
|
132
|
+
const current = currentIndexes[i];
|
|
133
|
+
|
|
134
|
+
if (current !== prev) {
|
|
135
|
+
computeSpan = true;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!computeSpan) {
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
const parentGroup = rowInfo.parents![groupIndex];
|
|
144
|
+
|
|
145
|
+
const rowspan = parentGroup
|
|
146
|
+
? parentGroup.groupCount -
|
|
147
|
+
(parentGroup.collapsedChildrenCount || 0) +
|
|
148
|
+
(parentGroup.collapsedGroupsCount || 0)
|
|
149
|
+
: 1;
|
|
150
|
+
|
|
151
|
+
return rowspan;
|
|
152
|
+
},
|
|
153
|
+
renderGroupIcon: getGroupColumnRenderGroupIcon({
|
|
154
|
+
groupIndexForColumn: groupIndex,
|
|
155
|
+
groupRenderStrategy,
|
|
156
|
+
toggleGroupRow,
|
|
157
|
+
initialRenderGroupIcon: column.renderGroupIcon,
|
|
158
|
+
}),
|
|
159
|
+
render: getGroupColumnRender({
|
|
160
|
+
groupIndexForColumn: groupIndex,
|
|
161
|
+
groupRenderStrategy,
|
|
162
|
+
}),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const clone = { ...base, ...column } as InfiniteTableColumn<T>;
|
|
166
|
+
|
|
167
|
+
computedColumns.set(id, clone);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return computedColumns.size === 0 ? undefined : computedColumns;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
const update = () => {
|
|
175
|
+
componentActions.columnsWhenInlineGroupRenderStrategy =
|
|
176
|
+
computeColumnsWhenInlineGroupRenderStrategy(
|
|
177
|
+
columns,
|
|
178
|
+
groupByMap,
|
|
179
|
+
groupRenderStrategy,
|
|
180
|
+
toggleGroupRow,
|
|
181
|
+
);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
update();
|
|
185
|
+
|
|
186
|
+
return interceptMap(columns, {
|
|
187
|
+
set: update,
|
|
188
|
+
delete: update,
|
|
189
|
+
clear: update,
|
|
190
|
+
});
|
|
191
|
+
}, [columns, groupByMap, groupRenderStrategy, toggleGroupRow]);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function useColumnsWhenGrouping<T>() {
|
|
195
|
+
const {
|
|
196
|
+
componentState: { groupBy, pivotBy, selectionMode },
|
|
197
|
+
} = useDataSourceContextValue<T>();
|
|
198
|
+
|
|
199
|
+
const {
|
|
200
|
+
componentActions,
|
|
201
|
+
componentState: {
|
|
202
|
+
columns,
|
|
203
|
+
groupColumn,
|
|
204
|
+
hideColumnWhenGrouped,
|
|
205
|
+
groupRenderStrategy,
|
|
206
|
+
pivotColumns,
|
|
207
|
+
pivotColumn,
|
|
208
|
+
pivotTotalColumnPosition,
|
|
209
|
+
pivotGrandTotalColumnPosition,
|
|
210
|
+
},
|
|
211
|
+
getComponentState,
|
|
212
|
+
} = useComponentState<InfiniteTableState<T>>();
|
|
213
|
+
|
|
214
|
+
const toggleGroupRow = useToggleGroupRow();
|
|
215
|
+
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
const update = () => {
|
|
218
|
+
const { columns: columnsWhenGrouping, groupColumnIds } =
|
|
219
|
+
getColumnsWhenGrouping({
|
|
220
|
+
columns,
|
|
221
|
+
groupColumn,
|
|
222
|
+
pivotColumn,
|
|
223
|
+
pivotTotalColumnPosition,
|
|
224
|
+
pivotGrandTotalColumnPosition,
|
|
225
|
+
groupRenderStrategy:
|
|
226
|
+
groupRenderStrategy === 'inline'
|
|
227
|
+
? 'single-column'
|
|
228
|
+
: groupRenderStrategy,
|
|
229
|
+
groupBy,
|
|
230
|
+
pivotBy,
|
|
231
|
+
pivotColumns,
|
|
232
|
+
toggleGroupRow,
|
|
233
|
+
selectionMode,
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
componentActions.columnsWhenGrouping = columnsWhenGrouping;
|
|
237
|
+
|
|
238
|
+
let currentColumnOrder = getComponentState().columnOrder;
|
|
239
|
+
if (groupColumnIds.length && Array.isArray(currentColumnOrder)) {
|
|
240
|
+
const colOrder = new Set(currentColumnOrder);
|
|
241
|
+
let shouldUpdate = false;
|
|
242
|
+
groupColumnIds.forEach((groupColId) => {
|
|
243
|
+
if (!colOrder.has(groupColId)) {
|
|
244
|
+
shouldUpdate = true;
|
|
245
|
+
currentColumnOrder = [
|
|
246
|
+
groupColId,
|
|
247
|
+
...(currentColumnOrder as string[]),
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
if (shouldUpdate) {
|
|
252
|
+
componentActions.columnOrder = currentColumnOrder;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
update();
|
|
258
|
+
|
|
259
|
+
return interceptMap(columns, {
|
|
260
|
+
set: update,
|
|
261
|
+
delete: update,
|
|
262
|
+
clear: update,
|
|
263
|
+
});
|
|
264
|
+
}, [
|
|
265
|
+
columns,
|
|
266
|
+
groupBy,
|
|
267
|
+
pivotBy,
|
|
268
|
+
selectionMode,
|
|
269
|
+
hideColumnWhenGrouped,
|
|
270
|
+
groupColumn,
|
|
271
|
+
groupRenderStrategy,
|
|
272
|
+
pivotColumns,
|
|
273
|
+
pivotTotalColumnPosition,
|
|
274
|
+
pivotColumn,
|
|
275
|
+
]);
|
|
276
|
+
|
|
277
|
+
return { toggleGroupRow };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function useHideColumns<T>(groupByMap: GroupByMap<T>) {
|
|
281
|
+
const {
|
|
282
|
+
componentState: {
|
|
283
|
+
dataArray,
|
|
284
|
+
groupRowsIndexesInDataArray: groupRowsIndexesInDataArray,
|
|
285
|
+
groupBy,
|
|
286
|
+
groupRowsState,
|
|
287
|
+
originalLazyGroupDataChangeDetect,
|
|
288
|
+
},
|
|
289
|
+
getState: getDataSourceState,
|
|
290
|
+
} = useDataSourceContextValue<T>();
|
|
291
|
+
|
|
292
|
+
const {
|
|
293
|
+
getComponentState,
|
|
294
|
+
componentActions,
|
|
295
|
+
componentState: {
|
|
296
|
+
columnTypes,
|
|
297
|
+
computedColumns,
|
|
298
|
+
|
|
299
|
+
hideColumnWhenGrouped,
|
|
300
|
+
hideEmptyGroupColumns,
|
|
301
|
+
|
|
302
|
+
groupRenderStrategy,
|
|
303
|
+
},
|
|
304
|
+
} = useComponentState<InfiniteTableState<T>>();
|
|
305
|
+
|
|
306
|
+
// implements hideEmptyGroupColumns
|
|
307
|
+
useLayoutEffect(() => {
|
|
308
|
+
if (groupRenderStrategy !== 'multi-column') {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const currentState = getComponentState();
|
|
312
|
+
|
|
313
|
+
const computedGroupColumns = getGroupColumnsMapForComputedColumns(
|
|
314
|
+
computedColumns,
|
|
315
|
+
groupByMap,
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
const newColumnVisibility = getColumnVisibilityForHideEmptyGroupColumns({
|
|
319
|
+
computedGroupColumns,
|
|
320
|
+
columnVisibility: currentState.columnVisibility,
|
|
321
|
+
hideEmptyGroupColumns,
|
|
322
|
+
groupRowsIndexesInDataArray,
|
|
323
|
+
dataArray,
|
|
324
|
+
groupBy,
|
|
325
|
+
groupByMap,
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
if (
|
|
329
|
+
!shallowEqualObjects(currentState.columnVisibility, newColumnVisibility)
|
|
330
|
+
) {
|
|
331
|
+
componentActions.columnVisibility = newColumnVisibility;
|
|
332
|
+
}
|
|
333
|
+
}, [
|
|
334
|
+
getDataSourceState,
|
|
335
|
+
groupRenderStrategy,
|
|
336
|
+
originalLazyGroupDataChangeDetect,
|
|
337
|
+
groupBy,
|
|
338
|
+
groupByMap,
|
|
339
|
+
computedColumns,
|
|
340
|
+
|
|
341
|
+
hideEmptyGroupColumns ? dataArray : null,
|
|
342
|
+
hideEmptyGroupColumns ? groupRowsState : null,
|
|
343
|
+
hideEmptyGroupColumns ? groupRowsIndexesInDataArray : null,
|
|
344
|
+
hideEmptyGroupColumns,
|
|
345
|
+
]);
|
|
346
|
+
|
|
347
|
+
// implements the functionality of column.defaultHiddenWhenGrouped and hideColumnWhenGrouped
|
|
348
|
+
useEffect(() => {
|
|
349
|
+
const isGrouped = groupBy.length > 0;
|
|
350
|
+
const currentState = getComponentState();
|
|
351
|
+
|
|
352
|
+
const {
|
|
353
|
+
columnVisibility,
|
|
354
|
+
columnVisibilityForGrouping,
|
|
355
|
+
hideColumnWhenGrouped,
|
|
356
|
+
} = currentState;
|
|
357
|
+
|
|
358
|
+
const newColumnVisibility = { ...columnVisibility };
|
|
359
|
+
let newColumnVisibilityForGrouping = { ...columnVisibilityForGrouping };
|
|
360
|
+
|
|
361
|
+
let updatedVisibilityWhenGrouping = false;
|
|
362
|
+
|
|
363
|
+
let newlyHiddenColumns = new Set<string>();
|
|
364
|
+
let newlyDisplayedColumns = new Set<string>();
|
|
365
|
+
|
|
366
|
+
computedColumns.forEach((col, id) => {
|
|
367
|
+
if (col.defaultHiddenWhenGroupedBy || hideColumnWhenGrouped != null) {
|
|
368
|
+
const hideWhenGrouped =
|
|
369
|
+
(col.defaultHiddenWhenGroupedBy === '*' && isGrouped) ||
|
|
370
|
+
((col.defaultHiddenWhenGroupedBy === true || hideColumnWhenGrouped) &&
|
|
371
|
+
col.field &&
|
|
372
|
+
groupByMap.get(col.field)) ||
|
|
373
|
+
(typeof col.defaultHiddenWhenGroupedBy === 'string' &&
|
|
374
|
+
groupByMap.get(col.defaultHiddenWhenGroupedBy as keyof T)) ||
|
|
375
|
+
(typeof col.defaultHiddenWhenGroupedBy === 'object' &&
|
|
376
|
+
Object.keys(col.defaultHiddenWhenGroupedBy).reduce(
|
|
377
|
+
(acc: boolean, field) => acc || groupByMap.has(field as keyof T),
|
|
378
|
+
false,
|
|
379
|
+
));
|
|
380
|
+
|
|
381
|
+
if (hideWhenGrouped) {
|
|
382
|
+
if (newColumnVisibilityForGrouping[id] !== false) {
|
|
383
|
+
if (columnVisibility[id] === false) {
|
|
384
|
+
// if the column is already specified as invisible,
|
|
385
|
+
// dont put it in the list of cols made invisible due to grouping rules
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
// should be hidden and was not already
|
|
389
|
+
newColumnVisibilityForGrouping[id] = false;
|
|
390
|
+
updatedVisibilityWhenGrouping = true;
|
|
391
|
+
newlyHiddenColumns.add(id);
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
if (newColumnVisibilityForGrouping[id] === false) {
|
|
395
|
+
//should be visible and was not already
|
|
396
|
+
delete newColumnVisibilityForGrouping[id];
|
|
397
|
+
updatedVisibilityWhenGrouping = true;
|
|
398
|
+
newlyDisplayedColumns.add(id);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
if (updatedVisibilityWhenGrouping) {
|
|
405
|
+
componentActions.columnVisibilityForGrouping =
|
|
406
|
+
newColumnVisibilityForGrouping;
|
|
407
|
+
|
|
408
|
+
newlyDisplayedColumns.forEach((colId) => {
|
|
409
|
+
delete newColumnVisibility[colId];
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
newlyHiddenColumns.forEach((colId) => {
|
|
413
|
+
newColumnVisibility[colId] = false;
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
componentActions.columnVisibility = newColumnVisibility;
|
|
417
|
+
}
|
|
418
|
+
}, [
|
|
419
|
+
computedColumns,
|
|
420
|
+
columnTypes,
|
|
421
|
+
groupBy,
|
|
422
|
+
groupByMap,
|
|
423
|
+
hideColumnWhenGrouped,
|
|
424
|
+
]);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export function getColumnsWhenGrouping<T>(params: {
|
|
428
|
+
columns: Map<string, InfiniteTableColumn<T>>;
|
|
429
|
+
groupBy: DataSourceGroupBy<T>[];
|
|
430
|
+
selectionMode: DataSourcePropSelectionMode;
|
|
431
|
+
pivotBy?: DataSourcePivotBy<T>[];
|
|
432
|
+
toggleGroupRow: (groupKeys: any[]) => void;
|
|
433
|
+
pivotTotalColumnPosition: InfiniteTableState<T>['pivotTotalColumnPosition'];
|
|
434
|
+
pivotGrandTotalColumnPosition: InfiniteTableState<T>['pivotGrandTotalColumnPosition'];
|
|
435
|
+
groupColumn: InfiniteTableProps<T>['groupColumn'];
|
|
436
|
+
groupRenderStrategy: InfiniteTablePropGroupRenderStrategy;
|
|
437
|
+
pivotColumns: InfiniteTableProps<T>['pivotColumns'];
|
|
438
|
+
pivotColumn: InfiniteTableProps<T>['pivotColumn'];
|
|
439
|
+
}): {
|
|
440
|
+
columns: Map<string, InfiniteTableColumn<T>> | undefined;
|
|
441
|
+
groupColumnIds: string[];
|
|
442
|
+
} {
|
|
443
|
+
const {
|
|
444
|
+
pivotColumns,
|
|
445
|
+
groupBy,
|
|
446
|
+
pivotBy,
|
|
447
|
+
selectionMode,
|
|
448
|
+
groupColumn,
|
|
449
|
+
pivotTotalColumnPosition,
|
|
450
|
+
pivotGrandTotalColumnPosition,
|
|
451
|
+
pivotColumn,
|
|
452
|
+
groupRenderStrategy,
|
|
453
|
+
toggleGroupRow,
|
|
454
|
+
columns,
|
|
455
|
+
} = params;
|
|
456
|
+
|
|
457
|
+
if (groupRenderStrategy === 'inline') {
|
|
458
|
+
return { columns: undefined, groupColumnIds: [] };
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const computedColumns = new Map<string, InfiniteTableColumn<T>>();
|
|
462
|
+
|
|
463
|
+
const groupColumnIds: string[] = [];
|
|
464
|
+
|
|
465
|
+
if (groupRenderStrategy === 'multi-column') {
|
|
466
|
+
groupBy.forEach((groupByForColumn, groupIndexForColumn, arr) => {
|
|
467
|
+
const generatedGroupColumn = getColumnForGroupBy<T>(
|
|
468
|
+
{
|
|
469
|
+
groupByForColumn,
|
|
470
|
+
groupBy,
|
|
471
|
+
pivotBy,
|
|
472
|
+
groupIndexForColumn,
|
|
473
|
+
groupCount: arr.length,
|
|
474
|
+
groupRenderStrategy,
|
|
475
|
+
selectionMode,
|
|
476
|
+
},
|
|
477
|
+
toggleGroupRow,
|
|
478
|
+
groupColumn,
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
const groupColumnId =
|
|
482
|
+
generatedGroupColumn.id || `group-by-${groupByForColumn.field}`;
|
|
483
|
+
|
|
484
|
+
groupColumnIds.push(groupColumnId);
|
|
485
|
+
computedColumns.set(groupColumnId, generatedGroupColumn);
|
|
486
|
+
});
|
|
487
|
+
} else if (groupRenderStrategy === 'single-column' && groupBy.length) {
|
|
488
|
+
// } else if (
|
|
489
|
+
// (groupRenderStrategy === 'single-column' ||
|
|
490
|
+
// groupRenderStrategy === 'single-column-extended') &&
|
|
491
|
+
// groupBy.length
|
|
492
|
+
// ) {
|
|
493
|
+
const singleGroupColumn = getSingleGroupColumn(
|
|
494
|
+
{
|
|
495
|
+
groupCount: groupBy.length,
|
|
496
|
+
groupBy,
|
|
497
|
+
pivotBy,
|
|
498
|
+
groupRenderStrategy,
|
|
499
|
+
selectionMode,
|
|
500
|
+
},
|
|
501
|
+
toggleGroupRow,
|
|
502
|
+
groupColumn,
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
const groupColumnId = singleGroupColumn.id || 'group-by';
|
|
506
|
+
groupColumnIds.push(groupColumnId);
|
|
507
|
+
computedColumns.set(groupColumnId, singleGroupColumn);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (pivotColumns) {
|
|
511
|
+
const columnsByField: Partial<Record<keyof T, InfiniteTableColumn<T>>> = {};
|
|
512
|
+
|
|
513
|
+
columns.forEach((col) => {
|
|
514
|
+
if (col.field) {
|
|
515
|
+
columnsByField[col.field] = col;
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
pivotColumns.forEach((col, key) => {
|
|
520
|
+
const isSimpleTotalColumn = col.pivotTotalColumn && col.columnGroup;
|
|
521
|
+
const isGrandTotalColumn = col.pivotTotalColumn && !col.columnGroup;
|
|
522
|
+
|
|
523
|
+
if (isSimpleTotalColumn && pivotTotalColumnPosition === false) {
|
|
524
|
+
// don't include the total columns if specified as false
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
if (isGrandTotalColumn && pivotGrandTotalColumnPosition === false) {
|
|
528
|
+
// don't include the grand total columns if specified as false
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
let column: InfiniteTablePivotColumn<T> = { ...col };
|
|
533
|
+
|
|
534
|
+
// const isPivotRowLabelsColumn =
|
|
535
|
+
// !column.pivotColumn && !column.pivotTotalColumn;
|
|
536
|
+
|
|
537
|
+
// if (!isPivotRowLabelsColumn) {
|
|
538
|
+
if (pivotColumn) {
|
|
539
|
+
if (typeof pivotColumn === 'function') {
|
|
540
|
+
column = {
|
|
541
|
+
...column,
|
|
542
|
+
...pivotColumn({
|
|
543
|
+
column: column as InfiniteTableComputedPivotFinalColumn<T>,
|
|
544
|
+
pivotBy: pivotBy!,
|
|
545
|
+
groupBy,
|
|
546
|
+
}),
|
|
547
|
+
} as InfiniteTablePivotColumn<T>;
|
|
548
|
+
} else {
|
|
549
|
+
column = {
|
|
550
|
+
...column,
|
|
551
|
+
...pivotColumn,
|
|
552
|
+
} as InfiniteTablePivotColumn<T>;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
if (column.inheritFromColumn !== false) {
|
|
556
|
+
const colToInheritFrom =
|
|
557
|
+
typeof column.inheritFromColumn === 'string'
|
|
558
|
+
? columns.get(column.inheritFromColumn)
|
|
559
|
+
: column.pivotAggregator?.field
|
|
560
|
+
? columnsByField[column.pivotAggregator?.field]
|
|
561
|
+
: undefined;
|
|
562
|
+
column = { ...colToInheritFrom, ...column };
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if (!column.render && column.renderValue) {
|
|
566
|
+
column.render = (renderOptions) => {
|
|
567
|
+
return column.renderValue!(renderOptions);
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
computedColumns.set(key, column);
|
|
571
|
+
});
|
|
572
|
+
} else {
|
|
573
|
+
columns.forEach((col, colId) => {
|
|
574
|
+
computedColumns.set(colId, col);
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return {
|
|
579
|
+
columns: computedColumns.size ? computedColumns : undefined,
|
|
580
|
+
groupColumnIds,
|
|
581
|
+
};
|
|
582
|
+
}
|