Navigate cleanup (#9202)

This commit is contained in:
Joakim Sørensen 2021-05-25 17:46:36 +02:00 committed by GitHub
parent 1026e90296
commit 21a3a8c594
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
62 changed files with 111 additions and 137 deletions

View File

@ -70,7 +70,7 @@ class HaDemo extends HomeAssistantAppEl {
} }
e.preventDefault(); e.preventDefault();
navigate(this, href); navigate(href);
}, },
{ capture: true } { capture: true }
); );

View File

@ -120,7 +120,7 @@ class HassioAddonRepositoryEl extends LitElement {
} }
private _addonTapped(ev) { private _addonTapped(ev) {
navigate(this, `/hassio/addon/${ev.currentTarget.addon.slug}`); navigate(`/hassio/addon/${ev.currentTarget.addon.slug}`);
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -138,7 +138,7 @@ class HassioAddonStore extends LitElement {
protected firstUpdated(changedProps: PropertyValues) { protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps); super.firstUpdated(changedProps);
const repositoryUrl = extractSearchParam("repository_url"); const repositoryUrl = extractSearchParam("repository_url");
navigate(this, "/hassio/store", true); navigate("/hassio/store", { replace: true });
if (repositoryUrl) { if (repositoryUrl) {
this._manageRepositories(repositoryUrl); this._manageRepositories(repositoryUrl);
} }

View File

@ -175,7 +175,7 @@ class HassioAddonDashboard extends LitElement {
if (!validAddon) { if (!validAddon) {
this._error = this.supervisor.localize("my.error_addon_not_found"); this._error = this.supervisor.localize("my.error_addon_not_found");
} else { } else {
navigate(this, `/hassio/addon/${requestedAddon}`, true); navigate(`/hassio/addon/${requestedAddon}`, { replace: true });
} }
} }
} }

View File

@ -761,7 +761,7 @@ class HassioAddonInfo extends LitElement {
} }
private _openIngress(): void { private _openIngress(): void {
navigate(this, `/hassio/ingress/${this.addon.slug}`); navigate(`/hassio/ingress/${this.addon.slug}`);
} }
private get _computeShowIngressUI(): boolean { private get _computeShowIngressUI(): boolean {
@ -1051,7 +1051,7 @@ class HassioAddonInfo extends LitElement {
} }
private _openConfiguration(): void { private _openConfiguration(): void {
navigate(this, `/hassio/addon/${this.addon.slug}/config`); navigate(`/hassio/addon/${this.addon.slug}/config`);
} }
private async _uninstallClicked(ev: CustomEvent): Promise<void> { private async _uninstallClicked(ev: CustomEvent): Promise<void> {

View File

@ -96,11 +96,11 @@ class HassioAddons extends LitElement {
} }
private _addonTapped(ev: any): void { private _addonTapped(ev: any): void {
navigate(this, `/hassio/addon/${ev.currentTarget.addon.slug}/info`); navigate(`/hassio/addon/${ev.currentTarget.addon.slug}/info`);
} }
private _openStore(): void { private _openStore(): void {
navigate(this, "/hassio/store"); navigate("/hassio/store");
} }
} }

View File

@ -63,7 +63,7 @@ export class HassioMain extends SupervisorBaseElement {
document.body.addEventListener("click", (ev) => { document.body.addEventListener("click", (ev) => {
const href = isNavigationClick(ev); const href = isNavigationClick(ev);
if (href) { if (href) {
navigate(document.body, href); navigate(href);
} }
}); });

View File

@ -89,7 +89,7 @@ class HassioMyRedirect extends LitElement {
return; return;
} }
navigate(this, url, true); navigate(url, { replace: true });
} }
protected render(): TemplateResult { protected render(): TemplateResult {

View File

@ -105,7 +105,7 @@ class HassioIngressView extends LitElement {
}); });
history.back(); history.back();
} else { } else {
navigate(this, `/hassio/ingress/${addonInfo.slug}`, true); navigate(`/hassio/ingress/${addonInfo.slug}`, { replace: true });
} }
} }
} }
@ -157,8 +157,8 @@ class HassioIngressView extends LitElement {
await showAlertDialog(this, { await showAlertDialog(this, {
text: "Add-on is not running. Please start it first", text: "Add-on is not running. Please start it first",
title: addon.name, title: addon.name,
confirm: () => navigate(`/hassio/addon/${addon.slug}`),
}); });
navigate(this, `/hassio/addon/${addon.slug}/info`, true);
return; return;
} }

View File

