@linzjs/step-ag-grid 13.3.2 → 13.5.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 (30) hide show
  1. package/README.md +27 -16
  2. package/dist/index.css +17 -4
  3. package/dist/src/components/gridFilter/GridFilterDownloadCsvButton.d.ts +3 -0
  4. package/dist/src/components/gridFilter/index.d.ts +1 -0
  5. package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +1 -0
  6. package/dist/src/contexts/GridContext.d.ts +2 -0
  7. package/dist/src/contexts/GridContextProvider.d.ts +7 -0
  8. package/dist/src/contexts/GridContextProvider.test.d.ts +1 -0
  9. package/dist/src/utils/util.d.ts +7 -0
  10. package/dist/src/utils/util.test.d.ts +1 -0
  11. package/dist/step-ag-grid.esm.js +299 -97
  12. package/dist/step-ag-grid.esm.js.map +1 -1
  13. package/package.json +4 -3
  14. package/src/components/Grid.tsx +4 -0
  15. package/src/components/GridCell.tsx +7 -0
  16. package/src/components/gridFilter/GridFilterDownloadCsvButton.tsx +43 -0
  17. package/src/components/gridFilter/GridFilterHeaderIconButton.tsx +1 -1
  18. package/src/components/gridFilter/GridFilterQuick.tsx +12 -10
  19. package/src/components/gridFilter/index.ts +1 -0
  20. package/src/components/gridPopoverEdit/GridPopoverMenu.tsx +1 -0
  21. package/src/components/gridRender/GridRenderGenericCell.tsx +1 -0
  22. package/src/contexts/GridContext.tsx +5 -0
  23. package/src/contexts/GridContextProvider.test.tsx +39 -0
  24. package/src/contexts/GridContextProvider.tsx +83 -3
  25. package/src/stories/grid/GridPopoverEditBearing.stories.tsx +22 -10
  26. package/src/stories/grid/GridPopoverEditDropDown.stories.tsx +20 -8
  27. package/src/stories/grid/GridReadOnly.stories.tsx +5 -2
  28. package/src/styles/Grid.scss +23 -4
  29. package/src/utils/util.test.ts +8 -0
  30. package/src/utils/util.ts +10 -0
