mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 07:36:28 +08:00
99d22c85ae
This commit ensures that additional keywords for admin sidebar links (which are also stored in the admin sidebar state manager) are translated with I18n, which was discussed in https://meta.discourse.org/t/introducing-experimental-admin-sidebar-navigation/289281/58?u=martin This also changes the admin sidebar state manager keywords to not be a TrackedObject -- this is not necessary as keywords are only set once, and it was causing rendering issues because the keywords were being set at the same time they were read. Finally this adds a "theme" keyword to the "Components" link because we often refer to components as Theme Components Co-authored-by: Jarek Radosz <jradosz@gmail.com>
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
import Service, { service } from "@ember/service";
|
|
import KeyValueStore from "discourse/lib/key-value-store";
|
|
import { ADMIN_PANEL } from "discourse/lib/sidebar/panels";
|
|
|
|
export default class AdminSidebarStateManager extends Service {
|
|
@service sidebarState;
|
|
@service currentUser;
|
|
|
|
keywords = {};
|
|
|
|
STORE_NAMESPACE = "discourse_admin_sidebar_experiment_";
|
|
|
|
store = new KeyValueStore(this.STORE_NAMESPACE);
|
|
|
|
setLinkKeywords(link_name, keywords) {
|
|
if (!this.keywords[link_name]) {
|
|
this.keywords[link_name] = {
|
|
navigation: keywords.map((keyword) => keyword.toLowerCase()),
|
|
};
|
|
return;
|
|
}
|
|
|
|
this.keywords[link_name].navigation = keywords.map((keyword) =>
|
|
keyword.toLowerCase()
|
|
);
|
|
}
|
|
|
|
get navConfig() {
|
|
return this.store.getObject("navConfig");
|
|
}
|
|
|
|
set navConfig(value) {
|
|
this.store.setObject({ key: "navConfig", value });
|
|
}
|
|
|
|
get currentUserUsingAdminSidebar() {
|
|
return this.currentUser?.use_admin_sidebar;
|
|
}
|
|
|
|
maybeForceAdminSidebar(opts = {}) {
|
|
opts.onlyIfAlreadyActive ??= true;
|
|
|
|
const isAdminSidebarActive =
|
|
this.sidebarState.currentPanel?.key === ADMIN_PANEL;
|
|
|
|
if (!this.currentUserUsingAdminSidebar) {
|
|
return false;
|
|
}
|
|
|
|
if (!opts.onlyIfAlreadyActive) {
|
|
return this.#forceAdminSidebar();
|
|
}
|
|
|
|
if (isAdminSidebarActive) {
|
|
return this.#forceAdminSidebar();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
#forceAdminSidebar() {
|
|
this.sidebarState.setPanel(ADMIN_PANEL);
|
|
this.sidebarState.setSeparatedMode();
|
|
this.sidebarState.hideSwitchPanelButtons();
|
|
return true;
|
|
}
|
|
}
|