mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Allow attaching additional data to schedule in UI (#22798)
* Allow attaching additional data to schedule in UI * use expandable
This commit is contained in:
parent
991cf83ff3
commit
d47966cdf7
@ -1,5 +1,6 @@
|
|||||||
import type { CSSResultGroup } from "lit";
|
import type { CSSResultGroup } from "lit";
|
||||||
import { html, LitElement, nothing } from "lit";
|
import { html, LitElement, nothing } from "lit";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
import { property, state } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { createCloseHeading } from "../../../../components/ha-dialog";
|
import { createCloseHeading } from "../../../../components/ha-dialog";
|
||||||
@ -13,19 +14,6 @@ import type {
|
|||||||
} from "./show-dialog-schedule-block-info";
|
} from "./show-dialog-schedule-block-info";
|
||||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||||
|
|
||||||
const SCHEMA = [
|
|
||||||
{
|
|
||||||
name: "from",
|
|
||||||
required: true,
|
|
||||||
selector: { time: { no_second: true } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "to",
|
|
||||||
required: true,
|
|
||||||
selector: { time: { no_second: true } },
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
class DialogScheduleBlockInfo extends LitElement {
|
class DialogScheduleBlockInfo extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@ -35,10 +23,39 @@ class DialogScheduleBlockInfo extends LitElement {
|
|||||||
|
|
||||||
@state() private _params?: ScheduleBlockInfoDialogParams;
|
@state() private _params?: ScheduleBlockInfoDialogParams;
|
||||||
|
|
||||||
|
private _expand = false;
|
||||||
|
|
||||||
|
private _schema = memoizeOne((expand: boolean) => [
|
||||||
|
{
|
||||||
|
name: "from",
|
||||||
|
required: true,
|
||||||
|
selector: { time: { no_second: true } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "to",
|
||||||
|
required: true,
|
||||||
|
selector: { time: { no_second: true } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "advanced_settings",
|
||||||
|
type: "expandable" as const,
|
||||||
|
flatten: true,
|
||||||
|
expanded: expand,
|
||||||
|
schema: [
|
||||||
|
{
|
||||||
|
name: "data",
|
||||||
|
required: false,
|
||||||
|
selector: { object: {} },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
public showDialog(params: ScheduleBlockInfoDialogParams): void {
|
public showDialog(params: ScheduleBlockInfoDialogParams): void {
|
||||||
this._params = params;
|
this._params = params;
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
this._data = params.block;
|
this._data = params.block;
|
||||||
|
this._expand = !!params.block?.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
@ -66,7 +83,7 @@ class DialogScheduleBlockInfo extends LitElement {
|
|||||||
<div>
|
<div>
|
||||||
<ha-form
|
<ha-form
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.schema=${SCHEMA}
|
.schema=${this._schema(this._expand)}
|
||||||
.data=${this._data}
|
.data=${this._data}
|
||||||
.error=${this._error}
|
.error=${this._error}
|
||||||
.computeLabel=${this._computeLabelCallback}
|
.computeLabel=${this._computeLabelCallback}
|
||||||
@ -110,12 +127,20 @@ class DialogScheduleBlockInfo extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
|
private _computeLabelCallback = (
|
||||||
|
schema: SchemaUnion<ReturnType<typeof this._schema>>
|
||||||
|
) => {
|
||||||
switch (schema.name) {
|
switch (schema.name) {
|
||||||
case "from":
|
case "from":
|
||||||
return this.hass!.localize("ui.dialogs.helper_settings.schedule.start");
|
return this.hass!.localize("ui.dialogs.helper_settings.schedule.start");
|
||||||
case "to":
|
case "to":
|
||||||
return this.hass!.localize("ui.dialogs.helper_settings.schedule.end");
|
return this.hass!.localize("ui.dialogs.helper_settings.schedule.end");
|
||||||
|
case "data":
|
||||||
|
return this.hass!.localize("ui.dialogs.helper_settings.schedule.data");
|
||||||
|
case "advanced_settings":
|
||||||
|
return this.hass!.localize(
|
||||||
|
"ui.dialogs.helper_settings.schedule.advanced_settings"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,7 @@ import { fireEvent } from "../../../../common/dom/fire_event";
|
|||||||
export interface ScheduleBlockInfo {
|
export interface ScheduleBlockInfo {
|
||||||
from: string;
|
from: string;
|
||||||
to: string;
|
to: string;
|
||||||
|
data?: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScheduleBlockInfoDialogParams {
|
export interface ScheduleBlockInfoDialogParams {
|
||||||
|
@ -1612,7 +1612,9 @@
|
|||||||
"confirm_delete": "Do you want to delete this item?",
|
"confirm_delete": "Do you want to delete this item?",
|
||||||
"edit_schedule_block": "Edit schedule block",
|
"edit_schedule_block": "Edit schedule block",
|
||||||
"start": "Start",
|
"start": "Start",
|
||||||
"end": "End"
|
"end": "End",
|
||||||
|
"data": "Additional data",
|
||||||
|
"advanced_settings": "Advanced settings"
|
||||||
},
|
},
|
||||||
"template": {
|
"template": {
|
||||||
"time": "[%key:ui::panel::developer-tools::tabs::templates::time%]",
|
"time": "[%key:ui::panel::developer-tools::tabs::templates::time%]",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user