diff --git a/README.md b/README.md index 32dd9cb..dbbd7c9 100644 --- a/README.md +++ b/README.md @@ -218,8 +218,8 @@ const YourComponent = () => | toolbar | array | false | \[] | Toolbar definition (Check below) | | columns | array | true | - | Columns to display | | styles | object | false | {} | Custom styles for your table | -| editable | boolean | false | {} | Set whether the table is editable | -| editing | boolean | false | {} | Set the default state of the table to be in editing mode | +| editable | boolean | false | {} | Set whether the table is editable | +| editing | boolean | false | {} | Set the default state of the table to be in editing mode | | primaryKey | string | true | {} | Set the primary key column of the table for actions like editing. | #### Pagination object @@ -255,19 +255,21 @@ const YourComponent = () => Toolbar config is an array of array of object where objects are the toolbar items. Each inner array represents a different row. -| Key | Type | Required | Default | Description | -| --------------------- | -------- | -------- | ------- | ------------------------------------------------------------------------- | -| type | string | false | actions | Available values resetFilters, print, editable and columns | -| label | string | true | - | Label for the toolbar item | -| visible | boolean | false | true | Whether the item is visible | -| state | boolean | false | false | Whether to pass the state object as item prop | -| **For type: actions** | | | | | -| options | array | true | - | Array of option objects | -| **-- options** | | | | | -| type | string | true | action | Available option: action | -| name | string | true | - | Unique name for the action | -| label | string | true | - | Label for the action | -| thunk | function | true | - | An action creator which is dispatched on action click. Check demo schema. | +| Key | Type | Required | Default | Description | +| ---------------------- | -------- | -------- | ------------------------------------------------------------- | ------------------------------------------------------------------------- | +| type | string | false | actions | Available values resetFilters, print, editable and columns | +| label | string | true | - | Label for the toolbar item | +| visible | boolean | false | true | Whether the item is visible | +| state | boolean | false | false | Whether to pass the state object as item prop | +| **For type: actions** | | | | | +| options | array | true | - | Array of option objects | +| **-- options** | | | | | +| type | string | true | action | Available option: action | +| name | string | true | - | Unique name for the action | +| label | string | true | - | Label for the action | +| thunk | function | true | - | An action creator which is dispatched on action click. Check demo schema. | +| **For type: editable** | | | | | +| labels | object | false | { show: 'Make editable', hide: 'Hide editable', save: 'Save'} | Labels for each of the buttons enabled when the table is editable | Note: action of type "editable" is required when you set the table to be editable @@ -279,7 +281,7 @@ Note: action of type "editable" is required when you set the table to be editabl | label | string | true | - | Label for the column | | sortable | boolean | false | true | Whether the column is sortable | | filterable | boolean | false | true | Whether the column is filterable | -| editable | boolean | false | false | When the table is set to be editable, set whether the respective column is among the editable | +| editable | boolean | false | false | When the table is set to be editable, set whether the respective column is among the editable | | visible | boolean | false | true | Whether the column is visible on load | | type | string | true | string | Available types: selection, number, date, string, image, options, actions | | width | integer | true | - | Width of the column | diff --git a/demo/src/schema/basic.js b/demo/src/schema/basic.js index 80828f0..0724a4c 100644 --- a/demo/src/schema/basic.js +++ b/demo/src/schema/basic.js @@ -1,4 +1,5 @@ import React from 'react'; +import { MODIFY_DATA } from '../../../src/actions'; export default { name: 'posts', @@ -149,7 +150,7 @@ export default { name: 'delete', label: 'Delete', indexField: '@id', - thunk: ( payload ) => ( dispatch, getState ) => { + thunk: ( config ) => ( dispatch, getState ) => { // Get current table state. const tableState = getState()[payload.reducerName][payload.name]; confirm('Are your sure you want to delete the selected items?') @@ -172,7 +173,7 @@ export default { label: 'Simple Button', visible: true, state: false, - thunk: ( payload ) => ( dispatch, getState ) => { + thunk: ( config ) => ( dispatch, getState ) => { console.log('toolbar button click', payload); } }, { @@ -194,16 +195,17 @@ export default { }, { name: 'editable', type: 'editable', - editableLabel: { - 0: 'Make editable', - 1: 'Hide editable' + labels: { + show: 'Make editable', + hide: 'Hide editable', + save: 'Save', }, - saveLabel: 'Save', - save: ( payload ) => ( dispatch, getState ) => { - const tableState = getState()[payload.reducerName][payload.name]; - console.log('toolbar save click with modified data', payload, tableState.modified); + save: ( config ) => ( dispatch, getState ) => { + const tableState = getState()[config.reducerName][config.name]; + console.log('toolbar save click with modified data', config, tableState.modified); + config.payload.action(MODIFY_DATA)({ clear: true }); // Dispatch MODIFY_DATA action with clear: true, to reset the modified data - // Dispatch REQUEST_DATA action "payload.action(REQUEST_DATA)" to refresh data. + // Dispatch REQUEST_DATA action "config.payload.action(REQUEST_DATA)" to refresh data. } }], ], @@ -230,6 +232,7 @@ export default { sortable: true, filterable: true, textAlign: "center", + width: 150, options: { "published": { "label": "Published" @@ -277,7 +280,7 @@ export default { params: { id: '@id', }, - thunk: ( payload ) => ( dispatch, getState ) => { + thunk: ( config ) => ( dispatch, getState ) => { console.log('edit', payload, getState()); } }, { @@ -288,7 +291,7 @@ export default { params: { id: '@id' }, - thunk: ( payload ) => ( dispatch, getState ) => { + thunk: ( config ) => ( dispatch, getState ) => { confirm('Are your sure you want to delete this page?') ? console.log('delete', getState()) : console.log(false); diff --git a/nwb.config.js b/nwb.config.js index cf35913..4a2d548 100644 --- a/nwb.config.js +++ b/nwb.config.js @@ -1,12 +1,15 @@ module.exports = { - type: 'react-component', - npm: { - esModules: true, - umd: { - global: 'ReduxDatatable', - externals: { - react: 'React' - } + type: 'react-component', + npm: { + esModules: true, + umd: { + global: 'ReduxDatatable', + externals: { + react: 'React', + lodash: '_', + "redux-observable": 'ReduxObservable', + "redux-thunk": 'ReduxThunk' + } + } } - } }; diff --git a/package-lock.json b/package-lock.json index 3969d62..cb614ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@flipbyte/redux-datatable", - "version": "0.5.1", + "version": "0.5.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -721,19 +721,36 @@ "dev": true }, "axios": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz", - "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=", + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz", + "integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==", "dev": true, "requires": { - "follow-redirects": "^1.3.0", - "is-buffer": "^1.1.5" + "follow-redirects": "1.5.10", + "is-buffer": "^2.0.2" + }, + "dependencies": { + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "dev": true, + "requires": { + "debug": "=3.1.0" + } + }, + "is-buffer": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz", + "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==", + "dev": true + } } }, "axios-observable": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/axios-observable/-/axios-observable-1.0.7.tgz", - "integrity": "sha512-pS2OXVSdS2exE0JplBSBx0E/SX2fuMJcQvg1FMudMr7DpYqT9htAuoeM9gMqTWVAt0H12+WE3xCAV4UwNAfmiQ==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/axios-observable/-/axios-observable-1.1.0.tgz", + "integrity": "sha512-+dmhX0BgbNt27DvsyA9lRmOJpk4yNXK8k2pCjeiFbbVdaiUR9A9g0x49z8O97SI25m5otadmTIrSPUG8bKhDdQ==", "dev": true }, "babel-cli": { @@ -5328,12 +5345,12 @@ "dev": true }, "handlebars": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.0.tgz", - "integrity": "sha512-l2jRuU1NAWK6AW5qqcTATWQJvNPEwkM7NEKSiv/gqOsoSQbVoWyqVEY5GS+XPQ88zLNmqASRpzfdm8d79hJS+w==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz", + "integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==", "dev": true, "requires": { - "async": "^2.5.0", + "neo-async": "^2.6.0", "optimist": "^0.6.1", "source-map": "^0.6.1", "uglify-js": "^3.1.4" @@ -6773,9 +6790,9 @@ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, "js-yaml": { - "version": "3.12.2", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.2.tgz", - "integrity": "sha512-QHn/Lh/7HhZ/Twc7vJYQTkjuCa0kaCcDcjK5Zlk2rvnUpy7DxMJ23+Jc2dcyvltwQVg1nygAVlB2oRDFHoRS5Q==", + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", + "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", "dev": true, "requires": { "argparse": "^1.0.7", @@ -7545,7 +7562,8 @@ "lodash": { "version": "4.17.11", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "dev": true }, "lodash.camelcase": { "version": "4.3.0", @@ -10400,14 +10418,16 @@ } }, "redux-observable": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/redux-observable/-/redux-observable-1.0.0.tgz", - "integrity": "sha512-6bXnpqWTBeLaLQjXHyN1giXq4nLxCmv+SUkdmiwBgvmVxvDbdmydvL1Z7DGo0WItyzI/kqXQKiucUuTxnrPRkA==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/redux-observable/-/redux-observable-1.1.0.tgz", + "integrity": "sha512-G0nxgmTZwTK3Z3KoQIL8VQu9n0YCUwEP3wc3zxKQ8zAZm+iYkoZvBqAnBJfLi4EsD1E64KR4s4jFH/dFXpV9Og==", + "dev": true }, "redux-thunk": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.3.0.tgz", - "integrity": "sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw==" + "integrity": "sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw==", + "dev": true }, "regenerate": { "version": "1.4.0", diff --git a/package.json b/package.json index b6897a0..0ae4f7e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@flipbyte/redux-datatable", - "version": "0.5.1", + "version": "0.5.2", "description": "React-Redux data table", "main": "lib/index.js", "module": "es/index.js", @@ -20,28 +20,29 @@ "test:watch": "nwb test-react --server" }, "peerDependencies": { + "lodash": ">=4.17.11", "react": "^16.8.6", "react-dom": "^16.8.6", "rxjs": "^6.4.0", "prop-types": "^15.6.2", "react-redux": "^6.0.1", "redux": "^4.0.1", - "styled-components": "^4.2.0" + "styled-components": "^4.2.0", + "redux-observable": "^1.1.0", + "redux-thunk": "^2.3.0" }, "dependencies": { - "lodash": ">=4.17.10", "normalizr": "^3.3.0", "object-assign-deep": "^0.4.0", "query-string": "^6.1.0", "react-pure-time": "^0.2.2", - "react-redux-notify": "^4.1.0", - "redux-observable": "^1.0.0", - "redux-thunk": "^2.3.0" + "react-redux-notify": "^4.1.1" }, "devDependencies": { - "axios": "^0.18.0", - "axios-observable": "^1.0.7", + "axios": "^0.19.0", + "axios-observable": "^1.1.0", "bootstrap": "^4.3.1", + "lodash": ">=4.17.11", "nwb": "0.23.x", "path-to-regexp": "^3.0.0", "react": "^16.8.6", @@ -49,6 +50,8 @@ "react-redux": "^6.0.1", "redux": "^4.0.1", "redux-logger": "^3.0.6", + "redux-observable": "^1.1.0", + "redux-thunk": "^2.3.0", "rxjs": "^6.4.0", "styled-components": "^4.2.0" }, diff --git a/src/Renderer/Body/Date.js b/src/Renderer/Body/Date.js index c017314..5be33b0 100644 --- a/src/Renderer/Body/Date.js +++ b/src/Renderer/Body/Date.js @@ -9,18 +9,22 @@ const Date = ({ index, isEditing, handleChange, - modifiedData, + isModified, + modifiedValue, + value = '', colConfig: { name, textAlign, format, editable } }) => ( - { (!editable || !isEditing) && diff --git a/src/Renderer/Filter/Number.js b/src/Renderer/Filter/Number.js index 3c33d91..3565fe9 100644 --- a/src/Renderer/Filter/Number.js +++ b/src/Renderer/Filter/Number.js @@ -38,6 +38,7 @@ const Number = ({ name, value = [], filterer }) => ( onChange={ applyFilter.bind(this, 0, filterer) } value={ value[0] || '' } placeholder="From" + autocomplete="off" /> @@ -48,6 +49,7 @@ const Number = ({ name, value = [], filterer }) => ( value={ value[1] || ''} onChange={ applyFilter.bind(this, 1, filterer) } placeholder="To" + autocomplete="off" /> diff --git a/src/Renderer/Filter/String.js b/src/Renderer/Filter/String.js index b49bc39..c5e1d06 100644 --- a/src/Renderer/Filter/String.js +++ b/src/Renderer/Filter/String.js @@ -22,6 +22,7 @@ const String = ({ name, value = '', filterer }) => ( name={ name } value={ value } onChange={ applyFilter.bind(this, filterer) } + autocomplete="off" /> ); diff --git a/src/Renderer/Toolbar/Columns.js b/src/Renderer/Toolbar/Columns.js index ca99a0a..6350a1c 100644 --- a/src/Renderer/Toolbar/Columns.js +++ b/src/Renderer/Toolbar/Columns.js @@ -84,9 +84,10 @@ class Columns extends Component {