Skip to content

Commit

Permalink
Add the option to reset the explorer entirely (#106 #62)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgonggrijp committed Aug 19, 2020
1 parent 42d7afa commit baa0a13
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion frontend/src/explorer/explorer-view-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $ } from 'backbone';
import { times, after } from 'lodash';
import { times, after, size } from 'lodash';

import './../core/scroll-easings';
import { enableI18n } from '../test-util';
Expand Down Expand Up @@ -232,4 +232,17 @@ describe('ExplorerView', function () {
this.view.popUntil(stack1Panel2);
expectSame();
});

it('can reset the panels wholesale', function() {
this.view.push(new View()).push(new View()).push(new View());
expect(this.view.stacks.length).toBe(4);
const replacement = new View();
const spy = jasmine.createSpy('resetSpy');
this.view.once('reset', spy);
this.view.reset(replacement);
expect(spy).toHaveBeenCalledWith(this.view);
expect(this.view.stacks.length).toBe(1);
expect(size(this.view.rltPanelStack)).toBe(1);
expect(this.view.rltPanelStack[replacement.cid]).toBe(0);
});
});
10 changes: 10 additions & 0 deletions frontend/src/explorer/explorer-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ export default class ExplorerView extends View {
return this;
}

/**
* Remove all panels, then make `panel` the new first panel.
* @param panel The panel that needs to become leftmost.
*/
reset(panel: View): this {
while (this.stacks.length) this.pop();
this.trigger('reset', this).push(panel);
return this;
}

/**
* Remove the topmost panel from the stack at position. Returns the deleted panel.
* @param position The indes of the stack to remove the panel from
Expand Down

0 comments on commit baa0a13

Please sign in to comment.