@linzjs/step-ag-grid 1.2.0 → 1.4.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.
Files changed (57) hide show
  1. package/dist/index.d.ts +4 -2
  2. package/dist/index.js +3463 -88181
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/components/GridCell.d.ts +2 -1
  5. package/dist/src/components/GridPopoverHook.d.ts +7 -0
  6. package/dist/src/components/gridForm/GridFormDropDown.d.ts +1 -0
  7. package/dist/src/components/gridForm/GridFormEditBearing.d.ts +1 -0
  8. package/dist/src/components/gridForm/GridFormPopoutMenu.d.ts +2 -1
  9. package/dist/src/components/gridForm/GridFormTextArea.d.ts +1 -0
  10. package/dist/src/components/gridForm/GridFormTextInput.d.ts +1 -0
  11. package/dist/src/components/gridPopoverEdit/GridPopoverEditBearing.d.ts +271 -1
  12. package/dist/src/components/gridPopoverEdit/{GridPopoutMenu.d.ts → GridPopoverMenu.d.ts} +2 -2
  13. package/dist/src/components/gridPopoverEdit/GridPopoverTextArea.d.ts +4 -0
  14. package/dist/src/components/gridPopoverEdit/GridPopoverTextInput.d.ts +4 -0
  15. package/dist/src/contexts/GridContext.d.ts +1 -1
  16. package/dist/src/stories/components/FormTest.d.ts +2 -2
  17. package/dist/src/stories/components/GridPopoutBearing.stories.d.ts +1 -1
  18. package/dist/src/stories/components/GridPopoutEditDropDown.stories.d.ts +1 -1
  19. package/dist/src/stories/components/GridPopoutEditGeneric.stories.d.ts +1 -1
  20. package/dist/src/stories/components/GridPopoutEditGenericTextArea.stories.d.ts +1 -1
  21. package/dist/src/stories/components/GridPopoutEditMultiSelect.stories.d.ts +1 -1
  22. package/dist/src/stories/components/GridReadOnly.stories.d.ts +1 -1
  23. package/dist/src/utils/bearing.d.ts +2 -1
  24. package/dist/src/utils/bearing.test.d.ts +1 -0
  25. package/dist/step-ag-grid.esm.js +3454 -88175
  26. package/dist/step-ag-grid.esm.js.map +1 -1
  27. package/package.json +38 -39
  28. package/src/components/Grid.tsx +3 -3
  29. package/src/components/GridCell.tsx +27 -3
  30. package/src/components/{GridPopoutHook.tsx → GridPopoverHook.tsx} +7 -5
  31. package/src/components/gridForm/GridFormDropDown.tsx +13 -6
  32. package/src/components/gridForm/GridFormEditBearing.tsx +6 -5
  33. package/src/components/gridForm/GridFormMessage.tsx +3 -3
  34. package/src/components/gridForm/GridFormMultiSelect.tsx +3 -3
  35. package/src/components/gridForm/GridFormPopoutMenu.tsx +9 -7
  36. package/src/components/gridForm/GridFormTextArea.tsx +8 -4
  37. package/src/components/gridForm/GridFormTextInput.tsx +8 -4
  38. package/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.ts +1 -2
  39. package/src/components/gridPopoverEdit/GridPopoverEditBearing.ts +29 -4
  40. package/src/components/gridPopoverEdit/GridPopoverEditDropDown.ts +1 -2
  41. package/src/components/gridPopoverEdit/{GridPopoutMenu.scss → GridPopoverMenu.scss} +0 -0
  42. package/src/components/gridPopoverEdit/{GridPopoutMenu.tsx → GridPopoverMenu.tsx} +2 -2
  43. package/src/components/gridPopoverEdit/GridPopoverTextArea.ts +20 -0
  44. package/src/components/gridPopoverEdit/GridPopoverTextInput.ts +20 -0
  45. package/src/contexts/GridContext.tsx +1 -1
  46. package/src/contexts/GridContextProvider.tsx +2 -2
  47. package/src/lui/TextInputFormatted.scss +1 -1
  48. package/src/stories/components/FormTest.tsx +6 -6
  49. package/src/stories/components/GridPopoutBearing.stories.tsx +18 -15
  50. package/src/stories/components/GridPopoutEditDropDown.stories.tsx +11 -10
  51. package/src/stories/components/GridPopoutEditGeneric.stories.tsx +4 -4
  52. package/src/stories/components/GridPopoutEditGenericTextArea.stories.tsx +17 -13
  53. package/src/stories/components/GridPopoutEditMultiSelect.stories.tsx +9 -9
  54. package/src/stories/components/GridReadOnly.stories.tsx +15 -10
  55. package/src/utils/bearing.test.ts +30 -0
  56. package/src/utils/bearing.ts +19 -8
  57. package/dist/src/components/GridPopoutHook.d.ts +0 -7
