Skip to content

Commit

Permalink
chore: add babel import aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
oze4 committed Aug 8, 2021
1 parent a5847e2 commit 6105afd
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 51 deletions.
13 changes: 12 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ module.exports = {
plugins: [
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread'
'@babel/plugin-proposal-object-rest-spread',
[
'module-resolver',
{
root: ['./'],
alias: {
'@components': './src/components',
'@store': './src/store',
'@utils': './src/utils'
}
}
]
]
};
8 changes: 4 additions & 4 deletions src/components/MTableBodyRow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
TableRow
} from '@material-ui/core';
// Internal
import { MTableDetailPanel } from '../m-table-detailpanel';
import * as CommonValues from '../../utils/common-values';
import { useDoubleClick } from '../../utils/hooks/useDoubleClick';
import { MTableCustomIcon } from '../../components';
import { MTableDetailPanel } from '@components/m-table-detailpanel';
import * as CommonValues from '@utils/common-values';
import { useDoubleClick } from '@utils/hooks/useDoubleClick';
import { MTableCustomIcon } from '@components';

export default function MTableBodyRow(props) {
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import parseISO from 'date-fns/parseISO';
import * as CommonValues from '../../utils/common-values';

/* eslint-disable no-useless-escape */
export const isoDateRegex = /^\d{4}-(0[1-9]|1[0-2])-([12]\d|0[1-9]|3[01])([T\s](([01]\d|2[0-3])\:[0-5]\d|24\:00)(\:[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3])\:?([0-5]\d)?)?)?$/;
Expand Down Expand Up @@ -42,37 +41,6 @@ export function getCurrencyValue(currencySetting, value) {
}
}

export function getStyle(props) {
const width = CommonValues.reducePercentsInCalc(
props.columnDef.tableData.width,
props.scrollWidth
);

let cellStyle = {
color: 'inherit',
width,
maxWidth: props.columnDef.maxWidth,
minWidth: props.columnDef.minWidth,
boxSizing: 'border-box',
fontSize: 'inherit',
fontFamily: 'inherit',
fontWeight: 'inherit'
};

if (typeof props.columnDef.cellStyle === 'function') {
cellStyle = {
...cellStyle,
...props.columnDef.cellStyle(props.value, props.rowData)
};
} else {
cellStyle = { ...cellStyle, ...props.columnDef.cellStyle };
}
if (props.columnDef.disableClick) {
cellStyle.cursor = 'default';
}
return { ...props.style, ...cellStyle };
}

export function getRenderValue(props) {
const dateLocale =
props.columnDef.dateSetting && props.columnDef.dateSetting.locale
Expand Down
7 changes: 4 additions & 3 deletions src/components/MTableCell/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable no-unused-vars */
import React from 'react';
import TableCell from '@material-ui/core/TableCell';
import PropTypes from 'prop-types';
import { getRenderValue, getStyle } from './utils';
/* eslint-enable no-unused-vars */
import { getRenderValue } from './cellUtils';
import { getStyle } from '@utils';

function MTableCell(props) {
const {
Expand All @@ -22,12 +21,14 @@ function MTableCell(props) {
}
};

/* eslint-disable indent */
const cellAlignment =
columnDef.align !== undefined
? columnDef.align
: ['numeric', 'currency'].indexOf(columnDef.type) !== -1
? 'right'
: 'left';
/* eslint-enable indent */

let renderValue = getRenderValue(props);

Expand Down
6 changes: 3 additions & 3 deletions src/components/MTableEditRow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import TableCell from '@material-ui/core/TableCell';
import TableRow from '@material-ui/core/TableRow';
import Typography from '@material-ui/core/Typography';
import PropTypes from 'prop-types';
import { byString, setByString } from '../../utils';
import * as CommonValues from '../../utils/common-values';
import { validateInput } from '../../utils/validate';
import { byString, setByString } from '@utils';
import * as CommonValues from '@utils/common-values';
import { validateInput } from '@utils/validate';

function MTableEditRow(props) {
const [state, setState] = useState(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/MTableSummaryRow/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { TableRow, TableCell, withStyles } from '@material-ui/core';
import { getStyle } from '../MTableCell/utils';
import * as CommonValues from '../../utils/common-values';
import { getStyle } from '@utils';
import * as CommonValues from '@utils/common-values';
import PropTypes from 'prop-types';

export function MTableSummaryRow({
Expand Down
6 changes: 3 additions & 3 deletions src/material-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
LinearProgress
} from '@material-ui/core';
import { DragDropContext, Droppable } from 'react-beautiful-dnd';
import DataManager from './utils/data-manager';
import * as CommonValues from './utils/common-values';
import DataManager from '@utils/data-manager';
import * as CommonValues from '@utils/common-values';
import {
MTablePagination,
MTableSteppedPagination,
MTableScrollbar
} from './components';
} from '@components';

export default class MaterialTable extends React.Component {
dataManager = new DataManager();
Expand Down
34 changes: 31 additions & 3 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as CommonValues from '@utils/common-values';

export const byString = (o, s) => {
if (!s) {
return;
}

s = s.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
s = s.replace(/^\./, ''); // strip a leading dot
const a = s.split('.');
Expand All @@ -19,7 +20,6 @@ export const byString = (o, s) => {

export const setByString = (obj, path, value) => {
let schema = obj; // a moving reference to internal objects within obj

path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
path = path.replace(/^\./, ''); // strip a leading dot
const pList = path.split('.');
Expand All @@ -29,6 +29,34 @@ export const setByString = (obj, path, value) => {
if (!schema[elem]) schema[elem] = {};
schema = schema[elem];
}

schema[pList[len - 1]] = value;
};

export function getStyle(props) {
const width = CommonValues.reducePercentsInCalc(
props.columnDef.tableData.width,
props.scrollWidth
);
let cellStyle = {
color: 'inherit',
width,
maxWidth: props.columnDef.maxWidth,
minWidth: props.columnDef.minWidth,
boxSizing: 'border-box',
fontSize: 'inherit',
fontFamily: 'inherit',
fontWeight: 'inherit'
};
if (typeof props.columnDef.cellStyle === 'function') {
cellStyle = {
...cellStyle,
...props.columnDef.cellStyle(props.value, props.rowData)
};
} else {
cellStyle = { ...cellStyle, ...props.columnDef.cellStyle };
}
if (props.columnDef.disableClick) {
cellStyle.cursor = 'default';
}
return { ...props.style, ...cellStyle };
}

0 comments on commit 6105afd

Please sign in to comment.