Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit e22dbdc

Browse files
authored
Merge pull request #566 from plotly/persistence
persistence props and transform
2 parents 293ee33 + 630f49b commit e22dbdc

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

Diff for: CHANGELOG.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased]
6+
### Added
7+
[#566](https://github.com/plotly/dash-table/pull/566)
8+
- Support persisting user edits when the component or the page is reloaded. New props are `persistence`, `persistence_type`, and `persisted_props`. Set `persistence` to a truthy value to enable, the other two modify persistence behavior. See [plotly/dash#903](https://github.com/plotly/dash/pull/903) for more details.
9+
10+
[#319](https://github.com/plotly/dash-table/issues/319)
11+
- New 'loading_state' prop that contains information about which prop, if any, is being computed.
12+
- Table no longer allows for editing while the `data` prop is loading.
13+
614
### Fixed
715
[#578](https://github.com/plotly/dash-table/pull/578)
816
- Fix [#576](https://github.com/plotly/dash-table/issues/576), editing column names or deleting columns while other columns are hidden causing the hidden columns to be lost.
@@ -26,11 +34,6 @@ multi-line & ellipsis with `style_data` and other style props.
2634
[#583](https://github.com/plotly/dash-table/issues/583)
2735
- Fix regression when editing the content of a cell in a scrolled virtualized table
2836

29-
### Added
30-
[#319](https://github.com/plotly/dash-table/issues/319)
31-
- New 'loading_state' prop that contains information about which prop, if any, is being computed.
32-
- Table no longer allows for editing while the `data` prop is loading.
33-
3437
## [4.2.0] - 2019-08-27
3538
### Added
3639
[#317](https://github.com/plotly/dash-table/issues/317)

Diff for: src/dash-table/dash/DataTable.js

+58-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,18 @@ export const defaultProps = {
101101
style_data_conditional: [],
102102
style_filter_conditional: [],
103103
style_header_conditional: [],
104-
virtualization: false
104+
virtualization: false,
105+
106+
persisted_props: [
107+
'columns.name',
108+
// data is not included by default
109+
'filter_query',
110+
'hidden_columns',
111+
'selected_columns',
112+
'selected_rows',
113+
'sort_by'
114+
],
115+
persistence_type: 'local'
105116
};
106117

107118
export const propTypes = {
@@ -1224,8 +1235,53 @@ export const propTypes = {
12241235
* Holds the name of the component that is loading
12251236
*/
12261237
component_name: PropTypes.string
1227-
})
1238+
}),
1239+
1240+
/**
1241+
* Used to allow user interactions in this component to be persisted when
1242+
* the component - or the page - is refreshed. If `persisted` is truthy and
1243+
* hasn't changed from its previous value, any `persisted_props` that the
1244+
* user has changed while using the app will keep those changes, as long as
1245+
* the new prop value also matches what was given originally.
1246+
* Used in conjunction with `persistence` and `persisted_props`.
1247+
*/
1248+
persistence: PropTypes.oneOfType(
1249+
[PropTypes.bool, PropTypes.string, PropTypes.number]
1250+
),
1251+
1252+
/**
1253+
* Properties whose user interactions will persist after refreshing the
1254+
* component or the page.
1255+
*/
1256+
persisted_props: PropTypes.arrayOf(
1257+
PropTypes.oneOf([
1258+
'columns.name',
1259+
'data',
1260+
'filter_query',
1261+
'hidden_columns',
1262+
'selected_columns',
1263+
'selected_rows',
1264+
'sort_by'
1265+
])
1266+
),
1267+
1268+
/**
1269+
* Where persisted user changes will be stored:
1270+
* memory: only kept in memory, reset on page refresh.
1271+
* local: window.localStorage, data is kept after the browser quit.
1272+
* session: window.sessionStorage, data is cleared once the browser quit.
1273+
*/
1274+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory'])
1275+
};
12281276

1277+
DataTable.persistenceTransforms = {
1278+
columns: {
1279+
name: {
1280+
extract: propValue => R.pluck('name', propValue),
1281+
apply: (storedValue, propValue) =>
1282+
R.zipWith(R.assoc('name'), storedValue, propValue)
1283+
}
1284+
}
12291285
};
12301286

12311287
DataTable.defaultProps = defaultProps;

0 commit comments

Comments
 (0)