11import {
22 mdiCheckCircleOutline ,
3- mdiDelete ,
4- mdiPencil ,
5- mdiDotsHorizontal ,
63} from "@mdi/js" ;
74import { LitElement , html , nothing } from "lit" ;
85import { property , state , query } from "lit/decorators.js" ;
@@ -15,6 +12,7 @@ import { loadConfigDashboard } from "./helpers";
1512import { commonStyle } from './styles'
1613import { EntityRegistryEntry , IntegrationConfig , IntervalType , INTERVAL_TYPES , getIntervalTypeLabels , Label , Task , Tag } from './types' ;
1714import { completeTask , getConfig , loadLabelRegistry , loadRegistryEntries , loadTags , loadTask , loadTasks , removeTask , saveTask , updateTask } from './data/websockets' ;
15+ import './components/hm-task-menu'
1816
1917interface TaskFormData {
2018 title : string ;
@@ -60,10 +58,6 @@ export class HomeMaintenancePanel extends LitElement {
6058 tag : "" ,
6159 } ;
6260
63- // Shared overflow menu state
64- @state ( ) private _selectedTaskId : string | null = null ;
65- @query ( "#actions-menu" ) private _actionsMenu ?: any ;
66-
6761 private get _columns ( ) {
6862 return {
6963 icon : {
@@ -172,12 +166,22 @@ export class HomeMaintenancePanel extends LitElement {
172166 hideable : false ,
173167 type : "overflow-menu" ,
174168 template : ( task : Task ) => html `
175- < ha-icon-button
176- @click =${ ( e : Event ) => this . _handleShowMenu ( task . id , e ) }
177- .label ="Actions"
178- title="Actions"
179- .path=${ mdiDotsHorizontal }
180- > </ ha-icon-button >
169+ < hm-task-menu
170+ .hass =${ this . hass }
171+ .items =${ [
172+ {
173+ value : 'edit' ,
174+ label : localize ( 'panel.cards.current.actions.edit' , this . hass ! . language ) ,
175+ icon : 'mdi:pencil'
176+ } ,
177+ {
178+ value : 'delete' ,
179+ label : localize ( 'panel.cards.current.actions.remove' , this . hass ! . language ) ,
180+ icon : 'mdi:delete'
181+ }
182+ ] }
183+ @menu-action=${ ( e : CustomEvent ) => this . _handleMenuAction ( e , task . id ) }
184+ > </ hm-task-menu >
181185 ` ,
182186 } ,
183187 }
@@ -427,7 +431,6 @@ export class HomeMaintenancePanel extends LitElement {
427431 </ div >
428432
429433 ${ this . renderEditDialog ( ) }
430- ${ this . renderActionsMenu ( ) }
431434 ` ;
432435 }
433436
@@ -448,6 +451,7 @@ export class HomeMaintenancePanel extends LitElement {
448451 header ="${ localize ( 'panel.cards.new.sections.optional' , this . hass . language ) } "
449452 .opened =${ this . _advancedOpen }
450453 @opened-changed =${ ( e : CustomEvent ) => ( this . _advancedOpen = e . detail . value ) }
454+ class="extras-panel"
451455 >
452456 < ha-form
453457 .hass =${ this . hass }
@@ -460,9 +464,9 @@ export class HomeMaintenancePanel extends LitElement {
460464 </ ha-expansion-panel >
461465
462466 < div class ="form-field ">
463- < mwc -button @click = ${ this . _handleAddTaskClick } >
464- ${ localize ( 'panel.cards.new.actions.add_task' , this . hass . language ) }
465- </ mwc -button>
467+ < ha -button size =" small " class =" add-button "
468+ @click = ${ this . _handleAddTaskClick } > ${ localize ( 'panel.cards.new.actions.add_task' , this . hass . language ) }
469+ </ ha -button>
466470 </ div >
467471 ` ;
468472 }
@@ -500,9 +504,11 @@ export class HomeMaintenancePanel extends LitElement {
500504 < ha-dialog
501505 open
502506 heading ="${ localize ( 'panel.dialog.edit_task.title' , this . hass . language ) } : ${ this . _editFormData . title } "
507+ prevent-scrim-close
503508 @closed =${ this . _handleDialogClosed }
504509 >
505510 < ha-form
511+ autofocus
506512 .hass =${ this . hass }
507513 .schema =${ this . _editSchema }
508514 .computeLabel=${ this . _computeEditLabel . bind ( this ) }
@@ -511,45 +517,17 @@ export class HomeMaintenancePanel extends LitElement {
511517 @value-changed=${ ( e : CustomEvent ) => this . _handleEditFormValueChanged ( e ) }
512518 > </ ha-form >
513519
514- < mwc-button slot ="secondaryAction " @click =${ ( ) => ( this . _editingTaskId = null ) } >
515- ${ localize ( 'panel.dialog.edit_task.actions.cancel' , this . hass . language ) }
516- </ mwc-button >
517- < mwc-button slot ="primaryAction " @click =${ this . _handleSaveEditClick } >
518- ${ localize ( 'panel.dialog.edit_task.actions.save' , this . hass . language ) }
519- </ mwc-button >
520+ < ha-dialog-footer slot ="footer ">
521+ < ha-button data-dialog ="close " appearance ="plain " slot ="secondaryAction ">
522+ ${ localize ( 'panel.dialog.edit_task.actions.cancel' , this . hass . language ) }
523+ </ ha-button >
524+ < ha-button slot ="primaryAction " @click =${ this . _handleSaveEditClick } >
525+ ${ localize ( 'panel.dialog.edit_task.actions.save' , this . hass . language ) }
526+ </ ha-button >
520527 </ ha-dialog >
521528 ` ;
522529 }
523530
524- renderActionsMenu ( ) {
525- if ( ! this . hass ) return html `` ;
526-
527- return html `
528- < ha-md-menu id ="actions-menu " positioning ="fixed ">
529- < ha-md-menu-item
530- @click =${ ( ) => {
531- if ( this . _selectedTaskId ) {
532- this . _handleOpenEditDialogClick ( this . _selectedTaskId ) ;
533- }
534- } }
535- >
536- < ha-svg-icon slot ="start " path =${ mdiPencil } > </ ha-svg-icon >
537- ${ localize ( 'panel.cards.current.actions.edit' , this . hass ! . language ) }
538- </ ha-md-menu-item >
539- < ha-md-menu-item
540- @click =${ ( ) => {
541- if ( this . _selectedTaskId ) {
542- this . _handleRemoveTaskClick ( this . _selectedTaskId ) ;
543- }
544- } }
545- >
546- < ha-svg-icon slot ="start " path =${ mdiDelete } > </ ha-svg-icon >
547- ${ localize ( 'panel.cards.current.actions.remove' , this . hass ! . language ) }
548- </ ha-md-menu-item >
549- </ ha-md-menu >
550- ` ;
551- }
552-
553531 private async _handleAddTaskClick ( ) {
554532 const { title, interval_value, interval_type, last_performed, tag, icon, label } = this . _formData ;
555533
@@ -661,9 +639,18 @@ export class HomeMaintenancePanel extends LitElement {
661639 }
662640
663641 private _handleDialogClosed ( e : CustomEvent ) {
664- const action = e . detail ?. action ;
665- if ( action === "close" || action === "cancel" ) {
666- this . _editingTaskId = null ;
642+ this . _editingTaskId = null ;
643+ }
644+
645+ private _handleMenuAction ( e : CustomEvent , taskId : string ) {
646+ const action = e . detail . action ;
647+ switch ( action ) {
648+ case 'edit' :
649+ this . _handleOpenEditDialogClick ( taskId ) ;
650+ break ;
651+ case 'delete' :
652+ this . _handleRemoveTaskClick ( taskId ) ;
653+ break ;
667654 }
668655 }
669656
@@ -675,18 +662,7 @@ export class HomeMaintenancePanel extends LitElement {
675662 this . _editFormData = { ...this . _editFormData , ...ev . detail . value } ;
676663 }
677664
678- private _handleShowMenu ( taskId : string , ev : Event ) {
679- this . _selectedTaskId = taskId ;
680-
681- if ( ! this . _actionsMenu ) {
682- return ;
683- }
684-
685- this . _actionsMenu . anchorElement = ev . currentTarget as HTMLElement ;
686- this . _actionsMenu . show ( ) ;
687-
688- ev . stopPropagation ( ) ;
689- } static styles = commonStyle ;
665+ static styles = commonStyle ;
690666}
691667
692668customElements . define ( "home-maintenance-panel" , HomeMaintenancePanel ) ;
0 commit comments