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

Commit 6d7434f

Browse files
authored
Merge pull request #646 from plotly/persistence
add persistence to relevant components
2 parents 67ec2b7 + 4e8aa32 commit 6d7434f

17 files changed

+528
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ 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+
8+
- Added support for persistence of user-edited props to value-input components: `Checklist`, `DatePickerRange`, `DatePickerSingle`, `Dropdown`, `Input`, `RadioItems`, `RangeSlider`, `Slider`, `Tabs`, and `Textarea`. 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. [#646](https://github.com/plotly/dash-core-components/pull/646)
9+
610
### Fixed
711

812
- Fixed an infinite loop problem when `Graph` is wrapped by `Loading` component [#608](https://github.com/plotly/dash-core-components/issues/608)

src/components/Checklist.react.js

+29
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,33 @@ Checklist.propTypes = {
158158
*/
159159
component_name: PropTypes.string,
160160
}),
161+
162+
/**
163+
* Used to allow user interactions in this component to be persisted when
164+
* the component - or the page - is refreshed. If `persisted` is truthy and
165+
* hasn't changed from its previous value, a `value` that the user has
166+
* changed while using the app will keep that change, as long as
167+
* the new `value` also matches what was given originally.
168+
* Used in conjunction with `persistence_type`.
169+
*/
170+
persistence: PropTypes.oneOfType(
171+
[PropTypes.bool, PropTypes.string, PropTypes.number]
172+
),
173+
174+
/**
175+
* Properties whose user interactions will persist after refreshing the
176+
* component or the page. Since only `value` is allowed this prop can
177+
* normally be ignored.
178+
*/
179+
persisted_props: PropTypes.arrayOf(PropTypes.oneOf(['value'])),
180+
181+
/**
182+
* Where persisted user changes will be stored:
183+
* memory: only kept in memory, reset on page refresh.
184+
* local: window.localStorage, data is kept after the browser quit.
185+
* session: window.sessionStorage, data is cleared once the browser quit.
186+
*/
187+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
161188
};
162189

163190
Checklist.defaultProps = {
@@ -167,4 +194,6 @@ Checklist.defaultProps = {
167194
labelClassName: '',
168195
options: [],
169196
value: [],
197+
persisted_props: ['value'],
198+
persistence_type: 'local',
170199
};

src/components/DatePickerRange.react.js

+30
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,34 @@ DatePickerRange.propTypes = {
398398
*/
399399
component_name: PropTypes.string,
400400
}),
401+
402+
/**
403+
* Used to allow user interactions in this component to be persisted when
404+
* the component - or the page - is refreshed. If `persisted` is truthy and
405+
* hasn't changed from its previous value, any `persisted_props` that the
406+
* user has changed while using the app will keep those changes, as long as
407+
* the new prop value also matches what was given originally.
408+
* Used in conjunction with `persistence_type` and `persisted_props`.
409+
*/
410+
persistence: PropTypes.oneOfType(
411+
[PropTypes.bool, PropTypes.string, PropTypes.number]
412+
),
413+
414+
/**
415+
* Properties whose user interactions will persist after refreshing the
416+
* component or the page.
417+
*/
418+
persisted_props: PropTypes.arrayOf(
419+
PropTypes.oneOf(['start_date', 'end_date'])
420+
),
421+
422+
/**
423+
* Where persisted user changes will be stored:
424+
* memory: only kept in memory, reset on page refresh.
425+
* local: window.localStorage, data is kept after the browser quit.
426+
* session: window.sessionStorage, data is cleared once the browser quit.
427+
*/
428+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
401429
};
402430

403431
DatePickerRange.defaultProps = {
@@ -413,4 +441,6 @@ DatePickerRange.defaultProps = {
413441
clearable: false,
414442
disabled: false,
415443
updatemode: 'singledate',
444+
persisted_props: ['start_date', 'end_date'],
445+
persistence_type: 'local',
416446
};

src/components/DatePickerSingle.react.js

+29
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,33 @@ DatePickerSingle.propTypes = {
288288
*/
289289
component_name: PropTypes.string,
290290
}),
291+
292+
/**
293+
* Used to allow user interactions in this component to be persisted when
294+
* the component - or the page - is refreshed. If `persisted` is truthy and
295+
* hasn't changed from its previous value, a `date` that the user has
296+
* changed while using the app will keep that change, as long as
297+
* the new `date` also matches what was given originally.
298+
* Used in conjunction with `persistence_type`.
299+
*/
300+
persistence: PropTypes.oneOfType(
301+
[PropTypes.bool, PropTypes.string, PropTypes.number]
302+
),
303+
304+
/**
305+
* Properties whose user interactions will persist after refreshing the
306+
* component or the page. Since only `date` is allowed this prop can
307+
* normally be ignored.
308+
*/
309+
persisted_props: PropTypes.arrayOf(PropTypes.oneOf(['date'])),
310+
311+
/**
312+
* Where persisted user changes will be stored:
313+
* memory: only kept in memory, reset on page refresh.
314+
* local: window.localStorage, data is kept after the browser quit.
315+
* session: window.sessionStorage, data is cleared once the browser quit.
316+
*/
317+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
291318
};
292319

