Skip to content

Commit

Permalink
[core] Allow to create one logger per Grid instance (#2529)
Browse files Browse the repository at this point in the history
* [core] Allow to create one logger per Grid instance (#2529)
  • Loading branch information
flaviendelangle authored Sep 3, 2021
1 parent fc31e9a commit e214b3a
Show file tree
Hide file tree
Showing 39 changed files with 119 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as React from 'react';
import { useGridState } from '../../hooks/features/core/useGridState';
import { useGridApiContext } from '../../hooks/root/useGridApiContext';
import { useLogger } from '../../hooks/utils/useLogger';
import { useGridLogger } from '../../hooks/utils/useGridLogger';
import { GridMainContainer } from '../containers/GridMainContainer';
import { ErrorBoundary } from '../ErrorBoundary';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';

export function GridErrorHandler(props) {
const { children } = props;
const logger = useLogger('GridErrorHandler');
const apiRef = useGridApiContext();
const logger = useGridLogger(apiRef, 'GridErrorHandler');
const rootProps = useGridRootProps();
const [gridState] = useGridState(apiRef);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { GridApiRef } from '../../../models/api/gridApiRef';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { useGridState } from '../core/useGridState';
import { useGridApiEventHandler } from '../../root/useGridApiEventHandler';
import { GridEvents } from '../../../constants/eventsConstants';
Expand All @@ -11,7 +11,7 @@ import { GridEvents } from '../../../constants/eventsConstants';
* @requires useGridVirtualRows (state)
*/
export const useGridColumnMenu = (apiRef: GridApiRef): void => {
const logger = useLogger('useGridColumnMenu');
const logger = useGridLogger(apiRef, 'useGridColumnMenu');
const [gridState, setGridState, forceUpdate] = useGridState(apiRef);

const showColumnMenu = React.useCallback(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { GridApiRef } from '../../../models/api/gridApiRef';
import { GridEvents } from '../../../constants/eventsConstants';
import { gridClasses } from '../../../gridClasses';
Expand Down Expand Up @@ -38,7 +38,7 @@ export const useGridColumnReorder = (
apiRef: GridApiRef,
props: Pick<GridComponentProps, 'disableColumnReorder'>,
): void => {
const logger = useLogger('useGridColumnReorder');
const logger = useGridLogger(apiRef, 'useGridColumnReorder');

const [, setGridState, forceUpdate] = useGridState(apiRef);
const dragColField = useGridSelector(apiRef, gridColumnReorderDragColSelector);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { ownerDocument } from '@material-ui/core/utils';
import { GridStateColDef } from '../../../models/colDef';
import { useLogger } from '../../utils';
import { useGridLogger } from '../../utils';
import { useEventCallback } from '../../../utils/material-ui-utils';
import { GridEvents } from '../../../constants/eventsConstants';
import { gridClasses } from '../../../gridClasses';
Expand Down Expand Up @@ -68,7 +68,7 @@ export const useGridColumnResize = (
apiRef: GridApiRef,
props: Pick<GridComponentProps, 'onColumnResize' | 'onColumnWidthChange'>,
) => {
const logger = useLogger('useGridColumnResize');
const logger = useGridLogger(apiRef, 'useGridColumnResize');
const [, setGridState, forceUpdate] = useGridState(apiRef);
const colDefRef = React.useRef<GridStateColDef>();
const colElementRef = React.useRef<HTMLDivElement>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getGridColDef } from '../../../models/colDef/getGridColDef';
import { GridColumnOrderChangeParams } from '../../../models/params/gridColumnOrderChangeParams';
import { mergeGridColTypes } from '../../../utils/mergeUtils';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { useGridSelector } from '../core/useGridSelector';
import { GridLocaleText, GridTranslationKeys } from '../../../models/api/gridLocaleTextApi';
import { useGridState } from '../core/useGridState';
Expand Down Expand Up @@ -134,7 +134,7 @@ export function useGridColumns(
'columns' | 'onColumnVisibilityChange' | 'columnTypes' | 'checkboxSelection'
>,
): void {
const logger = useLogger('useGridColumns');
const logger = useGridLogger(apiRef, 'useGridColumns');
const [gridState, setGridState, forceUpdate] = useGridState(apiRef);
const columnsMeta = useGridSelector(apiRef, gridColumnsMetaSelector);
const allColumns = useGridSelector(apiRef, allGridColumnsSelector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { GridApiRef } from '../../../models/api/gridApiRef';
import { GridApi } from '../../../models/api/gridApi';
import { isFunction } from '../../../utils/utils';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { getInitialGridState, GridState } from './gridState';

export const useGridApi = (apiRef: GridApiRef): GridApi => {
const logger = useLogger('useGridApi');
const logger = useGridLogger(apiRef, 'useGridApi');
const [, forceUpdate] = React.useState<GridState>();

if (!apiRef.current.state) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { GridDensity, GridDensityTypes } from '../../../models/gridDensity';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { GridApiRef } from '../../../models/api/gridApiRef';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useGridState } from '../core/useGridState';
Expand All @@ -15,7 +15,7 @@ export const useGridDensity = (
apiRef: GridApiRef,
props: Pick<GridComponentProps, 'headerHeight' | 'rowHeight' | 'density'>,
): void => {
const logger = useLogger('useDensity');
const logger = useGridLogger(apiRef, 'useDensity');
const [, setGridState, forceUpdate] = useGridState(apiRef);

const getUpdatedDensityState = React.useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { visibleSortedGridRowsSelector } from '../filter';
import { gridSelectionStateSelector } from '../selection';
import { GridCsvExportApi } from '../../../models/api/gridCsvExportApi';
import { GridExportCsvOptions } from '../../../models/gridExport';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { exportAs } from '../../../utils/exportAs';
import { buildCSV } from './serializers/csvSerializer';
import { GridStateColDef } from '../../../models';
Expand All @@ -20,7 +20,7 @@ import { GridStateColDef } from '../../../models';
* @requires useGridParamsApi (method)
*/
export const useGridCsvExport = (apiRef: GridApiRef): void => {
const logger = useLogger('useGridCsvExport');
const logger = useGridLogger(apiRef, 'useGridCsvExport');
const visibleColumns = useGridSelector(apiRef, visibleGridColumnsSelector);
const columns = useGridSelector(apiRef, allGridColumnsSelector);
const visibleSortedRows = useGridSelector(apiRef, visibleSortedGridRowsSelector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GridRowId, GridRowModel } from '../../../models/gridRows';
import { isDeepEqual } from '../../../utils/utils';
import { useGridApiEventHandler } from '../../root/useGridApiEventHandler';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { filterableGridColumnsIdsSelector } from '../columns/gridColumnsSelector';
import { useGridSelector } from '../core/useGridSelector';
import { useGridState } from '../core/useGridState';
Expand Down Expand Up @@ -37,7 +37,7 @@ export const useGridFilter = (
| 'disableMultipleColumnsFiltering'
>,
): void => {
const logger = useLogger('useGridFilter');
const logger = useGridLogger(apiRef, 'useGridFilter');
const [gridState, setGridState, forceUpdate] = useGridState(apiRef);
const filterableColumnsIds = useGridSelector(apiRef, filterableGridColumnsIdsSelector);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GridRowId } from '../../../models/gridRows';
import { GridCellParams } from '../../../models/params/gridCellParams';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useGridState } from '../core/useGridState';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { useGridApiEventHandler } from '../../root/useGridApiEventHandler';
import { GridComponentProps } from '../../../GridComponentProps';
import { isNavigationKey } from '../../../utils/keyboardUtils';
Expand All @@ -18,7 +18,7 @@ import { isNavigationKey } from '../../../utils/keyboardUtils';
* @requires useGridEditRows (event)
*/
export const useGridFocus = (apiRef: GridApiRef, props: Pick<GridComponentProps, 'rows'>): void => {
const logger = useLogger('useGridFocus');
const logger = useGridLogger(apiRef, 'useGridFocus');
const [, setGridState, forceUpdate] = useGridState(apiRef);
const lastClickedCell = React.useRef<GridCellParams | null>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
isGridHeaderCellRoot,
} from '../../../utils/domUtils';
import { isEnterKey, isNavigationKey, isSpaceKey } from '../../../utils/keyboardUtils';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { useGridApiEventHandler } from '../../root/useGridApiEventHandler';
import { GridCellModes } from '../../../models/gridEditRowModel';

Expand All @@ -21,7 +21,7 @@ import { GridCellModes } from '../../../models/gridEditRowModel';
* @requires useGridColumnMenu (method)
*/
export const useGridKeyboard = (apiRef: GridApiRef): void => {
const logger = useLogger('useGridKeyboard');
const logger = useGridLogger(apiRef, 'useGridKeyboard');

const expandSelection = React.useCallback(
(params: GridCellParams, event: React.KeyboardEvent) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { visibleGridColumnsLengthSelector } from '../columns/gridColumnsSelector
import { useGridSelector } from '../core/useGridSelector';
import { gridPaginationSelector } from '../pagination/gridPaginationSelector';
import { gridRowCountSelector } from '../rows/gridRowsSelector';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { useGridApiEventHandler } from '../../root/useGridApiEventHandler';
import { GridComponentProps } from '../../../GridComponentProps';
import { visibleSortedGridRowsAsArraySelector } from '../filter/gridFilterSelector';
Expand Down Expand Up @@ -74,7 +74,7 @@ export const useGridKeyboardNavigation = (
apiRef: GridApiRef,
props: Pick<GridComponentProps, 'pagination'>,
): void => {
const logger = useLogger('useGridKeyboardNavigation');
const logger = useGridLogger(apiRef, 'useGridKeyboardNavigation');
const paginationState = useGridSelector(apiRef, gridPaginationSelector);
const totalRowCount = useGridSelector(apiRef, gridRowCountSelector);
const colCount = useGridSelector(apiRef, visibleGridColumnsLengthSelector);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { GridApiRef } from '../../../models';
import { useGridSelector, useGridState } from '../core';
import { useLogger } from '../../utils';
import { useGridLogger } from '../../utils';
import { GridEvents } from '../../../constants/eventsConstants';
import { GridComponentProps } from '../../../GridComponentProps';
import { useGridApiEventHandler } from '../../root/useGridApiEventHandler';
Expand Down Expand Up @@ -38,7 +38,7 @@ export const useGridPage = (
apiRef: GridApiRef,
props: Pick<GridComponentProps, 'page' | 'onPageChange' | 'rowCount'>,
) => {
const logger = useLogger('useGridPage');
const logger = useGridLogger(apiRef, 'useGridPage');
const [, setGridState, forceUpdate] = useGridState(apiRef);
const visibleRowCount = useGridSelector(apiRef, visibleGridRowCountSelector);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GridComponentProps } from '../../../GridComponentProps';
import { GridPageSizeApi } from '../../../models/api/gridPageSizeApi';
import { useGridApiMethod } from '../../root';
import { GridEvents } from '../../../constants/eventsConstants';
import { useLogger } from '../../utils';
import { useGridLogger } from '../../utils';
import { useGridSelector, useGridState } from '../core';
import { visibleGridRowCountSelector } from '../filter';
import { gridContainerSizesSelector } from '../../root/gridContainerSizesSelector';
Expand All @@ -18,7 +18,7 @@ export const useGridPageSize = (
apiRef: GridApiRef,
props: Pick<GridComponentProps, 'pageSize' | 'onPageSizeChange' | 'autoPageSize'>,
) => {
const logger = useLogger('useGridPageSize');
const logger = useGridLogger(apiRef, 'useGridPageSize');
const [, setGridState, forceUpdate] = useGridState(apiRef);
const visibleRowCount = useGridSelector(apiRef, visibleGridRowCountSelector);
const containerSizes = useGridSelector(apiRef, gridContainerSizesSelector);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react';
import { GridApiRef } from '../../../models/api/gridApiRef';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { useGridState } from '../core/useGridState';
import { GridPreferencePanelsValue } from './gridPreferencePanelsValue';

export const useGridPreferencesPanel = (apiRef: GridApiRef): void => {
const logger = useLogger('useGridPreferencesPanel');
const logger = useGridLogger(apiRef, 'useGridPreferencesPanel');
const [, setGridState, forceUpdate] = useGridState(apiRef);
const hideTimeout = React.useRef<any>();
const immediateTimeout = React.useRef<any>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { useGridApiEventHandler, useGridApiOptionHandler } from '../../root/useG
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { allGridColumnsSelector } from '../columns/gridColumnsSelector';
import { useEventCallback } from '../../../utils/material-ui-utils';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { useGridState } from '../core/useGridState';
import { useGridSelector } from '../core/useGridSelector';

Expand All @@ -58,7 +58,7 @@ export function useGridEditRows(
| 'editMode'
>,
) {
const logger = useLogger('useGridEditRows');
const logger = useGridLogger(apiRef, 'useGridEditRows');
const [, setGridState, forceUpdate] = useGridState(apiRef);
const focusTimeout = React.useRef<any>(null);
const nextFocusedCell = React.useRef<GridCellParams | null>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
GridRowData,
} from '../../../models/gridRows';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { useGridState } from '../core/useGridState';
import { getInitialGridRowState, InternalGridRowsState } from './gridRowsState';
import { useGridSelector } from '../core/useGridSelector';
Expand Down Expand Up @@ -56,7 +56,7 @@ export const useGridRows = (
apiRef: GridApiRef,
props: Pick<GridComponentProps, 'rows' | 'getRowId' | 'rowCount'>,
): void => {
const logger = useLogger('useGridRows');
const logger = useGridLogger(apiRef, 'useGridRows');
const [, setGridState, updateComponent] = useGridState(apiRef);
const stateRows = useGridSelector(apiRef, gridRowsStateSelector);
const updateTimeout = React.useRef<any>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { GridCellIndexCoordinates } from '../../../models/gridCell';
import { GridApiRef } from '../../../models/api/gridApiRef';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import {
gridColumnsMetaSelector,
visibleGridColumnsSelector,
Expand Down Expand Up @@ -36,7 +36,7 @@ export const useGridScroll = (
apiRef: GridApiRef,
props: Pick<GridComponentProps, 'pagination'>,
): void => {
const logger = useLogger('useGridScroll');
const logger = useGridLogger(apiRef, 'useGridScroll');
const colRef = apiRef.current.columnHeadersElementRef!;
const windowRef = apiRef.current.windowRef!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GridRowParams } from '../../../models/params/gridRowParams';
import { GridRowId, GridRowModel } from '../../../models/gridRows';
import { useGridApiEventHandler } from '../../root/useGridApiEventHandler';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { useGridSelector } from '../core/useGridSelector';
import { useGridState } from '../core/useGridState';
import { gridRowsLookupSelector } from '../rows/gridRowsSelector';
Expand All @@ -24,7 +24,7 @@ import {
* @requires useGridControlState (method)
*/
export const useGridSelection = (apiRef: GridApiRef, props: GridComponentProps): void => {
const logger = useLogger('useGridSelection');
const logger = useGridLogger(apiRef, 'useGridSelection');
const [, setGridState, forceUpdate] = useGridState(apiRef);
const rowsLookup = useGridSelector(apiRef, gridRowsLookupSelector);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { isDesc, nextGridSortDirection } from '../../../utils/sortingUtils';
import { isEnterKey } from '../../../utils/keyboardUtils';
import { useGridApiEventHandler } from '../../root/useGridApiEventHandler';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { allGridColumnsSelector } from '../columns/gridColumnsSelector';
import { useGridSelector } from '../core/useGridSelector';
import { useGridState } from '../core/useGridState';
Expand All @@ -43,7 +43,7 @@ export const useGridSorting = (
| 'disableMultipleColumnsSorting'
>,
) => {
const logger = useLogger('useGridSorting');
const logger = useGridLogger(apiRef, 'useGridSorting');

const [gridState, setGridState, forceUpdate] = useGridState(apiRef);
const rowCount = useGridSelector(apiRef, gridRowCountSelector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const useGridNoVirtualization = (
const columnsHeaderRef = apiRef.current.columnHeadersElementRef;
const renderingZoneRef = apiRef.current.renderingZoneRef;
const [gridState, setGridState, forceUpdate] = useGridState(apiRef);
const [scrollTo] = useGridScrollFn(renderingZoneRef!, columnsHeaderRef!);
const [scrollTo] = useGridScrollFn(apiRef, renderingZoneRef!, columnsHeaderRef!);
const paginationState = useGridSelector(apiRef, gridPaginationSelector);
const visibleColumns = useGridSelector(apiRef, visibleGridColumnsSelector);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { gridPaginationSelector } from '../pagination/gridPaginationSelector';
import { gridRowCountSelector } from '../rows/gridRowsSelector';
import { useGridApiMethod } from '../../root/useGridApiMethod';
import { useNativeEventListener } from '../../root/useNativeEventListener';
import { useLogger } from '../../utils/useLogger';
import { useGridLogger } from '../../utils/useGridLogger';
import { useGridScrollFn } from '../../utils/useGridScrollFn';
import { InternalRenderingState } from './renderingState';
import { GridComponentProps } from '../../../GridComponentProps';
Expand Down Expand Up @@ -67,7 +67,7 @@ export const useGridVirtualization = (
| 'disableVirtualization'
>,
): void => {
const logger = useLogger('useGridVirtualization');
const logger = useGridLogger(apiRef, 'useGridVirtualization');
const colRef = apiRef.current.columnHeadersElementRef!;
const windowRef = apiRef.current.windowRef!;
const renderingZoneRef = apiRef.current.renderingZoneRef!;
Expand All @@ -81,7 +81,7 @@ export const useGridVirtualization = (
const containerPropsRef = React.useRef<GridContainerProps | null>(null);
const lastScrollLeftRef = React.useRef<number>(0);

const [scrollTo] = useGridScrollFn(renderingZoneRef, colRef);
const [scrollTo] = useGridScrollFn(apiRef, renderingZoneRef, colRef);

const setRenderingState = React.useCallback(
(newState: Partial<InternalRenderingState>) => {
Expand Down
Loading

0 comments on commit e214b3a

Please sign in to comment.