Delete To-do items in a batched single request (#18662)

This commit is contained in:
Allen Porter 2023-11-16 00:52:03 -08:00 committed by GitHub
parent a909c6d905
commit 244868348b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -82,16 +82,16 @@ export const createItem = (
{ entity_id } { entity_id }
); );
export const deleteItem = ( export const deleteItems = (
hass: HomeAssistant, hass: HomeAssistant,
entity_id: string, entity_id: string,
uid: string uids: string[]
): Promise<ServiceCallResponse> => ): Promise<ServiceCallResponse> =>
hass.callService( hass.callService(
"todo", "todo",
"remove_item", "remove_item",
{ {
item: uid, item: uids,
}, },
{ entity_id } { entity_id }
); );

View File

@ -35,7 +35,7 @@ import {
TodoItemStatus, TodoItemStatus,
TodoListEntityFeature, TodoListEntityFeature,
createItem, createItem,
deleteItem, deleteItems,
fetchItems, fetchItems,
moveItem, moveItem,
updateItem, updateItem,
@ -433,7 +433,7 @@ export class HuiTodoListCard
} else if ( } else if (
this.todoListSupportsFeature(TodoListEntityFeature.DELETE_TODO_ITEM) this.todoListSupportsFeature(TodoListEntityFeature.DELETE_TODO_ITEM)
) { ) {
deleteItem(this.hass!, this._entityId!, ev.target.itemId).finally(() => deleteItems(this.hass!, this._entityId!, [ev.target.itemId]).finally(() =>
this._fetchData() this._fetchData()
); );
} }
@ -445,11 +445,11 @@ export class HuiTodoListCard
if (!this.hass) { if (!this.hass) {
return; return;
} }
const deleteActions: Array<Promise<any>> = []; const checkedItems = this._getCheckedItems(this._items);
this._getCheckedItems(this._items).forEach((item: TodoItem) => { const uids = checkedItems.map((item: TodoItem) => item.uid);
deleteActions.push(deleteItem(this.hass!, this._entityId!, item.uid)); deleteItems(this.hass!, this._entityId!, uids).finally(() =>
}); this._fetchData()
await Promise.all(deleteActions).finally(() => this._fetchData()); );
} }
private get _newItem(): HaTextField { private get _newItem(): HaTextField {
@ -475,7 +475,7 @@ export class HuiTodoListCard
if (!item) { if (!item) {
return; return;
} }
deleteItem(this.hass!, this._entityId!, item.uid).finally(() => deleteItems(this.hass!, this._entityId!, [item.uid]).finally(() =>
this._fetchData() this._fetchData()
); );
} }