1- import React from 'react' ;
2- import styled from 'styled-components' ;
1+ import React , { useState } from 'react' ;
2+ import styled , { css } from 'styled-components' ;
33import determineColorForString from '../utils/determineColorForString' ;
44import DockContainerState from './DockContainerState' ;
55import useApi from '../hooks/useApi' ;
@@ -14,13 +14,18 @@ const DockContainerWrapper = styled.div`
1414 justify-content: space-between;
1515 padding: 1rem;
1616 border-bottom: 1px solid #624694;
17-
1817 @media all and (max-width: 450px) {
1918 flex-direction: column;
2019 }
20+
21+ ${ props => props . isRemoving && css `
22+ border-bottom: 0;
23+ background-color: #222;
24+ ` }
25+
2126` ;
2227
23- const StyledObjectLink = styled . a `
28+ const StyledObjectLink = styled ( ( { ... props } ) => < Link { ... props } /> ) `
2429 display: flex;
2530 flex-direction: column;
2631 text-decoration: none;
@@ -90,11 +95,16 @@ const StyledActionButton = styled.button`
9095 ${ COMMON_ACTION_BUTTON_STYLES }
9196 ` ;
9297
93- const LogLink = styled ( ( { ... props } ) => < Link { ... props } /> ) `
98+ const SiteLink = styled . a `
9499 color: lightskyblue;
95100 ${ COMMON_ACTION_BUTTON_STYLES }
96101` ;
97102
103+ const Cancel = styled ( StyledActionButton ) `
104+ color: #dbdbdb;
105+ ` ;
106+
107+
98108const Remove = styled ( StyledActionButton ) `
99109 color: salmon;
100110` ;
@@ -116,12 +126,34 @@ const Spinner = styled.span`
116126 }
117127` ;
118128
129+ const RemoveWarn = styled . div `
130+ width: 100%;
131+ display: flex;
132+ padding: 1rem;
133+ background: #222;
134+ align-items: center;
135+ justify-content: center;
136+ flex-direction: column;
137+ ` ;
138+
139+ const StyledWarnHeader = styled . h3 `
140+ color: salmon;
141+ margin: 0;
142+ ` ;
143+
144+ const StyledWarnText = styled . p `
145+ color: salmon;
146+ margin: 1rem;
147+ ` ;
148+
119149export default function DockContainer ( { imageId, container, handleRefetch } ) {
120150
121151 if ( ! container ) {
122152 return null ;
123153 }
124154
155+ const [ isRemoving , setIsRemoving ] = useState ( false ) ;
156+
125157 // eslint-disable-next-line
126158 const [ restartingContainer , restartResponse , err1 , restartContainer ] = useApi ( {
127159 endpoint : `containers/${ container . id } /restart` ,
@@ -151,8 +183,12 @@ export default function DockContainer({ imageId, container, handleRefetch }) {
151183 }
152184
153185 return (
154- < DockContainerWrapper >
155- < StyledObjectLink href = { containerHref } >
186+ < div >
187+
188+
189+
190+ < DockContainerWrapper isRemoving = { isRemoving } >
191+ < StyledObjectLink to = { `/${ imageId } /${ container . id } ` } >
156192 < ContainerNameWrapper >
157193 < ContainerTag color = { determineColorForString ( container . name ) } >
158194 { restartingContainer ? < Spinner > { loading } </ Spinner > : "#" }
@@ -171,11 +207,28 @@ export default function DockContainer({ imageId, container, handleRefetch }) {
171207 removingContainer && < StyledMessage > Removing container..</ StyledMessage >
172208 }
173209 </ StyledObjectLink >
174- < ContainerOptions >
175- { isRestartable && < Restart onClick = { ( ) => restartContainer ( ) } > RESTART</ Restart > }
176- { isRemovable && < Remove onClick = { ( ) => removeContainer ( ) } > REMOVE</ Remove > }
177- < LogLink to = { `/${ imageId } /${ container . id } ` } > VIEW DETAILS</ LogLink >
178- </ ContainerOptions >
210+ {
211+ ! isRemoving && (
212+ < ContainerOptions >
213+ { isRestartable && < Restart onClick = { ( ) => restartContainer ( ) } > RESTART</ Restart > }
214+ { isRemovable && < Remove onClick = { ( ) => setIsRemoving ( true ) } > REMOVE</ Remove > }
215+ { containerHref !== '#' && < SiteLink href = { containerHref } > VIEW SITE</ SiteLink > }
216+ </ ContainerOptions >
217+ )
218+ }
179219 </ DockContainerWrapper >
220+ {
221+ isRemoving && (
222+ < RemoveWarn >
223+ < StyledWarnHeader > Confirm remove</ StyledWarnHeader >
224+ < StyledWarnText > Warning: This action cannot be undone.</ StyledWarnText >
225+ < ContainerOptions >
226+ < Cancel onClick = { ( ) => setIsRemoving ( false ) } > CANCEL</ Cancel >
227+ < Remove onClick = { ( ) => removeContainer ( ) } > REMOVE</ Remove >
228+ </ ContainerOptions >
229+ </ RemoveWarn >
230+ )
231+ }
232+ </ div >
180233 ) ;
181234}
0 commit comments