@@ -0,0 +1,20 @@
1
+ import { GridCell } from "../GridCell";
2
+ import { GridBaseRow } from "../Grid";
3
+ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
4
+ import { GridFormTextArea, GridFormTextAreaProps } from "../gridForm/GridFormTextArea";
5
+
6
+ export const GridPopoverTextArea = <RowType extends GridBaseRow>(
7
+ colDef: GenericCellColDef<RowType, GridFormTextAreaProps<RowType>>,
8
+ ) => {
9
+ return GridCell<RowType, GridFormTextAreaProps<RowType>>({
10
+ maxWidth: 260,
11
+ ...colDef,
12
+ ...(colDef?.cellEditorParams && {
13
+ cellEditorParams: {
14
+ width: 260,
15
+ ...colDef.cellEditorParams,
16
+ form: GridFormTextArea,
17
+ },
18
+ }),
19
+ });
20
+ };
@@ -0,0 +1,20 @@
1
+ import { GridCell } from "../GridCell";
2
+ import { GridBaseRow } from "../Grid";
3
+ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
4
+ import { GridFormTextInput, GridFormTextInputProps } from "../gridForm/GridFormTextInput";
5
+
6
+ export const GridPopoverTextInput = <RowType extends GridBaseRow>(
7
+ colDef: GenericCellColDef<RowType, GridFormTextInputProps<RowType>>,
8
+ ) => {
9
+ return GridCell<RowType, GridFormTextInputProps<RowType>>({
10
+ maxWidth: 140,
11
+ ...colDef,
12
+ ...(colDef?.cellEditorParams && {
13
+ cellEditorParams: {
14
+ width: 240,
15
+ ...colDef.cellEditorParams,
16
+ form: GridFormTextInput,
17
+ },
18
+ }),
19
+ });
20
+ };
@@ -1,6 +1,6 @@
1
1
  import { createContext } from "react";
2
2
  import { GridApi } from "ag-grid-community";
3
- import { GridBaseRow } from "../components/Grid";
3
+ import { GridBaseRow } from "@components/Grid";
4
4
 
