mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 03:36:44 +00:00
Remove ha-call-api-button (#16182)
This commit is contained in:
parent
3a1fff81b8
commit
0478aed28c
@ -44,10 +44,6 @@ export const hassioStyle = css`
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 0.25fr));
|
||||
}
|
||||
}
|
||||
ha-call-api-button {
|
||||
font-weight: 500;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
.error {
|
||||
color: var(--error-color);
|
||||
margin-top: 16px;
|
||||
|
@ -1,77 +0,0 @@
|
||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import "./ha-progress-button";
|
||||
|
||||
@customElement("ha-call-api-button")
|
||||
class HaCallApiButton extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property() public method: "POST" | "GET" | "PUT" | "DELETE" = "POST";
|
||||
|
||||
@property() public data = {};
|
||||
|
||||
@property({ type: Boolean, reflect: true }) public disabled = false;
|
||||
|
||||
@property({ type: Boolean }) public progress = false;
|
||||
|
||||
@property() public path?: string;
|
||||
|
||||
@query("ha-progress-button", true) private _progressButton;
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<ha-progress-button
|
||||
.progress=${this.progress}
|
||||
@click=${this._buttonTapped}
|
||||
?disabled=${this.disabled}
|
||||
><slot></slot
|
||||
></ha-progress-button>
|
||||
`;
|
||||
}
|
||||
|
||||
async _buttonTapped() {
|
||||
this.progress = true;
|
||||
const eventData: {
|
||||
method: string;
|
||||
path: string;
|
||||
data: any;
|
||||
success?: boolean;
|
||||
response?: any;
|
||||
} = {
|
||||
method: this.method,
|
||||
path: this.path!,
|
||||
data: this.data,
|
||||
};
|
||||
|
||||
try {
|
||||
const resp = await this.hass.callApi(this.method, this.path!, this.data);
|
||||
this.progress = false;
|
||||
this._progressButton.actionSuccess();
|
||||
eventData.success = true;
|
||||
eventData.response = resp;
|
||||
} catch (err: any) {
|
||||
this.progress = false;
|
||||
this._progressButton.actionError();
|
||||
eventData.success = false;
|
||||
eventData.response = err;
|
||||
}
|
||||
|
||||
fireEvent(this, "hass-api-called", eventData as any);
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
:host([disabled]) {
|
||||
pointer-events: none;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-call-api-button": HaCallApiButton;
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import { formatDateTime } from "../../../../common/datetime/format_date_time";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { computeRTLDirection } from "../../../../common/util/compute_rtl";
|
||||
import { debounce } from "../../../../common/util/debounce";
|
||||
import "../../../../components/buttons/ha-call-api-button";
|
||||
import "../../../../components/ha-alert";
|
||||
import "../../../../components/ha-card";
|
||||
import "../../../../components/ha-tip";
|
||||
|
Loading…
x
Reference in New Issue
Block a user