293320
DatePickerSingle.defaultProps = {
@@ -303,4 +330,6 @@ DatePickerSingle.defaultProps = {
303330
reopen_calendar_on_clear: false,
304331
clearable: false,
305332
disabled: false,
333+
persisted_props: ['date'],
334+
persistence_type: 'local',
306335
};

src/components/Dropdown.react.js

+29
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,33 @@ Dropdown.propTypes = {
222222
*/
223223
component_name: PropTypes.string,
224224
}),
225+
226+
/**
227+
* Used to allow user interactions in this component to be persisted when
228+
* the component - or the page - is refreshed. If `persisted` is truthy and
229+
* hasn't changed from its previous value, a `value` that the user has
230+
* changed while using the app will keep that change, as long as
231+
* the new `value` also matches what was given originally.
232+
* Used in conjunction with `persistence_type`.
233+
*/
234+
persistence: PropTypes.oneOfType(
235+
[PropTypes.bool, PropTypes.string, PropTypes.number]
236+
),
237+
238+
/**
239+
* Properties whose user interactions will persist after refreshing the
240+
* component or the page. Since only `value` is allowed this prop can
241+
* normally be ignored.
242+
*/
243+
persisted_props: PropTypes.arrayOf(PropTypes.oneOf(['value'])),
244+
245+
/**
246+
* Where persisted user changes will be stored:
247+
* memory: only kept in memory, reset on page refresh.
248+
* local: window.localStorage, data is kept after the browser quit.
249+
* session: window.sessionStorage, data is cleared once the browser quit.
250+
*/
251+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
225252
};
226253

227254
Dropdown.defaultProps = {
@@ -230,4 +257,6 @@ Dropdown.defaultProps = {
230257
multi: false,
231258
searchable: true,
232259
optionHeight: 35,
260+
persisted_props: ['value'],
261+
persistence_type: 'local',
233262
};

src/components/Input.react.js

+29
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ Input.defaultProps = {
157157
n_submit_timestamp: -1,
158158
debounce: false,
159159
step: 'any',
160+
persisted_props: ['value'],
161+
persistence_type: 'local',
160162
};
161163

162164
Input.propTypes = {
@@ -437,4 +439,31 @@ Input.propTypes = {
437439
*/
438440
component_name: PropTypes.string,
439441
}),
442+
443+
/**
444+
* Used to allow user interactions in this component to be persisted when
445+
* the component - or the page - is refreshed. If `persisted` is truthy and
446+
* hasn't changed from its previous value, a `value` that the user has
447+
* changed while using the app will keep that change, as long as
448+
* the new `value` also matches what was given originally.
449+
* Used in conjunction with `persistence_type`.
450+
*/
451+
persistence: PropTypes.oneOfType(
452+
[PropTypes.bool, PropTypes.string, PropTypes.number]
453+
),
454+
455+
/**
456+
* Properties whose user interactions will persist after refreshing the
457+
* component or the page. Since only `value` is allowed this prop can
458+
* normally be ignored.
459+
*/
460+
persisted_props: PropTypes.arrayOf(PropTypes.oneOf(['value'])),
461+
462+
/**
463+
* Where persisted user changes will be stored:
464+
* memory: only kept in memory, reset on page refresh.
465+
* local: window.localStorage, data is kept after the browser quit.
466+
* session: window.sessionStorage, data is cleared once the browser quit.
467+
*/
468+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
440469
};

src/components/RadioItems.react.js

+29
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,33 @@ RadioItems.propTypes = {
155155
*/
156156
component_name: PropTypes.string,
157157
}),
158+
159+
/**
160+
* Used to allow user interactions in this component to be persisted when
161+
* the component - or the page - is refreshed. If `persisted` is truthy and
162+
* hasn't changed from its previous value, a `value` that the user has
163+
* changed while using the app will keep that change, as long as
164+
* the new `value` also matches what was given originally.
165+
* Used in conjunction with `persistence_type`.
166+
*/
167+
persistence: PropTypes.oneOfType(
168+
[PropTypes.bool, PropTypes.string, PropTypes.number]
169+
),
170+
171+
/**
172+
* Properties whose user interactions will persist after refreshing the
173+
* component or the page. Since only `value` is allowed this prop can
174+
* normally be ignored.
175+
*/
176+
persisted_props: PropTypes.arrayOf(PropTypes.oneOf(['value'])),
177+
178+
/**
179+
* Where persisted user changes will be stored:
180+
* memory: only kept in memory, reset on page refresh.
181+
* local: window.localStorage, data is kept after the browser quit.
182+
* session: window.sessionStorage, data is cleared once the browser quit.
183+
*/
184+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
158185
};
159186

