Skip to content

Commit

Permalink
Added 'Restore Defaults' method and affordance. #508
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTirapani committed Aug 10, 2018
1 parent 7a2a61d commit d1cc060
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
11 changes: 10 additions & 1 deletion core/XH.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
//----------------------------
Expand Down
59 changes: 59 additions & 0 deletions desktop/cmp/button/RestoreDefaultsButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | [email protected])
*
* 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);
3 changes: 2 additions & 1 deletion desktop/cmp/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export * from './LaunchAdminButton';
export * from './LogoutButton';
export * from './RefreshButton';
export * from './ExportButton';
export * from './FeedbackButton';
export * from './FeedbackButton';
export * from './RestoreDefaultsButton';

0 comments on commit d1cc060

Please sign in to comment.