Skip to content

Commit

Permalink
misc: small linter fixes, update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Domino987 committed Jan 13, 2023
1 parent d66a534 commit 66b73bb
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 81 deletions.
19 changes: 14 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{
"extends": ["standard", "eslint:recommended", "plugin:react/recommended"],
"env": {
"browser": true
},
"rules": {
"multiline-ternary": "off",
"react/prop-types": "off",
"indent": "off",
"no-restricted-imports": [
"error",
{
"patterns": ["@material-ui/*/*/*", "!@material-ui/core/test-utils/*"]
}
],
"one-var": "off",
"semi": ["error", "always", {
"omitLastInOneLineBlock": true
}],
"semi": [
"error",
"always",
{
"omitLastInOneLineBlock": true
}
],
"space-before-function-paren": "off"
},
"parser": "babel-eslint",
Expand All @@ -21,11 +30,11 @@
* Only warn for EVERYTHING (for now)
*
*/
"only-warn"
"only-warn"
],
"settings": {
"react": {
"version": "detect"
}
}
}
}
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"tsc": "npx tsc --noEmit --lib es6,dom --skipLibCheck types/index.d.ts",
"lint:fix": "npx eslint src/** -c ./.eslintrc --ignore-path ./.eslintignore --fix",
"prettify": "npx prettier -c ./.prettierrc --write **/*.js",
"pretest": "npm run build",
"test": "npx jest && check-dts **/*.ts",
"test:build": "npx jest __tests__/post.build.test.js",
"prerelease": "npm run t",
Expand Down Expand Up @@ -121,8 +122,8 @@
"classnames": "^2.3.2",
"date-fns": "^2.29.3",
"debounce": "^1.2.1",
"deepmerge": "^4.2.2",
"deep-eql": "^4.1.1",
"deepmerge": "^4.2.2",
"prop-types": "^15.8.1",
"react-double-scrollbar": "0.0.15",
"uuid": "^9.0.0",
Expand Down
1 change: 0 additions & 1 deletion src/components/MTableEditRow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ function MTableEditRow(props) {
if (!isValid) {
return;
}
const newData = state.data;
props.onEditingApproved(props.mode, state.data, props.data);
};

Expand Down
1 change: 0 additions & 1 deletion src/components/MTableFilterRow/LookupFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getLocalizedFilterPlaceHolder } from './utils';
import {
Checkbox,
FormControl,
Input,
InputLabel,
ListItemText,
MenuItem,
Expand Down
9 changes: 4 additions & 5 deletions src/components/MTableToolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export function MTableToolbar(props) {
About: column.customExport
This bit of code checks if prop customExport in column is a function, and if it is then it
uses that function to transform the data, this is useful in cases where a column contains
complex objects or array and it needs to be handled before it's passed to the exporter
to avoid [object Object] output (e.g. to flatten data).
Please note that it is also possible to transform data within under exportMenu
complex objects or array and it needs to be handled before it's passed to the exporter
to avoid [object Object] output (e.g. to flatten data).
Please note that it is also possible to transform data within under exportMenu
using a custom function (exportMenu.exportFunc) for each exporter.
*/
if (typeof columnDef.customExport === 'function') {
Expand Down Expand Up @@ -335,7 +335,7 @@ MTableToolbar.propTypes = {
originalData: PropTypes.array,
title: PropTypes.oneOfType([PropTypes.element, PropTypes.string]),
renderData: PropTypes.array,
data: PropTypes.array,
data: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
exportAllData: PropTypes.bool,
exportMenu: PropTypes.arrayOf(
PropTypes.shape({
Expand All @@ -344,7 +344,6 @@ MTableToolbar.propTypes = {
})
),
searchAutoFocus: PropTypes.bool,
data: PropTypes.func,
classes: PropTypes.object
};

Expand Down
1 change: 1 addition & 0 deletions src/components/m-table-edit-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class MTableEditCell extends React.Component {
);
})
.catch((error) => {
if (process.env.NODE_ENV === 'development') console.log(error);
this.setState({ isLoading: false });
});
});
Expand Down
47 changes: 1 addition & 46 deletions src/material-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,40 +241,6 @@ export default class MaterialTable extends React.Component {
...this.dataManager.getRenderState(),
actions: props.actions
});
if (
process.env.NODE_ENV === 'development' &&
columnPropsChanged &&
!this.checkedForFunctions &&
prevProps.columns.length !== 0 &&
props.data[0] &&
props.data[0].id !== undefined
) {
const bothContainFunctions =
fixedPropsColumns.some((column) =>
Object.values(column).some((val) => typeof val === 'function')
) &&
fixedPrevColumns.some((column) =>
Object.values(column).some((val) => typeof val === 'function')
);
if (bothContainFunctions) {
this.checkedForFunctions = true;
const currentColumnsWithoutFunctions = functionlessColumns(
fixedPropsColumns
);
const prevColumnsWithoutFunctions = functionlessColumns(
fixedPrevColumns
);
const columnsEqual = deepEql(
currentColumnsWithoutFunctions,
prevColumnsWithoutFunctions
);
if (columnsEqual) {
console.warn(
'The columns provided to material table are static, but contain functions which update on every render, resetting the table state. Provide a stable function or column reference or an row id to prevent state loss.'
);
}
}
}
}
const count = this.isRemoteData()
? this.state.query.totalCount
Expand Down Expand Up @@ -1325,17 +1291,6 @@ export default class MaterialTable extends React.Component {
}
}

