Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Nov 25, 2020
1 parent 0cc7025 commit 2cddd1a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
CONTEXT: JSON.stringify(process.env.CONTEXT),
LIB_VERSION: JSON.stringify(pkg.version),
REACT_MODE: JSON.stringify(reactMode),
ENABLE_EXPERIMENTAL: JSON.stringify(
EXPERIMENTAL_ENABLED: JSON.stringify(
// Set by Netlify
process.env.PULL_REQUEST === 'false' ? 'false' : 'true',
),
Expand Down
8 changes: 8 additions & 0 deletions packages/grid/_modules_/grid/constants/envConstants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { localStorageAvailable } from '../utils/utils';

const force =
localStorageAvailable() && window.localStorage.getItem('EXPERIMENTAL_ENABLED') != null;

export const EXPERIMENTAL_ENABLED =
process.env.EXPERIMENTAL_ENABLED !== undefined &&
(process.env.EXPERIMENTAL_ENABLED === 'true' || force);
1 change: 1 addition & 0 deletions packages/grid/_modules_/grid/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './envConstants';
export * from './eventsConstants';
export * from './cssClassesConstants';
16 changes: 1 addition & 15 deletions packages/grid/_modules_/grid/hooks/utils/useLogger.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import * as React from 'react';
import { isFunction } from '../../utils/utils';

function localStorageAvailable() {
try {
// Incognito mode might reject access to the localStorage for security reasons.
// window isn't defined on Node.js
// https://stackoverflow.com/questions/16427636/check-if-localstorage-is-available
const key = '__some_random_key_you_are_not_going_to_use__';
window.localStorage.setItem(key, key);
window.localStorage.removeItem(key);
return true;
} catch (err) {
return false;
}
}
import { isFunction, localStorageAvailable } from '../../utils/utils';

const forceDebug = localStorageAvailable() && window.localStorage.getItem('DEBUG') != null;

Expand Down
9 changes: 5 additions & 4 deletions packages/grid/_modules_/grid/models/gridOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { RowSelectedParams } from './params/rowSelectedParams';
import { SelectionChangeParams } from './params/selectionChangeParams';
import { SortModelParams } from './params/sortModelParams';
import { SortDirection, SortModel } from './sortModel';
import { EXPERIMENTAL_ENABLED } from '../constants/envConstants';

/**
* Set of icons used in the grid component UI.
Expand Down Expand Up @@ -307,10 +308,10 @@ export const DEFAULT_GRID_OPTIONS: GridOptions = {
sortingMode: FeatureModeConstant.client,
sortingOrder: ['asc', 'desc', null],
columnTypes: DEFAULT_COLUMN_TYPES,
disableColumnMenu: process.env.ENABLE_EXPERIMENTAL !== 'true',
disableColumnFilter: process.env.ENABLE_EXPERIMENTAL !== 'true',
disableColumnSelector: process.env.ENABLE_EXPERIMENTAL !== 'true',
hideToolbar: process.env.ENABLE_EXPERIMENTAL !== 'true',
disableColumnMenu: EXPERIMENTAL_ENABLED,
disableColumnFilter: EXPERIMENTAL_ENABLED,
disableColumnSelector: EXPERIMENTAL_ENABLED,
hideToolbar: EXPERIMENTAL_ENABLED,
icons: {
ColumnFiltering: FilterIcon,
ColumnSelector: ColumnIcon,
Expand Down
14 changes: 14 additions & 0 deletions packages/grid/_modules_/grid/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@ export function isFunction(value: any): value is Function {
export function isObject(value: any): value is Record<string, any> {
return typeof value === 'object';
}

export function localStorageAvailable() {
try {
// Incognito mode might reject access to the localStorage for security reasons.
// window isn't defined on Node.js
// https://stackoverflow.com/questions/16427636/check-if-localstorage-is-available
const key = '__some_random_key_you_are_not_going_to_use__';
window.localStorage.setItem(key, key);
window.localStorage.removeItem(key);
return true;
} catch (err) {
return false;
}
}
2 changes: 1 addition & 1 deletion packages/storybook/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = {
config.plugins.push(
new webpack.DefinePlugin({
'process.env': {
ENABLE_EXPERIMENTAL: JSON.stringify(
EXPERIMENTAL_ENABLED: JSON.stringify(
// Set by Netlify
process.env.PULL_REQUEST === 'false' ? 'false' : 'true',
),
Expand Down

0 comments on commit 2cddd1a

Please sign in to comment.