@@ -20,6 +20,7 @@ import { KeyboardEvent, useEffect, useState } from 'react';
20
20
21
21
import {
22
22
Alert ,
23
+ Box ,
23
24
ButtonPrimary ,
24
25
ButtonSecondary ,
25
26
Flex ,
@@ -33,50 +34,40 @@ import { Attempt } from 'shared/hooks/useAttemptNext';
33
34
34
35
import TextSelectCopy from 'teleport/components/TextSelectCopy' ;
35
36
import cfg from 'teleport/config' ;
37
+ import { LabelsCreater } from 'teleport/Discover/Shared' ;
38
+ import { ResourceLabelTooltip } from 'teleport/Discover/Shared/ResourceLabelTooltip' ;
39
+ import { ResourceLabel } from 'teleport/services/agents' ;
36
40
37
41
import { State } from './useAddApp' ;
38
42
39
43
export function Automatically ( props : Props ) {
40
- const { onClose, attempt, token } = props ;
44
+ const { onClose, attempt, token, labels , setLabels } = props ;
41
45
42
46
const [ name , setName ] = useState ( '' ) ;
43
47
const [ uri , setUri ] = useState ( '' ) ;
44
48
const [ cmd , setCmd ] = useState ( '' ) ;
45
49
46
50
useEffect ( ( ) => {
47
- if ( name && uri ) {
51
+ if ( name && uri && token ) {
48
52
const cmd = createAppBashCommand ( token . id , name , uri ) ;
49
53
setCmd ( cmd ) ;
50
54
}
51
55
} , [ token ] ) ;
52
56
53
- function handleRegenerate ( validator : Validator ) {
57
+ function onGenerateScript ( validator : Validator ) {
54
58
if ( ! validator . validate ( ) ) {
55
59
return ;
56
60
}
57
61
58
62
props . onCreate ( name , uri ) ;
59
63
}
60
64
61
- function handleGenerate ( validator : Validator ) {
62
- if ( ! validator . validate ( ) ) {
63
- return ;
64
- }
65
-
66
- const cmd = createAppBashCommand ( token . id , name , uri ) ;
67
- setCmd ( cmd ) ;
68
- }
69
-
70
65
function handleEnterPress (
71
66
e : KeyboardEvent < HTMLInputElement > ,
72
67
validator : Validator
73
68
) {
74
69
if ( e . key === 'Enter' ) {
75
- if ( cmd ) {
76
- handleRegenerate ( validator ) ;
77
- } else {
78
- handleGenerate ( validator ) ;
79
- }
70
+ onGenerateScript ( validator ) ;
80
71
}
81
72
}
82
73
@@ -96,6 +87,7 @@ export function Automatically(props: Props) {
96
87
mr = "3"
97
88
onKeyPress = { e => handleEnterPress ( e , validator ) }
98
89
onChange = { e => setName ( e . target . value . toLowerCase ( ) ) }
90
+ disabled = { attempt . status === 'processing' }
99
91
/>
100
92
< FieldInput
101
93
rule = { requiredAppUri }
@@ -105,8 +97,25 @@ export function Automatically(props: Props) {
105
97
placeholder = "https://localhost:4000"
106
98
onKeyPress = { e => handleEnterPress ( e , validator ) }
107
99
onChange = { e => setUri ( e . target . value ) }
100
+ disabled = { attempt . status === 'processing' }
108
101
/>
109
102
</ Flex >
103
+ < Box mt = { - 3 } mb = { 3 } >
104
+ < Flex alignItems = "center" gap = { 1 } mb = { 2 } mt = { 4 } >
105
+ < Text bold > Add Labels (Optional)</ Text >
106
+ < ResourceLabelTooltip
107
+ toolTipPosition = "top"
108
+ resourceKind = "app"
109
+ />
110
+ </ Flex >
111
+ < LabelsCreater
112
+ labels = { labels }
113
+ setLabels = { setLabels }
114
+ isLabelOptional = { true }
115
+ disableBtns = { attempt . status === 'processing' }
116
+ noDuplicateKey = { true }
117
+ />
118
+ </ Box >
110
119
{ ! cmd && (
111
120
< Text mb = "3" >
112
121
Teleport can automatically set up application access. Provide
@@ -136,24 +145,13 @@ export function Automatically(props: Props) {
136
145
) }
137
146
</ DialogContent >
138
147
< DialogFooter >
139
- { ! cmd && (
140
- < ButtonPrimary
141
- mr = "3"
142
- disabled = { attempt . status === 'processing' }
143
- onClick = { ( ) => handleGenerate ( validator ) }
144
- >
145
- Generate Script
146
- </ ButtonPrimary >
147
- ) }
148
- { cmd && (
149
- < ButtonPrimary
150
- mr = "3"
151
- disabled = { attempt . status === 'processing' }
152
- onClick = { ( ) => handleRegenerate ( validator ) }
153
- >
154
- Regenerate
155
- </ ButtonPrimary >
156
- ) }
148
+ < ButtonPrimary
149
+ mr = "3"
150
+ disabled = { attempt . status === 'processing' }
151
+ onClick = { ( ) => onGenerateScript ( validator ) }
152
+ >
153
+ { cmd ? 'Regenerate Script' : 'Generate Script' }
154
+ </ ButtonPrimary >
157
155
< ButtonSecondary
158
156
disabled = { attempt . status === 'processing' }
159
157
onClick = { onClose }
@@ -271,4 +269,6 @@ type Props = {
271
269
onCreate ( name : string , uri : string ) : Promise < any > ;
272
270
token : State [ 'token' ] ;
273
271
attempt : Attempt ;
272
+ labels : ResourceLabel [ ] ;
273
+ setLabels ( r : ResourceLabel [ ] ) : void ;
274
274
} ;
0 commit comments