function functionlessColumns(columns) {
return columns.map((col) =>
Object.entries(col).reduce((obj, [key, val]) => {
if (typeof val !== 'function') {
obj[key] = val;
}
return obj;
}, {})
);
}

function getDefaultCollectionSort(currentColumns, prevColumns, maxColumnSort) {
let defaultCollectionSort = [];
let prevCollectionSort = [];
Expand All @@ -1352,7 +1307,7 @@ function getDefaultCollectionSort(currentColumns, prevColumns, maxColumnSort) {
}

function reduceByDefaultSort(list, maxColumnSort) {
let sortColumns = list.filter(
const sortColumns = list.filter(
(column) => column.defaultSort && column.sorting !== false
);
return sortColumns.slice(0, maxColumnSort).map((column, index) => {
Expand Down
22 changes: 10 additions & 12 deletions src/utils/data-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export default class DataManager {

rootGroupsIndex = {};

constructor() {}

setData(data, idSynonym) {
this.selectedCount = 0;
let prevDataObject = {};
Expand Down Expand Up @@ -113,7 +111,7 @@ export default class DataManager {

setColumns(columns, prevColumns = [], savedColumns = {}) {
let usedWidthPx = 0;
let usedWidthNotPx = [];
const usedWidthNotPx = [];

this.columns = columns.map((columnDef, index) => {
const widthPx = widthToNumber(columnDef.width);
Expand All @@ -123,11 +121,11 @@ export default class DataManager {
: columnDef.width;

if (
width //&&
//columnDef.tableData // &&
width // &&
// columnDef.tableData // &&
// columnDef.tableData.width !== undefined
) {
if (widthPx !== NaN) {
if (!isNaN(widthPx)) {
usedWidthPx += widthPx;
} else {
usedWidthNotPx.push(width);
Expand All @@ -142,7 +140,7 @@ export default class DataManager {
groupSort: columnDef.defaultGroupSort || 'asc',
width,
initialWidth: width,
widthPx: widthPx === NaN ? undefined : widthPx,
widthPx: isNaN(widthPx) ? undefined : widthPx,
additionalWidth: 0,
...savedColumnTableData,
...(prevColumn ? prevColumn.tableData : {}),
Expand Down Expand Up @@ -332,7 +330,7 @@ export default class DataManager {
if (rowData) {
rowData.tableData.editing = mode;

if (this.lastEditingRow && this.lastEditingRow != rowData) {
if (this.lastEditingRow && this.lastEditingRow !== rowData) {
this.lastEditingRow.tableData.editing = undefined;
}

Expand Down Expand Up @@ -400,7 +398,7 @@ export default class DataManager {
let currentGroupArray = this.groupedData;

path.forEach((value) => {
currentGroup = currentGroupArray.find((group) => group.value == value);
currentGroup = currentGroupArray.find((group) => group.value === value);
currentGroupArray = currentGroup.groups;
});

Expand All @@ -410,7 +408,7 @@ export default class DataManager {
setCheck(element.groups);
} else {
element.data.forEach((d) => {
if (d.tableData.checked != checked) {
if (d.tableData.checked !== checked) {
d.tableData.checked = d.tableData.disabled ? false : checked;
this.selectedCount = this.selectedCount + (checked ? 1 : -1);
}
Expand Down Expand Up @@ -535,7 +533,7 @@ export default class DataManager {
result.source.droppableId === 'headers'
) {
const newGroup = this.columns.find(
(c) => c.tableData.id == result.draggableId
(c) => c.tableData.id === result.draggableId
);

if (newGroup.grouping === false || !newGroup.field) {
Expand All @@ -548,7 +546,7 @@ export default class DataManager {
result.source.droppableId === 'groups'
) {
const removeGroup = this.columns.find(
(c) => c.tableData.id == result.draggableId
(c) => c.tableData.id === result.draggableId
);
removeGroup.tableData.groupOrder = undefined;
groups.splice(result.source.index, 1);
Expand Down

0 comments on commit 66b73bb

Please sign in to comment.