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

persistence props and transform #566

Merged
merged 5 commits into from
Sep 16, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions src/dash-table/dash/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,18 @@ export const defaultProps = {
style_data_conditional: [],
style_filter_conditional: [],
style_header_conditional: [],
virtualization: false
virtualization: false,

persisted_props: [
'columns.name',
// data is not included by default
'filter_query',
'hidden_columns',
'selected_columns',
'selected_rows',
'sort_by'
],
persistence_type: 'local'
};

export const propTypes = {
Expand Down Expand Up @@ -1206,7 +1217,53 @@ export const propTypes = {
*/
derived_virtual_selected_row_ids: PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.number])
)
),

/**
* Used to allow user interactions in this component to be persisted when
* the component - or the page - is refreshed. If `persisted` is truthy and
* hasn't changed from its previous value, any `persisted_props` that the
* user has changed while using the app will keep those changes, as long as
* the new prop value also matches what was given originally.
* Used in conjunction with `persistence` and `persisted_props`.
*/
persistence: PropTypes.oneOfType(
[PropTypes.bool, PropTypes.string, PropTypes.number]
),

/**
* Properties whose user interactions will persist after refreshing the
* component or the page.
*/
persisted_props: PropTypes.arrayOf(
PropTypes.oneOf([
'columns.name',
'data',
'filter_query',
'hidden_columns',
'selected_columns',
'selected_rows',
'sort_by'
])
),

/**
* Where persisted user changes will be stored:
* memory: only kept in memory, reset on page refresh.
* local: window.localStorage, data is kept after the browser quit.
* session: window.sessionStorage, data is cleared once the browser quit.
*/
persistence_type: PropTypes.oneOf(['local', 'session', 'memory'])
};

DataTable.persistenceTransforms = {
columns: {
name: {
extract: propValue => R.pluck('name', propValue),
apply: (storedValue, propValue) =>
R.zipWith(R.assoc('name'), storedValue, propValue)
}
}
};

DataTable.defaultProps = defaultProps;
Expand Down