160187
RadioItems.defaultProps = {
@@ -163,4 +190,6 @@ RadioItems.defaultProps = {
163190
labelStyle: {},
164191
labelClassName: '',
165192
options: [],
193+
persisted_props: ['value'],
194+
persistence_type: 'local',
166195
};

src/components/RangeSlider.react.js

+29
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,37 @@ RangeSlider.propTypes = {
245245
*/
246246
component_name: PropTypes.string,
247247
}),
248+
249+
/**
250+
* Used to allow user interactions in this component to be persisted when
251+
* the component - or the page - is refreshed. If `persisted` is truthy and
252+
* hasn't changed from its previous value, a `value` that the user has
253+
* changed while using the app will keep that change, as long as
254+
* the new `value` also matches what was given originally.
255+
* Used in conjunction with `persistence_type`.
256+
*/
257+
persistence: PropTypes.oneOfType(
258+
[PropTypes.bool, PropTypes.string, PropTypes.number]
259+
),
260+
261+
/**
262+
* Properties whose user interactions will persist after refreshing the
263+
* component or the page. Since only `value` is allowed this prop can
264+
* normally be ignored.
265+
*/
266+
persisted_props: PropTypes.arrayOf(PropTypes.oneOf(['value'])),
267+
268+
/**
269+
* Where persisted user changes will be stored:
270+
* memory: only kept in memory, reset on page refresh.
271+
* local: window.localStorage, data is kept after the browser quit.
272+
* session: window.sessionStorage, data is cleared once the browser quit.
273+
*/
274+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
248275
};
249276

250277
RangeSlider.defaultProps = {
251278
updatemode: 'mouseup',
279+
persisted_props: ['value'],
280+
persistence_type: 'local',
252281
};

src/components/Slider.react.js

+29
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,37 @@ Slider.propTypes = {
226226
*/
227227
component_name: PropTypes.string,
228228
}),
229+
230+
/**
231+
* Used to allow user interactions in this component to be persisted when
232+
* the component - or the page - is refreshed. If `persisted` is truthy and
233+
* hasn't changed from its previous value, a `value` that the user has
234+
* changed while using the app will keep that change, as long as
235+
* the new `value` also matches what was given originally.
236+
* Used in conjunction with `persistence_type`.
237+
*/
238+
persistence: PropTypes.oneOfType(
239+
[PropTypes.bool, PropTypes.string, PropTypes.number]
240+
),
241+
242+
/**
243+
* Properties whose user interactions will persist after refreshing the
244+
* component or the page. Since only `value` is allowed this prop can
245+
* normally be ignored.
246+
*/
247+
persisted_props: PropTypes.arrayOf(PropTypes.oneOf(['value'])),
248+
249+
/**
250+
* Where persisted user changes will be stored:
251+
* memory: only kept in memory, reset on page refresh.
252+
* local: window.localStorage, data is kept after the browser quit.
253+
* session: window.sessionStorage, data is cleared once the browser quit.
254+
*/
255+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
229256
};
230257

231258
Slider.defaultProps = {
232259
updatemode: 'mouseup',
260+
persisted_props: ['value'],
261+
persistence_type: 'local'
233262
};

src/components/Tabs.react.js

+29
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ Tabs.defaultProps = {
326326
background: '#f9f9f9',
327327
},
328328
vertical: false,
329+
persisted_props: ['value'],
330+
persistence_type: 'local',
329331
};
330332

331333
Tabs.propTypes = {
@@ -420,4 +422,31 @@ Tabs.propTypes = {
420422
*/
421423
component_name: PropTypes.string,
422424
}),
425+
426+
/**
427+
* Used to allow user interactions in this component to be persisted when
428+
* the component - or the page - is refreshed. If `persisted` is truthy and
429+
* hasn't changed from its previous value, a `value` that the user has
430+
* changed while using the app will keep that change, as long as
431+
* the new `value` also matches what was given originally.
432+
* Used in conjunction with `persistence_type`.
433+
*/
434+
persistence: PropTypes.oneOfType(
435+
[PropTypes.bool, PropTypes.string, PropTypes.number]
436+
),
437+
438+
/**
439+
* Properties whose user interactions will persist after refreshing the
440+
* component or the page. Since only `value` is allowed this prop can
441+
* normally be ignored.
442+
*/
443+
persisted_props: PropTypes.arrayOf(PropTypes.oneOf(['value'])),
444+
445+
/**
446+
* Where persisted user changes will be stored:
447+
* memory: only kept in memory, reset on page refresh.
448+
* local: window.localStorage, data is kept after the browser quit.
449+
* session: window.sessionStorage, data is cleared once the browser quit.
450+
*/
451+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
423452
};

0 commit comments

Comments
 (0)