diff --git a/gulpfile.js b/gulpfile.js index 45ff96ed..bfcf498a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,8 +1,6 @@ var gulp = require('gulp'); var file = require('gulp-file'); -var ts = require('gulp-typescript'); -var tsProject = ts.createProject('tsconfig.json'); var jsonfile = require('jsonfile') var ghPages = require('gulp-gh-pages'); var replace = require('gulp-replace'); @@ -21,45 +19,36 @@ gulp.task('demos', function () { .pipe(gulp.dest('build/demos')); }); -gulp.task('build', function () { +gulp.task('compile', function () { return gulp .src([ - 'src/lib/**/*.tsx', - '!src/**/*.test.tsx', - 'src/lib/**/*.ts', - '!src/**/*.test.ts', + 'README.md', + 'LICENSE', ]) .pipe(gulp.dest('dist')) - .pipe(tsProject()) - .pipe(gulp.dest('dist')) .on('end', () => { var pkg = require('./package.json'); delete pkg.dependencies; delete pkg.devDependencies; + delete pkg.scripts; delete pkg.husky; delete pkg.jest; var outputFile = 'dist/package.json'; file(outputFile, ''); jsonfile.writeFile('dist/package.json', pkg, { spaces: 2 }); - gulp - .src([ - 'README.md', - 'LICENSE', - ]) - .pipe(gulp.dest('dist')); gulp .src([ 'src/lib/**/*.scss' ]) .pipe(gulp.dest('dist')) .on('end', () => { - gulp.src('dist/**/*.scss') + gulp.src('dist/*.scss') .pipe(sass().on('error', sass.logError)) .pipe(gulp.dest('dist')); }); gulp .src([ - 'src/lib/static/**/*' + 'src/lib/static/*' ]) .pipe(gulp.dest('dist/static')) }); diff --git a/package.json b/package.json index 40ede46f..6c53186e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ka-table", - "version": "5.5.1", + "version": "6.0.0", "license": "MIT", "repository": "github:komarovalexander/ka-table", "homepage": "https://komarovalexander.github.io/ka-table/#/overview", @@ -33,7 +33,7 @@ "coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls", "dist": "tsc --declaration --jsx react --esModuleInterop true --outDir dist src/lib/index.ts && gulp build", "pack": "gulp build && cd dist && npm pack && cd ..", - "compile": "tsc src/lib/index.ts --jsx react --esModuleInterop true --outDir dist --declaration true --target es5" + "compile": "tsc src/lib/index.ts --jsx react --esModuleInterop true --outDir dist --declaration true --target es5 && gulp compile" }, "eslintConfig": { "extends": "react-app" @@ -65,7 +65,6 @@ "gulp-gh-pages": "^0.5.4", "gulp-replace": "^1.0.0", "gulp-sass": "^4.0.2", - "gulp-typescript": "^5.0.1", "jsonfile": "^6.0.1", "node-sass": "^4.13.1", "react-filter-control": "^2.1.0", @@ -86,6 +85,12 @@ }, "keywords": [ "datagrid", + "ts", + "js", + "javascript", + "typescript", + "datatable", + "ui-component", "react", "table", "component", diff --git a/src/Demos/BootstrapDemo/customHooks.ts b/src/Demos/BootstrapDemo/customHooks.ts deleted file mode 100644 index 0d8ed1f3..00000000 --- a/src/Demos/BootstrapDemo/customHooks.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { useEffect, useRef } from 'react'; - -export function useOuterClick(callback: any) { - const innerRef = useRef(); - const callbackRef = useRef(); - - // set current callback in ref, before second useEffect uses it - useEffect(() => { // useEffect wrapper to be safe for concurrent mode - callbackRef.current = callback; - }); - - useEffect(() => { - document.addEventListener('click', handleClick); - return () => document.removeEventListener('click', handleClick); - - // read most recent callback and innerRef dom node from refs - function handleClick(e: any) { - if ( - innerRef.current && - callbackRef.current && - !innerRef.current.contains(e.target) - ) { - callbackRef.current(e); - } - } - }, []); // no need for callback + innerRef dep - - return innerRef; // return ref; client can omit `useRef` -} \ No newline at end of file diff --git a/src/Demos/BootstrapDemo/editors.tsx b/src/Demos/BootstrapDemo/editors.tsx index 45e6fc23..10bfc711 100644 --- a/src/Demos/BootstrapDemo/editors.tsx +++ b/src/Demos/BootstrapDemo/editors.tsx @@ -33,7 +33,7 @@ export const CustomLookupEditor: React.FC = ({ ); }; -export const FilterOperators: React.FC<{ column: Column; dispatch: DispatchFunc }> = ({ +const FilterOperators: React.FC<{ column: Column; dispatch: DispatchFunc }> = ({ column, dispatch, }) => { return ( diff --git a/src/Demos/CustomDataRowDemo/CustomDataRowDemo.tsx b/src/Demos/CustomDataRowDemo/CustomDataRowDemo.tsx index 2e3f27ee..06dc3790 100644 --- a/src/Demos/CustomDataRowDemo/CustomDataRowDemo.tsx +++ b/src/Demos/CustomDataRowDemo/CustomDataRowDemo.tsx @@ -1,6 +1,7 @@ import React, { useState } from 'react'; import { ITableProps, kaReducer, Table } from '../../lib'; +import defaultOptions from '../../lib/defaultOptions'; import { DataType, SortDirection, SortingMode } from '../../lib/enums'; import { IDataRowProps } from '../../lib/props'; import { DispatchFunc } from '../../lib/types'; @@ -14,11 +15,13 @@ const dataArray: any[] = [ { id: 6, name: 'Sunny Fox', score: 33, passed: false }, ]; -const DataRow: React.FC = ({rowData}) => { +const DataRow: React.FC = ({rowData, columns}) => { return ( -
- {rowData.name}: {rowData.score} ({rowData.passed ? 'Passed' : 'Failed'}) -
+ +
+ {rowData.name}: {rowData.score} ({rowData.passed ? 'Passed' : 'Failed'}) +
+ ); }; diff --git a/src/Demos/Demo.ts b/src/Demos/Demo.ts index c62ea7aa..67781a72 100644 --- a/src/Demos/Demo.ts +++ b/src/Demos/Demo.ts @@ -7,8 +7,7 @@ export default class Demo { public fileName: string, public jsLink: string = '', public tsLink: string = '', - public group: string = '', - public disableOnlineEditor: boolean = false) { + public group: string = '') { this.jsLink = jsLink + '?file=Demo.js'; this.tsLink = tsLink + '?file=Demo.tsx'; } diff --git a/src/Demos/DemoPage.tsx b/src/Demos/DemoPage.tsx index 255f5d2b..0e140e01 100644 --- a/src/Demos/DemoPage.tsx +++ b/src/Demos/DemoPage.tsx @@ -18,18 +18,14 @@ const getDemoPage = (demo: Demo) => {
Open in Online Editor: - {demo.disableOnlineEditor || ( - <> - { trackEvent('click', 'ts_example', demo.path); }} - rel='noopener noreferrer' - target='_blank'> - TS Example - - | - - )} + { trackEvent('click', 'ts_example', demo.path); }} + rel='noopener noreferrer' + target='_blank'> + TS Example + + | { trackEvent('click', 'js_example', demo.path); }} diff --git a/src/Demos/Demos.tsx b/src/Demos/Demos.tsx index bbe6665a..47c544bf 100644 --- a/src/Demos/Demos.tsx +++ b/src/Demos/Demos.tsx @@ -41,6 +41,7 @@ import LoadingDemo from './LoadingDemo/LoadingDemo'; import ManyColumnsDemo from './ManyColumnsDemo/ManyColumnsDemo'; import ManyRowsDemo from './ManyRowsDemo/ManyRowsDemo'; import ManyRowsGroupingDemo from './ManyRowsGroupingDemo/ManyRowsGroupingDemo'; +import ManyRowsMemoDemo from './ManyRowsMemoDemo/ManyRowsMemoDemo'; import MaterialDemo from './MaterialDemo/MaterialDemo'; import NullableCellDataDemo from './NullableCellDataDemo/NullableCellDataDemo'; import OverviewDemo from './OverviewDemo/OverviewDemo'; @@ -85,15 +86,16 @@ const demos: Demo[] = [ new Demo(FilterRowCustomEditorDemo, '/filter-row-custom-editor', 'Filter Row - Custom Editor', 'FilterRowCustomEditorDemo', 'https://stackblitz.com/edit/table-filter-row-custom-editor-js', 'https://stackblitz.com/edit/table-filter-row-custom-editor-ts', 'Filtering'), new Demo(FixedColumnDemo, '/fixed-column', 'Fixed Colum', 'FixedColumnDemo', 'https://stackblitz.com/edit/table-fixed-column-js', 'https://stackblitz.com/edit/table-fixed-column-ts', 'Columns'), new Demo(GetDataByPropsDemo, '/get-data-by-props', 'Get Data By Props', 'GetDataByPropsDemo', 'https://stackblitz.com/edit/table-get-data-by-props-js', 'https://stackblitz.com/edit/table-get-data-by-props-ts', 'Miscellaneous'), - new Demo(GroupingDemo, '/grouping', 'Grouping', 'GroupingDemo', 'https://stackblitz.com/edit/table-grouping-js', 'https://stackblitz.com/edit/table-grouping-ts', 'Grouping', true), - new Demo(GroupingCustomCellDemo, '/grouping-custom-cell', 'Grouping Custom Cell', 'GroupingCustomCellDemo', 'https://stackblitz.com/edit/table-grouping-custom-cell-js', 'https://stackblitz.com/edit/table-grouping-custom-cell-ts', 'Grouping', true), - new Demo(GroupingCustomRowDemo, '/grouping-custom-row', 'Grouping Custom Row', 'GroupingCustomRowDemo', 'https://stackblitz.com/edit/table-grouping-custom-row-js', 'https://stackblitz.com/edit/table-grouping-custom-row-ts', 'Grouping', true), + new Demo(GroupingDemo, '/grouping', 'Grouping', 'GroupingDemo', 'https://stackblitz.com/edit/table-grouping-js', 'https://stackblitz.com/edit/table-grouping-ts', 'Grouping'), + new Demo(GroupingCustomCellDemo, '/grouping-custom-cell', 'Grouping Custom Cell', 'GroupingCustomCellDemo', 'https://stackblitz.com/edit/table-grouping-custom-cell-js', 'https://stackblitz.com/edit/table-grouping-custom-cell-ts', 'Grouping'), + new Demo(GroupingCustomRowDemo, '/grouping-custom-row', 'Grouping Custom Row', 'GroupingCustomRowDemo', 'https://stackblitz.com/edit/table-grouping-custom-row-js', 'https://stackblitz.com/edit/table-grouping-custom-row-ts', 'Grouping'), new Demo(HoverRowDemo, '/hover-row', 'Hover Row', 'HoverRowDemo', 'https://stackblitz.com/edit/table-hover-row-js', 'https://stackblitz.com/edit/table-hover-row-ts', 'Rows'), new Demo(LoadingDemo, '/loading', 'Loading', 'LoadingDemo', 'https://stackblitz.com/edit/table-loading-js', 'https://stackblitz.com/edit/table-loading-ts', 'Miscellaneous'), new Demo(ManyColumnsDemo, '/many-columns', 'Many Columns', 'ManyColumnsDemo', 'https://stackblitz.com/edit/table-many-columns-js', 'https://stackblitz.com/edit/table-many-columns-ts', 'Columns'), - new Demo(ManyRowsDemo, '/many-rows', 'Many Rows (100k)', 'ManyRowsDemo', 'https://stackblitz.com/edit/table-many-rows-js', 'https://stackblitz.com/edit/table-many-rows-ts', 'Virtual Scrolling'), - new Demo(ManyRowsGroupingDemo, '/many-rows-grouping', 'Many Rows (10k Grouped)', 'ManyRowsGroupingDemo', 'https://stackblitz.com/edit/table-many-rows-grouping-js', 'https://stackblitz.com/edit/table-many-rows-grouping-ts', 'Virtual Scrolling', true), - new Demo(NullableCellDataDemo, '/nullable-cell-data', 'Nullable Cell Data', 'NullableCellDataDemo', 'https://stackblitz.com/edit/table-nullable-cell-data-js', 'https://stackblitz.com/edit/table-nullable-cell-data-ts', 'Miscellaneous', true), + new Demo(ManyRowsDemo, '/many-rows', '100K Rows', 'ManyRowsDemo', 'https://stackblitz.com/edit/table-many-rows-js', 'https://stackblitz.com/edit/table-many-rows-ts', 'Virtual Scrolling'), + new Demo(ManyRowsMemoDemo, '/many-rows-memo', '300K Rows & memo', 'ManyRowsMemoDemo', 'https://stackblitz.com/edit/table-many-rows-memo-js', 'https://stackblitz.com/edit/table-many-rows-memo-ts', 'Virtual Scrolling'), + new Demo(ManyRowsGroupingDemo, '/many-rows-grouping', '10k Grouped', 'ManyRowsGroupingDemo', 'https://stackblitz.com/edit/table-many-rows-grouping-js', 'https://stackblitz.com/edit/table-many-rows-grouping-ts', 'Virtual Scrolling'), + new Demo(NullableCellDataDemo, '/nullable-cell-data', 'Nullable Cell Data', 'NullableCellDataDemo', 'https://stackblitz.com/edit/table-nullable-cell-data-js', 'https://stackblitz.com/edit/table-nullable-cell-data-ts', 'Miscellaneous'), new Demo(PagingDemo, '/paging', 'Paging', 'PagingDemo', 'https://stackblitz.com/edit/table-paging-js', 'https://stackblitz.com/edit/table-paging-ts', 'Miscellaneous'), new Demo(PrintDemo, '/print', 'Print', 'PrintDemo', 'https://stackblitz.com/edit/table-print-js', 'https://stackblitz.com/edit/table-print-ts', 'Export / Print'), new Demo(ReduxDemo, '/redux', 'Redux', 'ReduxDemo', 'https://stackblitz.com/edit/table-redux-js', 'https://stackblitz.com/edit/table-redux-ts', ''), @@ -103,7 +105,7 @@ const demos: Demo[] = [ new Demo(SelectionDemo, '/selection', 'Selection - Multiple', 'SelectionDemo', 'https://stackblitz.com/edit/table-selection-js', 'https://stackblitz.com/edit/table-selection-ts', 'Selection'), new Demo(SelectionSingleDemo, '/selection-single', 'Selection - Single', 'SelectionSingleDemo', 'https://stackblitz.com/edit/table-selection-single-js', 'https://stackblitz.com/edit/table-selection-single-ts', 'Selection'), new Demo(SortingDemo, '/sorting', 'Sorting', 'SortingDemo', 'https://stackblitz.com/edit/table-sorting-js', 'https://stackblitz.com/edit/table-sorting-ts', ''), - new Demo(StateStoringDemo, '/state-storing', 'State Storing', 'StateStoringDemo', 'https://stackblitz.com/edit/table-state-storing-js', '', 'Miscellaneous', true), + new Demo(StateStoringDemo, '/state-storing', 'State Storing', 'StateStoringDemo', 'https://stackblitz.com/edit/table-state-storing-js', '', 'Miscellaneous'), new Demo(ValidationDemo, '/validation', 'Validation', 'ValidationDemo', 'https://stackblitz.com/edit/table-validation-js', 'https://stackblitz.com/edit/table-validation-ts', 'Editing'), ]; diff --git a/src/Demos/FilterExtendedDemo/FilterExtendedDemo.tsx b/src/Demos/FilterExtendedDemo/FilterExtendedDemo.tsx index 83eb9ea9..fc6ce9fb 100644 --- a/src/Demos/FilterExtendedDemo/FilterExtendedDemo.tsx +++ b/src/Demos/FilterExtendedDemo/FilterExtendedDemo.tsx @@ -28,7 +28,7 @@ const tablePropsInit: ITableProps = { rowKeyField: 'id', }; -export const fields = [{ +const fields = [{ caption: 'Name', name: 'name', operators: [{ @@ -56,14 +56,14 @@ export const fields = [{ }], }]; -export const groups = [{ +const groups = [{ caption: 'And', name: 'and', }, { caption: 'Or', name: 'or', }]; -export const filter: IFilterControlFilterValue = { +const filter: IFilterControlFilterValue = { groupName: 'and', items: [ { diff --git a/src/Demos/FilterExtendedDemo/filterData.ts b/src/Demos/FilterExtendedDemo/filterData.ts index 1301a51d..a7f2e999 100644 --- a/src/Demos/FilterExtendedDemo/filterData.ts +++ b/src/Demos/FilterExtendedDemo/filterData.ts @@ -1,5 +1,3 @@ -export const isEmpty = (value: any) => (value == null || value.length === 0); - const contains = (data: any[], item: any) => { if (!item.value) { return true; } return data[item.field].toLowerCase().includes(item.value.toLowerCase()); @@ -18,7 +16,7 @@ const isNotEqual = (data: any[], item: any) => { }; const more = (data: any[], item: any) => data[item.field] > item.value; const less = (data: any[], item: any) => data[item.field] < item.value; -export const filterItem = (data: any[], filter: any) => { +const filterItem = (data: any[], filter: any) => { switch (filter.operator) { case 'contains': return contains(data, filter); case 'doesNotContain': return doesNotContain(data, filter); @@ -30,7 +28,7 @@ export const filterItem = (data: any[], filter: any) => { } }; -export const filterGroup = (data: any[], groupName: string, items: any[]): any[] => +const filterGroup = (data: any[], groupName: string, items: any[]): any[] => (groupName.toLowerCase() === 'or' ? filterGroupOr(data, items) : filterGroupAnd(data, items)); export const filterGroupOr = (data: any[], items: any[]): any[] => { diff --git a/src/Demos/ManyRowsDemo/ManyRowsDemo.tsx b/src/Demos/ManyRowsDemo/ManyRowsDemo.tsx index 9b6e2185..6a6925fa 100644 --- a/src/Demos/ManyRowsDemo/ManyRowsDemo.tsx +++ b/src/Demos/ManyRowsDemo/ManyRowsDemo.tsx @@ -38,6 +38,11 @@ const ManyRowsDemo: React.FC = () => { ({ style: { maxHeight: 600 }}) + } + }} /> ); }; diff --git a/src/Demos/ManyRowsGroupingDemo/ManyRowsGroupingDemo.tsx b/src/Demos/ManyRowsGroupingDemo/ManyRowsGroupingDemo.tsx index f64bc6dc..6ba0834d 100644 --- a/src/Demos/ManyRowsGroupingDemo/ManyRowsGroupingDemo.tsx +++ b/src/Demos/ManyRowsGroupingDemo/ManyRowsGroupingDemo.tsx @@ -40,6 +40,11 @@ const ManyRowsGroupingDemo: React.FC = () => {
({ style: { maxHeight: 600 }}) + } + }} /> ); }; diff --git a/src/Demos/ManyRowsMemoDemo/ManyRowsMemoDemo.test.tsx b/src/Demos/ManyRowsMemoDemo/ManyRowsMemoDemo.test.tsx new file mode 100644 index 00000000..c830f9b8 --- /dev/null +++ b/src/Demos/ManyRowsMemoDemo/ManyRowsMemoDemo.test.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; + +import ManyRowsMemoDemo from './ManyRowsMemoDemo'; + +it('renders without crashing', () => { + const div = document.createElement('div'); + ReactDOM.render(, div); + ReactDOM.unmountComponentAtNode(div); +}); diff --git a/src/Demos/ManyRowsMemoDemo/ManyRowsMemoDemo.tsx b/src/Demos/ManyRowsMemoDemo/ManyRowsMemoDemo.tsx new file mode 100644 index 00000000..7ea4c071 --- /dev/null +++ b/src/Demos/ManyRowsMemoDemo/ManyRowsMemoDemo.tsx @@ -0,0 +1,66 @@ +import React, { useState } from 'react'; + +import { ITableProps, kaReducer, Table } from '../../lib'; +import DataRowContent from '../../lib/Components/DataRowContent/DataRowContent'; +import { DataType } from '../../lib/enums'; +import { IDataRowProps } from '../../lib/props'; +import { DispatchFunc } from '../../lib/types'; + +let dataArray: any[]; + +const getDataArray = () => { + if (!dataArray){ + dataArray = Array(300000).fill(undefined).map( + (_, index) => ({ + column1: `column:1 row:${index}`, + column2: `column:2 row:${index}`, + column3: `column:3 row:${index}`, + column4: `column:4 row:${index}`, + id: index, + }), + ); + } + return dataArray; +}; + +const tablePropsInit: ITableProps = { + columns: [ + { key: 'column1', title: 'Column 1', dataType: DataType.String }, + { key: 'column2', title: 'Column 2', dataType: DataType.String }, + { key: 'column3', title: 'Column 3', dataType: DataType.String }, + { key: 'column4', title: 'Column 4', dataType: DataType.String }, + ], + rowKeyField: 'id', + virtualScrolling: { + enabled: true + }, +}; + +const DataRowContentMemo = React.memo((props: IDataRowProps) => , () => true); + +const ManyRowsMemoDemo: React.FC = () => { + const [tableProps, changeTableProps] = useState({ ...tablePropsInit, data: getDataArray() }); + const dispatch: DispatchFunc = (action) => { + changeTableProps((prevState: ITableProps) => kaReducer(prevState, action)); + }; + + return ( +
({ style: {lineHeight: '25px'} }), + }, + dataRow: { + content: (props: IDataRowProps) => + }, + tableWrapper: { + elementAttributes: () => ({ style: { maxHeight: 600 }}) + } + }} + /> + ); +}; + +export default ManyRowsMemoDemo; diff --git a/src/Demos/MaterialDemo/editors.tsx b/src/Demos/MaterialDemo/editors.tsx deleted file mode 100644 index 45e6fc23..00000000 --- a/src/Demos/MaterialDemo/editors.tsx +++ /dev/null @@ -1,93 +0,0 @@ -import React from 'react'; - -import { updateFilterRowOperator, updateFilterRowValue } from '../../lib/actionCreators'; -import { Column } from '../../lib/models'; -import { IFilterRowEditorProps } from '../../lib/props'; -import { DispatchFunc } from '../../lib/types'; -import { kaDateUtils } from '../../lib/utils'; - -export const CustomLookupEditor: React.FC = ({ - column, dispatch, -}) => { - const toNullableBoolean = (value: any) => { - switch (value) { - case 'true': return true; - case 'false': return false; - } - return value; - }; - return ( - <> - - - ); -}; - -export const FilterOperators: React.FC<{ column: Column; dispatch: DispatchFunc }> = ({ - column, dispatch, -}) => { - return ( - - ); -}; - -export const NumberEditor: React.FC = ({ - column, dispatch, -}) => { - return ( - <> - - { - const filterRowValue = event.currentTarget.value !== '' ? Number(event.currentTarget.value) : null; - dispatch(updateFilterRowValue(column.key, filterRowValue)); - }} - type='number' - /> - - ); -}; - -export const DateEditor: React.FC = ({ - column, dispatch, -}) => { - const fieldValue = column.filterRowValue; - const value = fieldValue && kaDateUtils.getDateInputValue(fieldValue); - return ( - <> - - { - const targetValue = event.currentTarget.value; - const filterRowValue = targetValue ? new Date(targetValue) : null; - dispatch(updateFilterRowValue(column.key, filterRowValue)); - }} - /> - - ); -}; \ No newline at end of file diff --git a/src/Demos/MenuItems.tsx b/src/Demos/MenuItems.tsx index 9ed047d8..2033866f 100644 --- a/src/Demos/MenuItems.tsx +++ b/src/Demos/MenuItems.tsx @@ -11,8 +11,8 @@ export class MenuItem { public isActive?: boolean; } -const newItems: string[] = ['ColumnSettingsDemo']; -const updateItems: string[] = ['Columns']; +const newItems: string[] = ['ManyRowsMemoDemo']; +const updateItems: string[] = ['VirtualScrolling']; const MenuItems: React.FC<{ items: MenuItem[] }> = ({ items }) => { diff --git a/src/lib/Components/DataRow/DataRow.tsx b/src/lib/Components/DataRow/DataRow.tsx index d99132e5..f9e2c13c 100644 --- a/src/lib/Components/DataRow/DataRow.tsx +++ b/src/lib/Components/DataRow/DataRow.tsx @@ -12,7 +12,6 @@ import EmptyCells from '../EmptyCells/EmptyCells'; const DataRow: React.FunctionComponent = (props) => { const { dispatch, - columns, groupColumnsCount, isSelectedRow, rowKeyValue, @@ -33,11 +32,16 @@ const DataRow: React.FunctionComponent = (props) => { }, props, dataRow); return ( - - + {content - ? - : } + ? <>{content} + : ( + <> + + + + ) + } ); }; diff --git a/src/lib/Models/FilterCondition.ts b/src/lib/Models/FilterCondition.ts deleted file mode 100644 index e2eb56c1..00000000 --- a/src/lib/Models/FilterCondition.ts +++ /dev/null @@ -1,6 +0,0 @@ -/* Filter condition for specific field */ -export class FilterCondition { - public field!: string; - public operator!: string; - public value!: any; -} diff --git a/src/lib/Utils/CellResizeUtils.ts b/src/lib/Utils/CellResizeUtils.ts index 94ddc9aa..08d0d9bf 100644 --- a/src/lib/Utils/CellResizeUtils.ts +++ b/src/lib/Utils/CellResizeUtils.ts @@ -1,5 +1,3 @@ -import { isNumber } from 'util'; - import { DispatchFunc } from '../types'; export const HeadCellResizeStateAction = 'HeadCellResizeStateAction'; @@ -26,7 +24,7 @@ export const getValidatedWidth = (newWidth: number, minWidth: number) => { export const getMinWidth = (style: any): number => { let minWidth: number = 20; const styleMinWidth = style && style.minWidth; - if (styleMinWidth && isNumber(styleMinWidth)){ + if (styleMinWidth && typeof styleMinWidth === 'number'){ minWidth = styleMinWidth; } return minWidth; diff --git a/src/lib/Utils/DataUtils.ts b/src/lib/Utils/DataUtils.ts index fea2b447..d31e2b41 100644 --- a/src/lib/Utils/DataUtils.ts +++ b/src/lib/Utils/DataUtils.ts @@ -2,7 +2,7 @@ import { Column } from '../Models/Column'; import { Field } from '../types'; import { getField, getFieldParts, getLastField, getLastFieldParents } from './ColumnUtils'; -export const getParentValue = (rowData: any, fieldParents: Field[], sameObj = false) => { +export const getParentValue = (rowData: any, fieldParents: Field[]) => { const parentValue = fieldParents.reduce((previousValue, currentValue) => { const result = (previousValue && previousValue[currentValue]); return result !== undefined ? result : undefined; @@ -47,7 +47,7 @@ export const getValueByField = (rowData: any, field: Field) => { return o; }; -const _replaceValueForField = (rowData: any, field: Field, newValue: any, fieldParents?: Field[]): void => { +const replaceValueForField = (rowData: any, field: Field, newValue: any, fieldParents?: Field[]): void => { let result = {...rowData}; if (fieldParents && fieldParents.length) { const parentValue = getParentValue(result, fieldParents) || {}; @@ -55,7 +55,7 @@ const _replaceValueForField = (rowData: any, field: Field, newValue: any, fieldP const parentsOfParent = [...fieldParents]; const parentFieldName = parentsOfParent.pop() as string; - result = _replaceValueForField(result, parentFieldName, parentValue, parentsOfParent); + result = replaceValueForField(result, parentFieldName, parentValue, parentsOfParent); } else { result[field] = newValue; } @@ -63,11 +63,8 @@ const _replaceValueForField = (rowData: any, field: Field, newValue: any, fieldP }; export const replaceValue = (rowData: any, column: Column, newValue: any) => { - return replaceValueForField(rowData, getField(column), newValue); -}; - -export const replaceValueForField = (rowData: any, field: Field, newValue: any) => { - return _replaceValueForField(rowData, getLastField(field), newValue, getLastFieldParents(field)); + const field = getField(column); + return replaceValueForField(rowData, getLastField(field), newValue, getLastFieldParents(field)); }; export const reorderData = (data: any[], getKey: (d: any) => any, keyValue: any, targetKeyValue: any) => { diff --git a/src/lib/Utils/SortUtils.test.ts b/src/lib/Utils/SortUtils.test.ts index 7baf9121..3e4ea4be 100644 --- a/src/lib/Utils/SortUtils.test.ts +++ b/src/lib/Utils/SortUtils.test.ts @@ -6,11 +6,12 @@ import { const data: any[] = [ { column: 1, id: 1 }, + { column: null, id: 6 }, { column: 3, id: 2 }, { column: 2, id: 3 }, { column: 3, id: 4 }, { column: 3, id: 5 }, - { column: null, id: 5 }, + { column: null, id: 7 }, ]; const columns: Column[] = [ diff --git a/src/lib/Utils/SortUtils.ts b/src/lib/Utils/SortUtils.ts index 605a1f0b..d0d3ba42 100644 --- a/src/lib/Utils/SortUtils.ts +++ b/src/lib/Utils/SortUtils.ts @@ -29,7 +29,7 @@ export const sortData = (columns: Column[], data: any): any[] => { return newData; }; -export const ascendSort = (sortedColumn: Column) => { +const ascendSort = (sortedColumn: Column) => { return (a: any, b: any) => { const aValue = getValueByColumn(a, sortedColumn); const bValue = getValueByColumn(b, sortedColumn); @@ -44,7 +44,7 @@ export const ascendSort = (sortedColumn: Column) => { }; }; -export const descendSort = (sortedColumn: Column) => { +const descendSort = (sortedColumn: Column) => { return (a: any, b: any) => { const aValue = getValueByColumn(a, sortedColumn); const bValue = getValueByColumn(b, sortedColumn); diff --git a/src/lib/Utils/__snapshots__/SortUtils.test.ts.snap b/src/lib/Utils/__snapshots__/SortUtils.test.ts.snap index 61e0c64d..c75b61d5 100644 --- a/src/lib/Utils/__snapshots__/SortUtils.test.ts.snap +++ b/src/lib/Utils/__snapshots__/SortUtils.test.ts.snap @@ -37,7 +37,11 @@ exports[`sortData should be sorted by Ascend 1`] = ` Array [ Object { "column": null, - "id": 5, + "id": 6, + }, + Object { + "column": null, + "id": 7, }, Object { "column": 1, @@ -86,7 +90,11 @@ Array [ }, Object { "column": null, - "id": 5, + "id": 6, + }, + Object { + "column": null, + "id": 7, }, ] `; diff --git a/src/lib/bootstrapCssClasses.ts b/src/lib/bootstrapCssClasses.ts deleted file mode 100644 index ea23b654..00000000 --- a/src/lib/bootstrapCssClasses.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { CssClasses } from './Models/CssClasses'; - -const bootstrapCssClasses = new CssClasses(); -bootstrapCssClasses.table = 'table table-striped'; -bootstrapCssClasses.thead = 'thead-dark'; -bootstrapCssClasses.checkbox = 'form-control'; -bootstrapCssClasses.dateInput = 'form-control'; -bootstrapCssClasses.numberInput = 'form-control'; -bootstrapCssClasses.textInput = 'form-control'; - -export default bootstrapCssClasses; diff --git a/src/lib/models.ts b/src/lib/models.ts index 9088a365..97868236 100644 --- a/src/lib/models.ts +++ b/src/lib/models.ts @@ -4,7 +4,6 @@ export * from './Models/EditableCell'; export * from './Models/ChildComponents'; export * from './Models/Column'; export * from './Models/CssClasses'; -export * from './Models/FilterCondition'; export * from './Models/Group'; export * from './Models/GroupRowData'; export * from './Models/VirtualScrolling';
{content}