@adaptabletools/adaptable-react-aggrid 18.0.0-canary.18 → 18.0.0-canary.19

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/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@adaptabletools/adaptable-react-aggrid",
3
- "version": "18.0.0-canary.18",
3
+ "version": "18.0.0-canary.19",
4
4
  "description": "React version of AdapTable - the powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements",
5
5
  "keywords": [],
6
6
  "license": "contact sales@adaptabletools.com for details",
7
7
  "typings": "src/index.d.ts",
8
8
  "dependencies": {
9
9
  "tslib": "^2.3.0",
10
- "@adaptabletools/adaptable": "18.0.0-canary.18"
10
+ "@adaptabletools/adaptable": "18.0.0-canary.19"
11
11
  },
12
12
  "peerDependencies": {
13
13
  "@ag-grid-community/core": ">=31.1.0",
@@ -1,18 +1,22 @@
1
1
  import * as React from 'react';
2
2
  import { AgGridReact } from '@ag-grid-community/react';
3
- import { AdaptableReactProps } from './AdaptableReact';
4
- import { GridApi, GridOptions } from '@ag-grid-community/core';
5
- export interface AdaptableProviderProps extends Omit<AdaptableReactProps, 'renderAgGridFrameworkComponent'> {
6
- gridOptions: GridOptions;
3
+ import { GridApi, GridOptions, Module } from '@ag-grid-community/core';
4
+ import { AdaptableOptions, AdaptableReadyInfo } from '..';
5
+ export interface AdaptableProviderProps<TData = any> {
6
+ gridOptions: GridOptions<TData>;
7
+ modules: Module[];
8
+ adaptableOptions: AdaptableOptions<TData>;
9
+ onAdaptableReady?: (adaptableReadyInfo: AdaptableReadyInfo) => void;
10
+ children?: React.ReactNode;
7
11
  }
8
12
  export type RenderAgGridFrameworkComponentResult = false | GridApi;
9
- type AgGridReactPropsWithoutGridOptions = Omit<React.ComponentProps<typeof AgGridReact>, 'gridOptions'>;
13
+ type AgGridReactPropsWithoutGridOptionsAndModules = Omit<React.ComponentProps<typeof AgGridReact>, 'gridOptions' | 'modules'>;
10
14
  export declare const Adaptable: {
11
- Provider: React.FunctionComponent<AdaptableProviderProps>;
15
+ Provider: React.FunctionComponent<AdaptableProviderProps<any>>;
12
16
  UI: (props: {
13
17
  style?: React.CSSProperties;
14
18
  className?: string;
15
19
  }) => JSX.Element;
16
- AgGridReact: (props: AgGridReactPropsWithoutGridOptions) => JSX.Element;
20
+ AgGridReact: (props: AgGridReactPropsWithoutGridOptionsAndModules) => JSX.Element;
17
21
  };
18
22
  export {};
@@ -21,51 +21,73 @@ const AdaptableProvider = (props) => {
21
21
  const [agGridProps, setAgGridProps] = React.useState();
22
22
  const [gridOptions, setGridOptions] = React.useState(props.gridOptions);
23
23
  const [agGridApi, setAgGridApi] = React.useState();
24
+ const adaptableAgGridReactRenderedRef = React.useRef(false);
24
25
  const gridApiPromiseResolve = React.useRef();
25
26
  const gridApiPromise = React.useMemo(() => {
26
27
  return new Promise((resolve) => {
27
28
  gridApiPromiseResolve.current = resolve;
28
29
  });
29
30
  }, []);
30
- const handleSetGridApi = (api) => {
31
+ const handleSetGridApi = React.useCallback((api) => {
31
32
  setAgGridApi(api);
32
33
  gridApiPromiseResolve.current(api);
33
- };
34
+ }, []);
35
+ const renderAgGridFrameworkComponent = React.useCallback((gridOptions) => {
36
+ setGridOptions(gridOptions);
37
+ setCurrentTransition(AdaptableAgGridStateTransitions.INITIALIZE_AG_GRID);
38
+ return gridApiPromise;
39
+ }, [gridApiPromise]);
40
+ // this is a check to make sure the user is rendering Adaptable.AgGridReact inside Adaptable.Provider
41
+ // and not AgGridReact directly
42
+ // we're waiting 1s for this to happen
43
+ React.useEffect(() => {
44
+ const timeoutId = setTimeout(() => {
45
+ // this ref is updated in setAgridProps function in the context
46
+ // which is called by the Adaptable.AgGridReact component on mount
47
+ // so if this has not been updated, it means the user is not rendering Adaptable.AgGridReact
48
+ // so we show an error in the console and link to the docs
49
+ if (!adaptableAgGridReactRenderedRef.current) {
50
+ console.error('You are not rendering <Adaptable.AgGridReact /> inside <Adaptable.Provider />.');
51
+ console.error('You are probably rendering <AgGridReact /> directly. Please use <Adaptable.AgGridReact /> instead.');
52
+ console.error('For more details, please see https://docs.adaptabletools.com/guide/react-integration');
53
+ }
54
+ }, 1000);
55
+ return () => {
56
+ clearTimeout(timeoutId);
57
+ };
58
+ }, []);
34
59
  return (React.createElement(AdaptableAgGridContext.Provider, { value: {
35
60
  transition: currentTransition,
36
61
  setTransition: setCurrentTransition,
62
+ modules: props.modules,
37
63
  gridOptions,
38
64
  setGridOptions,
39
65
  agGridApi,
40
66
  setAgGridApi: handleSetGridApi,
41
67
  agGridProps,
42
68
  setAgGridProps: (agGridProps) => {
69
+ adaptableAgGridReactRenderedRef.current = true;
43
70
  setAgGridProps(agGridProps);
44
71
  // get props and add the to gridOptions
45
72
  const newGridOptions = Object.assign(Object.assign({}, gridOptions), agGridProps);
46
- delete newGridOptions.modules;
47
73
  setGridOptions(newGridOptions);
48
74
  // Adaptable has everything it needs to initialize
49
75
  setCurrentTransition(AdaptableAgGridStateTransitions.INITIALIZE_ADAPTABLE);
50
76
  },
51
- adaptableProps: Object.assign(Object.assign({}, props), { renderAgGridFrameworkComponent: (gridOptions) => {
52
- setGridOptions(gridOptions);
53
- setCurrentTransition(AdaptableAgGridStateTransitions.INITIALIZE_AG_GRID);
54
- return gridApiPromise;
55
- } }),
77
+ adaptableProps: Object.assign(Object.assign({}, props), { renderAgGridFrameworkComponent }),
56
78
  } }, props.children));
57
79
  };
58
80
  // -- ADAPTABLE UI WRAPPER -
59
81
  const AdaptableUI = (props) => {
60
- const { adaptableProps, agGridProps, gridOptions, transition } = useAdaptableAgGridContext();
82
+ const { adaptableProps, modules, gridOptions, transition } = useAdaptableAgGridContext();
61
83
  if (transition === AdaptableAgGridStateTransitions.AG_GRID_EMIT_PROPS) {
62
84
  return null;
63
85
  }
64
- return (React.createElement(AdaptableReactComponent, Object.assign({ style: props.style, className: props.className, gridOptions: gridOptions, modules: agGridProps.modules }, adaptableProps)));
86
+ return (React.createElement(AdaptableReactComponent, Object.assign({ style: props.style, className: props.className, gridOptions: gridOptions, modules: modules }, adaptableProps)));
65
87
  };
66
88
  const AdaptableAgGridReact = (props) => {
67
89
  const agGridRef = React.useRef(null);
68
- const { gridOptions, setAgGridApi, transition, setAgGridProps } = useAdaptableAgGridContext();
90
+ const { modules, gridOptions, setAgGridApi, transition, setAgGridProps } = useAdaptableAgGridContext();
69
91
  React.useEffect(() => {
70
92
  const LIST_OF_PROPS_NOT_ON_GRID_OPTIONS = [
71
93
  'containerStyle',
@@ -86,7 +108,7 @@ const AdaptableAgGridReact = (props) => {
86
108
  if (transition !== AdaptableAgGridStateTransitions.INITIALIZE_AG_GRID) {
87
109
  return null;
88
110
  }
89
- return (React.createElement(AgGridReact, Object.assign({ ref: agGridRef }, props, { onGridReady: (event) => {
111
+ return (React.createElement(AgGridReact, Object.assign({ ref: agGridRef }, props, { modules: modules, onGridReady: (event) => {
90
112
  setAgGridApi(event.api);
91
113
  if (props.onGridReady) {
92
114
  props.onGridReady(event);
@@ -7,7 +7,7 @@ export interface AdaptableReactProps<TData = any> extends React.HTMLProps<HTMLDi
7
7
  gridOptions?: GridOptions<TData>;
8
8
  onAdaptableReady?: (adaptableReadyInfo: AdaptableReadyInfo) => void;
9
9
  renderAgGridFrameworkComponent: (gridOptions: GridOptions<TData>) => Promise<RenderAgGridFrameworkComponentResult>;
10
- modules?: Module[];
10
+ modules: Module[];
11
11
  }
12
12
  declare const AdaptableReact: React.FunctionComponent<AdaptableReactProps>;
13
13
  export default AdaptableReact;