@linzjs/step-ag-grid 7.0.3 → 7.0.4
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 +13 -15
- package/dist/index.js.map +1 -1
- package/dist/src/contexts/GridPopoverContext.d.ts +1 -7
- package/dist/step-ag-grid.esm.js +13 -15
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/GridCell.tsx +1 -1
- package/src/components/gridForm/GridFormEditBearing.tsx +3 -3
- package/src/components/gridPopoverEdit/GridPopoverEditBearing.ts +0 -1
- package/src/components/gridRender/GridRenderGenericCell.tsx +3 -8
- package/src/contexts/GridPopoverContext.tsx +2 -8
- package/src/contexts/GridPopoverContextProvider.tsx +1 -0
- package/src/stories/grid/GridPopoutBearing.stories.tsx +15 -15
- package/src/utils/bearing.ts +2 -2
package/package.json
CHANGED
|
@@ -78,7 +78,7 @@ export const GridCell = <RowType extends GridBaseRow, Props extends CellEditorCo
|
|
|
78
78
|
}),
|
|
79
79
|
// Default value formatter, otherwise react freaks out on objects
|
|
80
80
|
valueFormatter: (params: ValueFormatterParams) => {
|
|
81
|
-
if (params.value == null) return "
|
|
81
|
+
if (params.value == null) return "–";
|
|
82
82
|
const types = ["number", "boolean", "string"];
|
|
83
83
|
if (types.includes(typeof params.value)) return `${params.value}`;
|
|
84
84
|
else return JSON.stringify(params.value);
|
|
@@ -3,7 +3,7 @@ import "../../styles/GridFormEditBearing.scss";
|
|
|
3
3
|
import { useCallback, useMemo, useState } from "react";
|
|
4
4
|
import { GridBaseRow } from "../Grid";
|
|
5
5
|
import { TextInputFormatted } from "../../lui/TextInputFormatted";
|
|
6
|
-
import { bearingNumberParser, bearingStringValidator
|
|
6
|
+
import { bearingNumberParser, bearingStringValidator } from "../../utils/bearing";
|
|
7
7
|
import { useGridPopoverHook } from "../GridPopoverHook";
|
|
8
8
|
import { CellEditorCommon } from "../GridCell";
|
|
9
9
|
import { useGridPopoverContext } from "../../contexts/GridPopoverContext";
|
|
@@ -15,7 +15,7 @@ export interface GridFormEditBearingProps<RowType extends GridBaseRow> extends C
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export const GridFormEditBearing = <RowType extends GridBaseRow>(props: GridFormEditBearingProps<RowType>) => {
|
|
18
|
-
const { field, value: initialValue } = useGridPopoverContext<RowType>();
|
|
18
|
+
const { field, value: initialValue, formatValue } = useGridPopoverContext<RowType>();
|
|
19
19
|
|
|
20
20
|
// This clears out any scientific precision
|
|
21
21
|
const defaultValue = useMemo(
|
|
@@ -65,7 +65,7 @@ export const GridFormEditBearing = <RowType extends GridBaseRow>(props: GridForm
|
|
|
65
65
|
}}
|
|
66
66
|
autoFocus={true}
|
|
67
67
|
placeholder={props.placeHolder}
|
|
68
|
-
formatted={bearingStringValidator(value, props.range) ? "?" :
|
|
68
|
+
formatted={bearingStringValidator(value, props.range) ? "?" : formatValue(bearingNumberParser(value))}
|
|
69
69
|
error={bearingStringValidator(value, props.range)}
|
|
70
70
|
helpText={"Press enter or tab to save"}
|
|
71
71
|
/>
|
|
@@ -5,7 +5,6 @@ import { GridUpdatingContext } from "../../contexts/GridUpdatingContext";
|
|
|
5
5
|
import { GridLoadableCell } from "../GridLoadableCell";
|
|
6
6
|
import { GridIcon } from "../GridIcon";
|
|
7
7
|
import { ColDef, ICellRendererParams } from "ag-grid-community";
|
|
8
|
-
import { ValueFormatterParams } from "ag-grid-community/dist/lib/entities/colDef";
|
|
9
8
|
import { GridBaseRow } from "../Grid";
|
|
10
9
|
import { ColDefT } from "../GridCell";
|
|
11
10
|
|
|
@@ -33,13 +32,9 @@ export const GridRendererGenericCell = <RowType extends GridBaseRow>(props: ICel
|
|
|
33
32
|
const infoFn = cellRendererParams?.info;
|
|
34
33
|
const infoText = infoFn ? infoFn(props) : undefined;
|
|
35
34
|
|
|
36
|
-
const defaultFormatter = (
|
|
37
|
-
const formatter =
|
|
38
|
-
|
|
39
|
-
console.error("valueFormatter must be a function");
|
|
40
|
-
return <span>valueFormatter must be a function</span>;
|
|
41
|
-
}
|
|
42
|
-
const formatted = formatter(props as ValueFormatterParams);
|
|
35
|
+
const defaultFormatter = (value: any): string => value;
|
|
36
|
+
const formatter = props.formatValue ?? defaultFormatter;
|
|
37
|
+
const formatted = formatter(props.value);
|
|
43
38
|
|
|
44
39
|
return (
|
|
45
40
|
<GridLoadableCell isLoading={checkUpdating(colDef.field ?? colDef.colId ?? "", props.data.id)}>
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { createContext, RefObject, useContext } from "react";
|
|
2
2
|
import { GridBaseRow } from "../components/Grid";
|
|
3
3
|
|
|
4
|
-
export interface PropsType {
|
|
5
|
-
value: any;
|
|
6
|
-
data: any;
|
|
7
|
-
field: string;
|
|
8
|
-
selectedRows: any[];
|
|
9
|
-
updateValue: (saveFn: (selectedRows: any[]) => Promise<boolean>) => Promise<boolean>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
4
|
export interface GridPopoverContextType<RowType extends GridBaseRow> {
|
|
13
5
|
anchorRef: RefObject<Element>;
|
|
14
6
|
saving: boolean;
|
|
@@ -18,6 +10,7 @@ export interface GridPopoverContextType<RowType extends GridBaseRow> {
|
|
|
18
10
|
data: RowType;
|
|
19
11
|
selectedRows: RowType[];
|
|
20
12
|
updateValue: (saveFn: (selectedRows: any[]) => Promise<boolean>, tabDirection: 1 | 0 | -1) => Promise<boolean>;
|
|
13
|
+
formatValue: (value: any) => any;
|
|
21
14
|
}
|
|
22
15
|
|
|
23
16
|
export const GridPopoverContext = createContext<GridPopoverContextType<any>>({
|
|
@@ -29,6 +22,7 @@ export const GridPopoverContext = createContext<GridPopoverContextType<any>>({
|
|
|
29
22
|
data: {} as GridBaseRow,
|
|
30
23
|
selectedRows: [],
|
|
31
24
|
updateValue: async () => false,
|
|
25
|
+
formatValue: () => "! No gridPopoverContextProvider !",
|
|
32
26
|
});
|
|
33
27
|
|
|
34
28
|
export const useGridPopoverContext = <RowType extends GridBaseRow>() =>
|
|
@@ -37,8 +37,8 @@ export default {
|
|
|
37
37
|
|
|
38
38
|
interface ITestRow {
|
|
39
39
|
id: number;
|
|
40
|
-
bearing1: string | number | null;
|
|
41
40
|
bearingCorrection: number | null;
|
|
41
|
+
bearing: string | number | null;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
|
|
@@ -51,29 +51,29 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
51
51
|
initialWidth: 65,
|
|
52
52
|
maxWidth: 85,
|
|
53
53
|
}),
|
|
54
|
-
|
|
54
|
+
GridPopoverEditBearingCorrection(
|
|
55
55
|
{
|
|
56
|
-
field: "
|
|
57
|
-
headerName: "Bearing
|
|
56
|
+
field: "bearingCorrection",
|
|
57
|
+
headerName: "Bearing correction",
|
|
58
58
|
cellRendererParams: {
|
|
59
|
-
warning: (props
|
|
60
|
-
info: (props
|
|
59
|
+
warning: (props) => props.data.id == 1002 && "Testers are testing",
|
|
60
|
+
info: (props) => props.data.id == 1001 && "Developers are developing",
|
|
61
61
|
},
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
64
|
multiEdit: false,
|
|
65
65
|
},
|
|
66
66
|
),
|
|
67
|
-
|
|
67
|
+
GridPopoverEditBearing(
|
|
68
68
|
{
|
|
69
|
-
field: "
|
|
70
|
-
headerName: "Bearing
|
|
69
|
+
field: "bearing",
|
|
70
|
+
headerName: "Bearing",
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
73
|
editorParams: {
|
|
74
|
-
onSave: async (selectedRows, value: ITestRow["
|
|
74
|
+
onSave: async (selectedRows, value: ITestRow["bearing"]) => {
|
|
75
75
|
await wait(1000);
|
|
76
|
-
selectedRows.forEach((row) => (row["
|
|
76
|
+
selectedRows.forEach((row) => (row["bearing"] = value));
|
|
77
77
|
return true;
|
|
78
78
|
},
|
|
79
79
|
},
|
|
@@ -84,10 +84,10 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
const [rowData] = useState([
|
|
87
|
-
{ id: 1000,
|
|
88
|
-
{ id: 1001,
|
|
89
|
-
{ id: 1002,
|
|
90
|
-
{ id: 1003,
|
|
87
|
+
{ id: 1000, bearing: 1.234, bearingCorrection: null },
|
|
88
|
+
{ id: 1001, bearing: "0E-12", bearingCorrection: 240 },
|
|
89
|
+
{ id: 1002, bearing: null, bearingCorrection: 355.1 },
|
|
90
|
+
{ id: 1003, bearing: null, bearingCorrection: 0 },
|
|
91
91
|
] as ITestRow[]);
|
|
92
92
|
|
|
93
93
|
return (
|
package/src/utils/bearing.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ValueFormatterParams } from "ag-grid-community/dist/lib/entities/colDef
|
|
|
3
3
|
export const bearingValueFormatter = (params: ValueFormatterParams): string => {
|
|
4
4
|
const value = typeof params.value == "string" ? parseFloat(params.value) : params.value;
|
|
5
5
|
if (value == null) {
|
|
6
|
-
return "
|
|
6
|
+
return "–";
|
|
7
7
|
}
|
|
8
8
|
return convertDDToDMS(value, false, false);
|
|
9
9
|
};
|
|
@@ -11,7 +11,7 @@ export const bearingValueFormatter = (params: ValueFormatterParams): string => {
|
|
|
11
11
|
export const bearingCorrectionValueFormatter = (params: ValueFormatterParams): string => {
|
|
12
12
|
const value = params.value;
|
|
13
13
|
if (value == null) {
|
|
14
|
-
return "
|
|
14
|
+
return "–";
|
|
15
15
|
}
|
|
16
16
|
if (typeof value === "string") {
|
|
17
17
|
return convertDDToDMS(bearingNumberParser(value), true, true);
|