Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close all nested drawers when navigating #6363

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions panel/src/panel/drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ export default (panel) => {
/**
* Closes the drawer and goes back to the
* parent one if it has been stored
* @param {String|true} id Which drawer to close, true for all
*/
async close(id) {
if (this.isOpen === false) {
return;
}

// Force close all drawers
if (id === true) {
this.history.clear();
}

// Compare the drawer id to avoid closing
// the wrong drawer. This is particularly useful
// in nested drawers.
Expand Down
3 changes: 3 additions & 0 deletions panel/src/panel/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default () => {
at(index) {
return this.milestones.at(index);
},
clear() {
this.milestones = [];
},
get(id = null) {
if (id === null) {
return this.milestones;
Expand Down
18 changes: 18 additions & 0 deletions panel/src/panel/history.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ describe.concurrent("panel.drawer.history", () => {
expect(history.has("b")).toStrictEqual(false);
});

it("should clear items", async () => {
const history = History();

history.add({
id: "a"
});

history.add({
id: "b"
});

expect(history.get()).toStrictEqual([{ id: "a" }, { id: "b" }]);

history.clear();

expect(history.get()).toStrictEqual([]);
});

it("should go to milestone", async () => {
const history = History();

Expand Down
3 changes: 2 additions & 1 deletion panel/src/panel/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ export default {
// modals will be closed if the response is null or false.
// on undefined, the state of the modal stays untouched
else if (state[modal] !== undefined) {
this[modal].close();
// force close all nested modals
this[modal].close(true);
}
}

Expand Down
Loading