@@ -9,7 +9,7 @@ import { LoaderButton } from '../../../components/LoaderButton'
99import { PageTitle } from '../../../components/PageTitle'
1010import { Scalars } from '../../../graphql-operations'
1111
12- import { SET_USER_COMPLETIONS_QUOTA , USER_REQUEST_QUOTAS } from './backend'
12+ import { SET_USER_CODE_COMPLETIONS_QUOTA , SET_USER_COMPLETIONS_QUOTA , USER_REQUEST_QUOTAS } from './backend'
1313
1414interface Props {
1515 user : {
@@ -22,6 +22,8 @@ export const UserQuotaProfilePage: React.FunctionComponent<React.PropsWithChildr
2222} ) => {
2323 const { data, loading, error } = useQuery ( USER_REQUEST_QUOTAS , { variables : { userID } } )
2424 const [ quota , setQuota ] = useState < string > ( '' )
25+ const [ codeCompletionsQuota , setCodeCompletionsQuota ] = useState < string > ( '' )
26+
2527 const [
2628 setUserCompletionsQuota ,
2729 {
@@ -31,13 +33,28 @@ export const UserQuotaProfilePage: React.FunctionComponent<React.PropsWithChildr
3133 } ,
3234 ] = useMutation ( SET_USER_COMPLETIONS_QUOTA )
3335
36+ const [
37+ setUserCodeCompletionsQuota ,
38+ {
39+ data : setCodeCompletionsQuotaResponse ,
40+ loading : setUserCodeCompletionsQuotaLoading ,
41+ error : setUserCodeCompletionsQuotaError ,
42+ } ,
43+ ] = useMutation ( SET_USER_CODE_COMPLETIONS_QUOTA )
44+
3445 useEffect ( ( ) => {
3546 if ( data ?. node ?. __typename === 'User' && data . node . completionsQuotaOverride !== null ) {
3647 setQuota ( data . node . completionsQuotaOverride )
3748 } else {
3849 // No overridden limit.
3950 setQuota ( '' )
4051 }
52+ if ( data ?. node ?. __typename === 'User' && data . node . codeCompletionsQuotaOverride !== null ) {
53+ setCodeCompletionsQuota ( data . node . codeCompletionsQuotaOverride )
54+ } else {
55+ // No overridden limit.
56+ setCodeCompletionsQuota ( '' )
57+ }
4158 } , [ data ] )
4259
4360 useEffect ( ( ) => {
@@ -51,6 +68,17 @@ export const UserQuotaProfilePage: React.FunctionComponent<React.PropsWithChildr
5168 }
5269 } , [ setCompletionsQuotaResponse ] )
5370
71+ useEffect ( ( ) => {
72+ if ( setCodeCompletionsQuotaResponse ) {
73+ if ( setCodeCompletionsQuotaResponse . codeCompletionsQuotaOverride !== null ) {
74+ setCodeCompletionsQuota ( setCodeCompletionsQuotaResponse . codeCompletionsQuotaOverride )
75+ } else {
76+ // No overridden limit.
77+ setCodeCompletionsQuota ( '' )
78+ }
79+ }
80+ } , [ setCodeCompletionsQuotaResponse ] )
81+
5482 const storeCompletionsQuota = useCallback ( ( ) => {
5583 setUserCompletionsQuota ( { variables : { userID, quota : quota === '' ? null : parseInt ( quota , 10 ) } } ) . catch (
5684 error => {
@@ -59,6 +87,14 @@ export const UserQuotaProfilePage: React.FunctionComponent<React.PropsWithChildr
5987 )
6088 } , [ quota , userID , setUserCompletionsQuota ] )
6189
90+ const storeCodeCompletionsQuota = useCallback ( ( ) => {
91+ setUserCodeCompletionsQuota ( {
92+ variables : { userID, quota : codeCompletionsQuota === '' ? null : parseInt ( codeCompletionsQuota , 10 ) } ,
93+ } ) . catch ( error => {
94+ logger . error ( error )
95+ } )
96+ } , [ codeCompletionsQuota , userID , setUserCodeCompletionsQuota ] )
97+
6298 if ( loading ) {
6399 return < LoadingSpinner />
64100 }
@@ -84,7 +120,7 @@ export const UserQuotaProfilePage: React.FunctionComponent<React.PropsWithChildr
84120 < Container className = "mb-3" >
85121 < H3 > Completions</ H3 >
86122 < Text > Number of requests per day allowed against the completions APIs.</ Text >
87- < div className = "d-flex justify-content-between align-items-end" >
123+ < div className = "d-flex justify-content-between align-items-end mb-5 " >
88124 < Input
89125 id = "completions-quota"
90126 name = "completions-quota"
@@ -112,6 +148,37 @@ export const UserQuotaProfilePage: React.FunctionComponent<React.PropsWithChildr
112148 />
113149 </ div >
114150 { setUserCompletionsQuotaError && < ErrorAlert error = { setUserCompletionsQuotaError } className = "mb-0" /> }
151+ < Text > Number of requests per day allowed against the code completions APIs.</ Text >
152+ < div className = "d-flex justify-content-between align-items-end" >
153+ < Input
154+ id = "code-completions-quota"
155+ name = "code-completions-quota"
156+ type = "number"
157+ value = { codeCompletionsQuota }
158+ onChange = { event => setCodeCompletionsQuota ( event . currentTarget . value ) }
159+ spellCheck = { false }
160+ min = { 1 }
161+ disabled = { setUserCodeCompletionsQuotaLoading }
162+ placeholder = { `Global limit: ${
163+ data ?. site . perUserCodeCompletionsQuota === null
164+ ? 'infinite'
165+ : data ?. site . perUserCodeCompletionsQuota
166+ } `}
167+ label = "Custom code completions quota"
168+ className = "flex-grow-1 mb-0"
169+ />
170+ < LoaderButton
171+ loading = { setUserCodeCompletionsQuotaLoading }
172+ label = "Save"
173+ onClick = { storeCodeCompletionsQuota }
174+ disabled = { setUserCodeCompletionsQuotaLoading }
175+ variant = "primary"
176+ className = "ml-2"
177+ />
178+ </ div >
179+ { setUserCodeCompletionsQuotaError && (
180+ < ErrorAlert error = { setUserCodeCompletionsQuotaError } className = "mb-0" />
181+ ) }
115182 </ Container >
116183 </ >
117184 )
0 commit comments