From d1cc060ef6dc9380b942329473e84bb219513d46 Mon Sep 17 00:00:00 2001 From: Tom Tirapani Date: Fri, 10 Aug 2018 14:55:17 +0100 Subject: [PATCH] Added 'Restore Defaults' method and affordance. #508 --- core/XH.js | 11 +++- desktop/cmp/button/RestoreDefaultsButton.js | 59 +++++++++++++++++++++ desktop/cmp/button/index.js | 3 +- 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 desktop/cmp/button/RestoreDefaultsButton.js diff --git a/core/XH.js b/core/XH.js index fcba76f3b5..2ad2e02b49 100644 --- a/core/XH.js +++ b/core/XH.js @@ -293,7 +293,16 @@ class XHClass { showAboutDialog() { return this.acm.aboutDialogModel.show(); } - + + /** Clear grid state and preferences */ + async restoreDefaultsAsync(reload = true) { + return XH.prefService.clearAllAsync().then(() => { + XH.localStorageService.clear(); + }).then(() => { + if (reload) XH.reloadApp(); + }); + } + //---------------------------- // Service Aliases //---------------------------- diff --git a/desktop/cmp/button/RestoreDefaultsButton.js b/desktop/cmp/button/RestoreDefaultsButton.js new file mode 100644 index 0000000000..d30791c409 --- /dev/null +++ b/desktop/cmp/button/RestoreDefaultsButton.js @@ -0,0 +1,59 @@ +/* + * This file belongs to Hoist, an application development toolkit + * developed by Extremely Heavy Industries (www.xh.io | info@xh.io) + * + * Copyright © 2018 Extremely Heavy Industries Inc. + */ + +import {Component} from 'react'; +import {PropTypes as PT} from 'prop-types'; +import {elemFactory, HoistComponent, XH} from '@xh/hoist/core'; +import {button} from '@xh/hoist/kit/blueprint'; +import {Icon} from '@xh/hoist/icon'; + +/** + * Convenience Button preconfigured for use as a trigger for resetting user + * customizations. Clears all grid state and preferences, then reloads the app. + * Accepts props documented below as well as any supported by Blueprint's Button. + * + * Can be provided an onClick handler, otherwise will call default framework handler. + */ +@HoistComponent() +export class RestoreDefaultsButton extends Component { + + static propTypes = { + icon: PT.element, + text: PT.string, + intent: PT.string, + warningTitle: PT.string, + warningMessage: PT.string, + onClick: PT.func + }; + + render() { + const {icon, text, intent, onClick, ...rest} = this.props; + return button({ + icon: icon || Icon.refresh(), + text: text || 'Restore Defaults', + intent: intent || 'danger', + onClick: onClick || this.onRestoreClick, + ...rest + }); + } + + //--------------------------- + // Implementation + //--------------------------- + onRestoreClick = () => { + const {warningTitle, warningMessage} = this.props; + XH.confirm({ + title: warningTitle || 'Are you sure you want to restore defaults?', + message: warningMessage || 'All customizations will be restored to their default settings', + icon: Icon.warning({size: 'lg'}), + onConfirm: () => XH.restoreDefaultsAsync() + }); + } + +} + +export const restoreDefaultsButton = elemFactory(RestoreDefaultsButton); \ No newline at end of file diff --git a/desktop/cmp/button/index.js b/desktop/cmp/button/index.js index a3aabc3adf..c1d4abd9d6 100644 --- a/desktop/cmp/button/index.js +++ b/desktop/cmp/button/index.js @@ -10,4 +10,5 @@ export * from './LaunchAdminButton'; export * from './LogoutButton'; export * from './RefreshButton'; export * from './ExportButton'; -export * from './FeedbackButton'; \ No newline at end of file +export * from './FeedbackButton'; +export * from './RestoreDefaultsButton'; \ No newline at end of file