Skip to content

Commit

Permalink
Fix: showing current settings tab broken in MULTI_ORG. (getredash#4855)
Browse files Browse the repository at this point in the history
* Fix: showing current settings tab broken in MULTI_ORG.

* Revert "Fix: showing current settings tab broken in MULTI_ORG."

This reverts commit a88defd.

* Add test for SettingsMenu#isActive

* Use stripBase to remove slug from url
  • Loading branch information
arikfr authored May 2, 2020
1 parent ae9bbe2 commit 873c87b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client/app/services/settingsMenu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isFunction, extend, omit, sortBy, find } from "lodash";
import { stripBase } from "@/components/ApplicationArea/Router";
import { currentUser } from "@/services/auth";

class SettingsMenuItem {
Expand Down Expand Up @@ -29,7 +30,8 @@ class SettingsMenu {
}

getActiveItem(path) {
return find(this.items, item => item.isActive(path));
const strippedPath = stripBase(path);
return find(this.items, item => item.isActive(strippedPath));
}
}

Expand Down
33 changes: 33 additions & 0 deletions client/app/services/settingsMenu.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import settingsMenu from "./settingsMenu";

const dataSourcesItem = {
permission: "admin",
title: "Data Sources",
path: "data_sources",
};

const usersItem = {
title: "Users",
path: "users",
};

settingsMenu.add(dataSourcesItem);
settingsMenu.add(usersItem);

describe("SettingsMenu", () => {
describe("isActive", () => {
test("works with non multi org paths", () => {
expect(settingsMenu.getActiveItem("/data_sources/").title).toBe(dataSourcesItem.title);
});

test("works with multi org paths", () => {
// Set base href:
const base = document.createElement("base");
base.setAttribute("href", "http://localhost/acme/");
document.head.appendChild(base);

expect(settingsMenu.getActiveItem("/acme/data_sources/")).toBeTruthy();
expect(settingsMenu.getActiveItem("/acme/data_sources/").title).toBe(dataSourcesItem.title);
});
});
});

0 comments on commit 873c87b

Please sign in to comment.