Allow Markdown and description placeholder usage in data field descriptions (#13377)

Co-authored-by: Zack Barett <zackbarett@hey.com>
This commit is contained in:
Franck Nijhof 2022-08-13 20:57:28 +02:00 committed by GitHub
parent 38607a6410
commit 651cafc464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 10 deletions

View File

@ -89,9 +89,13 @@ export const showConfigFlowDialog = (
},
renderShowFormStepFieldHelper(hass, step, field) {
return hass.localize(
`component.${step.handler}.config.step.${step.step_id}.data_description.${field.name}`
const description = hass.localize(
`component.${step.handler}.config.step.${step.step_id}.data_description.${field.name}`,
step.description_placeholders
);
return description
? html`<ha-markdown breaks .content=${description}></ha-markdown>`
: "";
},
renderShowFormStepFieldError(hass, step, error) {

View File

@ -61,7 +61,7 @@ export interface FlowConfig {
hass: HomeAssistant,
step: DataEntryFlowStepForm,
field: HaFormSchema
): string;
): TemplateResult | string;
renderShowFormStepFieldError(
hass: HomeAssistant,

View File

@ -93,9 +93,13 @@ export const showOptionsFlowDialog = (
},
renderShowFormStepFieldHelper(hass, step, field) {
return hass.localize(
`component.${configEntry.domain}.options.step.${step.step_id}.data_description.${field.name}`
const description = hass.localize(
`component.${configEntry.domain}.options.step.${step.step_id}.data_description.${field.name}`,
step.description_placeholders
);
return description
? html`<ha-markdown breaks .content=${description}></ha-markdown>`
: "";
},
renderShowFormStepFieldError(hass, step, error) {

View File

@ -10,12 +10,12 @@ import {
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event";
import "../../components/ha-alert";
import "../../components/ha-circular-progress";
import { computeInitialHaFormData } from "../../components/ha-form/compute-initial-ha-form-data";
import type { HaFormSchema } from "../../components/ha-form/types";
import "../../components/ha-form/ha-form";
import type { HaFormSchema } from "../../components/ha-form/types";
import "../../components/ha-markdown";
import "../../components/ha-alert";
import type { DataEntryFlowStepForm } from "../../data/data_entry_flow";
import type { HomeAssistant } from "../../types";
import type { FlowConfig } from "./show-dialog-data-entry-flow";
@ -167,7 +167,7 @@ class StepFlowForm extends LitElement {
private _labelCallback = (field: HaFormSchema): string =>
this.flowConfig.renderShowFormStepFieldLabel(this.hass, this.step, field);
private _helperCallback = (field: HaFormSchema): string =>
private _helperCallback = (field: HaFormSchema): string | TemplateResult =>
this.flowConfig.renderShowFormStepFieldHelper(this.hass, this.step, field);
private _errorCallback = (error: string) =>

View File

@ -100,11 +100,15 @@ export const showRepairsFlowDialog = (
},
renderShowFormStepFieldHelper(hass, step, field) {
return hass.localize(
const description = hass.localize(
`component.${issue.domain}.issues.${
issue.translation_key || issue.issue_id
}.fix_flow.step.${step.step_id}.data_description.${field.name}`
}.fix_flow.step.${step.step_id}.data_description.${field.name}`,
step.description_placeholders
);
return description
? html`<ha-markdown breaks .content=${description}></ha-markdown>`
: "";
},
renderShowFormStepFieldError(hass, step, error) {