@linzjs/step-ag-grid 29.11.3 → 29.12.0
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/src/contexts/GridContext.d.ts +1 -1
- package/dist/src/utils/__tests__/storybookTestUtil.ts +28 -1
- package/dist/src/utils/__tests__/testQuick.ts +2 -0
- package/dist/src/utils/util.d.ts +1 -0
- package/dist/step-ag-grid.cjs +315 -91
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +315 -92
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/components/Grid.tsx +139 -66
- package/src/contexts/GridContext.tsx +3 -3
- package/src/contexts/GridContextProvider.tsx +55 -36
- package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +9 -3
- package/src/stories/grid/GridSorting.stories.tsx +189 -0
- package/src/stories/grid/gridAutosize/GridAutoSize.stories.tsx +84 -0
- package/src/stories/grid/gridAutosize/GridFitSize.stories.tsx +84 -0
- package/src/stories/grid/gridAutosize/GridFitSizeFlex.stories.tsx +86 -0
- package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +49 -16
- package/src/utils/__tests__/storybookTestUtil.ts +28 -1
- package/src/utils/__tests__/testQuick.ts +2 -0
- package/src/utils/util.ts +19 -0
|
@@ -38,7 +38,7 @@ export interface GridContextType<TData extends GridBaseRow> {
|
|
|
38
38
|
ensureRowVisible: (id: number | string) => boolean;
|
|
39
39
|
ensureSelectedRowIsVisible: () => void;
|
|
40
40
|
getFirstRowId: () => number;
|
|
41
|
-
autoSizeColumns: (props?: AutoSizeColumnsProps) => AutoSizeColumnsResult
|
|
41
|
+
autoSizeColumns: (props?: AutoSizeColumnsProps) => Promise<AutoSizeColumnsResult>;
|
|
42
42
|
sizeColumnsToFit: (paramsOrGridWidth?: ISizeColumnsToFitParams) => void;
|
|
43
43
|
startCellEditing: ({ rowId, colId }: StartCellEditingProps) => Promise<void>;
|
|
44
44
|
resetFocusedCellAfterCellEditing: () => void;
|
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sortBy } from 'lodash-es';
|
|
2
|
+
import { expect, userEvent, waitFor } from 'storybook/test';
|
|
3
|
+
|
|
4
|
+
import { findQuick, getAllQuick } from './testQuick';
|
|
2
5
|
|
|
3
6
|
export const waitForGridReady = ({ canvasElement }: { canvasElement: HTMLElement }) =>
|
|
4
7
|
waitFor(() => expect(canvasElement.querySelector('.Grid-ready')).toBeInTheDocument(), { timeout: 5000 });
|
|
8
|
+
|
|
9
|
+
export const waitForGridRows = async (props?: { grid?: HTMLElement; timeout?: number }) =>
|
|
10
|
+
waitFor(() => expect(getAllQuick({ classes: '.ag-row' }, props?.grid).length > 0).toBe(true), {
|
|
11
|
+
timeout: props?.timeout ?? 4000,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const clickColumnHeaderToSort = async (colId: string, within: HTMLElement): Promise<void> => {
|
|
15
|
+
const user = userEvent.setup({
|
|
16
|
+
delay: 100,
|
|
17
|
+
});
|
|
18
|
+
const header = await findQuick({ selector: `.ag-header-cell[col-id="${colId}"]` }, within);
|
|
19
|
+
await expect(header).toBeInTheDocument();
|
|
20
|
+
// For some reason clicks in storybook don't trigger ag-grid, but manual clicks do
|
|
21
|
+
await user.click(header);
|
|
22
|
+
await user.keyboard('{Enter}');
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const gridColumnValues = (colId: string, within: HTMLElement): string[] => {
|
|
26
|
+
return sortBy(
|
|
27
|
+
getAllQuick({ tagName: `[col-id="${colId}"]`, classes: `.ag-cell` }, within),
|
|
28
|
+
// @ts-expect-error css style type
|
|
29
|
+
(el) => el.parentElement?.attributeStyleMap.get('transform')?.[0]?.y.value,
|
|
30
|
+
).map((cell) => cell.innerText);
|
|
31
|
+
};
|
|
@@ -25,6 +25,7 @@ export interface IQueryQuick {
|
|
|
25
25
|
role?: string;
|
|
26
26
|
classes?: string;
|
|
27
27
|
child?: IQueryQuick;
|
|
28
|
+
selector?: string;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
const escapeSelectorParam = (param: string): string => param.replace(/["\\]/g, '\\$&');
|
|
@@ -51,6 +52,7 @@ const quickSelector = <T extends HTMLElement>(
|
|
|
51
52
|
let lastIQueryQuick = props;
|
|
52
53
|
for (let loop: IQueryQuick | undefined = props; loop; loop = loop.child) {
|
|
53
54
|
lastIQueryQuick = loop;
|
|
55
|
+
loop.selector && (selector += loop.selector);
|
|
54
56
|
loop.tagName && (selector += loop.tagName);
|
|
55
57
|
loop.ariaLabel && (selector += `[aria-label='${escapeSelectorParam(loop.ariaLabel)}']`);
|
|
56
58
|
loop.role && (selector += `[role="${escapeSelectorParam(loop.role)}"]`);
|
package/dist/src/utils/util.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare const hasParentClass: (className: string, child: Node) => boolean
|
|
|
6
6
|
export declare const stringByteLengthIsInvalid: (str: string, maxBytes: number) => boolean;
|
|
7
7
|
export declare const fnOrVar: (fn: any, param?: any) => any;
|
|
8
8
|
export declare const sanitiseFileName: (filename: string) => string;
|
|
9
|
+
export declare const compareNaturalInsensitive: (a?: object | string | number | null, b?: object | string | number | null) => number;
|
package/dist/step-ag-grid.cjs
CHANGED
|
@@ -509,9 +509,9 @@ const GridContext = React.createContext({
|
|
|
509
509
|
console.error('no context provider for getFirstRowId');
|
|
510
510
|
return -1;
|
|
511
511
|
},
|
|
512
|
-
autoSizeColumns: () => {
|
|
512
|
+
autoSizeColumns: async () => {
|
|
513
513
|
console.error('no context provider for autoSizeColumns');
|
|
514
|
-
return null;
|
|
514
|
+
return Promise.resolve(null);
|
|
515
515
|
},
|
|
516
516
|
sizeColumnsToFit: () => {
|
|
517
517
|
console.error('no context provider for autoSizeAllColumns');
|
|
@@ -592,6 +592,131 @@ const GridUpdatingContext = React.createContext({
|
|
|
592
592
|
updatedDep: 0,
|
|
593
593
|
});
|
|
594
594
|
|
|
595
|
+
var lib = {};
|
|
596
|
+
|
|
597
|
+
var hasRequiredLib;
|
|
598
|
+
|
|
599
|
+
function requireLib () {
|
|
600
|
+
if (hasRequiredLib) return lib;
|
|
601
|
+
hasRequiredLib = 1;
|
|
602
|
+
Object.defineProperty(lib, "__esModule", { value: true });
|
|
603
|
+
function natsort(options) {
|
|
604
|
+
if (options === void 0) { options = {}; }
|
|
605
|
+
var ore = /^0/;
|
|
606
|
+
var sre = /\s+/g;
|
|
607
|
+
var tre = /^\s+|\s+$/g;
|
|
608
|
+
// unicode
|
|
609
|
+
var ure = /[^\x00-\x80]/;
|
|
610
|
+
// hex
|
|
611
|
+
var hre = /^0x[0-9a-f]+$/i;
|
|
612
|
+
// numeric
|
|
613
|
+
var nre = /(0x[\da-fA-F]+|(^[\+\-]?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?(?=\D|\s|$))|\d+)/g;
|
|
614
|
+
// datetime
|
|
615
|
+
var dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/; // tslint:disable-line
|
|
616
|
+
var toLowerCase = String.prototype.toLocaleLowerCase || String.prototype.toLowerCase;
|
|
617
|
+
var GREATER = options.desc ? -1 : 1;
|
|
618
|
+
var SMALLER = -GREATER;
|
|
619
|
+
var normalize = options.insensitive
|
|
620
|
+
? function (s) { return toLowerCase.call("" + s).replace(tre, ''); }
|
|
621
|
+
: function (s) { return ("" + s).replace(tre, ''); };
|
|
622
|
+
function tokenize(s) {
|
|
623
|
+
return s.replace(nre, '\0$1\0')
|
|
624
|
+
.replace(/\0$/, '')
|
|
625
|
+
.replace(/^\0/, '')
|
|
626
|
+
.split('\0');
|
|
627
|
+
}
|
|
628
|
+
function parse(s, l) {
|
|
629
|
+
// normalize spaces; find floats not starting with '0',
|
|
630
|
+
// string or 0 if not defined (Clint Priest)
|
|
631
|
+
return (!s.match(ore) || l === 1)
|
|
632
|
+
&& parseFloat(s)
|
|
633
|
+
|| s.replace(sre, ' ').replace(tre, '')
|
|
634
|
+
|| 0;
|
|
635
|
+
}
|
|
636
|
+
return function (a, b) {
|
|
637
|
+
// trim pre-post whitespace
|
|
638
|
+
var aa = normalize(a);
|
|
639
|
+
var bb = normalize(b);
|
|
640
|
+
// return immediately if at least one of the values is empty.
|
|
641
|
+
// empty string < any others
|
|
642
|
+
if (!aa && !bb) {
|
|
643
|
+
return 0;
|
|
644
|
+
}
|
|
645
|
+
if (!aa && bb) {
|
|
646
|
+
return SMALLER;
|
|
647
|
+
}
|
|
648
|
+
if (aa && !bb) {
|
|
649
|
+
return GREATER;
|
|
650
|
+
}
|
|
651
|
+
// tokenize: split numeric strings and default strings
|
|
652
|
+
var aArr = tokenize(aa);
|
|
653
|
+
var bArr = tokenize(bb);
|
|
654
|
+
// hex or date detection
|
|
655
|
+
var aHex = aa.match(hre);
|
|
656
|
+
var bHex = bb.match(hre);
|
|
657
|
+
var av = (aHex && bHex) ? parseInt(aHex[0], 16) : (aArr.length !== 1 && Date.parse(aa));
|
|
658
|
+
var bv = (aHex && bHex)
|
|
659
|
+
? parseInt(bHex[0], 16)
|
|
660
|
+
: av && bb.match(dre) && Date.parse(bb) || null;
|
|
661
|
+
// try and sort Hex codes or Dates
|
|
662
|
+
if (bv) {
|
|
663
|
+
if (av === bv) {
|
|
664
|
+
return 0;
|
|
665
|
+
}
|
|
666
|
+
if (av < bv) {
|
|
667
|
+
return SMALLER;
|
|
668
|
+
}
|
|
669
|
+
if (av > bv) {
|
|
670
|
+
return GREATER;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
var al = aArr.length;
|
|
674
|
+
var bl = bArr.length;
|
|
675
|
+
// handle numeric strings and default strings
|
|
676
|
+
for (var i = 0, l = Math.max(al, bl); i < l; i += 1) {
|
|
677
|
+
var af = parse(aArr[i] || '', al);
|
|
678
|
+
var bf = parse(bArr[i] || '', bl);
|
|
679
|
+
// handle numeric vs string comparison.
|
|
680
|
+
// numeric < string
|
|
681
|
+
if (isNaN(af) !== isNaN(bf)) {
|
|
682
|
+
return isNaN(af) ? GREATER : SMALLER;
|
|
683
|
+
}
|
|
684
|
+
// if unicode use locale comparison
|
|
685
|
+
if (ure.test(af + bf) && af.localeCompare) {
|
|
686
|
+
var comp = af.localeCompare(bf);
|
|
687
|
+
if (comp > 0) {
|
|
688
|
+
return GREATER;
|
|
689
|
+
}
|
|
690
|
+
if (comp < 0) {
|
|
691
|
+
return SMALLER;
|
|
692
|
+
}
|
|
693
|
+
if (i === l - 1) {
|
|
694
|
+
return 0;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
if (af < bf) {
|
|
698
|
+
return SMALLER;
|
|
699
|
+
}
|
|
700
|
+
if (af > bf) {
|
|
701
|
+
return GREATER;
|
|
702
|
+
}
|
|
703
|
+
if ("" + af < "" + bf) {
|
|
704
|
+
return SMALLER;
|
|
705
|
+
}
|
|
706
|
+
if ("" + af > "" + bf) {
|
|
707
|
+
return GREATER;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return 0;
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
lib.default = natsort;
|
|
714
|
+
return lib;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
var libExports = requireLib();
|
|
718
|
+
var natsort = /*@__PURE__*/getDefaultExportFromCjs(libExports);
|
|
719
|
+
|
|
595
720
|
const isNotEmpty = lodashEs.negate(lodashEs.isEmpty);
|
|
596
721
|
const wait = (timeoutMs) => new Promise((resolve) => {
|
|
597
722
|
setTimeout(resolve, timeoutMs);
|
|
@@ -643,6 +768,20 @@ const sanitiseFileName = (filename) => {
|
|
|
643
768
|
return valid.slice().slice(0, 64);
|
|
644
769
|
return valid.slice(0, -fileExt.length - 1).slice(0, 64) + '.' + fileExt;
|
|
645
770
|
};
|
|
771
|
+
const naturalSortInsensitive = natsort({ insensitive: true });
|
|
772
|
+
const santitizeNaturalValue = (v) => {
|
|
773
|
+
if (v === '–' || v === '-' || v == null) {
|
|
774
|
+
return '';
|
|
775
|
+
}
|
|
776
|
+
return String(v);
|
|
777
|
+
};
|
|
778
|
+
const compareNaturalInsensitive = (a, b) => {
|
|
779
|
+
if ((a !== null && typeof a === 'object') || (b !== null && typeof b === 'object')) {
|
|
780
|
+
// We can't compare objects
|
|
781
|
+
return 0;
|
|
782
|
+
}
|
|
783
|
+
return naturalSortInsensitive(santitizeNaturalValue(a), santitizeNaturalValue(b));
|
|
784
|
+
};
|
|
646
785
|
|
|
647
786
|
/**
|
|
648
787
|
* AgGrid checkbox select does not pass clicks within cell but not on the checkbox to checkbox.
|
|
@@ -2787,66 +2926,77 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2787
2926
|
const needsAutoSize = React.useRef(true);
|
|
2788
2927
|
const autoSizeResultRef = React.useRef(null);
|
|
2789
2928
|
const prevRowsVisibleRef = React.useRef(false);
|
|
2790
|
-
const
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
needsAutoSize.current = true;
|
|
2794
|
-
return;
|
|
2795
|
-
}
|
|
2796
|
-
const gridRendered = gridRenderState();
|
|
2797
|
-
if (gridRendered === null) {
|
|
2798
|
-
// Don't resize until grid has rendered, or it has 0 rows.
|
|
2799
|
-
needsAutoSize.current = true;
|
|
2929
|
+
const initialContentSizeInProgressRef = React.useRef(false);
|
|
2930
|
+
const setInitialContentSize = React.useCallback(async () => {
|
|
2931
|
+
if (initialContentSizeInProgressRef.current) {
|
|
2800
2932
|
return;
|
|
2801
2933
|
}
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
prevRowsVisibleRef.current = rowsVisible;
|
|
2810
|
-
autoSizeResultRef.current = null;
|
|
2934
|
+
initialContentSizeInProgressRef.current = true;
|
|
2935
|
+
try {
|
|
2936
|
+
needsAutoSize.current = false;
|
|
2937
|
+
if (!gridDivRef.current?.clientWidth || rowData == null) {
|
|
2938
|
+
// Don't resize grids if they are offscreen as it doesn't work.
|
|
2939
|
+
needsAutoSize.current = true;
|
|
2940
|
+
return;
|
|
2811
2941
|
}
|
|
2812
|
-
const
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
2816
|
-
});
|
|
2817
|
-
// Auto-size failed retry later
|
|
2818
|
-
if (!autoSizeResult) {
|
|
2942
|
+
const gridRendered = gridRenderState();
|
|
2943
|
+
if (gridRendered === null) {
|
|
2944
|
+
// Don't resize until grid has rendered, or it has 0 rows.
|
|
2819
2945
|
needsAutoSize.current = true;
|
|
2820
2946
|
return;
|
|
2821
2947
|
}
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
//
|
|
2828
|
-
if (
|
|
2829
|
-
|
|
2830
|
-
|
|
2948
|
+
// 1. First we autosize to get the size of the columns on an infinite grid.
|
|
2949
|
+
if (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') {
|
|
2950
|
+
// You can't skip headers until the grid has content
|
|
2951
|
+
const rowsVisible = gridRendered === 'rows-visible';
|
|
2952
|
+
const skipHeader = sizeColumns === 'auto-skip-headers' && rowsVisible;
|
|
2953
|
+
// If grid was empty and now has content we need to autosize
|
|
2954
|
+
if (rowsVisible !== prevRowsVisibleRef.current && rowsVisible) {
|
|
2955
|
+
prevRowsVisibleRef.current = rowsVisible;
|
|
2956
|
+
autoSizeResultRef.current = null;
|
|
2831
2957
|
}
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2958
|
+
const autoSizeResult = autoSizeResultRef.current ??
|
|
2959
|
+
(await autoSizeColumns({
|
|
2960
|
+
skipHeader,
|
|
2961
|
+
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
2962
|
+
}));
|
|
2963
|
+
// Auto-size failed retry later
|
|
2964
|
+
if (!autoSizeResult) {
|
|
2965
|
+
needsAutoSize.current = true;
|
|
2966
|
+
return;
|
|
2967
|
+
}
|
|
2968
|
+
autoSizeResultRef.current = autoSizeResult;
|
|
2969
|
+
// Calculate the auto-sized width, limit it to maxInitialWidth
|
|
2970
|
+
autoSizeResult.width = maxInitialWidth ? Math.min(autoSizeResult.width, maxInitialWidth) : autoSizeResult.width;
|
|
2971
|
+
if (gridRendered === 'empty') {
|
|
2972
|
+
// If the grid is empty we still do an onContentSize callback, we will do another callback when grid has data
|
|
2973
|
+
// We don't do this callback if we have previously had row data, or have already called back for empty
|
|
2974
|
+
if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
|
|
2975
|
+
hasSetContentSizeEmpty.current = true;
|
|
2976
|
+
params.onContentSize?.(autoSizeResult);
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
else if (gridRendered === 'rows-visible') {
|
|
2980
|
+
// we have rows now so callback grid size
|
|
2981
|
+
if (!hasSetContentSize.current) {
|
|
2982
|
+
hasSetContentSize.current = true;
|
|
2983
|
+
params.onContentSize?.(autoSizeResult);
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
else {
|
|
2987
|
+
// It should be impossible to get here
|
|
2988
|
+
console.error('Unknown value returned from hasGridRendered');
|
|
2838
2989
|
}
|
|
2839
2990
|
}
|
|
2840
2991
|
else {
|
|
2841
|
-
|
|
2842
|
-
console.error('Unknown value returned from hasGridRendered');
|
|
2992
|
+
sizeColumnsToFit();
|
|
2843
2993
|
}
|
|
2994
|
+
setAutoSized(true);
|
|
2995
|
+
needsAutoSize.current = false;
|
|
2844
2996
|
}
|
|
2845
|
-
|
|
2846
|
-
|
|
2997
|
+
finally {
|
|
2998
|
+
initialContentSizeInProgressRef.current = false;
|
|
2847
2999
|
}
|
|
2848
|
-
setAutoSized(true);
|
|
2849
|
-
needsAutoSize.current = false;
|
|
2850
3000
|
}, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
|
|
2851
3001
|
const lastOwnerDocumentRef = React.useRef();
|
|
2852
3002
|
const wasVisibleRef = React.useRef(false);
|
|
@@ -2880,8 +3030,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2880
3030
|
}
|
|
2881
3031
|
if (needsAutoSize.current ||
|
|
2882
3032
|
(!hasSetContentSize.current && (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers'))) {
|
|
2883
|
-
|
|
2884
|
-
setInitialContentSize();
|
|
3033
|
+
void setInitialContentSize();
|
|
2885
3034
|
}
|
|
2886
3035
|
}, 200);
|
|
2887
3036
|
/**
|
|
@@ -3010,11 +3159,13 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3010
3159
|
if (previousRowDataLength.current !== length) {
|
|
3011
3160
|
// We need to autosize all cells again
|
|
3012
3161
|
autoSizeResultRef.current = null;
|
|
3013
|
-
setInitialContentSize();
|
|
3014
3162
|
previousRowDataLength.current = length;
|
|
3163
|
+
void setInitialContentSize();
|
|
3164
|
+
return;
|
|
3015
3165
|
}
|
|
3016
|
-
if (lastUpdatedDep.current === updatedDep || lodashEs.isEmpty(colIdsEdited.current))
|
|
3166
|
+
if (lastUpdatedDep.current === updatedDep || lodashEs.isEmpty(colIdsEdited.current)) {
|
|
3017
3167
|
return;
|
|
3168
|
+
}
|
|
3018
3169
|
lastUpdatedDep.current = updatedDep;
|
|
3019
3170
|
// Don't update while there are spinners
|
|
3020
3171
|
if (anyUpdating()) {
|
|
@@ -3022,7 +3173,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3022
3173
|
}
|
|
3023
3174
|
const skipHeader = sizeColumns === 'auto-skip-headers';
|
|
3024
3175
|
if ((sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && hasSetContentSize.current) {
|
|
3025
|
-
autoSizeColumns({
|
|
3176
|
+
void autoSizeColumns({
|
|
3026
3177
|
skipHeader,
|
|
3027
3178
|
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
3028
3179
|
colIds: colIdsEdited.current,
|
|
@@ -3112,11 +3263,51 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3112
3263
|
...colDef,
|
|
3113
3264
|
children: colDef.children.map((colDef) => adjustColDefOrGroup(colDef)),
|
|
3114
3265
|
});
|
|
3115
|
-
const adjustColDef = (colDef) =>
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
sortable
|
|
3119
|
-
|
|
3266
|
+
const adjustColDef = (colDef) => {
|
|
3267
|
+
const flex = colDef.flex ?? (sizeColumns === 'fit' ? 1 : undefined);
|
|
3268
|
+
const valueFormatter = colDef.valueFormatter;
|
|
3269
|
+
const sortable = colDef.sortable && params.defaultColDef?.sortable !== false;
|
|
3270
|
+
let comparator = colDef.comparator;
|
|
3271
|
+
if (sortable && !comparator) {
|
|
3272
|
+
comparator = (value1, value2, node1, node2) => {
|
|
3273
|
+
let r = 0;
|
|
3274
|
+
if (typeof valueFormatter === 'function') {
|
|
3275
|
+
r = compareNaturalInsensitive(valueFormatter({
|
|
3276
|
+
data: node1.data,
|
|
3277
|
+
value: value1,
|
|
3278
|
+
node: node1,
|
|
3279
|
+
colDef: adjustedColDef,
|
|
3280
|
+
...NotAGridValueFormatterCall,
|
|
3281
|
+
}), valueFormatter({
|
|
3282
|
+
data: node2.data,
|
|
3283
|
+
value: value2,
|
|
3284
|
+
node: node2,
|
|
3285
|
+
colDef: adjustedColDef,
|
|
3286
|
+
...NotAGridValueFormatterCall,
|
|
3287
|
+
}));
|
|
3288
|
+
}
|
|
3289
|
+
else {
|
|
3290
|
+
r = compareNaturalInsensitive(value1, value2);
|
|
3291
|
+
}
|
|
3292
|
+
// secondary compare as primary sort column rows are equal
|
|
3293
|
+
return r === 0 ? compareNaturalInsensitive(node1.data?.id, node2.data?.id) : r;
|
|
3294
|
+
};
|
|
3295
|
+
}
|
|
3296
|
+
const adjustedColDef = {
|
|
3297
|
+
...colDef,
|
|
3298
|
+
// You cannot pass a width to a flex
|
|
3299
|
+
width: !!colDef.flex ? undefined : colDef.width,
|
|
3300
|
+
...(!!colDef.flex && { flexAutoSizeWidth: colDef.width }),
|
|
3301
|
+
// If this is allowed flex columns don't size based on flex
|
|
3302
|
+
suppressSizeToFit: true,
|
|
3303
|
+
// Auto-sizing flex columns breaks everything
|
|
3304
|
+
flex,
|
|
3305
|
+
suppressAutoSize: !!flex,
|
|
3306
|
+
sortable,
|
|
3307
|
+
comparator,
|
|
3308
|
+
};
|
|
3309
|
+
return adjustedColDef;
|
|
3310
|
+
};
|
|
3120
3311
|
return columnDefs.map((colDef) => adjustColDefOrGroup(colDef));
|
|
3121
3312
|
}, [columnDefs, params.defaultColDef?.sortable, sizeColumns]);
|
|
3122
3313
|
/**
|
|
@@ -3141,7 +3332,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3141
3332
|
if (sizeColumns === 'auto' || skipHeader) {
|
|
3142
3333
|
lodashEs.defer(() => {
|
|
3143
3334
|
if (hasSetContentSize.current) {
|
|
3144
|
-
autoSizeColumns({
|
|
3335
|
+
void autoSizeColumns({
|
|
3145
3336
|
skipHeader,
|
|
3146
3337
|
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
3147
3338
|
colIds: colIdsEdited.current,
|
|
@@ -3296,7 +3487,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3296
3487
|
}, [columnDefs, params.loading, params.noRowsMatchingOverlayText, params.noRowsOverlayText, rowData, rowHeight]);
|
|
3297
3488
|
const selectionColumnDef = React.useMemo(() => {
|
|
3298
3489
|
// Note this has to be 1 for hidden otherwise ag-grid does crazy things whilst resizing
|
|
3299
|
-
const selectWidth = params.
|
|
3490
|
+
const selectWidth = params.onRowDragEnd ? 76 : 48;
|
|
3300
3491
|
return {
|
|
3301
3492
|
suppressNavigable: params.hideSelectColumn,
|
|
3302
3493
|
rowDrag: !!params.onRowDragEnd,
|
|
@@ -3306,6 +3497,8 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3306
3497
|
headerComponentParams: {
|
|
3307
3498
|
exportable: false,
|
|
3308
3499
|
},
|
|
3500
|
+
suppressAutoSize: true,
|
|
3501
|
+
suppressSizeToFit: true,
|
|
3309
3502
|
headerClass: clsx('ag-header-hide-default-select', params.onRowDragEnd && 'ag-header-select-draggable'),
|
|
3310
3503
|
headerComponent: rowSelection == 'multiple' ? GridHeaderSelect : undefined,
|
|
3311
3504
|
suppressHeaderKeyboardEvent: (e) => {
|
|
@@ -3336,7 +3529,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3336
3529
|
selectable,
|
|
3337
3530
|
]);
|
|
3338
3531
|
const onGridSizeChanged = React.useCallback((event) => {
|
|
3339
|
-
if (sizeColumns === 'fit') {
|
|
3532
|
+
if (sizeColumns === 'fit' || (['auto', 'auto-skip-headers'].includes(sizeColumns) && hasSetContentSize.current)) {
|
|
3340
3533
|
event.api.sizeColumnsToFit();
|
|
3341
3534
|
}
|
|
3342
3535
|
}, [sizeColumns]);
|
|
@@ -3345,13 +3538,26 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3345
3538
|
enableSelectionWithoutKeys: params.enableSelectionWithoutKeys ?? false,
|
|
3346
3539
|
enableClickSelection: params.enableClickSelection ?? false,
|
|
3347
3540
|
mode: rowSelection === 'single' ? 'singleRow' : 'multiRow',
|
|
3541
|
+
...(params.hideSelectColumn && {
|
|
3542
|
+
checkboxes: false,
|
|
3543
|
+
headerCheckbox: false,
|
|
3544
|
+
}),
|
|
3348
3545
|
}
|
|
3349
|
-
: undefined, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onGridSizeChanged: onGridSizeChanged, onColumnVisible: setInitialContentSize, onRowDataUpdated: onRowDataUpdated, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStopped: onCellEditingStopped, domLayout: params.domLayout, onColumnResized: onColumnResized, defaultColDef: defaultColDef, columnDefs: columnDefsAdjusted,
|
|
3546
|
+
: undefined, selectionColumnDef: selectionColumnDef, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onGridSizeChanged: onGridSizeChanged, onColumnVisible: () => void setInitialContentSize(), onRowDataUpdated: onRowDataUpdated, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStopped: onCellEditingStopped, domLayout: params.domLayout, onColumnResized: onColumnResized, defaultColDef: defaultColDef, columnDefs: columnDefsAdjusted, rowData: rowData, postSortRows: params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, quickFilterParser: quickFilterParser, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, noRowsOverlayComponent: noRowsOverlayComponent, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true, preventDefaultOnContextMenu: true, onCellContextMenu: gridContextMenu.cellContextMenu, rowDragText: params.rowDragText, onRowDragCancel: clearHighlightRowClasses, onRowDragMove: onRowDragMove, onRowDragEnd: onRowDragEnd, suppressCellFocus: params.suppressCellFocus, pinnedTopRowData: params.pinnedTopRowData, pinnedBottomRowData: params.pinnedBottomRowData, onRowClicked: params.onRowClicked, onRowDoubleClicked: params.onRowDoubleClicked, suppressStartEditOnTab: true }) })] }));
|
|
3350
3547
|
};
|
|
3351
3548
|
const quickFilterParser = (filterStr) => {
|
|
3352
3549
|
// filter is exact matches exactly groups separated by commas
|
|
3353
3550
|
return filterStr.split(',').map((str) => str.trim());
|
|
3354
3551
|
};
|
|
3552
|
+
/**
|
|
3553
|
+
* Columns to indicate to user when they debug why things are broken in the default comparator if their valueFormatter
|
|
3554
|
+
* is too complicated.
|
|
3555
|
+
*/
|
|
3556
|
+
const NotAGridValueFormatterCall = {
|
|
3557
|
+
column: 'Default comparator has no access to column, write your own comparator',
|
|
3558
|
+
api: 'Default comparator has no access to api, write your own comparator',
|
|
3559
|
+
context: 'Default comparator has no access to context, write your own comparator',
|
|
3560
|
+
};
|
|
3355
3561
|
|
|
3356
3562
|
const GridPopoverContext = React.createContext({
|
|
3357
3563
|
anchorRef: { current: null },
|
|
@@ -5610,40 +5816,57 @@ const GridContextProvider = (props) => {
|
|
|
5610
5816
|
* If you don't clear flex column widths ag-grid gets confused and does random sizing's.
|
|
5611
5817
|
* Then we size the flexed columns.
|
|
5612
5818
|
*/
|
|
5613
|
-
const autoSizeColumns = React.useCallback(({ skipHeader, colIds, userSizedColIds } = {}) => {
|
|
5819
|
+
const autoSizeColumns = React.useCallback(async ({ skipHeader, colIds, userSizedColIds } = {}) => {
|
|
5614
5820
|
if (!gridApi || !gridApi.getColumnState()) {
|
|
5615
5821
|
return null;
|
|
5616
5822
|
}
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
const
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5823
|
+
try {
|
|
5824
|
+
const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
|
|
5825
|
+
const getVisibleColStates = () => {
|
|
5826
|
+
const colStates = gridApi.getColumnState();
|
|
5827
|
+
return colStates.filter((colState) => {
|
|
5828
|
+
const colId = colState.colId;
|
|
5829
|
+
return (lodashEs.isEmpty(colIdsSet) || colIdsSet.has(colId)) && !userSizedColIds?.has(colId);
|
|
5830
|
+
});
|
|
5831
|
+
};
|
|
5832
|
+
const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
|
|
5833
|
+
const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
|
|
5834
|
+
// You cannot autosize flex columns it will break layout randomly
|
|
5835
|
+
// So, a flex column is assumed to be 150 wide, unless width is provided
|
|
5836
|
+
const flexColumns = getFlexColStates().map(colStateId);
|
|
5837
|
+
let width = 0;
|
|
5838
|
+
flexColumns.forEach((colId) => {
|
|
5839
|
+
const colDef = gridApi.getColumnDef(colId);
|
|
5840
|
+
width += colDef?.flexAutoSizeWidth ?? 200;
|
|
5623
5841
|
});
|
|
5624
|
-
|
|
5625
|
-
const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
|
|
5626
|
-
const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
|
|
5627
|
-
// If we don't reset the flex columns auto size it causes issues with random resizing of flex columns
|
|
5628
|
-
let flexColumns = getFlexColStates();
|
|
5629
|
-
let width = 0;
|
|
5630
|
-
if (!lodashEs.isEmpty(flexColumns)) {
|
|
5631
|
-
gridApi.autoSizeColumns(flexColumns.map(colStateId), skipHeader);
|
|
5632
|
-
const flexColumnIds = flexColumns.map(colStateId);
|
|
5633
|
-
flexColumns = getVisibleColStates().filter((colState) => flexColumnIds.includes(colState.colId));
|
|
5634
|
-
width += lodashEs.sumBy(flexColumns.filter((col) => !col.hide), 'width');
|
|
5635
|
-
gridApi.resetColumnState();
|
|
5636
|
-
}
|
|
5637
|
-
let nonFlexColumns = getNonFlexColStates();
|
|
5638
|
-
if (!lodashEs.isEmpty(nonFlexColumns)) {
|
|
5639
|
-
gridApi.autoSizeColumns(nonFlexColumns.map(colStateId), skipHeader);
|
|
5842
|
+
const nonFlexColumns = getNonFlexColStates();
|
|
5640
5843
|
const nonFlexColumnIds = nonFlexColumns.map(colStateId);
|
|
5641
|
-
|
|
5642
|
-
|
|
5844
|
+
gridApi.autoSizeColumns({ colIds: nonFlexColumnIds, skipHeader });
|
|
5845
|
+
const calcSubWidth = () => {
|
|
5846
|
+
const updatedFlexColumns = getVisibleColStates().filter((colState) => nonFlexColumnIds.includes(colState.colId));
|
|
5847
|
+
return lodashEs.sumBy(updatedFlexColumns.filter((col) => !col.hide), 'width');
|
|
5848
|
+
};
|
|
5849
|
+
// ag-grid updates widths asynchronously, so we wait here for the default calculated width to change
|
|
5850
|
+
let lastSubWidth = calcSubWidth();
|
|
5851
|
+
const endTime = Date.now() + 1000;
|
|
5852
|
+
while (Date.now() < endTime) {
|
|
5853
|
+
await wait(40);
|
|
5854
|
+
const newSubWidth = calcSubWidth();
|
|
5855
|
+
if (lastSubWidth !== newSubWidth) {
|
|
5856
|
+
lastSubWidth = newSubWidth;
|
|
5857
|
+
break;
|
|
5858
|
+
}
|
|
5859
|
+
}
|
|
5860
|
+
width += lastSubWidth;
|
|
5861
|
+
gridApi.sizeColumnsToFit();
|
|
5862
|
+
return {
|
|
5863
|
+
width,
|
|
5864
|
+
};
|
|
5865
|
+
}
|
|
5866
|
+
catch (ex) {
|
|
5867
|
+
console.info('autosize failed', ex);
|
|
5868
|
+
return null;
|
|
5643
5869
|
}
|
|
5644
|
-
return {
|
|
5645
|
-
width,
|
|
5646
|
-
};
|
|
5647
5870
|
}, [gridApi]);
|
|
5648
5871
|
/**
|
|
5649
5872
|
* Resize columns to fit container
|
|
@@ -6210,6 +6433,7 @@ exports.bearingValueFormatter = bearingValueFormatter;
|
|
|
6210
6433
|
exports.colStateFlexed = colStateFlexed;
|
|
6211
6434
|
exports.colStateId = colStateId;
|
|
6212
6435
|
exports.colStateNotFlexed = colStateNotFlexed;
|
|
6436
|
+
exports.compareNaturalInsensitive = compareNaturalInsensitive;
|
|
6213
6437
|
exports.convertDDToDMS = convertDDToDMS;
|
|
6214
6438
|
exports.createCheckboxMultiFilterParams = createCheckboxMultiFilterParams;
|
|
6215
6439
|
exports.defaultValueFormatter = defaultValueFormatter;
|