11import React from 'react'
22import styles from '../scss/selectIteration.module.scss'
33import { ApolloError } from '@apollo/client'
4- import { Submission , GetPreviousSubmissionsQuery } from '../graphql'
4+ import {
5+ Submission ,
6+ GetPreviousSubmissionsQuery ,
7+ SubmissionStatus
8+ } from '../graphql'
59import { Badge , Button } from 'react-bootstrap'
610
711type IterationLink = {
812 iteration : number
913 current : number
1014 id : number
1115 comments : number | undefined
16+ status : SubmissionStatus
17+ loading ?: boolean
1218}
1319
1420type SelectIteration = {
@@ -21,30 +27,41 @@ type SelectIteration = {
2127 currentIndex : number
2228}
2329
30+ const statusToBtnVariant = {
31+ [ SubmissionStatus . Overwritten ] : 'info' ,
32+ [ SubmissionStatus . Open ] : 'warning' ,
33+ [ SubmissionStatus . NeedMoreWork ] : 'danger' ,
34+ [ SubmissionStatus . Passed ] : 'success'
35+ }
36+
2437const IterationLink : React . FC < IterationLink | { loading : boolean } > = props => {
25- if ( ! props . hasOwnProperty ( 'loading' ) ) {
26- props = props as IterationLink
27- return (
28- < Button
29- variant = { props . current === props . id ? 'info' : 'success' }
30- className = { `${ styles [ 'button' ] } m-2` }
31- >
32- { props . iteration }
33- { props . comments !== 0 && (
34- < Badge variant = "light" className = { styles [ 'badge' ] } >
35- { props . comments }
36- </ Badge >
37- ) }
38- < span className = "sr-only" > comment count</ span >
39- </ Button >
40- )
41- } else
38+ if ( props . loading )
4239 return (
4340 < Button
4441 variant = "light"
4542 className = { `${ styles [ 'button' ] } ${ styles [ 'loading' ] } ` }
4643 />
4744 )
45+
46+ props = props as IterationLink
47+ const isSelected = props . current === props . id
48+ return (
49+ < Button
50+ variant = { `outline-${ statusToBtnVariant [ props . status ] } ` }
51+ className = { `${ styles [ 'button' ] } ${
52+ isSelected ? styles [ 'active' ] : ''
53+ } m-2`}
54+ active = { isSelected }
55+ >
56+ { props . iteration }
57+ { props . comments !== 0 && (
58+ < Badge variant = "light" className = { styles [ 'badge' ] } >
59+ { props . comments }
60+ </ Badge >
61+ ) }
62+ < span className = "sr-only" > comment count</ span >
63+ </ Button >
64+ )
4865}
4966
5067const SelectDisplay : React . FC < Omit < SelectIteration , 'error' > > = ( {
@@ -54,7 +71,7 @@ const SelectDisplay: React.FC<Omit<SelectIteration, 'error'>> = ({
5471 setSubmission,
5572 currentId
5673} ) => {
57- if ( loading ) return < IterationLink loading = { true } />
74+ if ( loading ) return < IterationLink loading />
5875 if ( data ?. getPreviousSubmissions )
5976 return (
6077 < div >
@@ -74,6 +91,7 @@ const SelectDisplay: React.FC<Omit<SelectIteration, 'error'>> = ({
7491 current = { currentId }
7592 id = { submission . id }
7693 comments = { submission . comments ?. length }
94+ status = { submission . status }
7795 />
7896 </ div >
7997 )
0 commit comments