Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/src/ha-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class HaDemo extends HomeAssistantAppEl {
}

e.preventDefault();
navigate(this, href);
navigate(href);
},
{ capture: true }
);
Expand Down
2 changes: 1 addition & 1 deletion hassio/src/addon-store/hassio-addon-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class HassioAddonRepositoryEl extends LitElement {
}

private _addonTapped(ev) {
navigate(this, `/hassio/addon/${ev.currentTarget.addon.slug}`);
navigate(`/hassio/addon/${ev.currentTarget.addon.slug}`);
}

static get styles(): CSSResultGroup {
Expand Down
2 changes: 1 addition & 1 deletion hassio/src/addon-store/hassio-addon-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class HassioAddonStore extends LitElement {
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
const repositoryUrl = extractSearchParam("repository_url");
navigate(this, "/hassio/store", true);
navigate("/hassio/store", { replace: true });
if (repositoryUrl) {
this._manageRepositories(repositoryUrl);
}
Expand Down
2 changes: 1 addition & 1 deletion hassio/src/addon-view/hassio-addon-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class HassioAddonDashboard extends LitElement {
if (!validAddon) {
this._error = this.supervisor.localize("my.error_addon_not_found");
} else {
navigate(this, `/hassio/addon/${requestedAddon}`, true);
navigate(`/hassio/addon/${requestedAddon}`, { replace: true });
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions hassio/src/addon-view/info/hassio-addon-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ class HassioAddonInfo extends LitElement {
}

private _openIngress(): void {
navigate(this, `/hassio/ingress/${this.addon.slug}`);
navigate(`/hassio/ingress/${this.addon.slug}`);
}

private get _computeShowIngressUI(): boolean {
Expand Down Expand Up @@ -1051,7 +1051,7 @@ class HassioAddonInfo extends LitElement {
}

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> {
Expand Down
4 changes: 2 additions & 2 deletions hassio/src/dashboard/hassio-addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ class HassioAddons extends LitElement {
}

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 {
navigate(this, "/hassio/store");
navigate("/hassio/store");
}
}

Expand Down
2 changes: 1 addition & 1 deletion hassio/src/hassio-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class HassioMain extends SupervisorBaseElement {
document.body.addEventListener("click", (ev) => {
const href = isNavigationClick(ev);
if (href) {
navigate(document.body, href);
navigate(href);
}
});

Expand Down
2 changes: 1 addition & 1 deletion hassio/src/hassio-my-redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class HassioMyRedirect extends LitElement {
return;
}

navigate(this, url, true);
navigate(url, { replace: true });
}

protected render(): TemplateResult {
Expand Down
4 changes: 2 additions & 2 deletions hassio/src/ingress-view/hassio-ingress-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class HassioIngressView extends LitElement {
});
history.back();
} else {
navigate(this, `/hassio/ingress/${addonInfo.slug}`, true);
navigate(`/hassio/ingress/${addonInfo.slug}`, { replace: true });
}
}
}
Expand Down Expand Up @@ -157,8 +157,8 @@ class HassioIngressView extends LitElement {
await showAlertDialog(this, {
text: "Add-on is not running. Please start it first",
title: addon.name,
confirm: () => navigate(`/hassio/addon/${addon.slug}`),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No replace anymore?

});
navigate(this, `/hassio/addon/${addon.slug}/info`, true);
return;
}

Expand Down
16 changes: 9 additions & 7 deletions src/common/navigate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { fireEvent } from "./dom/fire_event";
declare global {
// for fire event
interface HASSDomEvents {
"location-changed": {
replace: boolean;
};
"location-changed": NavigateOptions;
}
}

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 (replace) {
top.history.replaceState(
Expand All @@ -29,7 +33,5 @@ export const navigate = (_node: any, path: string, replace = false) => {
} else {
top.history.pushState(null, "", path);
}
fireEvent(top, "location-changed", {
replace,
});
fireEvent(top, "location-changed", options);
};
7 changes: 2 additions & 5 deletions src/data/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,9 @@ let inititialAutomationEditorData: Partial<AutomationConfig> | undefined;
export const getAutomationConfig = (hass: HomeAssistant, id: string) =>
hass.callApi<AutomationConfig>("GET", `config/automation/config/${id}`);

export const showAutomationEditor = (
el: HTMLElement,
data?: Partial<AutomationConfig>
) => {
export const showAutomationEditor = (data?: Partial<AutomationConfig>) => {
inititialAutomationEditorData = data;
navigate(el, "/config/automation/edit/new");
navigate("/config/automation/edit/new");
};

export const getAutomationEditorInitData = () => {
Expand Down
7 changes: 2 additions & 5 deletions src/data/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ export const SCENE_IGNORED_DOMAINS = [

let inititialSceneEditorData: Partial<SceneConfig> | undefined;

export const showSceneEditor = (
el: HTMLElement,
data?: Partial<SceneConfig>
) => {
export const showSceneEditor = (data?: Partial<SceneConfig>) => {
inititialSceneEditorData = data;
navigate(el, "/config/scene/edit/new");
navigate("/config/scene/edit/new");
};

export const getSceneEditorInitData = () => {
Expand Down
7 changes: 2 additions & 5 deletions src/data/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,9 @@ export const deleteScript = (hass: HomeAssistant, objectId: string) =>

let inititialScriptEditorData: Partial<ScriptConfig> | undefined;

export const showScriptEditor = (
el: HTMLElement,
data?: Partial<ScriptConfig>
) => {
export const showScriptEditor = (data?: Partial<ScriptConfig>) => {
inititialScriptEditorData = data;
navigate(el, "/config/script/edit/new");
navigate("/config/script/edit/new");
};

export const getScriptEditorInitData = () => {
Expand Down
7 changes: 2 additions & 5 deletions src/data/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ export const deleteZone = (hass: HomeAssistant, zoneId: string) =>

let inititialZoneEditorData: Partial<ZoneMutableParams> | undefined;

export const showZoneEditor = (
el: HTMLElement,
data?: Partial<ZoneMutableParams>
) => {
export const showZoneEditor = (data?: Partial<ZoneMutableParams>) => {
inititialZoneEditorData = data;
navigate(el, "/config/zone/new");
navigate("/config/zone/new");
};

export const getZoneEditorInitData = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/more-info/controls/more-info-person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MoreInfoPerson extends LitElement {
}

private _handleAction() {
showZoneEditor(this, {
showZoneEditor({
latitude: this.stateObj!.attributes.latitude,
longitude: this.stateObj!.attributes.longitude,
});
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/more-info/ha-more-info-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export class MoreInfoDialog extends LitElement {
idToPassThroughUrl = stateObj.attributes.id;
}

navigate(this, `/config/${domain}/edit/${idToPassThroughUrl}`);
navigate(`/config/${domain}/edit/${idToPassThroughUrl}`);
this.closeDialog();
}

Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/quick-bar/ha-quick-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ export class QuickBar extends LitElement {
categoryText: this.hass.localize(
`ui.dialogs.quick-bar.commands.types.${categoryKey}`
),
action: () => navigate(this, item.path),
action: () => navigate(item.path),
};

return {
Expand Down
4 changes: 2 additions & 2 deletions src/entrypoints/custom-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function initialize(
if (window.parent.customPanel) {
window.parent.customPanel.navigate(
window.location.pathname,
ev.detail ? ev.detail.replace : false
ev.detail
);
}
});
Expand Down Expand Up @@ -116,7 +116,7 @@ function initialize(
document.body.addEventListener("click", (ev) => {
const href = isNavigationClick(ev);
if (href) {
navigate(document.body, href);
navigate(href);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/hass-router-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class HassRouterPage extends ReactiveElement {
const defaultPage = routerOptions.defaultPage;

if (route && route.path === "" && defaultPage !== undefined) {
navigate(this, `${route.prefix}/${defaultPage}`, true);
navigate(`${route.prefix}/${defaultPage}`, { replace: true });
}

let newPage = route
Expand Down Expand Up @@ -127,7 +127,7 @@ export class HassRouterPage extends ReactiveElement {

// Update the url if we know where we're mounted.
if (route) {
navigate(this, `${route.prefix}/${result}`, true);
navigate(`${route.prefix}/${result}`, { replace: true });
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/home-assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
window.addEventListener("click", (ev) => {
const href = isNavigationClick(ev);
if (href) {
navigate(this, href);
navigate(href);
}
});

// Handle first navigation
if (["", "/"].includes(curPath())) {
navigate(this, `/${getStorageDefaultPanelUrlPath()}`, true);
navigate(`/${getStorageDefaultPanelUrlPath()}`, { replace: true });
} else {
updateRoute();
}
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/navigate-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default dedupingMixin(
(superClass) =>
class extends superClass {
navigate(...args) {
navigate(this, ...args);
navigate(...args);
}
}
);
2 changes: 1 addition & 1 deletion src/onboarding/onboarding-restore-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class OnboardingRestoreSnapshot extends ProvideHassLitMixin(LitElement) {
});
if (response.status === 401) {
// If we get a unauthorized response, the restore is done
navigate(this, "/", true);
navigate("/", { replace: true });
location.reload();
}
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/areas/dialog-area-registry-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class DialogAreaDetail extends LitElement {
this._submitting = false;
}

navigate(this, "/config/areas/dashboard");
navigate("/config/areas/dashboard");
}

static get styles(): CSSResultGroup {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/areas/ha-config-areas-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class HaConfigAreasDashboard extends LitElement {

private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) {
const areaId = ev.detail.id;
navigate(this, `/config/areas/area/${areaId}`);
navigate(`/config/areas/area/${areaId}`);
}

private _openDialog(entry?: AreaRegistryEntry) {
Expand Down
6 changes: 3 additions & 3 deletions src/panels/config/automation/dialog-new-automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class DialogNewAutomation extends LitElement implements HassDialog {
replaceDialog();
showThingtalkDialog(this, {
callback: (config: Partial<AutomationConfig> | undefined) =>
showAutomationEditor(this, config),
showAutomationEditor(config),
input: this.shadowRoot!.querySelector("paper-input")!.value as string,
});
this.closeDialog();
Expand All @@ -117,13 +117,13 @@ class DialogNewAutomation extends LitElement implements HassDialog {
private async _blueprintPicked(ev: CustomEvent) {
this.closeDialog();
await nextRender();
showAutomationEditor(this, { use_blueprint: { path: ev.detail.value } });
showAutomationEditor({ use_blueprint: { path: ev.detail.value } });
}

private async _blank() {
this.closeDialog();
await nextRender();
showAutomationEditor(this);
showAutomationEditor();
}

static get styles(): CSSResultGroup {
Expand Down
4 changes: 2 additions & 2 deletions src/panels/config/automation/ha-automation-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
// Wait for dialog to complate closing
await new Promise((resolve) => setTimeout(resolve, 0));
}
showAutomationEditor(this, {
showAutomationEditor({
...this._config,
id: undefined,
alias: `${this._config?.alias} (${this.hass.localize(
Expand Down Expand Up @@ -503,7 +503,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
this._dirty = false;

if (!this.automationId) {
navigate(this, `/config/automation/edit/${id}`, true);
navigate(`/config/automation/edit/${id}`, { replace: true });
}
},
(errors) => {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/automation/ha-automation-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class HaAutomationPicker extends LitElement {
) {
showNewAutomationDialog(this);
} else {
navigate(this, "/config/automation/edit/new");
navigate("/config/automation/edit/new");
}
}

Expand Down
11 changes: 4 additions & 7 deletions src/panels/config/blueprint/ha-blueprint-overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ interface BlueprintMetaDataPath extends BlueprintMetaData {
}

const createNewFunctions = {
automation: (
context: HaBlueprintOverview,
blueprintMeta: BlueprintMetaDataPath
) => {
showAutomationEditor(context, {
automation: (blueprintMeta: BlueprintMetaDataPath) => {
showAutomationEditor({
alias: blueprintMeta.name,
use_blueprint: { path: blueprintMeta.path },
});
Expand Down Expand Up @@ -183,7 +180,7 @@ class HaBlueprintOverview extends LitElement {
super.firstUpdated(changedProps);
if (this.route.path === "/import") {
const url = extractSearchParam("blueprint_url");
navigate(this, "/config/blueprint/dashboard", true);
navigate("/config/blueprint/dashboard", { replace: true });
if (url) {
this._addBlueprint(url);
}
Expand Down Expand Up @@ -280,7 +277,7 @@ class HaBlueprintOverview extends LitElement {

private _createNew(ev) {
const blueprint = ev.currentTarget.blueprint as BlueprintMetaDataPath;
createNewFunctions[blueprint.domain](this, blueprint);
createNewFunctions[blueprint.domain](blueprint);
}

private _share(ev) {
Expand Down
Loading