Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Batch small changes #104

Merged
merged 4 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified packages/demo-app/public/ag-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/aggrid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/android-icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/android-icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/android-icon-36x36.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/android-icon-48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/android-icon-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/android-icon-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon-114x114.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon-120x120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon-152x152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon-180x180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon-57x57.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon-60x60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon-76x76.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon-precomposed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/apple-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/favicon-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/ms-icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/demo-app/public/ms-icon-150x150.png
Binary file modified packages/demo-app/public/ms-icon-310x310.png
Binary file modified packages/demo-app/public/ms-icon-70x70.png
Binary file modified packages/demo-app/public/storybook.png
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Button from '@material-ui/core/Button';
import FormLabel from '@material-ui/core/FormLabel';
import MenuItem from '@material-ui/core/MenuItem';
import Select from '@material-ui/core/Select';
import { useContext } from 'react';
import { darkThemeId, lightThemeId, ThemeContext } from '../../theme';
import { StyledPanels } from './styled-panel';

Expand All @@ -24,7 +23,7 @@ export interface SettingsPanelProps {
export const SettingsPanel: React.FC<SettingsPanelProps> = ({ onApply, type, size }) => {
const [sizeState, setSize] = React.useState<number>(size);
const [typeState, setType] = React.useState<string>(type);
const currentTheme = useContext(ThemeContext);
const currentTheme = React.useContext(ThemeContext);
const [selectedTheme, setSelectedTheme] = React.useState<string>(currentTheme.theme);
const [selectedPaginationValue, setSelectedPaginationValue] = React.useState<number>(-1);

Expand Down
8 changes: 4 additions & 4 deletions packages/demo-app/src/app/demos/theme/useTheme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import * as React from 'react';
import { useLocalStorage } from '../utils/useLocalStorage';
import { DEFAULT_THEME, STORAGE_THEME_KEY, ThemeValuePair } from './themeProvider';
import { darkTheme } from './dark';
Expand All @@ -15,10 +15,10 @@ type ReturnType = {
export function useTheme(): ReturnType {
const [selectedThemeId, setSelectedTheme] = useLocalStorage(STORAGE_THEME_KEY, DEFAULT_THEME);

const [theme, setTheme] = useState(ThemeValuePair[selectedThemeId]);
const [isDark, setIsDark] = useState(theme.id === darkTheme.id);
const [theme, setTheme] = React.useState(ThemeValuePair[selectedThemeId]);
const [isDark, setIsDark] = React.useState(theme.id === darkTheme.id);

useEffect(() => {
React.useEffect(() => {
setIsDark(theme === darkTheme);
}, [theme]);

Expand Down
6 changes: 3 additions & 3 deletions packages/grid/x-grid-modules/lib/autosizer/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, PureComponent } from 'react';
import * as React from 'react';

/**
* Detect Element Resize.
Expand Down Expand Up @@ -378,7 +378,7 @@ var AutoSizer = function (_React$PureComponent) {
childParams.width = width;
}

return createElement(
return React.createElement(
'div',
{
className: className,
Expand All @@ -389,7 +389,7 @@ var AutoSizer = function (_React$PureComponent) {
}
}]);
return AutoSizer;
}(PureComponent);
}(React.PureComponent);

AutoSizer.defaultProps = {
onResize: function onResize() {},
Expand Down
36 changes: 18 additions & 18 deletions packages/grid/x-grid-modules/src/hooks/features/usePagination.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useReducer, useRef } from 'react';
import * as React from 'react';
import { useLogger } from '../utils';
import {
PAGE_CHANGED_EVENT,
Expand Down Expand Up @@ -64,10 +64,10 @@ export const usePagination = (
options.rowCount == null ? rows.length : options.rowCount,
),
};
const stateRef = useRef(initialState);
const [state, dispatch] = useReducer(paginationReducer, initialState);
const stateRef = React.useRef(initialState);
const [state, dispatch] = React.useReducer(paginationReducer, initialState);

const updateState = useCallback(
const updateState = React.useCallback(
(stateUpdate: Partial<PaginationState>) => {
const newState = { ...stateRef.current, ...stateUpdate };
stateRef.current = newState;
Expand All @@ -76,7 +76,7 @@ export const usePagination = (
[dispatch],
);

const setPage = useCallback(
const setPage = React.useCallback(
(page: number) => {
if (apiRef && apiRef.current) {
page = stateRef.current.pageCount >= page ? page : stateRef.current.pageCount;
Expand All @@ -98,7 +98,7 @@ export const usePagination = (
);

// We use stateRef in this method to avoid reattaching this method to the api every time the state changes
const setPageSize = useCallback(
const setPageSize = React.useCallback(
(pageSize: number) => {
if (stateRef.current.pageSize === pageSize) {
return;
Expand Down Expand Up @@ -127,51 +127,51 @@ export const usePagination = (
[stateRef, apiRef, setPage, updateState, logger],
);

const onPageChanged = useCallback(
const onPageChanged = React.useCallback(
(handler: (param: PageChangedParams) => void): (() => void) => {
return apiRef!.current!.registerEvent(PAGE_CHANGED_EVENT, handler);
},
[apiRef],
);
const onPageSizeChanged = useCallback(
const onPageSizeChanged = React.useCallback(
(handler: (param: PageChangedParams) => void): (() => void) => {
return apiRef!.current!.registerEvent(PAGESIZE_CHANGED_EVENT, handler);
},
[apiRef],
);

const getAutoPageSize = useCallback(() => {
const getAutoPageSize = React.useCallback(() => {
const containerProps = apiRef?.current?.getContainerPropsState();
return containerProps?.viewportPageSize;
}, [apiRef]);

const resetAutopageSize = useCallback(() => {
const resetAutopageSize = React.useCallback(() => {
const autoPagesize = getAutoPageSize();
if (autoPagesize) {
logger.debug(`Setting autoPagesize to ${autoPagesize}`);
setPageSize(autoPagesize);
}
}, [setPageSize, logger, getAutoPageSize]);

useEffect(() => {
React.useEffect(() => {
stateRef.current = state;
}, [state]);

useEffect(() => {
React.useEffect(() => {
if (apiRef.current?.isInitialised) {
apiRef.current!.emit(PAGE_CHANGED_EVENT, stateRef.current);
}
}, [apiRef, stateRef, apiRef.current?.isInitialised]);

useEffect(() => {
React.useEffect(() => {
updateState({ paginationMode: options.paginationMode! });
}, [options.paginationMode, updateState]);

useEffect(() => {
React.useEffect(() => {
setPage(options.page != null ? options.page : 1);
}, [options.page, setPage]);

useEffect(() => {
React.useEffect(() => {
const rowCount = options.rowCount == null ? rows.length : options.rowCount;
if (rowCount !== state.rowCount) {
logger.info(`Options or rows changed, recalculating pageCount and rowCount`);
Expand All @@ -193,7 +193,7 @@ export const usePagination = (
state.page,
]);

useEffect(() => {
React.useEffect(() => {
if (
!options.autoPageSize &&
options.pageSize &&
Expand All @@ -203,7 +203,7 @@ export const usePagination = (
}
}, [options.autoPageSize, options.pageSize, logger, setPageSize]);

useEffect(() => {
React.useEffect(() => {
if (options.autoPageSize && columns.visible.length > 0) {
resetAutopageSize();
}
Expand All @@ -212,7 +212,7 @@ export const usePagination = (
useApiEventHandler(apiRef, PAGE_CHANGED_EVENT, options.onPageChanged);
useApiEventHandler(apiRef, PAGESIZE_CHANGED_EVENT, options.onPageSizeChanged);

const onResize = useCallback(() => {
const onResize = React.useCallback(() => {
if (options.autoPageSize) {
resetAutopageSize();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/x-grid-modules/src/hooks/utils/useLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Logger {

const noop = () => {};

export const noopLogger: Logger = {
const noopLogger: Logger = {
debug: noop,
info: noop,
warn: noop,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useRef } from 'react';
import * as React from 'react';
import {
ContainerProps,
GridOptions,
Expand All @@ -25,11 +25,11 @@ export const useVirtualColumns = (
apiRef: ApiRef,
): UseVirtualColumnsReturnType => {
const logger = useLogger('useVirtualColumns');
const renderedColRef = useRef<RenderColumnsProps | null>(null);
const containerPropsRef = useRef<ContainerProps | null>(null);
const lastScrollLeftRef = useRef<number>(0);
const renderedColRef = React.useRef<RenderColumnsProps | null>(null);
const containerPropsRef = React.useRef<ContainerProps | null>(null);
const lastScrollLeftRef = React.useRef<number>(0);

const getColumnIdxFromScroll = useCallback(
const getColumnIdxFromScroll = React.useCallback(
(left: number) => {
const positions = apiRef.current!.getColumnsMeta().positions;
const hasColumns = apiRef.current!.getVisibleColumns().length;
Expand All @@ -44,7 +44,7 @@ export const useVirtualColumns = (
[apiRef],
);

const getColumnFromScroll = useCallback(
const getColumnFromScroll = React.useCallback(
(left: number) => {
const visibleColumns = apiRef.current!.getVisibleColumns();
if (!visibleColumns.length) {
Expand All @@ -55,7 +55,7 @@ export const useVirtualColumns = (
[apiRef, getColumnIdxFromScroll],
);

const isColumnVisibleInWindow = useCallback(
const isColumnVisibleInWindow = React.useCallback(
(colIndex: number): boolean => {
if (!containerPropsRef.current) {
return false;
Expand All @@ -73,7 +73,7 @@ export const useVirtualColumns = (
[containerPropsRef, getColumnFromScroll, apiRef],
);

const updateRenderedCols: UpdateRenderedColsFnType = useCallback(
const updateRenderedCols: UpdateRenderedColsFnType = React.useCallback(
(containerProps: ContainerProps | null, scrollLeft: number) => {
if (!containerProps) {
return false;
Expand Down Expand Up @@ -147,7 +147,7 @@ export const useVirtualColumns = (
};
useApiMethod(apiRef, virtualApi, 'ColumnVirtualizationApi');

const resetRenderedColState = useCallback(() => {
const resetRenderedColState = React.useCallback(() => {
logger.debug('Clearing previous renderedColRef');
renderedColRef.current = null;
}, [logger, renderedColRef]);
Expand Down
Loading