ux: When adding a new panel we should scroll to top until we figure o… (#10417)

* ux: When adding a new panel we should scroll to top until we figure out a better solution #10299

* ux: Use jquery to add smooth scrolling when scrolling up to add a panel, and make sure to pass the scope to the event emitter, #10299

* ux: Add a close button to the "New panel"-box and make sure you scroll to top every time you click "Add panel" #10299
This commit is contained in:
Johannes Schill 2018-01-09 15:27:53 +01:00 committed by Torkel Ödegaard
parent 3ea63a1064
commit aac1b250af
4 changed files with 38 additions and 6 deletions

View File

@ -1,5 +1,6 @@
import PerfectScrollbar from 'perfect-scrollbar'; import PerfectScrollbar from 'perfect-scrollbar';
import coreModule from 'app/core/core_module'; import coreModule from 'app/core/core_module';
import appEvents from 'app/core/app_events';
export function geminiScrollbar() { export function geminiScrollbar() {
return { return {
@ -7,6 +8,19 @@ export function geminiScrollbar() {
link: function(scope, elem, attrs) { link: function(scope, elem, attrs) {
let scrollbar = new PerfectScrollbar(elem[0]); let scrollbar = new PerfectScrollbar(elem[0]);
appEvents.on(
'smooth-scroll-top',
() => {
elem.animate(
{
scrollTop: 0,
},
500
);
},
scope
);
scope.$on('$routeChangeSuccess', () => { scope.$on('$routeChangeSuccess', () => {
elem[0].scrollTop = 0; elem[0].scrollTop = 0;
}); });

View File

@ -21,6 +21,8 @@ export interface AddPanelPanelState {
export class AddPanelPanel extends React.Component<AddPanelPanelProps, AddPanelPanelState> { export class AddPanelPanel extends React.Component<AddPanelPanelProps, AddPanelPanelState> {
constructor(props) { constructor(props) {
super(props); super(props);
this.handleCloseAddPanel = this.handleCloseAddPanel.bind(this);
this.renderPanelItem = this.renderPanelItem.bind(this);
this.state = { this.state = {
panelPlugins: this.getPanelPlugins(), panelPlugins: this.getPanelPlugins(),
@ -83,6 +85,13 @@ export class AddPanelPanel extends React.Component<AddPanelPanelProps, AddPanelP
dashboard.removePanel(this.props.panel); dashboard.removePanel(this.props.panel);
}; };
handleCloseAddPanel(evt) {
evt.preventDefault();
const panelContainer = this.props.getPanelContainer();
const dashboard = panelContainer.getDashboard();
dashboard.removePanel(dashboard.panels[0]);
}
renderPanelItem(panel, index) { renderPanelItem(panel, index) {
console.log('render panel', index); console.log('render panel', index);
return ( return (
@ -101,10 +110,11 @@ export class AddPanelPanel extends React.Component<AddPanelPanelProps, AddPanelP
<i className="gicon gicon-add-panel" /> <i className="gicon gicon-add-panel" />
<span className="add-panel__title">New Panel</span> <span className="add-panel__title">New Panel</span>
<span className="add-panel__sub-title">Select a visualization</span> <span className="add-panel__sub-title">Select a visualization</span>
<button className="add-panel__close" onClick={this.handleCloseAddPanel}>
<i className="fa fa-close" />
</button>
</div> </div>
<ScrollBar className="add-panel__items"> <ScrollBar className="add-panel__items">{this.state.panelPlugins.map(this.renderPanelItem)}</ScrollBar>
{this.state.panelPlugins.map(this.renderPanelItem.bind(this))}
</ScrollBar>
</div> </div>
</div> </div>
); );

View File

@ -73,9 +73,9 @@ export class DashNavCtrl {
} }
addPanel() { addPanel() {
appEvents.emit('smooth-scroll-top');
if (this.dashboard.panels.length > 0 && this.dashboard.panels[0].type === 'add-panel') { if (this.dashboard.panels.length > 0 && this.dashboard.panels[0].type === 'add-panel') {
this.dashboard.removePanel(this.dashboard.panels[0]); return; // Return if the "Add panel" exists already
return;
} }
this.dashboard.addPanel({ this.dashboard.addPanel({

View File

@ -7,12 +7,20 @@
display: flex; display: flex;
align-items: center; align-items: center;
i { .gicon {
font-size: 30px; font-size: 30px;
margin-right: $spacer; margin-right: $spacer;
} }
} }
.add-panel__close {
margin-left: auto;
background-color: transparent;
border: 0;
font-size: 16px;
margin-right: -10px;
}
.add-panel__title { .add-panel__title {
font-size: $font-size-md; font-size: $font-size-md;
margin-right: $spacer/2; margin-right: $spacer/2;