@ -4,13 +4,17 @@ import { mainWindow } from "./dom/get_main_window";
declare global { declare global {
// for fire event // for fire event
interface HASSDomEvents { interface HASSDomEvents {
"location-changed": { "location-changed": NavigateOptions;
replace: boolean;
};
} }
} }
export const navigate = (_node: any, path: string, replace = false) => { export interface NavigateOptions {
replace?: boolean;
}
export const navigate = (path: string, options?: NavigateOptions) => {
const replace = options?.replace || false;
if (__DEMO__) { if (__DEMO__) {
if (replace) { if (replace) {
mainWindow.history.replaceState( mainWindow.history.replaceState(

View File

@ -241,12 +241,9 @@ let inititialAutomationEditorData: Partial<AutomationConfig> | undefined;
export const getAutomationConfig = (hass: HomeAssistant, id: string) => export const getAutomationConfig = (hass: HomeAssistant, id: string) =>
hass.callApi<AutomationConfig>("GET", `config/automation/config/${id}`); hass.callApi<AutomationConfig>("GET", `config/automation/config/${id}`);
export const showAutomationEditor = ( export const showAutomationEditor = (data?: Partial<AutomationConfig>) => {
el: HTMLElement,
data?: Partial<AutomationConfig>
) => {
inititialAutomationEditorData = data; inititialAutomationEditorData = data;
navigate(el, "/config/automation/edit/new"); navigate("/config/automation/edit/new");
}; };
export const getAutomationEditorInitData = () => { export const getAutomationEditorInitData = () => {

View File

@ -20,12 +20,9 @@ export const SCENE_IGNORED_DOMAINS = [
let inititialSceneEditorData: Partial<SceneConfig> | undefined; let inititialSceneEditorData: Partial<SceneConfig> | undefined;
export const showSceneEditor = ( export const showSceneEditor = (data?: Partial<SceneConfig>) => {
el: HTMLElement,
data?: Partial<SceneConfig>
) => {
inititialSceneEditorData = data; inititialSceneEditorData = data;
navigate(el, "/config/scene/edit/new"); navigate("/config/scene/edit/new");
}; };
export const getSceneEditorInitData = () => { export const getSceneEditorInitData = () => {

View File

@ -182,12 +182,9 @@ export const deleteScript = (hass: HomeAssistant, objectId: string) =>
let inititialScriptEditorData: Partial<ScriptConfig> | undefined; let inititialScriptEditorData: Partial<ScriptConfig> | undefined;
export const showScriptEditor = ( export const showScriptEditor = (data?: Partial<ScriptConfig>) => {
el: HTMLElement,
data?: Partial<ScriptConfig>
) => {
inititialScriptEditorData = data; inititialScriptEditorData = data;
navigate(el, "/config/script/edit/new"); navigate("/config/script/edit/new");
}; };
export const getScriptEditorInitData = () => { export const getScriptEditorInitData = () => {

View File

@ -56,12 +56,9 @@ export const deleteZone = (hass: HomeAssistant, zoneId: string) =>
let inititialZoneEditorData: Partial<ZoneMutableParams> | undefined; let inititialZoneEditorData: Partial<ZoneMutableParams> | undefined;
export const showZoneEditor = ( export const showZoneEditor = (data?: Partial<ZoneMutableParams>) => {
el: HTMLElement,
data?: Partial<ZoneMutableParams>
) => {
inititialZoneEditorData = data; inititialZoneEditorData = data;
navigate(el, "/config/zone/new"); navigate("/config/zone/new");
}; };
export const getZoneEditorInitData = () => { export const getZoneEditorInitData = () => {

View File

@ -55,7 +55,7 @@ class MoreInfoPerson extends LitElement {
} }
private _handleAction() { private _handleAction() {
showZoneEditor(this, { showZoneEditor({
latitude: this.stateObj!.attributes.latitude, latitude: this.stateObj!.attributes.latitude,
longitude: this.stateObj!.attributes.longitude, longitude: this.stateObj!.attributes.longitude,
}); });

View File

@ -306,7 +306,7 @@ export class MoreInfoDialog extends LitElement {
idToPassThroughUrl = stateObj.attributes.id; idToPassThroughUrl = stateObj.attributes.id;
} }
navigate(this, `/config/${domain}/edit/${idToPassThroughUrl}`); navigate(`/config/${domain}/edit/${idToPassThroughUrl}`);
this.closeDialog(); this.closeDialog();
} }

View File

@ -557,7 +557,7 @@ export class QuickBar extends LitElement {
categoryText: this.hass.localize( categoryText: this.hass.localize(
`ui.dialogs.quick-bar.commands.types.${categoryKey}` `ui.dialogs.quick-bar.commands.types.${categoryKey}`
), ),
action: () => navigate(this, item.path), action: () => navigate(item.path),
}; };
return { return {

View File

@ -88,7 +88,7 @@ function initialize(
if (window.parent.customPanel) { if (window.parent.customPanel) {
window.parent.customPanel.navigate( window.parent.customPanel.navigate(
window.location.pathname, window.location.pathname,
ev.detail ? ev.detail.replace : false ev.detail
); );
} }
}); });
@ -122,7 +122,7 @@ function initialize(
document.body.addEventListener("click", (ev) => { document.body.addEventListener("click", (ev) => {
const href = isNavigationClick(ev); const href = isNavigationClick(ev);
if (href) { if (href) {
navigate(document.body, href); navigate(href);
} }
}); });
} }

View File

@ -99,7 +99,7 @@ export class HassRouterPage extends ReactiveElement {
const defaultPage = routerOptions.defaultPage; const defaultPage = routerOptions.defaultPage;
if (route && route.path === "" && defaultPage !== undefined) { if (route && route.path === "" && defaultPage !== undefined) {
navigate(this, `${route.prefix}/${defaultPage}`, true); navigate(`${route.prefix}/${defaultPage}`, { replace: true });
} }
let newPage = route let newPage = route
@ -127,7 +127,7 @@ export class HassRouterPage extends ReactiveElement {
// Update the url if we know where we're mounted. // Update the url if we know where we're mounted.
if (route) { if (route) {
navigate(this, `${route.prefix}/${result}`, true); navigate(`${route.prefix}/${result}`, { replace: true });
} }
} }
} }

View File

@ -45,7 +45,7 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
const path = curPath(); const path = curPath();
if (["", "/"].includes(path)) { if (["", "/"].includes(path)) {
navigate(this, `/${getStorageDefaultPanelUrlPath()}`, true); navigate(`/${getStorageDefaultPanelUrlPath()}`, { replace: true });
} }
this._route = { this._route = {
prefix: "", prefix: "",
@ -106,7 +106,7 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
window.addEventListener("click", (ev) => { window.addEventListener("click", (ev) => {
const href = isNavigationClick(ev); const href = isNavigationClick(ev);
if (href) { if (href) {
navigate(this, href); navigate(href);
} }
}); });
} }

View File

@ -9,7 +9,7 @@ export default dedupingMixin(
(superClass) => (superClass) =>
class extends superClass { class extends superClass {
navigate(...args) { navigate(...args) {
navigate(this, ...args); navigate(...args);
} }
} }
); );

View File

@ -63,7 +63,7 @@ class OnboardingRestoreSnapshot extends ProvideHassLitMixin(LitElement) {
}); });
if (response.status === 401) { if (response.status === 401) {
// If we get a unauthorized response, the restore is done // If we get a unauthorized response, the restore is done
navigate(this, "/", true); navigate("/", { replace: true });
location.reload(); location.reload();
} }
} catch (err) { } catch (err) {

View File

@ -149,7 +149,7 @@ class DialogAreaDetail extends LitElement {
this._submitting = false; this._submitting = false;
} }
navigate(this, "/config/areas/dashboard"); navigate("/config/areas/dashboard");
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -192,7 +192,7 @@ export class HaConfigAreasDashboard extends LitElement {
private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) { private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) {
const areaId = ev.detail.id; const areaId = ev.detail.id;
navigate(this, `/config/areas/area/${areaId}`); navigate(`/config/areas/area/${areaId}`);
} }
private _openDialog(entry?: AreaRegistryEntry) { private _openDialog(entry?: AreaRegistryEntry) {

View File

@ -108,7 +108,7 @@ class DialogNewAutomation extends LitElement implements HassDialog {
replaceDialog(); replaceDialog();
showThingtalkDialog(this, { showThingtalkDialog(this, {
callback: (config: Partial<AutomationConfig> | undefined) => callback: (config: Partial<AutomationConfig> | undefined) =>
showAutomationEditor(this, config), showAutomationEditor(config),
input: this.shadowRoot!.querySelector("paper-input")!.value as string, input: this.shadowRoot!.querySelector("paper-input")!.value as string,
}); });
this.closeDialog(); this.closeDialog();
@ -117,13 +117,13 @@ class DialogNewAutomation extends LitElement implements HassDialog {
private async _blueprintPicked(ev: CustomEvent) { private async _blueprintPicked(ev: CustomEvent) {
this.closeDialog(); this.closeDialog();
await nextRender(); await nextRender();
showAutomationEditor(this, { use_blueprint: { path: ev.detail.value } }); showAutomationEditor({ use_blueprint: { path: ev.detail.value } });
} }
private async _blank() { private async _blank() {
this.closeDialog(); this.closeDialog();
await nextRender(); await nextRender();
showAutomationEditor(this); showAutomationEditor();
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -450,7 +450,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
// Wait for dialog to complate closing // Wait for dialog to complate closing
await new Promise((resolve) => setTimeout(resolve, 0)); await new Promise((resolve) => setTimeout(resolve, 0));
} }
showAutomationEditor(this, { showAutomationEditor({
...this._config, ...this._config,
id: undefined, id: undefined,
alias: `${this._config?.alias} (${this.hass.localize( alias: `${this._config?.alias} (${this.hass.localize(
@ -503,7 +503,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
this._dirty = false; this._dirty = false;
if (!this.automationId) { if (!this.automationId) {
navigate(this, `/config/automation/edit/${id}`, true); navigate(`/config/automation/edit/${id}`, { replace: true });
} }
}, },
(errors) => { (errors) => {

View File

@ -324,7 +324,7 @@ class HaAutomationPicker extends LitElement {
) { ) {
showNewAutomationDialog(this); showNewAutomationDialog(this);
} else { } else {
navigate(this, "/config/automation/edit/new"); navigate("/config/automation/edit/new");
} }
} }

View File

@ -46,11 +46,8 @@ interface BlueprintMetaDataPath extends BlueprintMetaData {
} }
const createNewFunctions = { const createNewFunctions = {
automation: ( automation: (blueprintMeta: BlueprintMetaDataPath) => {
context: HaBlueprintOverview, showAutomationEditor({
blueprintMeta: BlueprintMetaDataPath
) => {
showAutomationEditor(context, {
alias: blueprintMeta.name, alias: blueprintMeta.name,
use_blueprint: { path: blueprintMeta.path }, use_blueprint: { path: blueprintMeta.path },
}); });
@ -183,7 +180,7 @@ class HaBlueprintOverview extends LitElement {
super.firstUpdated(changedProps); super.firstUpdated(changedProps);
if (this.route.path === "/import") { if (this.route.path === "/import") {
const url = extractSearchParam("blueprint_url"); const url = extractSearchParam("blueprint_url");
navigate(this, "/config/blueprint/dashboard", true); navigate("/config/blueprint/dashboard", { replace: true });
if (url) { if (url) {
this._addBlueprint(url); this._addBlueprint(url);
} }
@ -280,7 +277,7 @@ class HaBlueprintOverview extends LitElement {
private _createNew(ev) { private _createNew(ev) {
const blueprint = ev.currentTarget.blueprint as BlueprintMetaDataPath; const blueprint = ev.currentTarget.blueprint as BlueprintMetaDataPath;
createNewFunctions[blueprint.domain](this, blueprint); createNewFunctions[blueprint.domain](blueprint);
} }
private _share(ev) { private _share(ev) {

View File

@ -81,7 +81,7 @@ class HaConfigCloud extends HassRouterPage {
super.firstUpdated(changedProps); super.firstUpdated(changedProps);
this.addEventListener("cloud-done", (ev) => { this.addEventListener("cloud-done", (ev) => {
this._flashMessage = (ev as any).detail.flashMessage; this._flashMessage = (ev as any).detail.flashMessage;
navigate(this, "/config/cloud/login"); navigate("/config/cloud/login");
}); });
} }
@ -95,7 +95,7 @@ class HaConfigCloud extends HassRouterPage {
if (oldStatus === undefined) { if (oldStatus === undefined) {
this._resolveCloudStatusLoaded(); this._resolveCloudStatusLoaded();
} else if (oldStatus.logged_in !== this.cloudStatus.logged_in) { } else if (oldStatus.logged_in !== this.cloudStatus.logged_in) {
navigate(this, this.route.prefix, true); navigate(this.route.prefix, { replace: true });
} }
} }
} }

View File

@ -72,12 +72,12 @@ export abstract class HaDeviceAutomationCard<
return; return;
} }
if (this.script) { if (this.script) {
showScriptEditor(this, { sequence: [automation as DeviceAction] }); showScriptEditor({ sequence: [automation as DeviceAction] });
return; return;
} }
const data = {}; const data = {};
data[this.type] = [automation]; data[this.type] = [automation];
showAutomationEditor(this, data); showAutomationEditor(data);
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -66,7 +66,6 @@ export class HaDeviceActionsOzw extends LitElement {
private async _nodeDetailsClicked() { private async _nodeDetailsClicked() {
navigate( navigate(
this,
`/config/ozw/network/${this.ozw_instance}/node/${this.node_id}/dashboard` `/config/ozw/network/${this.ozw_instance}/node/${this.node_id}/dashboard`
); );
} }

View File

@ -107,14 +107,11 @@ export class HaDeviceActionsZha extends LitElement {
} }
private _onAddDevicesClick() { private _onAddDevicesClick() {
navigate(this, "/config/zha/add/" + this._zhaDevice!.ieee); navigate(`/config/zha/add/${this._zhaDevice!.ieee}`);
} }
private _onViewInVisualizationClick() { private _onViewInVisualizationClick() {
navigate( navigate(`/config/zha/visualization/${this._zhaDevice!.device_reg_id}`);
this,
"/config/zha/visualization/" + this._zhaDevice!.device_reg_id
);
} }
private async _handleZigbeeInfoClicked() { private async _handleZigbeeInfoClicked() {

View File

@ -533,7 +533,7 @@ export class HaConfigDevicePage extends LitElement {
this._entities(this.deviceId, this.entities).forEach((entity) => { this._entities(this.deviceId, this.entities).forEach((entity) => {
entities[entity.entity_id] = ""; entities[entity.entity_id] = "";
}); });
showSceneEditor(this, { showSceneEditor({
entities, entities,
}); });
} }

View File

@ -455,7 +455,7 @@ export class HaConfigDeviceDashboard extends LitElement {
private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) { private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) {
const deviceId = ev.detail.id; const deviceId = ev.detail.id;
this._ignoreLocationChange = true; this._ignoreLocationChange = true;
navigate(this, `/config/devices/device/${deviceId}`); navigate(`/config/devices/device/${deviceId}`);
} }
private _showDisabledChanged(ev: CustomEvent<RequestSelectedDetail>) { private _showDisabledChanged(ev: CustomEvent<RequestSelectedDetail>) {
@ -473,7 +473,7 @@ export class HaConfigDeviceDashboard extends LitElement {
if ( if (
this._activeFilters(this.entries, this._searchParms, this.hass.localize) this._activeFilters(this.entries, this._searchParms, this.hass.localize)
) { ) {
navigate(this, window.location.pathname, true); navigate(window.location.pathname, { replace: true });
} }
this._showDisabled = true; this._showDisabled = true;
} }

View File

@ -837,7 +837,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
if ( if (
this._activeFilters(this._searchParms, this.hass.localize, this._entries) this._activeFilters(this._searchParms, this.hass.localize, this._entries)
) { ) {
navigate(this, window.location.pathname, true); navigate(window.location.pathname, { replace: true });
} }
this._showDisabled = true; this._showDisabled = true;
this._showReadOnly = true; this._showReadOnly = true;

View File

@ -599,7 +599,7 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
private async _handleAdd(localizePromise: Promise<LocalizeFunc>) { private async _handleAdd(localizePromise: Promise<LocalizeFunc>) {
const domain = extractSearchParam("domain"); const domain = extractSearchParam("domain");
navigate(this, "/config/integrations", true); navigate("/config/integrations", { replace: true });
if (!domain) { if (!domain) {
return; return;
} }

View File

@ -143,11 +143,9 @@ class OZWConfigDashboard extends LitElement {
private async _fetchData() { private async _fetchData() {
this._instances = await fetchOZWInstances(this.hass!); this._instances = await fetchOZWInstances(this.hass!);
if (this._instances.length === 1) { if (this._instances.length === 1) {
navigate( navigate(`/config/ozw/network/${this._instances[0].ozw_instance}`, {
this, replace: true,
`/config/ozw/network/${this._instances[0].ozw_instance}`, });
true
);
} }
} }

View File

@ -46,7 +46,7 @@ class OZWNetworkDashboard extends LitElement {
protected firstUpdated() { protected firstUpdated() {
if (!this.ozwInstance) { if (!this.ozwInstance) {
navigate(this, "/config/ozw/dashboard", true); navigate("/config/ozw/dashboard", { replace: true });
} else if (this.hass) { } else if (this.hass) {
this._fetchData(); this._fetchData();
} }

View File

@ -88,7 +88,7 @@ class OZWNetworkNodes extends LitElement {
protected firstUpdated() { protected firstUpdated() {
if (!this.ozwInstance) { if (!this.ozwInstance) {
navigate(this, "/config/ozw/dashboard", true); navigate("/config/ozw/dashboard", { replace: true });
} else if (this.hass) { } else if (this.hass) {
this._fetchData(); this._fetchData();
} }
@ -117,7 +117,7 @@ class OZWNetworkNodes extends LitElement {
private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) { private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) {
const nodeId = ev.detail.id; const nodeId = ev.detail.id;
navigate(this, `/config/ozw/network/${this.ozwInstance}/node/${nodeId}`); navigate(`/config/ozw/network/${this.ozwInstance}/node/${nodeId}`);
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -47,9 +47,11 @@ class OZWNodeConfig extends LitElement {
protected firstUpdated() { protected firstUpdated() {
if (!this.ozwInstance) { if (!this.ozwInstance) {
navigate(this, "/config/ozw/dashboard", true); navigate("/config/ozw/dashboard", { replace: true });
} else if (!this.nodeId) { } else if (!this.nodeId) {
navigate(this, `/config/ozw/network/${this.ozwInstance}/nodes`, true); navigate(`/config/ozw/network/${this.ozwInstance}/nodes`, {
replace: true,
});
} else { } else {
this._fetchData(); this._fetchData();
} }

View File

@ -43,9 +43,11 @@ class OZWNodeDashboard extends LitElement {
protected firstUpdated() { protected firstUpdated() {
if (!this.ozwInstance) { if (!this.ozwInstance) {
navigate(this, "/config/ozw/dashboard", true); navigate("/config/ozw/dashboard", { replace: true });
} else if (!this.nodeId) { } else if (!this.nodeId) {
navigate(this, `/config/ozw/network/${this.ozwInstance}/nodes`, true); navigate(`/config/ozw/network/${this.ozwInstance}/nodes`, {
replace: true,
});
} else if (this.hass) { } else if (this.hass) {
this._fetchData(); this._fetchData();
} }

View File

@ -68,11 +68,10 @@ class OZWNodeRouter extends HassRouterPage {
if (this._configEntry && !searchParams.has("config_entry")) { if (this._configEntry && !searchParams.has("config_entry")) {
searchParams.append("config_entry", this._configEntry); searchParams.append("config_entry", this._configEntry);
navigate( navigate(
this,
`${this.routeTail.prefix}${ `${this.routeTail.prefix}${
this.routeTail.path this.routeTail.path
}?${searchParams.toString()}`, }?${searchParams.toString()}`,
true { replace: true }
); );
} }
} }

View File

@ -138,7 +138,7 @@ export class ZHAAddGroupPage extends LitElement {
this._processingAdd = false; this._processingAdd = false;
this._groupName = ""; this._groupName = "";
this._zhaDevicesDataTable.clearSelection(); this._zhaDevicesDataTable.clearSelection();
navigate(this, `/config/zha/group/${group.group_id}`, true); navigate(`/config/zha/group/${group.group_id}`, { replace: true });
} }
private _handleNameChange(ev: PolymerChangedEvent<string>) { private _handleNameChange(ev: PolymerChangedEvent<string>) {

View File

@ -67,11 +67,10 @@ class ZHAConfigDashboardRouter extends HassRouterPage {
if (this._configEntry && !searchParams.has("config_entry")) { if (this._configEntry && !searchParams.has("config_entry")) {
searchParams.append("config_entry", this._configEntry); searchParams.append("config_entry", this._configEntry);
navigate( navigate(
this,
`${this.routeTail.prefix}${ `${this.routeTail.prefix}${
this.routeTail.path this.routeTail.path
}?${searchParams.toString()}`, }?${searchParams.toString()}`,
true { replace: true }
); );
} }
} }

View File

@ -273,7 +273,7 @@ export class ZHAGroupPage extends LitElement {
private async _deleteGroup(): Promise<void> { private async _deleteGroup(): Promise<void> {
await removeGroups(this.hass, [this.groupId]); await removeGroups(this.hass, [this.groupId]);
navigate(this, `/config/zha/groups`, true); navigate(`/config/zha/groups`, { replace: true });
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -140,7 +140,7 @@ export class ZHAGroupsDashboard extends LitElement {
private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) { private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) {
const groupId = ev.detail.id; const groupId = ev.detail.id;
navigate(this, `/config/zha/group/${groupId}`); navigate(`/config/zha/group/${groupId}`);
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -100,11 +100,7 @@ export class ZHANetworkVisualizationPage extends LitElement {
if (ieee) { if (ieee) {
const device = this._devices.get(ieee); const device = this._devices.get(ieee);
if (device) { if (device) {
navigate( navigate(`/config/devices/device/${device.device_reg_id}`);
this,
`/config/devices/device/${device.device_reg_id}`,
false
);
} }
} }
}); });

View File

@ -46,11 +46,10 @@ class ZWaveConfigRouter extends HassRouterPage {
if (this._configEntry && !searchParams.has("config_entry")) { if (this._configEntry && !searchParams.has("config_entry")) {
searchParams.append("config_entry", this._configEntry); searchParams.append("config_entry", this._configEntry);
navigate( navigate(
this,
`${this.routeTail.prefix}${ `${this.routeTail.prefix}${
this.routeTail.path this.routeTail.path
}?${searchParams.toString()}`, }?${searchParams.toString()}`,
true { replace: true }
); );
} }
} }

View File

@ -439,7 +439,7 @@ export class ZwaveMigration extends LitElement {
} }
private _navigateOzw() { private _navigateOzw() {
navigate(this, "/config/ozw"); navigate("/config/ozw");
} }
private _networkStopped(): void { private _networkStopped(): void {

View File

@ -64,11 +64,10 @@ class ZWaveJSConfigRouter extends HassRouterPage {
if (this._configEntry && !searchParams.has("config_entry")) { if (this._configEntry && !searchParams.has("config_entry")) {
searchParams.append("config_entry", this._configEntry); searchParams.append("config_entry", this._configEntry);
navigate( navigate(
this,
`${this.routeTail.prefix}${ `${this.routeTail.prefix}${
this.routeTail.path this.routeTail.path
}?${searchParams.toString()}`, }?${searchParams.toString()}`,
true { replace: true }
); );
} }
} }

View File

@ -239,8 +239,7 @@ export class HaConfigLovelaceDashboards extends LitElement {
private _navigate(ev: Event) { private _navigate(ev: Event) {
ev.stopPropagation(); ev.stopPropagation();
const url = `/${(ev.target as any).urlPath}`; navigate(`/${(ev.target as any).urlPath}`);
navigate(this, url);
} }
private _editDashboard(ev: CustomEvent) { private _editDashboard(ev: CustomEvent) {

View File

@ -749,7 +749,7 @@ export class HaSceneEditor extends SubscribeMixin(
// Wait for dialog to complete closing // Wait for dialog to complete closing
await new Promise((resolve) => setTimeout(resolve, 0)); await new Promise((resolve) => setTimeout(resolve, 0));
} }
showSceneEditor(this, { showSceneEditor({
...this._config, ...this._config,
id: undefined, id: undefined,
name: `${this._config?.name} (${this.hass.localize( name: `${this._config?.name} (${this.hass.localize(
@ -796,7 +796,7 @@ export class HaSceneEditor extends SubscribeMixin(
this._dirty = false; this._dirty = false;
if (!this.sceneId) { if (!this.sceneId) {
navigate(this, `/config/scene/edit/${id}`, true); navigate(`/config/scene/edit/${id}`, { replace: true });
} }
} catch (err) { } catch (err) {
this._errors = err.body.message || err.message; this._errors = err.body.message || err.message;

View File

@ -600,7 +600,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
// Wait for dialog to complate closing // Wait for dialog to complate closing
await new Promise((resolve) => setTimeout(resolve, 0)); await new Promise((resolve) => setTimeout(resolve, 0));
} }
showScriptEditor(this, { showScriptEditor({
...this._config, ...this._config,
alias: `${this._config?.alias} (${this.hass.localize( alias: `${this._config?.alias} (${this.hass.localize(
"ui.panel.config.script.picker.duplicate" "ui.panel.config.script.picker.duplicate"
@ -665,7 +665,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
this._dirty = false; this._dirty = false;
if (!this.scriptEntityId) { if (!this.scriptEntityId) {
navigate(this, `/config/script/edit/${id}`, true); navigate(`/config/script/edit/${id}`, { replace: true });
} }
}, },
(errors) => { (errors) => {

View File

@ -260,7 +260,7 @@ export class HaConfigTags extends SubscribeMixin(LitElement) {
), ),
trigger: [{ platform: "tag", tag_id: tag.id } as TagTrigger], trigger: [{ platform: "tag", tag_id: tag.id } as TagTrigger],
}; };
showAutomationEditor(this, data); showAutomationEditor(data);
} }
private _addTag() { private _addTag() {

View File

@ -269,7 +269,7 @@ export class HaConfigZone extends SubscribeMixin(LitElement) {
["storage", "default"].includes(this.hass.config.config_source); ["storage", "default"].includes(this.hass.config.config_source);
this._fetchData(); this._fetchData();
if (this.route.path === "/new") { if (this.route.path === "/new") {
navigate(this, "/config/zone", true); navigate("/config/zone", { replace: true });
this._createZone(); this._createZone();
} }
} }
@ -399,7 +399,7 @@ export class HaConfigZone extends SubscribeMixin(LitElement) {
) { ) {
return; return;
} }
navigate(this, "/config/core"); navigate("/config/core");
} }
private async _createEntry(values: ZoneMutableParams) { private async _createEntry(values: ZoneMutableParams) {

View File

@ -1,6 +1,6 @@
import { PropertyValues, ReactiveElement } from "lit"; import { PropertyValues, ReactiveElement } from "lit";
import { property } from "lit/decorators"; import { property } from "lit/decorators";
import { navigate } from "../../common/navigate"; import { navigate, NavigateOptions } from "../../common/navigate";
import { CustomPanelInfo } from "../../data/panel_custom"; import { CustomPanelInfo } from "../../data/panel_custom";
import { HomeAssistant, Route } from "../../types"; import { HomeAssistant, Route } from "../../types";
import { createCustomPanelElement } from "../../util/custom-panel/create-custom-panel-element"; import { createCustomPanelElement } from "../../util/custom-panel/create-custom-panel-element";
@ -34,8 +34,8 @@ export class HaPanelCustom extends ReactiveElement {
// Since navigate fires events on `window`, we need to expose this as a function // Since navigate fires events on `window`, we need to expose this as a function
// to allow custom panels to forward their location changes to the main window // to allow custom panels to forward their location changes to the main window
// instead of their iframe window. // instead of their iframe window.
public navigate = (path: string, replace?: boolean) => public navigate = (path: string, options?: NavigateOptions) =>
navigate(this, path, replace); navigate(path, options);
public registerIframe(initialize, setProperties) { public registerIframe(initialize, setProperties) {
initialize(this.panel, { initialize(this.panel, {

View File

@ -77,7 +77,7 @@ class PanelDeveloperTools extends LitElement {
private handlePageSelected(ev) { private handlePageSelected(ev) {
const newPage = ev.detail.item.getAttribute("page-name"); const newPage = ev.detail.item.getAttribute("page-name");
if (newPage !== this._page) { if (newPage !== this._page) {
navigate(this, `/developer-tools/${newPage}`); navigate(`/developer-tools/${newPage}`);
} else { } else {
scrollTo(0, 0); scrollTo(0, 0);
} }

View File

@ -101,7 +101,7 @@ export const handleAction = async (
} }
case "navigate": case "navigate":
if (actionConfig.navigation_path) { if (actionConfig.navigation_path) {
navigate(node, actionConfig.navigation_path); navigate(actionConfig.navigation_path);
} else { } else {
showToast(node, { showToast(node, {
message: hass.localize( message: hass.localize(

View File

@ -228,7 +228,7 @@ export class HuiDialogEditView extends LitElement {
deleteView(this._params.lovelace!.config, this._params.viewIndex!) deleteView(this._params.lovelace!.config, this._params.viewIndex!)
); );
this.closeDialog(); this.closeDialog();
navigate(this, `/${window.location.pathname.split("/")[1]}`); navigate(`/${window.location.pathname.split("/")[1]}`);
} catch (err) { } catch (err) {
showAlertDialog(this, { showAlertDialog(this, {
text: `Deleting failed: ${err.message}`, text: `Deleting failed: ${err.message}`,

View File

@ -680,21 +680,21 @@ class HUIRoot extends LitElement {
if (!shouldHandleRequestSelectedEvent(ev)) { if (!shouldHandleRequestSelectedEvent(ev)) {
return; return;
} }
navigate(this, "/config/lovelace/dashboards"); navigate("/config/lovelace/dashboards");
} }
private _handleManageResources(ev: CustomEvent<RequestSelectedDetail>): void { private _handleManageResources(ev: CustomEvent<RequestSelectedDetail>): void {
if (!shouldHandleRequestSelectedEvent(ev)) { if (!shouldHandleRequestSelectedEvent(ev)) {
return; return;
} }
navigate(this, "/config/lovelace/resources"); navigate("/config/lovelace/resources");
} }
private _handleUnusedEntities(ev: CustomEvent<RequestSelectedDetail>): void { private _handleUnusedEntities(ev: CustomEvent<RequestSelectedDetail>): void {
if (!shouldHandleRequestSelectedEvent(ev)) { if (!shouldHandleRequestSelectedEvent(ev)) {
return; return;
} }
navigate(this, `${this.route?.prefix}/hass-unused-entities`); navigate(`${this.route?.prefix}/hass-unused-entities`);
} }
private _showVoiceCommandDialog(): void { private _showVoiceCommandDialog(): void {
@ -724,14 +724,12 @@ class HUIRoot extends LitElement {
private _navigateToView(path: string | number, replace?: boolean) { private _navigateToView(path: string | number, replace?: boolean) {
if (!this.lovelace!.editMode) { if (!this.lovelace!.editMode) {
navigate(this, `${this.route!.prefix}/${path}`, replace); navigate(`${this.route!.prefix}/${path}`, { replace });
return; return;
} }
navigate( navigate(`${this.route!.prefix}/${path}?${addSearchParam({ edit: "1" })}`, {
this, replace,
`${this.route!.prefix}/${path}?${addSearchParam({ edit: "1" })}`, });
replace
);
} }
private _editView() { private _editView() {

View File

@ -94,7 +94,7 @@ class HaPanelMap extends LocalizeMixin(PolymerElement) {
} }
openZonesEditor() { openZonesEditor() {
navigate(this, "/config/zone"); navigate("/config/zone");
} }
fitMap() { fitMap() {

View File

@ -173,11 +173,9 @@ class HaPanelMy extends LitElement {
this._error = "no_supervisor"; this._error = "no_supervisor";
return; return;
} }
navigate( navigate(`/hassio/_my_redirect/${path}${window.location.search}`, {
this, replace: true,
`/hassio/_my_redirect/${path}${window.location.search}`, });
true
);
return; return;
} }
@ -204,7 +202,7 @@ class HaPanelMy extends LitElement {
return; return;
} }
navigate(this, url, true); navigate(url, { replace: true });
} }
protected render() { protected render() {