package/README.md CHANGED
@@ -65,6 +65,7 @@ import {
65
65
  // Only required for LINZ themes otherwise import the default theme from ag-grid
66
66
  import "@linzjs/step-ag-grid/dist/GridTheme.scss";
67
67
  import "@linzjs/step-ag-grid/dist/index.css";
68
+ import { GridFilterDownloadCsvButton } from "./GridFilterDownloadCsvButton";
68
69
 
69
70
  const GridDemo = () => {
70
71
  interface ITestRow {
@@ -80,6 +81,7 @@ const GridDemo = () => {
80
81
  headerName: "Id",
81
82
  initialWidth: 65,
82
83
  maxWidth: 85,
84
+ export: false,
83
85
  }),
84
86
  GridCell({
85
87
  field: "name",
@@ -113,7 +115,7 @@ const GridDemo = () => {
113
115
  {
114
116
  multiEdit: true,
115
117
  editorParams: {
116
- message: async ({ selectedRows }) => {
118
+ message: async ({selectedRows}) => {
117
119
  return `There are ${selectedRows.length} row(s) selected`;
118
120
  },
119
121
  },
@@ -136,25 +138,26 @@ const GridDemo = () => {
136
138
  <GridContextProvider>
137
139
  <GridWrapper>
138
140
  <GridFilters>
139
- <GridFilterQuick quickFilterPlaceholder={"Search..."} />
141
+ <GridFilterQuick/>
140
142
  <GridFilterButtons<ITestRow>
141
- options={[
142
- {
143
- label: "All",
144
- },
145
- {
146
- label: "Developers",
147
- filter: (row) => row.position === "Developer",
148
- },
149
- {
150
- label: "Testers",
151
- filter: (row) => row.position === "Tester",
152
- },
153
- ]}
143
+ options={[
144
+ {
145
+ label: "All",
146
+ },
147
+ {
148
+ label: "Developers",
149
+ filter: (row) => row.position === "Developer",
150
+ },
151
+ {
152
+ label: "Testers",
153
+ filter: (row) => row.position === "Tester",
154
+ },
155
+ ]}
154
156
  />
155
157
  <GridFilterColumnsToggle/>
158
+ <GridFilterDownloadCsvButton fileName={"exportFile"}/>
156
159
  </GridFilters>
157
- <Grid selectable={true} columnDefs={columnDefs} rowData={rowData} />
160
+ <Grid selectable={true} columnDefs={columnDefs} rowData={rowData}/>
158
161
  </GridWrapper>
159
162
  </GridContextProvider>
160
163
  </GridUpdatingContextProvider>
@@ -162,6 +165,14 @@ const GridDemo = () => {
162
165
  };
163
166
  ```
164
167
 
168
+ ## CSV Download
169
+ CSV download relies on column valueFormatters vs ag-grid's default valueGetter implementation.
170
+ If you use a customRenderer for a column be sure to include a valueFormatter.
171
+ To disable this behaviour pass undefined to processCellCallback.
172
+ ```<GridFilterDownloadCsvButton processCellCallback={undefined}/>```
173
+
174
+ To exclude a column from CSV download add ```export: false``` to the GridCell definition.
175
+
165
176
  ## Writing tests
166
177
 
167
178
  The following testing calls can be imported from step-ag-grid:
package/dist/index.css CHANGED
@@ -339,16 +339,29 @@
339
339
 
340
340
  .Grid-container-filters {
341
341
  width: 100%;
342
- margin-bottom: 16px;
343
342
  flex: 0;
344
343
  display: flex;
345
344
  align-items: center;
346
345
  flex-direction: row;
347
- grid-column-gap: 1em;
348
- padding: 0.25rem 0;
346
+ padding: 16px;
347
+ background-color: #f9f9f9;
348
+ border-bottom: 1px solid #beb9b4;
349
+ border-top: 2px solid #eaeaea;
349
350
  }
350
351
 
351
- .Grid-quickFilterBox {
352
+ .Grid-container-filters button {
353
+ margin-left: 0 !important;
354
+ }
355
+
356
+ .GridFilterQuick-container:not(:last-child), .GridFilter-container:not(:last-child) {
357
+ margin-right: 8px;
358
+ }
359
+
360
+ .GridFilterQuick-container {
361
+ flex: 1;
362
+ }
363
+
364
+ .GridFilterQuick-input {
352
365
  width: 100%;
353
366
  height: 40px;
354
367
  border: 0.06rem solid #beb9b4;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { CsvExportParams } from "ag-grid-community/dist/lib/interfaces/exportParams";
3
+ export declare const GridFilterDownloadCsvButton: (csvExportParams: CsvExportParams) => JSX.Element;
@@ -3,4 +3,5 @@ export * from "./GridFilterColumnsToggle";
3
3
  export * from "./GridFilterButtons";
4
4
  export * from "./GridFilterQuick";
5
5
  export * from "./GridFilters";
6
+ export * from "./GridFilterDownloadCsvButton";
6
7
  export * from "./useGridFilter";
@@ -25,6 +25,7 @@ export interface GenericCellColDef<RowType extends GridBaseRow> extends ColDefT<
25
25
  valueFormatter?: string | ((params: RowValueFormatterParams<RowType>) => string);
26
26
  filterValueGetter?: string | ((params: RowValueGetterParams<RowType>) => string);
27
27
  editable?: boolean | ((params: RowEditableCallbackParams<RowType>) => boolean);
28
+ exportable?: boolean;
28
29
  }
29
30
  export interface GenericCellRendererParams<RowType extends GridBaseRow> {
30
31
  singleClickEdit?: boolean;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { ColumnApi, GridApi, RowNode } from "ag-grid-community";
3
+ import { CsvExportParams } from "ag-grid-community/dist/lib/interfaces/exportParams";
3
4
  import { ColDefT, GridBaseRow } from "../components";
4
5
  export type GridFilterExternal<RowType extends GridBaseRow> = (data: RowType, rowNode: RowNode) => boolean;
5
6
  export interface GridContextType<RowType extends GridBaseRow> {
@@ -38,6 +39,7 @@ export interface GridContextType<RowType extends GridBaseRow> {
38
39
  getColumns: () => ColDefT<RowType>[];
39
40
  invisibleColumnIds: string[];
40
41
  setInvisibleColumnIds: (colIds: string[]) => void;
42
+ downloadCsv: (csvExportParams?: CsvExportParams) => void;
41
43
  }
42
44
  export declare const GridContext: import("react").Context<GridContextType<any>>;
43
45
  export declare const useGridContext: <RowType extends GridBaseRow>() => GridContextType<RowType>;
@@ -1,3 +1,4 @@
1
+ import { ProcessCellForExportParams } from "ag-grid-community/dist/lib/interfaces/exportParams";
1
2
  import { ReactElement, ReactNode } from "react";
2
3
  import { GridBaseRow } from "../components";
3
4
  interface GridContextProps {
@@ -9,4 +10,10 @@ interface GridContextProps {
9
10
  * Also, make sure the provider is created in a separate component, otherwise it won't be found.
10
11
  */
11
12
  export declare const GridContextProvider: <RowType extends GridBaseRow>(props: GridContextProps) => ReactElement;
13
+ /**
14
+ * Aggrid defaults to using getters and ignores formatters.
15
+ * step-ag-grid by default has a valueFormatter for every column that defaults to the getter if no valueFormatter
16
+ * This function uses valueFormatter by default
17
+ */
18
+ export declare const downloadCsvUseValueFormattersProcessCellCallback: (params: ProcessCellForExportParams) => string;
12
19
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -5,3 +5,10 @@ export declare const findParentWithClass: (className: string, child: Node) => HT
5
5
  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
+ /**
9
+ * Trim filename and replaces troublesome characters.
10
+ *
11
+ * e.g. " LT 1235/543 &%//*$ " => "LT_1235-543_&%-$"
12
+ * e.g. " @filename here!!!" => "@filename_here!!!"
13
+ */
14
+ export declare const sanitiseFileName: (filename: string) => string;
@@ -0,0 +1 @@
1
+ export {};