@@ -13,6 +13,7 @@ import { getCurrentTeam, TeamsContext } from "../teams/teams-context";
13
13
import { PageWithSubMenu } from "../components/PageWithSubMenu" ;
14
14
import PillLabel from "../components/PillLabel" ;
15
15
import { ProjectContext } from "./project-context" ;
16
+ import { getExperimentsClient } from "./../experiments/client" ;
16
17
17
18
export function getProjectSettingsMenu ( project ?: Project , team ?: Team ) {
18
19
const teamOrUserSlug = ! ! team ? "t/" + team . slug : "projects" ;
@@ -50,17 +51,37 @@ export function ProjectSettingsPage(props: { project?: Project; children?: React
50
51
51
52
export default function ( ) {
52
53
const { project } = useContext ( ProjectContext ) ;
54
+ const location = useLocation ( ) ;
55
+ const { teams } = useContext ( TeamsContext ) ;
56
+ const team = getCurrentTeam ( location , teams ) ;
53
57
54
58
const [ isLoading , setIsLoading ] = useState < boolean > ( true ) ;
55
59
const [ isIncrementalPrebuildsEnabled , setIsIncrementalPrebuildsEnabled ] = useState < boolean > ( false ) ;
60
+ const [ isPersistentVolumeClaimEnabled , setIsPersistentVolumeClaimEnabled ] = useState < boolean > ( false ) ;
61
+ const [ isShowPersistentVolumeClaim , setIsShowPersistentVolumeClaim ] = useState < boolean > ( false ) ;
56
62
57
63
useEffect ( ( ) => {
58
64
if ( ! project ) {
59
65
return ;
60
66
}
61
67
setIsLoading ( false ) ;
62
68
setIsIncrementalPrebuildsEnabled ( ! ! project . settings ?. useIncrementalPrebuilds ) ;
63
- } , [ project ] ) ;
69
+ setIsPersistentVolumeClaimEnabled ( ! ! project . settings ?. usePersistentVolumeClaim ) ;
70
+
71
+ ( async ( ) => {
72
+ const showPersistentVolumeClaim = await getExperimentsClient ( ) . getValueAsync (
73
+ "persistent_volume_claim" ,
74
+ false ,
75
+ {
76
+ projectId : project ?. id ,
77
+ teamId : team ?. id ,
78
+ teamName : team ?. name ,
79
+ teams,
80
+ } ,
81
+ ) ;
82
+ setIsShowPersistentVolumeClaim ( showPersistentVolumeClaim ) ;
83
+ } ) ( ) ;
84
+ } , [ project , team , teams ] ) ;
64
85
65
86
const toggleIncrementalPrebuilds = async ( ) => {
66
87
if ( ! project ) {
@@ -80,6 +101,24 @@ export default function () {
80
101
}
81
102
} ;
82
103
104
+ const togglePersistentVolumeClaim = async ( ) => {
105
+ if ( ! project ) {
106
+ return ;
107
+ }
108
+ setIsLoading ( true ) ;
109
+ try {
110
+ await getGitpodService ( ) . server . updateProjectPartial ( {
111
+ id : project . id ,
112
+ settings : {
113
+ usePersistentVolumeClaim : ! isPersistentVolumeClaimEnabled ,
114
+ } ,
115
+ } ) ;
116
+ setIsPersistentVolumeClaimEnabled ( ! isPersistentVolumeClaimEnabled ) ;
117
+ } finally {
118
+ setIsLoading ( false ) ;
119
+ }
120
+ } ;
121
+
83
122
return (
84
123
< ProjectSettingsPage project = { project } >
85
124
< h3 > Incremental Prebuilds</ h3 >
@@ -106,6 +145,22 @@ export default function () {
106
145
disabled = { isLoading }
107
146
onChange = { toggleIncrementalPrebuilds }
108
147
/>
148
+ < br > </ br >
149
+ < h3 > Persistent Volume Claim</ h3 >
150
+ < CheckBox
151
+ title = {
152
+ < span >
153
+ Enable Persistent Volume Claim{ " " }
154
+ < PillLabel type = "warn" className = "font-semibold mt-2 ml-2 py-0.5 px-2 self-center" >
155
+ Experimental
156
+ </ PillLabel >
157
+ </ span >
158
+ }
159
+ desc = { < span > Experimental feature that is still under development.</ span > }
160
+ checked = { isPersistentVolumeClaimEnabled }
161
+ disabled = { isLoading || ! isShowPersistentVolumeClaim }
162
+ onChange = { togglePersistentVolumeClaim }
163
+ />
109
164
</ ProjectSettingsPage >
110
165
) ;
111
166
}
0 commit comments