Skip to content

Commit

Permalink
Combine component/components PageNavigation keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Feb 27, 2024
1 parent fb3c94f commit 2a8b12d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
13 changes: 6 additions & 7 deletions src/common/config/can_show_page.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { PageNavigation } from "../../layouts/hass-tabs-subpage";
import { HomeAssistant } from "../../types";
import { ensureArray } from "../array/ensure-array";
import { isComponentLoaded } from "./is_component_loaded";

export const canShowPage = (hass: HomeAssistant, page: PageNavigation) =>
(isCore(page) || isLoadedIntegration(hass, page)) &&
!hideAdvancedPage(hass, page);

const isLoadedIntegration = (hass: HomeAssistant, page: PageNavigation) =>
page.component
? isComponentLoaded(hass, page.component)
: page.components
? page.components.some((integration) =>
isComponentLoaded(hass, integration)
)
: true;
!page.component ||
ensureArray(page.component).some((integration) =>
isComponentLoaded(hass, integration)
);

const isCore = (page: PageNavigation) => page.core;
const isAdvancedPage = (page: PageNavigation) => page.advancedOnly;
const userWantsAdvanced = (hass: HomeAssistant) => hass.userData?.showAdvanced;
Expand Down
15 changes: 3 additions & 12 deletions src/layouts/hass-tabs-subpage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { customElement, eventOptions, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import memoizeOne from "memoize-one";
import { isComponentLoaded } from "../common/config/is_component_loaded";
import { restoreScroll } from "../common/decorators/restore-scroll";
import { LocalizeFunc } from "../common/translations/localize";
import "../components/ha-icon-button-arrow-prev";
Expand All @@ -19,12 +18,12 @@ import "../components/ha-svg-icon";
import "../components/ha-tab";
import { HomeAssistant, Route } from "../types";
import { haStyleScrollbar } from "../resources/styles";
import { canShowPage } from "../common/config/can_show_page";

export interface PageNavigation {
path: string;
translationKey?: string;
component?: string;
components?: string[];
component?: string | string[];
name?: string;
core?: boolean;
advancedOnly?: boolean;
Expand Down Expand Up @@ -66,19 +65,12 @@ class HassTabsSubpage extends LitElement {
(
tabs: PageNavigation[],
activeTab: PageNavigation | undefined,
showAdvanced: boolean | undefined,
_components,
_language,
_narrow,
localizeFunc
) => {
const shownTabs = tabs.filter(
(page) =>
(!page.component ||
page.core ||
isComponentLoaded(this.hass, page.component)) &&
(!page.advancedOnly || showAdvanced)
);
const shownTabs = tabs.filter((page) => canShowPage(this.hass, page));

if (shownTabs.length < 2) {
if (shownTabs.length === 1) {
Expand Down Expand Up @@ -127,7 +119,6 @@ class HassTabsSubpage extends LitElement {
const tabs = this._getTabs(
this.tabs,
this._activeTab,
this.hass.userData?.showAdvanced,
this.hass.config.components,
this.hass.language,
this.narrow,
Expand Down
6 changes: 3 additions & 3 deletions src/panels/config/ha-panel-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const configSections: { [name: string]: PageNavigation[] } = {
translationKey: "areas",
iconPath: mdiSofa,
iconColor: "#E48629",
components: ["zone"],
component: ["zone"],
},
{
path: "/hassio",
Expand Down Expand Up @@ -108,7 +108,7 @@ export const configSections: { [name: string]: PageNavigation[] } = {
translationKey: "people",
iconPath: mdiAccount,
iconColor: "#5A87FA",
components: ["person", "users"],
component: ["person", "users"],
},
{
path: "#external-app-configuration",
Expand Down Expand Up @@ -341,7 +341,7 @@ export const configSections: { [name: string]: PageNavigation[] } = {
translationKey: "hardware",
iconPath: mdiMemory,
iconColor: "#301A8E",
components: ["hassio", "hardware"],
component: ["hassio", "hardware"],
},
],
about: [
Expand Down

0 comments on commit 2a8b12d

Please sign in to comment.