mirror of
https://github.com/home-assistant/frontend.git
synced 2026-12-04 18:49:22 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c47461b4d | ||
|
|
5a3486e945 | ||
|
|
c2ebec32d9 | ||
|
|
9b421dc0a8 |
No files matched your search
+2
-2
@@ -113,7 +113,7 @@
|
||||
"marked-footnote": "1.4.0",
|
||||
"marked-gfm-heading-id": "4.1.4",
|
||||
"memoize-one": "7.0.0",
|
||||
"mermaid": "12.4.1",
|
||||
"mermaid": "12.4.0",
|
||||
"nanoid": "6.0.2",
|
||||
"node-vibrant": "4.0.4",
|
||||
"object-hash": "3.0.0",
|
||||
@@ -191,7 +191,7 @@
|
||||
"fs-extra": "11.4.1",
|
||||
"generate-license-file": "4.2.5",
|
||||
"glob": "15.0.0",
|
||||
"globals": "17.15.0",
|
||||
"globals": "17.14.0",
|
||||
"gulp": "5.0.1",
|
||||
"gulp-json-transform": "0.5.0",
|
||||
"gulp-rename": "2.1.0",
|
||||
|
||||
Generated
+10
-10
@@ -419,8 +419,8 @@ importers:
|
||||
specifier: 7.0.0
|
||||
version: 7.0.0
|
||||
mermaid:
|
||||
specifier: 12.4.1
|
||||
version: 12.4.1
|
||||
specifier: 12.4.0
|
||||
version: 12.4.0
|
||||
nanoid:
|
||||
specifier: 6.0.2
|
||||
version: 6.0.2
|
||||
@@ -648,8 +648,8 @@ importers:
|
||||
specifier: 15.0.0
|
||||
version: 15.0.0
|
||||
globals:
|
||||
specifier: 17.15.0
|
||||
version: 17.15.0
|
||||
specifier: 17.14.0
|
||||
version: 17.14.0
|
||||
gulp:
|
||||
specifier: 5.0.1
|
||||
version: 5.0.1
|
||||
@@ -5747,8 +5747,8 @@ packages:
|
||||
resolution: {integrity: sha512-5lsx1NUDHtSjfg0eHlmYvZKv8/nVqX4ckFbM+FrGcQ+04KWcWFo9P5MxPZYSzUvyzmdTbI7Eix8Q4IbELDqzKg==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
[email protected]5.0:
|
||||
resolution: {integrity: sha512-OyBOdPnzu9B2lFpums9/4wcyNHx4haAxY2X5PgO9LqCvXJgKYMMr/1y4TU7om/vTy4eYqRsVes1ZTJEJYKap8Q==}
|
||||
[email protected]4.0:
|
||||
resolution: {integrity: sha512-UtdkTVyAJePQv0J2M9Xe4L0ruNSDV314XiIJsADI2Zf40bcdAonE/D/OhAU8AT99oij9mhLByb+NvA3QWZYgCg==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
[email protected]:
|
||||
@@ -6607,8 +6607,8 @@ packages:
|
||||
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
[email protected].1:
|
||||
resolution: {integrity: sha512-8uCLCSeow+N6CrNzAB54lbNFipC1DOPXZeOTeSlfvJaNUohg0A9eebmJNxs4Ik/OyEDqmF2thvyCzkwkmNnTtg==}
|
||||
[email protected].0:
|
||||
resolution: {integrity: sha512-j2gvsGUFeS/53WdYLl9H5G2YtMZX9G/PlCvV3E5Pf4j5XSnK19DwazU6wki7OTcKeYKed7+qujRDLhy8NV2zBg==}
|
||||
engines: {node: '>=22.12.0'}
|
||||
|
||||
[email protected]:
|
||||
@@ -14181,7 +14181,7 @@ snapshots:
|
||||
is-windows: 1.0.2
|
||||
which: 1.3.1
|
||||
|
||||
[email protected]5.0: {}
|
||||
[email protected]4.0: {}
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
@@ -15065,7 +15065,7 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected].1:
|
||||
[email protected].0:
|
||||
dependencies:
|
||||
'@braintree/sanitize-url': 7.1.2
|
||||
'@iconify/utils': 3.1.7
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
closeAllDialogs,
|
||||
DIALOG_WAIT_TIMEOUT,
|
||||
isDialogHistoryEntry,
|
||||
updateClosedDialogSearch,
|
||||
} from "../dialogs/make-dialog-manager";
|
||||
import { fireEvent } from "./dom/fire_event";
|
||||
@@ -69,9 +70,10 @@ export const setRefreshUrl = (path: string) => {
|
||||
* Returns true if navigation can proceed, false if a dialog refused to close.
|
||||
*/
|
||||
const ensureDialogsClosed = async (timestamp: number): Promise<boolean> => {
|
||||
const { history } = mainWindow;
|
||||
|
||||
if (!history.state?.dialog || Date.now() - timestamp >= DIALOG_WAIT_TIMEOUT) {
|
||||
if (
|
||||
!isDialogHistoryEntry() ||
|
||||
Date.now() - timestamp >= DIALOG_WAIT_TIMEOUT
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,22 +4,6 @@ import type { RecorderInfo } from "./recorder";
|
||||
|
||||
export interface WindowWithPreloads extends Window {
|
||||
llConfProm?: Promise<LovelaceRawConfig>;
|
||||
llConfUrlPath?: string;
|
||||
llResProm?: Promise<LovelaceResource[]>;
|
||||
recorderInfoProm?: Promise<RecorderInfo>;
|
||||
}
|
||||
|
||||
const HYPHENATED_NON_DASHBOARD_PATHS = ["developer-tools", "media-browser"];
|
||||
|
||||
export const getPreloadDashboardUrlPath = (
|
||||
pathname: string
|
||||
): string | undefined => {
|
||||
const urlPath = pathname.split("/")[1];
|
||||
if (urlPath === "lovelace") {
|
||||
return urlPath;
|
||||
}
|
||||
return urlPath?.includes("-") &&
|
||||
!HYPHENATED_NON_DASHBOARD_PATHS.includes(urlPath)
|
||||
? urlPath
|
||||
: undefined;
|
||||
};
|
||||
@@ -40,6 +40,10 @@ export const DialogHistoryMixin = <
|
||||
|
||||
private _hasManagerHistoryEntry = false;
|
||||
|
||||
// Depth of the current level, also while a dialog opened over this one
|
||||
// has replaced its history entry
|
||||
private _historyDepth = 0;
|
||||
|
||||
private _historyPending = false;
|
||||
|
||||
private _closedWhileHistoryPending = false;
|
||||
@@ -62,12 +66,14 @@ export const DialogHistoryMixin = <
|
||||
}
|
||||
|
||||
// Navigating back in history goes up a level instead of closing
|
||||
if (
|
||||
!this._historyClosing &&
|
||||
historyState &&
|
||||
this.restoreHistoryLevel(this._ownHistoryData(historyState))
|
||||
) {
|
||||
return false;
|
||||
if (!this._historyClosing && historyState) {
|
||||
const level = this._ownHistoryData(historyState);
|
||||
if (this.restoreHistoryLevel(level)) {
|
||||
if (level) {
|
||||
this._historyDepth = level.depth;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._historyClosing) {
|
||||
@@ -93,17 +99,21 @@ export const DialogHistoryMixin = <
|
||||
}
|
||||
|
||||
protected pushHistoryLevel(level: L) {
|
||||
const current = this._ownHistoryData(mainWindow.history.state);
|
||||
if (!current) {
|
||||
// Code that runs on after closing may still pick a level
|
||||
if (this._historyClosing || !this.isConnected) {
|
||||
return;
|
||||
}
|
||||
if (!this._historyDepth) {
|
||||
this._hasManagerHistoryEntry =
|
||||
mainWindow.history.state?.dialog === this.localName;
|
||||
}
|
||||
this._historyDepth++;
|
||||
mainWindow.history.pushState(
|
||||
{
|
||||
dialogData: {
|
||||
...level,
|
||||
dialogId: this._historyId,
|
||||
depth: (current?.depth ?? 0) + 1,
|
||||
depth: this._historyDepth,
|
||||
},
|
||||
},
|
||||
""
|
||||
@@ -124,7 +134,13 @@ export const DialogHistoryMixin = <
|
||||
// Goes back to the opener entry, where the dialog manager closes this
|
||||
// dialog as the top one, so a dialog below it stays open.
|
||||
private _unwindHistory(): boolean {
|
||||
const depth = this._ownHistoryData(mainWindow.history.state)?.depth;
|
||||
const { state } = mainWindow.history;
|
||||
const depth =
|
||||
this._ownHistoryData(state)?.depth ??
|
||||
// A dialog opened over this one replaced the current level's entry
|
||||
(state?.dialog && state.dialog !== this.localName
|
||||
? this._historyDepth
|
||||
: undefined);
|
||||
if (!depth) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,9 @@ export interface DialogState {
|
||||
dialogParams: unknown;
|
||||
dialogImport?: () => Promise<unknown>;
|
||||
addHistory?: boolean;
|
||||
// The history entry of a level of the dialog below (see
|
||||
// DialogHistoryMixin), which the entry of this dialog replaced
|
||||
replacedLevel?: unknown;
|
||||
}
|
||||
|
||||
interface LoadedDialogInfo {
|
||||
@@ -90,6 +93,41 @@ const _removeOpenDialogTag = (dialogTag: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
// An entry a dialog pushed for one of its levels (see DialogHistoryMixin),
|
||||
// while that dialog is still open
|
||||
const isLevelOfOpenDialog = (historyState: any): boolean =>
|
||||
Boolean(historyState?.dialogData && OPEN_DIALOG_STACK.length);
|
||||
|
||||
/**
|
||||
* Whether Back went from a dialog to the entry of a dialog below it, which
|
||||
* only has its own entry under its first level (see DialogHistoryMixin).
|
||||
*/
|
||||
export const isEntryOfDialogBelow = (historyState: any): boolean =>
|
||||
OPEN_DIALOG_STACK.slice(0, -1).some(
|
||||
(dialog) => dialog.dialogTag === historyState?.dialog
|
||||
);
|
||||
|
||||
// Whether Back went from a dialog over a level to the dialog below, not to
|
||||
// a level of its own
|
||||
const wentToDialogBelow = (dialog: DialogState, historyState: any) => {
|
||||
const level = dialog.replacedLevel as
|
||||
{ dialogData: { dialogId: string } } | undefined;
|
||||
return Boolean(
|
||||
level &&
|
||||
(historyState?.dialog ||
|
||||
historyState?.dialogData?.dialogId === level.dialogData.dialogId)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether the current history entry belongs to an open dialog, so leaving
|
||||
* the page must wait until the dialogs closed and went back past it.
|
||||
*/
|
||||
export const isDialogHistoryEntry = (): boolean => {
|
||||
const { state } = mainWindow.history;
|
||||
return Boolean(state?.dialog) || isLevelOfOpenDialog(state);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the tag name of the topmost open dialog, or `undefined` when no
|
||||
* dialog is open.
|
||||
@@ -191,18 +229,23 @@ export const showDialog = async (
|
||||
const dialogIndex = OPEN_DIALOG_STACK.findIndex(
|
||||
(state) => state.dialogTag === dialogTag
|
||||
);
|
||||
if (dialogIndex !== -1) {
|
||||
OPEN_DIALOG_STACK.splice(dialogIndex, 1);
|
||||
}
|
||||
const shownState =
|
||||
dialogIndex !== -1
|
||||
? OPEN_DIALOG_STACK.splice(dialogIndex, 1)[0]
|
||||
: undefined;
|
||||
const replacedLevel = isLevelOfOpenDialog(history.state)
|
||||
? history.state
|
||||
: shownState?.replacedLevel;
|
||||
OPEN_DIALOG_STACK.push({
|
||||
element,
|
||||
dialogTag,
|
||||
dialogParams,
|
||||
dialogImport,
|
||||
addHistory,
|
||||
replacedLevel,
|
||||
});
|
||||
const newState = { dialog: dialogTag };
|
||||
if (history.state?.dialog) {
|
||||
if (history.state?.dialog || replacedLevel) {
|
||||
// if a dialog is already open, replace the name
|
||||
history.replaceState(newState, "");
|
||||
} else {
|
||||
@@ -281,9 +324,17 @@ export const closeLastDialog = async (historyState?: any) => {
|
||||
if (!closed) {
|
||||
// if the dialog was not closed, put it back on the stack
|
||||
OPEN_DIALOG_STACK.push(lastDialog);
|
||||
if (wentToDialogBelow(lastDialog, historyState)) {
|
||||
mainWindow.history.pushState({ dialog: lastDialog.dialogTag }, "");
|
||||
}
|
||||
} else if (lastDialog.replacedLevel && historyState) {
|
||||
// Back went past the level the dialog below is still on
|
||||
mainWindow.history.pushState(lastDialog.replacedLevel, "");
|
||||
} else if (
|
||||
OPEN_DIALOG_STACK.length &&
|
||||
mainWindow.history.state?.opensDialog
|
||||
(mainWindow.history.state?.opensDialog ||
|
||||
// Back went past the level a dialog below covers
|
||||
OPEN_DIALOG_STACK.some((dialog) => dialog.replacedLevel))
|
||||
) {
|
||||
// if there are more dialogs open, push a new state so back() will close the next top dialog
|
||||
mainWindow.history.pushState(
|
||||
@@ -360,14 +411,17 @@ const _handleClosed = (ev: HASSDomEvent<DialogClosedParams>) => {
|
||||
const dialogIndex = OPEN_DIALOG_STACK.findIndex(
|
||||
(state) => state.dialogTag === ev.detail.dialog
|
||||
);
|
||||
if (dialogIndex !== -1) {
|
||||
OPEN_DIALOG_STACK.splice(dialogIndex, 1);
|
||||
}
|
||||
const closedState =
|
||||
dialogIndex !== -1
|
||||
? OPEN_DIALOG_STACK.splice(dialogIndex, 1)[0]
|
||||
: undefined;
|
||||
if (mainWindow.history.state?.dialog === ev.detail.dialog) {
|
||||
if (OPEN_DIALOG_STACK.length) {
|
||||
// if there are more dialogs open, set the top one in history
|
||||
mainWindow.history.replaceState(
|
||||
{ dialog: OPEN_DIALOG_STACK[OPEN_DIALOG_STACK.length - 1].dialogTag },
|
||||
closedState?.replacedLevel ?? {
|
||||
dialog: OPEN_DIALOG_STACK[OPEN_DIALOG_STACK.length - 1].dialogTag,
|
||||
},
|
||||
""
|
||||
);
|
||||
} else if (dialogIndex !== -1) {
|
||||
@@ -376,6 +430,12 @@ const _handleClosed = (ev: HASSDomEvent<DialogClosedParams>) => {
|
||||
closedDialogUrl = { pathname, search };
|
||||
mainWindow.history.back();
|
||||
}
|
||||
} else if (
|
||||
closedState?.replacedLevel &&
|
||||
dialogIndex < OPEN_DIALOG_STACK.length
|
||||
) {
|
||||
// The dialog above took over the entry that covers the level
|
||||
OPEN_DIALOG_STACK[dialogIndex].replacedLevel ??= closedState.replacedLevel;
|
||||
}
|
||||
|
||||
const loaded = ev.detail.dialog ? LOADED[ev.detail.dialog] : undefined;
|
||||
|
||||
@@ -14,10 +14,7 @@ import { isExternal } from "../data/external";
|
||||
import { fetchConfig } from "../data/lovelace/config/types";
|
||||
import { fetchResources } from "../data/lovelace/resource";
|
||||
import { MAIN_WINDOW_NAME } from "../data/main_window";
|
||||
import {
|
||||
getPreloadDashboardUrlPath,
|
||||
type WindowWithPreloads,
|
||||
} from "../data/preloads";
|
||||
import type { WindowWithPreloads } from "../data/preloads";
|
||||
import { getRecorderInfo } from "../data/recorder";
|
||||
import { subscribeRepairsIssueRegistry } from "../data/repairs";
|
||||
import { subscribeAreaRegistry } from "../data/ws-area_registry";
|
||||
@@ -196,11 +193,9 @@ window.hassConnection.then(({ conn }) => {
|
||||
preloadWindow.recorderInfoProm = getRecorderInfo(conn);
|
||||
|
||||
// "/" opens the default panel, which is not known yet, so only preload the
|
||||
// config when a dashboard is opened directly.
|
||||
const dashboardUrlPath = getPreloadDashboardUrlPath(location.pathname);
|
||||
if (dashboardUrlPath) {
|
||||
preloadWindow.llConfUrlPath = dashboardUrlPath;
|
||||
preloadWindow.llConfProm = fetchConfig(conn, dashboardUrlPath, false);
|
||||
// config when the "lovelace" dashboard is opened directly.
|
||||
if (location.pathname.startsWith("/lovelace/")) {
|
||||
preloadWindow.llConfProm = fetchConfig(conn, "lovelace", false);
|
||||
preloadWindow.llConfProm.catch(() => {
|
||||
// Ignore it, it is handled by Lovelace panel.
|
||||
});
|
||||
|
||||
@@ -87,7 +87,7 @@ import {
|
||||
getIntegrationDescriptions,
|
||||
} from "../../../data/integrations";
|
||||
import { showConfigFlowDialog } from "../../../dialogs/config-flow/show-dialog-config-flow";
|
||||
import { DialogMixin } from "../../../dialogs/dialog-mixin";
|
||||
import { DialogHistoryMixin } from "../../../dialogs/dialog-history-mixin";
|
||||
import {
|
||||
showAlertDialog,
|
||||
showConfirmationDialog,
|
||||
@@ -130,10 +130,19 @@ import type { AddIntegrationDialogParams } from "./show-add-integration-dialog";
|
||||
import { showYamlIntegrationDialog } from "./show-add-integration-dialog";
|
||||
import { showSingleConfigEntryWarning } from "./show-single-config-entry-warning";
|
||||
|
||||
// A view the dialog went into, so Back returns from it
|
||||
interface AddIntegrationHistoryLevel {
|
||||
drilled?: boolean;
|
||||
subcategory?: string;
|
||||
pickedBrand?: string;
|
||||
discoveredDomain?: string;
|
||||
}
|
||||
|
||||
@customElement("dialog-add-integration")
|
||||
class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
LitElement
|
||||
) {
|
||||
class AddIntegrationDialog extends DialogHistoryMixin<
|
||||
AddIntegrationDialogParams,
|
||||
AddIntegrationHistoryLevel
|
||||
>(LitElement) {
|
||||
@state()
|
||||
@consume({ context: internationalizationContext, subscribe: true })
|
||||
private _i18n!: HomeAssistantInternationalization;
|
||||
@@ -199,8 +208,6 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
|
||||
@state() private _brand?: string;
|
||||
|
||||
@state() private _prevPickedBrand?: string;
|
||||
|
||||
@state() private _flowsInProgress?: DataEntryFlowProgress[];
|
||||
|
||||
@state() private _showDiscovered = false;
|
||||
@@ -309,7 +316,52 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
);
|
||||
this._narrowQuery.addEventListener("change", this._narrowChanged);
|
||||
this._narrow = this._narrowQuery.matches;
|
||||
this._drilled = this._narrow && !!params?.category;
|
||||
this._pushHistoryLevel();
|
||||
if (this._narrow && params?.category) {
|
||||
// Back returns to the categories, like after picking it there
|
||||
this._drilled = true;
|
||||
this._pushDrilledLevels(false);
|
||||
}
|
||||
}
|
||||
|
||||
private _pushHistoryLevel(level: AddIntegrationHistoryLevel = {}) {
|
||||
this.pushHistoryLevel({
|
||||
drilled: this._drilled,
|
||||
subcategory: this._subcategory,
|
||||
pickedBrand: this._pickedBrand,
|
||||
discoveredDomain: this._discoveredDomain,
|
||||
...level,
|
||||
});
|
||||
}
|
||||
|
||||
// Back from a subcategory goes to its category first, also when it was
|
||||
// picked from outside the category, like a search result
|
||||
private _pushDrilledLevels(wasDrilled: boolean) {
|
||||
if (this._subcategory && !wasDrilled) {
|
||||
this._pushHistoryLevel({ subcategory: undefined });
|
||||
}
|
||||
this._pushHistoryLevel();
|
||||
}
|
||||
|
||||
protected restoreHistoryLevel(level: AddIntegrationHistoryLevel | undefined) {
|
||||
if (!level) {
|
||||
return false;
|
||||
}
|
||||
if (this._narrow && this._drilled && !level.drilled) {
|
||||
this._focusAfterDrill = "out";
|
||||
}
|
||||
const discoveredDomain = this._discoveredDomain;
|
||||
this._drilled = !!level.drilled;
|
||||
// Wide, the subcategory is picked in the browse pane, not a level
|
||||
if (this._narrow) {
|
||||
this._subcategory = level.subcategory;
|
||||
}
|
||||
this._pickedBrand = level.pickedBrand;
|
||||
this._discoveredDomain = level.discoveredDomain;
|
||||
if (discoveredDomain && !level.discoveredDomain) {
|
||||
this._focusFlowGroupAfterBack(discoveredDomain);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private _pickProtocol(domain: string, brand?: string) {
|
||||
@@ -1016,7 +1068,7 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
? html`
|
||||
<ha-icon-button-prev
|
||||
slot="headerNavigationIcon"
|
||||
@click=${this._prevClicked}
|
||||
@click=${this.historyBack}
|
||||
></ha-icon-button-prev>
|
||||
`
|
||||
: nothing
|
||||
@@ -1033,7 +1085,7 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
this._narrow && this._drilled
|
||||
? html`<ha-icon-button-prev
|
||||
slot="headerNavigationIcon"
|
||||
@click=${this._drillOut}
|
||||
@click=${this.historyBack}
|
||||
></ha-icon-button-prev>`
|
||||
: nothing
|
||||
}
|
||||
@@ -1134,13 +1186,12 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
.domain=${domain}
|
||||
.integration=${integration}
|
||||
.flowsInProgress=${flowsInProgress}
|
||||
.navigateToResult=${this._navigateToResult}
|
||||
.showManageLink=${this._showDiscovered || this._showDiscoveredView}
|
||||
.boxed=${!integration}
|
||||
.groupFlows=${groupFlows}
|
||||
.brands=${this._integrations}
|
||||
.dialogParent=${this._dialogParent}
|
||||
@close-dialog=${this._closeDialog}
|
||||
@config-flow-picked=${this._handleConfigFlowPicked}
|
||||
@protocol-picked=${this._handleProtocolPicked}
|
||||
@supported-by=${this._handleSupportedByEvent}
|
||||
@select-brand=${this._handleSelectBrandEvent}
|
||||
@@ -1152,17 +1203,24 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
this.closeDialog();
|
||||
}
|
||||
|
||||
private _handleProtocolPicked(
|
||||
private async _handleProtocolPicked(
|
||||
ev: HASSDomEvent<HASSDomEvents["protocol-picked"]>
|
||||
) {
|
||||
this.closeDialog();
|
||||
await this.closeDialog();
|
||||
this._pickProtocol(ev.detail.domain, ev.detail.brand);
|
||||
}
|
||||
|
||||
private _handleConfigFlowPicked(
|
||||
ev: HASSDomEvent<HASSDomEvents["config-flow-picked"]>
|
||||
) {
|
||||
this._showConfigFlow(ev.detail.domain, ev.detail.flowId);
|
||||
}
|
||||
|
||||
private async _handleDiscoveredGroupPicked(
|
||||
ev: HASSDomEvent<HASSDomEvents["discovered-group-picked"]>
|
||||
) {
|
||||
this._discoveredDomain = ev.detail.domain;
|
||||
this._pushHistoryLevel();
|
||||
// The picked row is gone, and the back button renders after this element
|
||||
await nextRender();
|
||||
if (this._discoveredDomain) {
|
||||
@@ -1171,8 +1229,8 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
}
|
||||
|
||||
private _handleSelectBrandEvent(ev: CustomEvent) {
|
||||
this._prevPickedBrand = this._pickedBrand;
|
||||
this._pickedBrand = ev.detail.brand;
|
||||
this._pushHistoryLevel();
|
||||
}
|
||||
|
||||
private _handleSupportedByEvent(ev: CustomEvent) {
|
||||
@@ -1196,8 +1254,8 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
domainToName(this._i18n.localize, integration.supported_by),
|
||||
}
|
||||
),
|
||||
confirm: () => {
|
||||
this.closeDialog();
|
||||
confirm: async () => {
|
||||
await this.closeDialog();
|
||||
if (PROTOCOL_INTEGRATIONS.includes(integration.supported_by)) {
|
||||
this._pickProtocol(integration.supported_by);
|
||||
return;
|
||||
@@ -1556,17 +1614,10 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
if (!this._narrow) {
|
||||
return;
|
||||
}
|
||||
const wasDrilled = this._drilled;
|
||||
this._drilled = true;
|
||||
this._focusAfterDrill = "in";
|
||||
}
|
||||
|
||||
private _drillOut() {
|
||||
if (this._subcategory) {
|
||||
this._subcategory = undefined;
|
||||
return;
|
||||
}
|
||||
this._drilled = false;
|
||||
this._focusAfterDrill = "out";
|
||||
this._pushDrilledLevels(wasDrilled);
|
||||
}
|
||||
|
||||
private _withEndSpace = memoizeOne(
|
||||
@@ -1810,12 +1861,12 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
this._browse({ discovered: true });
|
||||
}
|
||||
|
||||
private _protocolPicked(
|
||||
private async _protocolPicked(
|
||||
ev: HASSDomCurrentTargetEvent<HaListItemButton & { protocol: string }>
|
||||
) {
|
||||
const domain = ev.currentTarget.protocol;
|
||||
await this.closeDialog();
|
||||
this._pickProtocol(domain);
|
||||
this.closeDialog();
|
||||
}
|
||||
|
||||
private _treeSelectionChanged(ev: WaSelectionChangeEvent) {
|
||||
@@ -2034,19 +2085,20 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
}
|
||||
|
||||
if (integration.is_add) {
|
||||
await this.closeDialog();
|
||||
this._pickProtocol(integration.domain);
|
||||
this.closeDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if (integration.is_helper) {
|
||||
this.closeDialog();
|
||||
await this.closeDialog();
|
||||
navigate(`/config/helpers/add?domain=${integration.domain}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (integration.integrations) {
|
||||
this._pickedBrand = integration.domain;
|
||||
this._pushHistoryLevel();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2058,11 +2110,13 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
this._hasProtocol(integration.domain)
|
||||
) {
|
||||
this._pickedBrand = integration.domain;
|
||||
this._pushHistoryLevel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (integration.iot_standards) {
|
||||
this._pickedBrand = integration.domain;
|
||||
this._pushHistoryLevel();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2071,9 +2125,10 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
domain: integration.domain,
|
||||
});
|
||||
if (configEntries.length > 0) {
|
||||
this.closeDialog();
|
||||
|
||||
showSingleConfigEntryWarning(this, { domain: integration.domain });
|
||||
await this.closeDialog();
|
||||
showSingleConfigEntryWarning(this._dialogParent, {
|
||||
domain: integration.domain,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2087,7 +2142,7 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
integration.domain === "cloud" &&
|
||||
isComponentLoaded(this._hassConfig, "cloud")
|
||||
) {
|
||||
this.closeDialog();
|
||||
await this.closeDialog();
|
||||
navigate("/config/cloud");
|
||||
return;
|
||||
}
|
||||
@@ -2096,7 +2151,7 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
["google_assistant", "alexa"].includes(integration.domain) &&
|
||||
isComponentLoaded(this._hassConfig, "cloud")
|
||||
) {
|
||||
this.closeDialog();
|
||||
await this.closeDialog();
|
||||
navigate("/config/voice-assistants/assistants");
|
||||
return;
|
||||
}
|
||||
@@ -2116,15 +2171,20 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
|
||||
if (flowsInProgress.length) {
|
||||
this._pickedBrand = domain;
|
||||
this._pushHistoryLevel();
|
||||
return;
|
||||
}
|
||||
|
||||
await this._showConfigFlow(domain);
|
||||
}
|
||||
|
||||
private async _showConfigFlow(domain: string, flowId?: string) {
|
||||
const manifest = await fetchIntegrationManifest(this._api, domain);
|
||||
|
||||
this.closeDialog();
|
||||
|
||||
// Its history entry must not go on top of this dialog's levels
|
||||
await this.closeDialog();
|
||||
showConfigFlowDialog(this._dialogParent, {
|
||||
startFlowHandler: domain,
|
||||
startFlowHandler: flowId ? undefined : domain,
|
||||
continueFlowId: flowId,
|
||||
manifest,
|
||||
navigateToResult: this._navigateToResult,
|
||||
});
|
||||
@@ -2174,21 +2234,6 @@ class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
|
||||
}
|
||||
}
|
||||
|
||||
private _prevClicked() {
|
||||
if (this._pickedBrand) {
|
||||
this._pickedBrand = this._prevPickedBrand;
|
||||
this._prevPickedBrand = undefined;
|
||||
return;
|
||||
}
|
||||
if (this._discoveredDomain) {
|
||||
const domain = this._discoveredDomain;
|
||||
this._discoveredDomain = undefined;
|
||||
this._focusFlowGroupAfterBack(domain);
|
||||
return;
|
||||
}
|
||||
this._showDiscovered = false;
|
||||
}
|
||||
|
||||
private async _focusFlowGroupAfterBack(domain: string) {
|
||||
await nextRender();
|
||||
if (this._open && !this._discoveredDomain) {
|
||||
|
||||
@@ -32,7 +32,6 @@ import {
|
||||
} from "../../../data/integration";
|
||||
import type { Brand, Brands, Integration } from "../../../data/integrations";
|
||||
import { findIntegration } from "../../../data/integrations";
|
||||
import { showConfigFlowDialog } from "../../../dialogs/config-flow/show-dialog-config-flow";
|
||||
import { haStyle } from "../../../resources/styles";
|
||||
import type {
|
||||
HomeAssistantApi,
|
||||
@@ -87,9 +86,6 @@ export class HaDomainIntegrations extends LitElement {
|
||||
@property({ attribute: false })
|
||||
public flowsInProgress?: DataEntryFlowProgress[];
|
||||
|
||||
@property({ attribute: false })
|
||||
public navigateToResult = false;
|
||||
|
||||
@property({ attribute: false })
|
||||
public showManageLink = false;
|
||||
|
||||
@@ -101,9 +97,6 @@ export class HaDomainIntegrations extends LitElement {
|
||||
/** Names integrations that have no translated title, like most that aren't set up. */
|
||||
@property({ attribute: false }) public brands?: Brands;
|
||||
|
||||
/** Opens the config flow, which keeps it to open dialogs after the add dialog has closed. */
|
||||
@property({ attribute: false }) public dialogParent?: HTMLElement;
|
||||
|
||||
@queryAll("ha-list-item-button.flow-group")
|
||||
private _flowGroups!: NodeListOf<HaListItemButton & { domain: string }>;
|
||||
|
||||
@@ -461,22 +454,15 @@ export class HaDomainIntegrations extends LitElement {
|
||||
return;
|
||||
}
|
||||
|
||||
showConfigFlowDialog(this.dialogParent ?? this, {
|
||||
startFlowHandler: domain,
|
||||
navigateToResult: this.navigateToResult,
|
||||
manifest: await fetchIntegrationManifest(this._api, domain),
|
||||
});
|
||||
fireEvent(this, "close-dialog");
|
||||
fireEvent(this, "config-flow-picked", { domain });
|
||||
}
|
||||
|
||||
private async _flowInProgressPicked(ev: Event) {
|
||||
private _flowInProgressPicked(ev: Event) {
|
||||
const flow: DataEntryFlowProgress = (ev.currentTarget as any).flow;
|
||||
showConfigFlowDialog(this.dialogParent ?? this, {
|
||||
continueFlowId: flow.flow_id,
|
||||
navigateToResult: this.navigateToResult,
|
||||
manifest: await fetchIntegrationManifest(this._api, flow.handler),
|
||||
fireEvent(this, "config-flow-picked", {
|
||||
domain: flow.handler,
|
||||
flowId: flow.flow_id,
|
||||
});
|
||||
fireEvent(this, "close-dialog");
|
||||
}
|
||||
|
||||
private _manageDiscovered() {
|
||||
@@ -609,6 +595,8 @@ declare global {
|
||||
}
|
||||
|
||||
interface HASSDomEvents {
|
||||
// The add dialog starts it, so it can close first
|
||||
"config-flow-picked": { domain: string; flowId?: string };
|
||||
"discovered-group-picked": { domain: string };
|
||||
"protocol-picked": { domain: string; brand?: string };
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { LitElement } from "lit";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
|
||||
export interface SingleConfigEntryWarningDialogParams {
|
||||
@@ -6,7 +5,7 @@ export interface SingleConfigEntryWarningDialogParams {
|
||||
}
|
||||
|
||||
export const showSingleConfigEntryWarning = (
|
||||
element: LitElement,
|
||||
element: HTMLElement,
|
||||
params: SingleConfigEntryWarningDialogParams
|
||||
) =>
|
||||
fireEvent(element, "show-dialog", {
|
||||
|
||||
@@ -315,9 +315,7 @@ export class LovelacePanel extends LitElement {
|
||||
|
||||
// On first load, we speed up loading page by having LL promise ready
|
||||
if (preloadWindow.llConfProm) {
|
||||
if (preloadWindow.llConfUrlPath === this.urlPath) {
|
||||
confProm = preloadWindow.llConfProm;
|
||||
}
|
||||
confProm = preloadWindow.llConfProm;
|
||||
preloadWindow.llConfProm = undefined;
|
||||
}
|
||||
if (!resourcesLoaded) {
|
||||
@@ -335,9 +333,12 @@ export class LovelacePanel extends LitElement {
|
||||
|
||||
const fetchDashboardConfig = () =>
|
||||
fetchConfig(this.hass!.connection, this.urlPath, forceDiskRefresh);
|
||||
// The preload is the config of the dashboard in the URL. Fetch it again if
|
||||
// The preload is the config of the "lovelace" dashboard. Fetch it again if
|
||||
// it failed, for example because the connection dropped before it came back.
|
||||
confProm = confProm?.catch(fetchDashboardConfig) ?? fetchDashboardConfig();
|
||||
confProm =
|
||||
confProm && this.urlPath === "lovelace"
|
||||
? confProm.catch(fetchDashboardConfig)
|
||||
: fetchDashboardConfig();
|
||||
|
||||
try {
|
||||
rawConf = await confProm;
|
||||
|
||||
@@ -5,6 +5,7 @@ import { mainWindow } from "../common/dom/get_main_window";
|
||||
import { updateHistoryState } from "../common/navigate";
|
||||
import {
|
||||
closeLastDialog,
|
||||
isEntryOfDialogBelow,
|
||||
restoreClosedDialogSearch,
|
||||
} from "../dialogs/make-dialog-manager";
|
||||
import type { ProvideHassElement } from "../mixins/provide-hass-lit-mixin";
|
||||
@@ -78,6 +79,8 @@ export const urlSyncMixin = <
|
||||
// if we have dialog data we are closing a dialog with appended state
|
||||
// so dialog has the change to navigate back to the previous state
|
||||
closeLastDialog(ev.state);
|
||||
} else if (isEntryOfDialogBelow(ev.state)) {
|
||||
closeLastDialog(ev.state);
|
||||
} else if ("dialog" in ev.state) {
|
||||
// coming to a dialog
|
||||
// the dialog stack must be empty in this case so this state should be cleaned up
|
||||
|
||||
@@ -22,6 +22,7 @@ vi.mock("../../src/dialogs/make-dialog-manager", () => ({
|
||||
window.history.replaceState(null, "");
|
||||
return true;
|
||||
}),
|
||||
isDialogHistoryEntry: () => Boolean(window.history.state?.dialog),
|
||||
}));
|
||||
|
||||
// Fabricates a raw entry like a document load, which navigate() never produces.
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getPreloadDashboardUrlPath } from "../../src/data/preloads";
|
||||
|
||||
describe("getPreloadDashboardUrlPath", () => {
|
||||
it("returns the lovelace dashboard", () => {
|
||||
expect(getPreloadDashboardUrlPath("/lovelace")).toBe("lovelace");
|
||||
expect(getPreloadDashboardUrlPath("/lovelace/0")).toBe("lovelace");
|
||||
});
|
||||
|
||||
it("returns a dashboard with a hyphen in its url path", () => {
|
||||
expect(getPreloadDashboardUrlPath("/dashboard-test")).toBe(
|
||||
"dashboard-test"
|
||||
);
|
||||
expect(getPreloadDashboardUrlPath("/dashboard-test/kitchen")).toBe(
|
||||
"dashboard-test"
|
||||
);
|
||||
});
|
||||
|
||||
it("returns nothing when the default panel is opened", () => {
|
||||
expect(getPreloadDashboardUrlPath("/")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns nothing for panels that cannot be a dashboard", () => {
|
||||
expect(getPreloadDashboardUrlPath("/home")).toBeUndefined();
|
||||
expect(getPreloadDashboardUrlPath("/config/dashboard")).toBeUndefined();
|
||||
expect(getPreloadDashboardUrlPath("/lovelaces")).toBeUndefined();
|
||||
expect(
|
||||
getPreloadDashboardUrlPath("/media-browser/browser")
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
getPreloadDashboardUrlPath("/developer-tools/state")
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -84,6 +84,8 @@ describe("DialogHistoryMixin", () => {
|
||||
expect(dialog.level).toBe(1);
|
||||
expect(dialog.isConnected).toBe(true);
|
||||
|
||||
// A dialog opened over this one takes over the entry of the level
|
||||
window.history.replaceState({ dialog: "test-other-dialog" }, "");
|
||||
const closed = dialog.closeDialog();
|
||||
expect(dialog.isConnected).toBe(true);
|
||||
expect(await closed).toBe(true);
|
||||
|
||||
@@ -4,8 +4,11 @@ import { deepActiveElement } from "../../src/common/dom/deep-active-element";
|
||||
import { fireEvent } from "../../src/common/dom/fire_event";
|
||||
import { nextRender } from "../../src/common/util/render-status";
|
||||
import {
|
||||
closeLastDialog,
|
||||
DIALOG_WAIT_TIMEOUT,
|
||||
getTopOpenDialogTag,
|
||||
isDialogHistoryEntry,
|
||||
isEntryOfDialogBelow,
|
||||
showDialog,
|
||||
} from "../../src/dialogs/make-dialog-manager";
|
||||
import type { ProvideHassElement } from "../../src/mixins/provide-hass-lit-mixin";
|
||||
@@ -46,11 +49,22 @@ class TestFlowDialog extends TestNextDialog {}
|
||||
|
||||
class TestHistoryDialog extends TestNextDialog {}
|
||||
|
||||
class TestTopDialog extends TestNextDialog {}
|
||||
|
||||
// Like a confirmation, which only closes from its buttons
|
||||
class TestRefusingDialog extends TestNextDialog {
|
||||
public closeDialog() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define("test-manager-dialog", TestDialog);
|
||||
customElements.define("test-manager-nested-dialog", TestNestedDialog);
|
||||
customElements.define("test-manager-next-dialog", TestNextDialog);
|
||||
customElements.define("test-manager-flow-dialog", TestFlowDialog);
|
||||
customElements.define("test-manager-history-dialog", TestHistoryDialog);
|
||||
customElements.define("test-manager-top-dialog", TestTopDialog);
|
||||
customElements.define("test-manager-refusing-dialog", TestRefusingDialog);
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
@@ -59,6 +73,8 @@ declare global {
|
||||
"test-manager-next-dialog": TestNextDialog;
|
||||
"test-manager-flow-dialog": TestFlowDialog;
|
||||
"test-manager-history-dialog": TestHistoryDialog;
|
||||
"test-manager-top-dialog": TestTopDialog;
|
||||
"test-manager-refusing-dialog": TestRefusingDialog;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,3 +245,108 @@ describe("dialog manager history wait", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// A dialog opened over a level of another dialog (see DialogHistoryMixin)
|
||||
// must keep the number of history entries and give the level back, or Back
|
||||
// and closing the lower dialog land on the wrong entry.
|
||||
describe("dialog manager over a dialog level", () => {
|
||||
it("works", async () => {
|
||||
const element = host();
|
||||
const showWithHistory = async (dialogTag: string) => {
|
||||
await showDialog(element, dialogTag, {}, () => Promise.resolve());
|
||||
return element.shadowRoot!.querySelector(dialogTag) as TestNextDialog;
|
||||
};
|
||||
const popstate = () =>
|
||||
new Promise((resolve) => {
|
||||
window.addEventListener("popstate", resolve, { once: true });
|
||||
});
|
||||
const level = (depth: number) => ({
|
||||
dialogData: { dialogId: "lower", depth },
|
||||
});
|
||||
try {
|
||||
window.history.replaceState({ opener: true }, "");
|
||||
const lower = await showWithHistory("test-manager-next-dialog");
|
||||
window.history.pushState(level(1), "");
|
||||
window.history.pushState(level(2), "");
|
||||
const { length } = window.history;
|
||||
expect(isDialogHistoryEntry()).toBe(true);
|
||||
|
||||
let upper = await showWithHistory("test-manager-flow-dialog");
|
||||
expect(window.history.state).toEqual({
|
||||
dialog: "test-manager-flow-dialog",
|
||||
});
|
||||
expect(window.history.length).toBe(length);
|
||||
upper.close();
|
||||
expect(window.history.state).toEqual(level(2));
|
||||
|
||||
upper = await showWithHistory("test-manager-flow-dialog");
|
||||
window.history.back();
|
||||
await popstate();
|
||||
// Like the url-sync mixin
|
||||
await closeLastDialog(window.history.state);
|
||||
expect(window.history.state).toEqual(level(2));
|
||||
upper.close();
|
||||
|
||||
// Three dialogs over the level, Back closes one at a time
|
||||
upper = await showWithHistory("test-manager-flow-dialog");
|
||||
let top = await showWithHistory("test-manager-top-dialog");
|
||||
const third = await showWithHistory("test-manager-history-dialog");
|
||||
window.history.back();
|
||||
await popstate();
|
||||
await closeLastDialog(window.history.state);
|
||||
third.close();
|
||||
expect(window.history.state).toEqual({
|
||||
dialog: "test-manager-top-dialog",
|
||||
});
|
||||
window.history.back();
|
||||
await popstate();
|
||||
await closeLastDialog(window.history.state);
|
||||
top.close();
|
||||
expect(window.history.state).toEqual({
|
||||
dialog: "test-manager-flow-dialog",
|
||||
});
|
||||
window.history.back();
|
||||
await popstate();
|
||||
await closeLastDialog(window.history.state);
|
||||
upper.close();
|
||||
expect(window.history.state).toEqual(level(2));
|
||||
|
||||
// Shown again, then the next dialog takes over the entry
|
||||
upper = await showWithHistory("test-manager-flow-dialog");
|
||||
upper = await showWithHistory("test-manager-flow-dialog");
|
||||
top = await showWithHistory("test-manager-top-dialog");
|
||||
upper.close();
|
||||
top.close();
|
||||
expect(window.history.state).toEqual(level(2));
|
||||
|
||||
// Refusing Back keeps the dialog's entry
|
||||
const refusing = await showWithHistory("test-manager-refusing-dialog");
|
||||
window.history.back();
|
||||
await popstate();
|
||||
expect(await closeLastDialog(window.history.state)).toBe(false);
|
||||
expect(window.history.state).toEqual({
|
||||
dialog: "test-manager-refusing-dialog",
|
||||
});
|
||||
refusing.close();
|
||||
expect(window.history.state).toEqual(level(2));
|
||||
expect(window.history.length).toBe(length);
|
||||
|
||||
// Over the first level, Back lands on the lower dialog's own entry
|
||||
window.history.back();
|
||||
await popstate();
|
||||
upper = await showWithHistory("test-manager-flow-dialog");
|
||||
window.history.back();
|
||||
await popstate();
|
||||
expect(isEntryOfDialogBelow(window.history.state)).toBe(true);
|
||||
await closeLastDialog(window.history.state);
|
||||
expect(window.history.state).toEqual(level(1));
|
||||
upper.close();
|
||||
|
||||
lower.close();
|
||||
// Left behind, like after a page reload
|
||||
expect(isDialogHistoryEntry()).toBe(false);
|
||||
} finally {
|
||||
window.history.replaceState(null, "");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import { PreventUnsavedMixin } from "../../src/mixins/prevent-unsaved-mixin";
|
||||
// navigate() closes open dialogs before touching history.
|
||||
vi.mock("../../src/dialogs/make-dialog-manager", () => ({
|
||||
closeAllDialogs: vi.fn(async () => true),
|
||||
isDialogHistoryEntry: () => Boolean(window.history.state?.dialog),
|
||||
}));
|
||||
|
||||
interface TestState {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { subscribeLovelaceUpdates } from "../../../src/data/lovelace";
|
||||
import type { LovelaceRawConfig } from "../../../src/data/lovelace/config/types";
|
||||
import { fetchConfig } from "../../../src/data/lovelace/config/types";
|
||||
import type { WindowWithPreloads } from "../../../src/data/preloads";
|
||||
import "../../../src/panels/lovelace/ha-panel-lovelace";
|
||||
|
||||
type LovelacePanel = HTMLElement & {
|
||||
@@ -65,54 +63,9 @@ const openPanel = async (urlPath: string) => {
|
||||
return { panel, unsub, notifyUpdated: () => notifyUpdated() };
|
||||
};
|
||||
|
||||
const preloadWindow = window as WindowWithPreloads;
|
||||
|
||||
const preloadConfig = (
|
||||
urlPath: string,
|
||||
confProm: Promise<LovelaceRawConfig>
|
||||
) => {
|
||||
confProm.catch(() => undefined);
|
||||
preloadWindow.llConfUrlPath = urlPath;
|
||||
preloadWindow.llConfProm = confProm;
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
document.body.replaceChildren();
|
||||
vi.clearAllMocks();
|
||||
delete preloadWindow.llConfProm;
|
||||
delete preloadWindow.llConfUrlPath;
|
||||
});
|
||||
|
||||
describe("ha-panel-lovelace config preload", () => {
|
||||
it("uses the preloaded config of its own dashboard", async () => {
|
||||
preloadConfig("dashboard-test", Promise.resolve({ views: [] }));
|
||||
await openPanel("dashboard-test");
|
||||
expect(fetchConfig).not.toHaveBeenCalled();
|
||||
expect(preloadWindow.llConfProm).toBeUndefined();
|
||||
});
|
||||
|
||||
it("ignores the preloaded config of another dashboard", async () => {
|
||||
preloadConfig("dashboard-other", Promise.resolve({ views: [] }));
|
||||
await openPanel("dashboard-test");
|
||||
expect(fetchConfig).toHaveBeenCalledTimes(1);
|
||||
expect(fetchConfig).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
"dashboard-test",
|
||||
false
|
||||
);
|
||||
expect(preloadWindow.llConfProm).toBeUndefined();
|
||||
});
|
||||
|
||||
it("fetches the config again when its preload failed", async () => {
|
||||
preloadConfig("dashboard-test", Promise.reject(new Error("closed")));
|
||||
await openPanel("dashboard-test");
|
||||
expect(fetchConfig).toHaveBeenCalledTimes(1);
|
||||
expect(fetchConfig).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
"dashboard-test",
|
||||
false
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ha-panel-lovelace config updates", () => {
|
||||
|
||||
Reference in new issue
Block a user