5
5
  export interface GridContextType {
6
6
  gridReady: () => boolean;
@@ -2,9 +2,9 @@ import { ReactElement, ReactNode, useContext, useRef } from "react";
2
2
  import { GridApi, RowNode } from "ag-grid-community";
3
3
  import { GridContext } from "./GridContext";
4
4
  import { delay, difference, isEmpty, last, sortBy } from "lodash-es";
5
- import { isNotEmpty } from "../utils/util";
5
+ import { isNotEmpty } from "@utils/util";
6
6
  import { UpdatingContext } from "./UpdatingContext";
7
- import { GridBaseRow } from "../components/Grid";
7
+ import { GridBaseRow } from "@components/Grid";
8
8
 
9
9
  interface GridContextProps {
10
10
  children: ReactNode;
@@ -1,5 +1,5 @@
1
1
  .LuiTextInput {
2
- margin-bottom: 0px;
2
+ margin-bottom: 0;
3
3
  }
4
4
 
5
5
  .LuiTextInput-formatted {
@@ -2,10 +2,10 @@ import "./FormTest.scss";
2
2
 
3
3
  import { useCallback, useState } from "react";
4
4
  import { LuiTextInput } from "@linzjs/lui";
5
- import { wait } from "../../utils/util";
6
- import { GridFormProps } from "../../components/GridCell";
7
- import { useGridPopoutHook } from "../../components/GridPopoutHook";
8
- import { GridBaseRow } from "../../components/Grid";
5
+ import { wait } from "@utils/util";
6
+ import { GridFormProps } from "@components/GridCell";
7
+ import { useGridPopoverHook } from "@components/GridPopoverHook";
8
+ import { GridBaseRow } from "@components/Grid";
9
9
 
10
10
  export interface IFormTestRow {
11
11
  id: number;
@@ -33,9 +33,9 @@ export const FormTest = <RowType extends GridBaseRow>(props: GridFormProps<RowTy
33
33
  // Close form
34
34
  return true;
35
35
  }, [nameType, numba, plan, props.selectedRows]);
36
- const { popoutWrapper } = useGridPopoutHook(props, save);
36
+ const { popoverWrapper } = useGridPopoverHook(props, save);
37
37
 
38
- return popoutWrapper(
38
+ return popoverWrapper(
39
39
  <div style={{ display: "flex", flexDirection: "row" }} className={"FormTest Grid-popoverContainer"}>
40
40
  <div className={"FormTest-textInput"}>
41
41
  <LuiTextInput label={"Name type"} value={nameType} onChange={(e) => setNameType(e.target.value)} />
@@ -3,13 +3,16 @@ import "@linzjs/lui/dist/fonts";
3
3
  import "../../lui-overrides.scss";
4
4
 
5
5
  import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
6
- import { GridContextProvider } from "../../contexts/GridContextProvider";
7
- import { Grid, GridProps } from "../../components/Grid";
8
6
  import { useMemo, useState } from "react";
9
- import { UpdatingContextProvider } from "../../contexts/UpdatingContextProvider";
10
- import { GridPopoverEditBearing } from "../../components/gridPopoverEdit/GridPopoverEditBearing";
11
- import { wait } from "../../utils/util";
12
- import { GridCell } from "../../components/GridCell";
7
+ import { UpdatingContextProvider } from "@contexts/UpdatingContextProvider";
8
+ import { GridContextProvider } from "@contexts/GridContextProvider";
9
+ import { Grid, GridProps } from "@components/Grid";
10
+ import { GridCell } from "@components/GridCell";
11
+ import {
12
+ GridPopoverEditBearing,
13
+ GridPopoverEditBearingCorrection,
14
+ } from "@components/gridPopoverEdit/GridPopoverEditBearing";
15
+ import { wait } from "@utils/util";
13
16
 
14
17
  export default {
15
18
  title: "Components / Grids",
@@ -34,7 +37,7 @@ export default {
34
37
  interface ITestRow {
35
38
  id: number;
36
39
  bearing1: number | null;
37
- bearing2: number | null;
40
+ bearingCorrection: number | null;
38
41
  }
39
42
 
40
43
  const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
@@ -59,15 +62,15 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
59
62
  placeHolder: "Enter Bearing",
60
63
  },
61
64
  }),
62
- GridPopoverEditBearing<ITestRow>({
63
- field: "bearing2",
64
- headerName: "Bearing onSave",
65
+ GridPopoverEditBearingCorrection<ITestRow>({
66
+ field: "bearingCorrection",
67
+ headerName: "Bearing Correction",
65
68
  cellEditorParams: {
66
69
  multiEdit: true,
67
70
  placeHolder: "Enter Bearing",
68
- onSave: async (selectedRows: ITestRow[], value: ITestRow["bearing2"]) => {
71
+ onSave: async (selectedRows: ITestRow[], value: ITestRow["bearingCorrection"]) => {
69
72
  await wait(1000);
70
- selectedRows.forEach((row) => (row["bearing2"] = value));
73
+ selectedRows.forEach((row) => (row["bearingCorrection"] = value));
71
74
  return true;
72
75
  },
73
76
  },
@@ -79,9 +82,9 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
79
82
  const rowData = useMemo(
80
83
  () =>
81
84
  [
82
- { id: 1000, bearing1: 1.234, bearing2: 90 },
83
- { id: 1001, bearing1: 1.565, bearing2: 240 },
84
- { id: 1002, bearing1: null, bearing2: 355.1 },
85
+ { id: 1000, bearing1: 1.234, bearingCorrection: 90 },
86
+ { id: 1001, bearing1: 1.565, bearingCorrection: 240 },
87
+ { id: 1002, bearing1: null, bearingCorrection: 355.1 },
85
88
  ] as ITestRow[],
86
89
  [],
87
90
  );
@@ -3,20 +3,20 @@ import "@linzjs/lui/dist/fonts";
3
3
  import "../../lui-overrides.scss";
4
4
 
5
5
  import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
6
- import { GridContextProvider } from "../../contexts/GridContextProvider";
7
- import { Grid, GridProps } from "../../components/Grid";
6
+ import { UpdatingContextProvider } from "@contexts/UpdatingContextProvider";
7
+ import { GridContextProvider } from "@contexts/GridContextProvider";
8
+ import { Grid, GridProps } from "@components/Grid";
8
9
  import { useCallback, useMemo, useState } from "react";
9
10
  import {
10
11
  GridFormDropDown,
11
12
  GridFormPopoutDropDownProps,
12
13
  MenuSeparator,
13
14
  MenuSeparatorString,
14
- } from "../../components/gridForm/GridFormDropDown";
15
- import { UpdatingContextProvider } from "../../contexts/UpdatingContextProvider";
15
+ } from "@components/gridForm/GridFormDropDown";
16
16
  import { ColDef } from "ag-grid-community";
17
- import { wait } from "../../utils/util";
18
- import { GridCell } from "../../components/GridCell";
19
- import { GridPopoverEditDropDown } from "../../components/gridPopoverEdit/GridPopoverEditDropDown";
17
+ import { wait } from "@utils/util";
18
+ import { GridCell } from "@components/GridCell";
19
+ import { GridPopoverEditDropDown } from "@components/gridPopoverEdit/GridPopoverEditDropDown";
20
20
 
21
21
  export default {
22
22
  title: "Components / Grids",
@@ -94,11 +94,12 @@ const GridEditDropDownTemplate: ComponentStory<typeof Grid> = (props: GridProps)
94
94
  options: [
95
95
  {
96
96
  value: "1",
97
- label: <span style={{ border: "2px dashed blue" }}>One</span>,
97
+ label: "One",
98
+ disabled: "Disabled for test",
98
99
  },
99
- { value: "2", label: <span style={{ border: "2px dashed red" }}>Two</span> },
100
+ { value: "2", label: "Two" },
100
101
  MenuSeparator,
101
- { value: "3", label: <span style={{ border: "2px dashed green" }}>Three</span> },
102
+ { value: "3", label: "Three" },
102
103
  ],
103
104
  },
104
105
  }),
@@ -3,11 +3,11 @@ import "@linzjs/lui/dist/fonts";
3
3
  import "../../lui-overrides.scss";
4
4
 
5
5
  import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
6
- import { GridContextProvider } from "../../contexts/GridContextProvider";
7
- import { Grid, GridProps } from "../../components/Grid";
6
+ import { UpdatingContextProvider } from "@contexts/UpdatingContextProvider";
7
+ import { GridContextProvider } from "@contexts/GridContextProvider";
8
+ import { Grid, GridProps } from "@components/Grid";
8
9
  import { useMemo, useState } from "react";
9
- import { UpdatingContextProvider } from "../../contexts/UpdatingContextProvider";
10
- import { GridCell } from "../../components/GridCell";
10
+ import { GridCell } from "@components/GridCell";
11
11
  import { FormTest, IFormTestRow } from "./FormTest";
12
12
 
13
13
  export default {
@@ -3,15 +3,15 @@ import "@linzjs/lui/dist/fonts";
3
3
  import "../../lui-overrides.scss";
4
4
 
5
5
  import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
6
- import { GridContextProvider } from "../../contexts/GridContextProvider";
7
- import { Grid, GridProps } from "../../components/Grid";
6
+ import { UpdatingContextProvider } from "@contexts/UpdatingContextProvider";
7
+ import { GridContextProvider } from "@contexts/GridContextProvider";
8
+ import { Grid, GridProps } from "@components/Grid";
8
9
  import { useMemo, useState } from "react";
9
- import { UpdatingContextProvider } from "../../contexts/UpdatingContextProvider";
10
- import { GridCell } from "../../components/GridCell";
10
+ import { GridCell } from "@components/GridCell";
11
11
  import { IFormTestRow } from "./FormTest";
12
- import { GridFormTextArea, GridFormTextAreaProps } from "../../components/gridForm/GridFormTextArea";
13
- import { GridFormTextInput, GridFormTextInputProps } from "../../components/gridForm/GridFormTextInput";
14
- import { wait } from "../../utils/util";
12
+ import { wait } from "@utils/util";
13
+ import { GridPopoverTextArea } from "@components/gridPopoverEdit/GridPopoverTextArea";
14
+ import { GridPopoverTextInput } from "@components/gridPopoverEdit/GridPopoverTextInput";
15
15
 
16
16
  export default {
17
17
  title: "Components / Grids",
@@ -43,16 +43,18 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
43
43
  initialWidth: 65,
44
44
  maxWidth: 85,
45
45
  }),
46
- GridCell<IFormTestRow, GridFormTextInputProps<IFormTestRow>>({
46
+ GridPopoverTextInput<IFormTestRow>({
47
47
  field: "name",
48
48
  headerName: "Text input",
49
49
  maxWidth: 140,
50
50
  cellEditorParams: {
51
- form: GridFormTextInput,
52
51
  required: true,
53
52
  maxlength: 12,
54
53
  placeholder: "Enter some text...",
55
- width: 240,
54
+ validate: (value: string) => {
55
+ if (value === "never") return "The value 'never' is not allowed";
56
+ return null;
57
+ },
56
58
  multiEdit: false,
57
59
  onSave: async (selectedRows, value) => {
58
60
  await wait(1000);
@@ -61,17 +63,19 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
61
63
  },
62
64
  },
63
65
  }),
64
- GridCell<IFormTestRow, GridFormTextAreaProps<IFormTestRow>>({
66
+ GridPopoverTextArea<IFormTestRow>({
65
67
  field: "plan",
66
68
  headerName: "Text area",
67
69
  maxWidth: 140,
68
70
  cellEditorParams: {
69
- form: GridFormTextArea,
70
71
  required: true,
71
72
  maxlength: 32,
72
73
  placeholder: "Enter some text...",
73
- width: 260,
74
74
  multiEdit: true,
75
+ validate: (value: string) => {
76
+ if (value === "never") return "The value 'never' is not allowed";
77
+ return null;
78
+ },
75
79
  onSave: async (selectedRows, value) => {
76
80
  await wait(1000);
77
81
  selectedRows.forEach((selectedRow) => (selectedRow["plan"] = value));
@@ -3,17 +3,17 @@ import "@linzjs/lui/dist/fonts";
3
3
  import "../../lui-overrides.scss";
4
4
 
5
5
  import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
6
- import { GridContextProvider } from "../../contexts/GridContextProvider";
7
- import { Grid, GridProps } from "../../components/Grid";
6
+ import { UpdatingContextProvider } from "@contexts/UpdatingContextProvider";
7
+ import { GridContextProvider } from "@contexts/GridContextProvider";
8
+ import { Grid, GridProps } from "@components/Grid";
8
9
  import { useMemo, useState } from "react";
9
- import { MenuSeparator } from "../../components/gridForm/GridFormDropDown";
10
- import { UpdatingContextProvider } from "../../contexts/UpdatingContextProvider";
10
+ import { MenuSeparator } from "@components/gridForm/GridFormDropDown";
11
11
  import { ColDef } from "ag-grid-community";
12
- import { wait } from "../../utils/util";
13
- import { MultiSelectResult } from "../../components/gridForm/GridFormMultiSelect";
14
- import { GridSubComponentTextArea } from "../../components/GridSubComponentTextArea";
15
- import { GridCell } from "../../components/GridCell";
16
- import { GridPopoutEditMultiSelect } from "../../components/gridPopoverEdit/GridPopoutEditMultiSelect";
12
+ import { wait } from "@utils/util";
13
+ import { MultiSelectResult } from "@components/gridForm/GridFormMultiSelect";
14
+ import { GridSubComponentTextArea } from "@components/GridSubComponentTextArea";
15
+ import { GridCell } from "@components/GridCell";
16
+ import { GridPopoutEditMultiSelect } from "@components/gridPopoverEdit/GridPopoutEditMultiSelect";
17
17
 
18
18
  export default {
19
19
  title: "Components / Grids",
@@ -3,15 +3,15 @@ import "@linzjs/lui/dist/fonts";
3
3
  import "../../lui-overrides.scss";
4
4
 
5
5
  import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
6
- import { GridContextProvider } from "../../contexts/GridContextProvider";
7
- import { Grid, GridProps } from "../../components/Grid";
6
+ import { UpdatingContextProvider } from "@contexts/UpdatingContextProvider";
7
+ import { GridContextProvider } from "@contexts/GridContextProvider";
8
+ import { Grid, GridProps } from "@components/Grid";
8
9
  import { useMemo, useState } from "react";
9
- import { UpdatingContextProvider } from "../../contexts/UpdatingContextProvider";
10
- import { wait } from "../../utils/util";
10
+ import { wait } from "@utils/util";
11
11
  import { ICellRendererParams } from "ag-grid-community";
12
- import { GridPopoutMenu } from "../../components/gridPopoverEdit/GridPopoutMenu";
13
- import { GridPopoverMessage } from "../../components/gridPopoverEdit/GridPopoverMessage";
14
- import { GridCell } from "../../components/GridCell";
12
+ import { GridPopoverMenu } from "@components/gridPopoverEdit/GridPopoverMenu";
13
+ import { GridPopoverMessage } from "@components/gridPopoverEdit/GridPopoverMessage";
14
+ import { GridCell } from "@components/GridCell";
15
15
 
16
16
  export default {
17
17
  title: "Components / Grids",
@@ -84,7 +84,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
84
84
  multiEdit: true,
85
85
  },
86
86
  }),
87
- GridPopoutMenu<ITestRow>({
87
+ GridPopoverMenu<ITestRow>({
88
88
  headerName: "Menu",
89
89
  cellEditorParams: {
90
90
  options: async () => {
@@ -109,11 +109,16 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
109
109
  },
110
110
  multiEdit: true,
111
111
  },
112
+ {
113
+ label: "Disabled item",
114
+ disabled: "Disabled for test",
115
+ multiEdit: true,
116
+ },
112
117
  ];
113
118
  },
114
119
  },
115
120
  }),
116
- GridPopoutMenu<ITestRow>({
121
+ GridPopoverMenu<ITestRow>({
117
122
  headerName: "Menu disabled",
118
123
  editable: false,
119
124
  cellEditorParams: {
@@ -138,7 +143,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
138
143
  return (
139
144
  <Grid
140
145
  {...props}
141
- selectable={false}
146
+ selectable={true}
142
147
  externalSelectedItems={externalSelectedItems}
143
148
  setExternalSelectedItems={setExternalSelectedItems}
144
149
  columnDefs={columnDefs}
@@ -0,0 +1,30 @@
1
+ import { convertDDToDMS } from "./bearing";
2
+
3
+ describe("convertDDToDMS", () => {
4
+ test("converts decimal-ish degrees to DMS", () => {
5
+ expect(convertDDToDMS(-0.001, false, false)).toBe("-0° 00' 10\"");
6
+ expect(convertDDToDMS(-10.001, false, false)).toBe("-10° 00' 10\"");
7
+ expect(convertDDToDMS(-370.001, false, false)).toBe("-10° 00' 10\"");
8
+ expect(convertDDToDMS(359.595999, false, false)).toBe("0° 00'");
9
+ expect(convertDDToDMS(369.696999, false, false)).toBe("10° 10' 10\"");
10
+ expect(convertDDToDMS(221.555999, false, false)).toBe("221° 56'");
11
+ expect(convertDDToDMS(221.555999, false, true)).toBe("221° 56' 00.0\"");
12
+ expect(convertDDToDMS(5)).toBe("+5° 00' 00.0\"");
13
+ expect(convertDDToDMS(5.0)).toBe("+5° 00' 00.0\"");
14
+ expect(convertDDToDMS(5.00001)).toBe("+5° 00' 00.1\"");
15
+ expect(convertDDToDMS(5.1)).toBe("+5° 10' 00.0\"");
16
+ expect(convertDDToDMS(5.12345)).toBe("+5° 12' 34.5\"");
17
+ expect(convertDDToDMS(5.12345, false)).toBe("5° 12' 34.5\"");
18
+
19
+ expect(convertDDToDMS(300)).toBe("+300° 00' 00.0\"");
20
+ expect(convertDDToDMS(300.0)).toBe("+300° 00' 00.0\"");
21
+ expect(convertDDToDMS(300.00001)).toBe("+300° 00' 00.1\"");
22
+ expect(convertDDToDMS(300.1)).toBe("+300° 10' 00.0\"");
23
+ expect(convertDDToDMS(300.12345)).toBe("+300° 12' 34.5\"");
24
+ expect(convertDDToDMS(300.12345, false)).toBe("300° 12' 34.5\"");
25
+
26
+ expect(convertDDToDMS(300, false, false)).toBe("300° 00'");
27
+ expect(convertDDToDMS(300.1, false, false)).toBe("300° 10'");
28
+ expect(convertDDToDMS(0, false)).toBe("0° 00'");
29
+ });
30
+ });
@@ -5,7 +5,15 @@ export const bearingValueFormatter = (params: ValueFormatterParams): string => {
5
5
  if (value == null) {
6
6
  return "-";
7
7
  }
8
- return convertDDToDMS(value);
8
+ return convertDDToDMS(value, false, false);
9
+ };
10
+
11
+ export const bearingCorrectionValueFormatter = (params: ValueFormatterParams): string => {
12
+ const value = params.value;
13
+ if (value == null) {
14
+ return "-";
15
+ }
16
+ return convertDDToDMS(value, true, true);
9
17
  };
10
18
 
11
19
  export const bearingNumberParser = (value: string): number | null => {
@@ -13,27 +21,30 @@ export const bearingNumberParser = (value: string): number | null => {
13
21
  return parseFloat(value);
14
22
  };
15
23
 
16
- const validMaskForDmsBearing = /^(\d+)?(\.([0-5](\d([0-5](\d(\d+)?)?)?)?)?)?$/;
17
- export const bearingStringValidator = (value: string): string | null => {
24
+ const validMaskForDmsBearing = /^((-)?\d+)?(\.([0-5](\d([0-5](\d(\d+)?)?)?)?)?)?$/;
25
+ export const bearingStringValidator = (
26
+ value: string,
27
+ customValidate?: (value: number | null) => string | null,
28
+ ): string | null => {
18
29
  value = value.trim();
19
30
  if (value === "") return null;
20
31
  const match = value.match(validMaskForDmsBearing);
21
32
  if (!match) return "Bearing must be a positive number in D.MMSSS format";
22
- const decimalPart = match[3];
33
+ const decimalPart = match[4];
23
34
  if (decimalPart != null && decimalPart.length > 5) {
24
35
  return "Bearing has a maximum of 5 decimal places";
25
36
  }
26
37
 
27
38
  const bearing = parseFloat(value);
28
- if (bearing >= 360) return "Bearing must be between 0 and 360 inclusive";
29
- return null;
39
+
40
+ return customValidate ? customValidate(bearing) : null;
30
41
  };
31
42
 
32
43
  // Decimal-ish degrees to Degrees Minutes Seconds converter
33
44
  export const convertDDToDMS = (dd: number | null, showPositiveSymbol = true, addTrailingZeros = true): string => {
34
45
  if (dd == null) return "–";
35
46
 
36
- if (dd === 0) addTrailingZeros = true;
47
+ if (dd === 0) addTrailingZeros = false;
37
48
 
38
49
  // toFixed rounds parts up greater than 60, which has to be corrected below
39
50
  const [bearingWholeString, beringDecimalString] = dd.toFixed(5).split(".");
@@ -64,7 +75,7 @@ export const convertDDToDMS = (dd: number | null, showPositiveSymbol = true, add
64
75
  dmsString += `\xa0${minString}'\xa0${secString}.${deciSecString}"`; // "\xa0" is here for non-breaking space
65
76
  } else if (secNumeric != 0) {
66
77
  dmsString += `\xa0${minString}'\xa0${secString}"`;
67
- } else if (minNumeric != 0) {
78
+ } else {
68
79
  dmsString += `\xa0${minString}'`;
69
80
  }
70
81
 
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- import { GridFormProps } from "./GridCell";
3
- import { GridBaseRow } from "./Grid";
4
- export declare const useGridPopoutHook: <RowType extends GridBaseRow>(props: GridFormProps<RowType>, save?: ((selectedRows: any[]) => Promise<boolean>) | undefined) => {
5
- popoutWrapper: (children: JSX.Element) => JSX.Element;
6
- triggerSave: (reason?: string) => Promise<void>;
7
- };