44 ComponentColor ,
55 ComponentStatus ,
66 Form ,
7+ IconFont ,
78 Input ,
89 InputLabel ,
910 InputType ,
@@ -25,16 +26,18 @@ import {
2526} from 'src/shared/copy/notifications/categories/scripts'
2627import { getOrg } from 'src/organizations/selectors'
2728import OpenScript from 'src/dataExplorer/components/OpenScript'
29+ import { DeleteScript } from 'src/dataExplorer/components/DeleteScript'
2830
2931interface Props {
3032 onClose : ( ) => void
33+ setOverlayType : ( type : OverlayType ) => void
3134 type : OverlayType | null
3235}
3336
34- const SaveAsScript : FC < Props > = ( { onClose, type} ) => {
37+ const SaveAsScript : FC < Props > = ( { onClose, setOverlayType , type} ) => {
3538 const dispatch = useDispatch ( )
3639 const history = useHistory ( )
37- const { hasChanged, resource, setResource, clearCompositionSelection , save} =
40+ const { hasChanged, resource, setResource, save} =
3841 useContext ( PersistanceContext )
3942 const { cancel} = useContext ( QueryContext )
4043 const { setStatus, setResult} = useContext ( ResultsContext )
@@ -67,6 +70,10 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
6770 } )
6871 }
6972
73+ const handleBackClick = ( ) => {
74+ setOverlayType ( OverlayType . EDIT )
75+ }
76+
7077 const handleUpdateName = ( event : ChangeEvent < HTMLInputElement > ) => {
7178 setResource ( {
7279 ...resource ,
@@ -80,14 +87,13 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
8087 const clear = useCallback ( ( ) => {
8188 cancel ( )
8289 setStatus ( RemoteDataState . NotStarted )
83- clearCompositionSelection ( )
8490 setResult ( null )
8591
8692 history . replace ( `/orgs/${ org . id } /data-explorer/from/script` )
8793 if ( type !== OverlayType . OPEN ) {
8894 onClose ( )
8995 }
90- } , [ onClose , setStatus , setResult , cancel , history , org ?. id ] )
96+ } , [ onClose , setStatus , setResult , cancel , history , org ?. id , type ] )
9197
9298 const handleSaveScript = ( ) => {
9399 save ( )
@@ -108,6 +114,10 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
108114 } )
109115 }
110116
117+ const handleDeleteScript = ( ) => {
118+ setOverlayType ( OverlayType . DELETE )
119+ }
120+
111121 if ( type == null ) {
112122 return null
113123 }
@@ -121,6 +131,13 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
121131 overlayTitle = 'Do you want to save your script first?'
122132 }
123133 }
134+ if ( type === OverlayType . EDIT ) {
135+ overlayTitle = 'Edit Script Details'
136+ }
137+
138+ if ( type === OverlayType . DELETE ) {
139+ return < DeleteScript onBack = { handleBackClick } onClose = { onClose } />
140+ }
124141
125142 if ( ! hasChanged && type === OverlayType . OPEN ) {
126143 return < OpenScript onCancel = { handleClose } onClose = { onClose } />
@@ -141,6 +158,9 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
141158 saveText = 'Yes, Save'
142159 }
143160 }
161+ if ( type === OverlayType . EDIT ) {
162+ saveText = 'Update'
163+ }
144164
145165 return (
146166 < Overlay . Container maxWidth = { 540 } >
@@ -170,6 +190,16 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
170190 value = { resource ?. data ?. description }
171191 onChange = { handleUpdateDescription }
172192 />
193+ { type === OverlayType . EDIT && (
194+ < Button
195+ icon = { IconFont . Trash_New }
196+ className = "edit-overlay__delete-script"
197+ color = { ComponentColor . Danger }
198+ onClick = { handleDeleteScript }
199+ text = "Delete Script"
200+ testID = "flux-query-builder--no-save"
201+ />
202+ ) }
173203 </ Form >
174204 </ Overlay . Body >
175205 < Overlay . Footer >
@@ -178,7 +208,7 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
178208 onClick = { handleClose }
179209 text = "Cancel"
180210 />
181- { type !== OverlayType . SAVE && (
211+ { ( type === OverlayType . NEW || type === OverlayType . OPEN ) && (
182212 < Button
183213 color = { ComponentColor . Default }
184214 onClick = { clear }
0 commit comments