1
- import type { UmbWorkspaceAction } from '../workspace-action.interface.js' ;
2
1
import type {
3
2
ManifestWorkspaceAction ,
4
3
ManifestWorkspaceActionMenuItem ,
5
4
MetaWorkspaceActionDefaultKind ,
5
+ UmbWorkspaceActionDefaultKind ,
6
6
} from '../../../types.js' ;
7
7
import { UmbActionExecutedEvent } from '@umbraco-cms/backoffice/event' ;
8
- import { html , customElement , property , state , ifDefined , when } from '@umbraco-cms/backoffice/external/lit' ;
8
+ import { html , customElement , property , state , when } from '@umbraco-cms/backoffice/external/lit' ;
9
9
import type { UUIButtonState } from '@umbraco-cms/backoffice/external/uui' ;
10
10
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
11
11
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry' ;
@@ -19,7 +19,7 @@ import '../../workspace-action-menu/index.js';
19
19
@customElement ( 'umb-workspace-action' )
20
20
export class UmbWorkspaceActionElement <
21
21
MetaType extends MetaWorkspaceActionDefaultKind = MetaWorkspaceActionDefaultKind ,
22
- ApiType extends UmbWorkspaceAction < MetaType > = UmbWorkspaceAction < MetaType > ,
22
+ ApiType extends UmbWorkspaceActionDefaultKind < MetaType > = UmbWorkspaceActionDefaultKind < MetaType > ,
23
23
> extends UmbLitElement {
24
24
#manifest?: ManifestWorkspaceAction < MetaType > ;
25
25
#api?: ApiType ;
@@ -29,21 +29,14 @@ export class UmbWorkspaceActionElement<
29
29
ManifestWorkspaceActionMenuItem
30
30
> ;
31
31
32
- @state ( )
33
- private _buttonState ?: UUIButtonState ;
34
-
35
- @state ( )
36
- _href ?: string ;
37
-
38
- @state ( )
39
- _isDisabled = false ;
40
-
41
32
@property ( { type : Object , attribute : false } )
42
33
public set manifest ( value : ManifestWorkspaceAction < MetaType > | undefined ) {
43
34
if ( ! value ) return ;
44
35
const oldValue = this . #manifest;
45
- this . #manifest = value ;
46
- if ( oldValue !== this . #manifest) {
36
+ if ( oldValue !== value ) {
37
+ this . #manifest = value ;
38
+ this . _href = value ?. meta . href ;
39
+ this . _additionalOptions = value ?. meta . additionalOptions ;
47
40
this . #createAliases( ) ;
48
41
this . requestUpdate ( 'manifest' , oldValue ) ;
49
42
}
@@ -56,10 +49,12 @@ export class UmbWorkspaceActionElement<
56
49
public set api ( api : ApiType | undefined ) {
57
50
this . #api = api ;
58
51
59
- // TODO: Fix so when we use a HREF it does not refresh the page?
60
52
this . #api?. getHref ?.( ) . then ( ( href ) => {
61
- this . _href = href ;
62
- // TODO: Do we need to update the component here? [NL]
53
+ this . _href = href ?? this . manifest ?. meta . href ;
54
+ } ) ;
55
+
56
+ this . #api?. hasAdditionalOptions ?.( ) . then ( ( additionalOptions ) => {
57
+ this . _additionalOptions = additionalOptions ?? this . manifest ?. meta . additionalOptions ;
63
58
} ) ;
64
59
65
60
this . #observeIsDisabled( ) ;
@@ -68,6 +63,18 @@ export class UmbWorkspaceActionElement<
68
63
return this . #api;
69
64
}
70
65
66
+ @state ( )
67
+ private _buttonState ?: UUIButtonState ;
68
+
69
+ @state ( )
70
+ private _additionalOptions ?: boolean ;
71
+
72
+ @state ( )
73
+ private _href ?: string ;
74
+
75
+ @state ( )
76
+ _isDisabled = false ;
77
+
71
78
@state ( )
72
79
private _items : Array < UmbExtensionElementAndApiInitializer < ManifestWorkspaceActionMenuItem > > = [ ] ;
73
80
@@ -92,21 +99,28 @@ export class UmbWorkspaceActionElement<
92
99
this . #observeExtensions( Array . from ( aliases ) ) ;
93
100
}
94
101
95
- private async _onClick ( event : MouseEvent ) {
102
+ async #onClick ( event : MouseEvent ) {
96
103
if ( this . _href ) {
97
104
event . stopPropagation ( ) ;
98
105
}
106
+ // If its a link or has additional options, then we do not want to display state on the button. [NL]
107
+ if ( ! this . _href ) {
108
+ if ( ! this . _additionalOptions ) {
109
+ this . _buttonState = 'waiting' ;
110
+ }
99
111
100
- this . _buttonState = 'waiting' ;
101
-
102
- try {
103
- if ( ! this . #api) throw new Error ( 'No api defined' ) ;
104
- await this . #api. execute ( ) ;
105
- this . _buttonState = 'success' ;
106
- } catch {
107
- this . _buttonState = 'failed' ;
112
+ try {
113
+ if ( ! this . #api) throw new Error ( 'No api defined' ) ;
114
+ await this . #api. execute ( ) ;
115
+ if ( ! this . _additionalOptions ) {
116
+ this . _buttonState = 'success' ;
117
+ }
118
+ } catch {
119
+ if ( ! this . _additionalOptions ) {
120
+ this . _buttonState = 'failed' ;
121
+ }
122
+ }
108
123
}
109
-
110
124
this . dispatchEvent ( new UmbActionExecutedEvent ( ) ) ;
111
125
}
112
126
@@ -144,27 +158,28 @@ export class UmbWorkspaceActionElement<
144
158
}
145
159
146
160
#renderButton( ) {
161
+ const label = this . #manifest?. meta . label
162
+ ? this . localize . string ( this . #manifest. meta . label )
163
+ : ( this . #manifest?. name ?? '' ) ;
147
164
return html `
148
165
< uui-button
149
- id =" action-button "
166
+ data-mark =" workspace-action: ${ this . #manifest ?. alias } "
150
167
.href =${ this . _href }
151
- @click =${ this . _onClick }
152
- look=${ this . #manifest?. meta . look || 'default' }
153
- color=${ this . #manifest?. meta . color || 'default' }
154
- label=${ ifDefined (
155
- this . #manifest?. meta . label ? this . localize . string ( this . #manifest. meta . label ) : this . #manifest?. name ,
156
- ) }
168
+ look =${ this . #manifest?. meta . look ?? 'default' }
169
+ color=${ this . #manifest?. meta . color ?? 'default' }
170
+ label=${ this . _additionalOptions ? label + '…' : label }
157
171
.disabled=${ this . _isDisabled }
158
- .state=${ this . _buttonState } > </ uui-button >
172
+ .state=${ this . _buttonState }
173
+ @click=${ this . #onClick} > </ uui-button >
159
174
` ;
160
175
}
161
176
162
177
#renderActionMenu( ) {
163
178
return html `
164
179
< umb-workspace-action-menu
165
180
.items =${ this . _items }
166
- color ="${ this . #manifest?. meta . color || 'default' } "
167
- look="${ this . #manifest?. meta . look || 'default' } "> </ umb-workspace-action-menu >
181
+ color ="${ this . #manifest?. meta . color ?? 'default' } "
182
+ look="${ this . #manifest?. meta . look ?? 'default' } "> </ umb-workspace-action-menu >
168
183
` ;
169
184
}
170
185
0 commit comments