Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions __tests__/__snapshots__/storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13620,7 +13620,7 @@ exports[`Storyshots Components/SelectIteration Active 1`] = `
onClick={[Function]}
>
<button
className="button m-2 btn btn-success"
className="button m-2 btn btn-outline-danger"
disabled={false}
type="button"
>
Expand All @@ -13638,7 +13638,7 @@ exports[`Storyshots Components/SelectIteration Active 1`] = `
onClick={[Function]}
>
<button
className="button m-2 btn btn-info"
className="button active m-2 btn active btn-outline-warning"
disabled={false}
type="button"
>
Expand All @@ -13656,7 +13656,7 @@ exports[`Storyshots Components/SelectIteration Active 1`] = `
onClick={[Function]}
>
<button
className="button m-2 btn btn-success"
className="button m-2 btn btn-outline-warning"
disabled={false}
type="button"
>
Expand Down
6 changes: 3 additions & 3 deletions __tests__/pages/review/__snapshots__/[lesson].test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ exports[`Lesson Page Should render new submissions 1`] = `
data-testid="iteration 0"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-danger"
type="button"
>
1
Expand All @@ -667,7 +667,7 @@ exports[`Lesson Page Should render new submissions 1`] = `
data-testid="iteration 1"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-warning"
type="button"
>
2
Expand All @@ -683,7 +683,7 @@ exports[`Lesson Page Should render new submissions 1`] = `
data-testid="iteration 2"
>
<button
class="button m-2 btn btn-info"
class="button active m-2 btn active btn-outline-warning"
type="button"
>
3
Expand Down
4 changes: 2 additions & 2 deletions components/ChallengeMaterial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ describe('Curriculum challenge page', () => {
await screen.findByText('Select submission')
expect(
await screen.findByRole('button', { name: '3 2 comment count' })
).toHaveClass('btn-info')
).toHaveClass('active')
userEvent.click(screen.getByTestId('iteration 1'))
expect(
await screen.findByRole('button', { name: '3 2 comment count' })
).not.toHaveClass('btn-info')
).not.toHaveClass('active')
expect(container).toMatchSnapshot()
})
test('Should be able to select another challenge', async () => {
Expand Down
56 changes: 37 additions & 19 deletions components/SelectIteration.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import React from 'react'
import styles from '../scss/selectIteration.module.scss'
import { ApolloError } from '@apollo/client'
import { Submission, GetPreviousSubmissionsQuery } from '../graphql'
import {
Submission,
GetPreviousSubmissionsQuery,
SubmissionStatus
} from '../graphql'
import { Badge, Button } from 'react-bootstrap'

type IterationLink = {
iteration: number
current: number
id: number
comments: number | undefined
status: SubmissionStatus
loading?: boolean
}

type SelectIteration = {
Expand All @@ -21,30 +27,41 @@ type SelectIteration = {
currentIndex: number
}

const statusToBtnVariant = {
[SubmissionStatus.Overwritten]: 'info',
[SubmissionStatus.Open]: 'warning',
[SubmissionStatus.NeedMoreWork]: 'danger',
[SubmissionStatus.Passed]: 'success'
}

const IterationLink: React.FC<IterationLink | { loading: boolean }> = props => {
if (!props.hasOwnProperty('loading')) {
props = props as IterationLink
return (
<Button
variant={props.current === props.id ? 'info' : 'success'}
className={`${styles['button']} m-2`}
>
{props.iteration}
{props.comments !== 0 && (
<Badge variant="light" className={styles['badge']}>
{props.comments}
</Badge>
)}
<span className="sr-only">comment count</span>
</Button>
)
} else
if (props.loading)
return (
<Button
variant="light"
className={`${styles['button']} ${styles['loading']}`}
/>
)

props = props as IterationLink
const isSelected = props.current === props.id
return (
<Button
variant={`outline-${statusToBtnVariant[props.status]}`}
className={`${styles['button']} ${
isSelected ? styles['active'] : ''
} m-2`}
active={isSelected}
>
{props.iteration}
{props.comments !== 0 && (
<Badge variant="light" className={styles['badge']}>
{props.comments}
</Badge>
)}
<span className="sr-only">comment count</span>
</Button>
)
}

const SelectDisplay: React.FC<Omit<SelectIteration, 'error'>> = ({
Expand All @@ -54,7 +71,7 @@ const SelectDisplay: React.FC<Omit<SelectIteration, 'error'>> = ({
setSubmission,
currentId
}) => {
if (loading) return <IterationLink loading={true} />
if (loading) return <IterationLink loading />
if (data?.getPreviousSubmissions)
return (
<div>
Expand All @@ -74,6 +91,7 @@ const SelectDisplay: React.FC<Omit<SelectIteration, 'error'>> = ({
current={currentId}
id={submission.id}
comments={submission.comments?.length}
status={submission.status}
/>
</div>
)
Expand Down
12 changes: 6 additions & 6 deletions components/__snapshots__/ChallengeMaterial.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ exports[`Curriculum challenge page Should be able to select another challenge 1`
data-testid="iteration 0"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-danger"
type="button"
>
1
Expand All @@ -111,7 +111,7 @@ exports[`Curriculum challenge page Should be able to select another challenge 1`
data-testid="iteration 1"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-warning"
type="button"
>
2
Expand All @@ -127,7 +127,7 @@ exports[`Curriculum challenge page Should be able to select another challenge 1`
data-testid="iteration 2"
>
<button
class="button m-2 btn btn-info"
class="button active m-2 btn active btn-outline-warning"
type="button"
>
3
Expand Down Expand Up @@ -7463,7 +7463,7 @@ exports[`Curriculum challenge page Should select previous iterations 1`] = `
data-testid="iteration 0"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-danger"
type="button"
>
1
Expand All @@ -7479,7 +7479,7 @@ exports[`Curriculum challenge page Should select previous iterations 1`] = `
data-testid="iteration 1"
>
<button
class="button m-2 btn btn-info"
class="button active m-2 btn active btn-outline-warning"
type="button"
>
2
Expand All @@ -7495,7 +7495,7 @@ exports[`Curriculum challenge page Should select previous iterations 1`] = `
data-testid="iteration 2"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-warning"
type="button"
>
3
Expand Down
6 changes: 3 additions & 3 deletions components/__snapshots__/ReviewCard.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ exports[`ReviewCard Component Should be able to select previous submissions 1`]
data-testid="iteration 0"
>
<button
class="button m-2 btn btn-info"
class="button active m-2 btn active btn-outline-danger"
type="button"
>
1
Expand All @@ -597,7 +597,7 @@ exports[`ReviewCard Component Should be able to select previous submissions 1`]
data-testid="iteration 1"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-warning"
type="button"
>
2
Expand All @@ -613,7 +613,7 @@ exports[`ReviewCard Component Should be able to select previous submissions 1`]
data-testid="iteration 2"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-warning"
type="button"
>
3
Expand Down
12 changes: 6 additions & 6 deletions components/__snapshots__/SelectIteration.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ exports[`SelectIteration component Should be able to select submissions 1`] = `
data-testid="iteration 0"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-danger"
type="button"
>
1
Expand All @@ -70,7 +70,7 @@ exports[`SelectIteration component Should be able to select submissions 1`] = `
data-testid="iteration 1"
>
<button
class="button m-2 btn btn-info"
class="button active m-2 btn active btn-outline-warning"
type="button"
>
2
Expand All @@ -86,7 +86,7 @@ exports[`SelectIteration component Should be able to select submissions 1`] = `
data-testid="iteration 2"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-warning"
type="button"
>
3
Expand Down Expand Up @@ -123,7 +123,7 @@ exports[`SelectIteration component Should treat negative index as last iteration
data-testid="iteration 0"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-danger"
type="button"
>
1
Expand All @@ -139,7 +139,7 @@ exports[`SelectIteration component Should treat negative index as last iteration
data-testid="iteration 1"
>
<button
class="button m-2 btn btn-info"
class="button active m-2 btn active btn-outline-warning"
type="button"
>
2
Expand All @@ -155,7 +155,7 @@ exports[`SelectIteration component Should treat negative index as last iteration
data-testid="iteration 2"
>
<button
class="button m-2 btn btn-success"
class="button m-2 btn btn-outline-warning"
type="button"
>
3
Expand Down
7 changes: 7 additions & 0 deletions scss/selectIteration.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
min-width: 2.5rem;
min-height: 2.5rem;
max-width: max-content;

&.active, &:hover {
// Warning variant button has non-white color
color: white !important;
}

& .badge {
color: rgb(122, 126, 120);
position: absolute;
Expand All @@ -17,6 +23,7 @@
border: 1px solid gainsboro;
border-radius: 50%;
}

&.loading {
min-height: 3rem;
}
Expand Down