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
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ export const isAIReviewer = (reviewer) => {
(reviewer.isMemberReview === false)
)
}

export const hasAiReviewers = (reviewers) => {
return Array.isArray(reviewers) && reviewers.some(isAIReviewer)
}
54 changes: 38 additions & 16 deletions src/components/ChallengeEditor/ChallengeView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import {
DEV_TRACK_ID,
MARATHON_TYPE_ID,
CHALLENGE_TYPE_ID,
COMMUNITY_APP_URL
COMMUNITY_APP_URL,
AI_SCREENING_PHASE_NAME
} from '../../../config/constants'
import PhaseInput from '../../PhaseInput'
import { hasAiReviewers } from '../ChallengeReviewer-Field/AiReviewerTab/utils'
import CheckpointPrizesField from '../CheckpointPrizes-Field'
import { isBetaMode } from '../../../util/localstorage'
import WiproAllowedField from '../WiproAllowedField'
Expand Down Expand Up @@ -224,21 +226,41 @@ const ChallengeView = ({
</div>
</div>
{
challenge.legacy.subTrack === 'WEB_DESIGNS' && challenge.phases.length === 8 ? phases.map((phase, index) => (
<PhaseInput
phase={phase}
phaseIndex={index}
key={index}
readOnly
/>
)) : _.sortBy(phases, ['scheduledEndDate']).map((phase, index) => (
<PhaseInput
phase={phase}
phaseIndex={index}
key={index}
readOnly
/>
))
(() => {
const phaseList = challenge.legacy.subTrack === 'WEB_DESIGNS' && challenge.phases.length === 8
? phases
: _.sortBy(phases, ['scheduledEndDate'])
const hasRealAiScreeningPhase = phaseList.some(p => p.name === AI_SCREENING_PHASE_NAME)
const showVirtualAiScreening = hasAiReviewers(challenge.reviewers) && !hasRealAiScreeningPhase
const submissionIndex = phaseList.findIndex(p => p.name === 'Submission')
return (
<>
{phaseList.map((phase, index) => (
<React.Fragment key={index}>
<PhaseInput
phase={phase}
phaseIndex={index}
readOnly
/>
{showVirtualAiScreening && index === submissionIndex && (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 design]
The PhaseInput component is conditionally rendered for the virtual AI screening phase. Ensure that the PhaseInput component can handle the isVirtual prop correctly.

<PhaseInput
phase={{ name: AI_SCREENING_PHASE_NAME }}
readOnly
isVirtual
/>
)}
</React.Fragment>
))}
{showVirtualAiScreening && submissionIndex === -1 && (
<PhaseInput
phase={{ name: AI_SCREENING_PHASE_NAME }}
readOnly
isVirtual
/>
)}
</>
)
})()
}
{showTimeline && (
<ChallengeScheduleField
Expand Down
51 changes: 38 additions & 13 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
QA_TRACK_ID, DESIGN_CHALLENGE_TYPES, ROUND_TYPES,
MULTI_ROUND_CHALLENGE_TEMPLATE_ID,
CHALLENGE_STATUS,
SKILLS_OPTIONAL_BILLING_ACCOUNT_IDS
SKILLS_OPTIONAL_BILLING_ACCOUNT_IDS,
AI_SCREENING_PHASE_NAME
} from '../../config/constants'
import {
getDomainTypes,
Expand Down Expand Up @@ -62,6 +63,7 @@ import Track from '../Track'
import ConfirmationModal from '../Modal/ConfirmationModal'
import AlertModal from '../Modal/AlertModal'
import PhaseInput from '../PhaseInput'
import { hasAiReviewers } from './ChallengeReviewer-Field/AiReviewerTab/utils'
import LegacyLinks from '../LegacyLinks'
import AssignedMemberField from './AssignedMember-Field'
import Tooltip from '../Tooltip'
Expand Down Expand Up @@ -2047,18 +2049,41 @@ class ChallengeEditor extends Component {
</div>
</div>
{
phases.map((phase, index) => (
<PhaseInput
phase={phase}
phaseIndex={index}
key={index}
readOnly={false}
onUpdatePhase={(item) => {
this.onUpdatePhaseDate(item, index)
}}
/>
)
)
(() => {
const hasRealAiScreeningPhase = phases.some(p => p.name === AI_SCREENING_PHASE_NAME)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ performance]
The use of some and findIndex to check for the presence of specific phases could be optimized by using a single iteration over phases. Consider refactoring to improve performance, especially if phases can be large.

const showVirtualAiScreening = hasAiReviewers(challenge.reviewers) && !hasRealAiScreeningPhase
const submissionIndex = phases.findIndex(p => p.name === 'Submission')
return (
<>
{phases.map((phase, index) => (
<React.Fragment key={index}>
<PhaseInput
phase={phase}
phaseIndex={index}
readOnly={false}
onUpdatePhase={(item) => {
this.onUpdatePhaseDate(item, index)
}}
/>
{showVirtualAiScreening && index === submissionIndex && (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
The logic for rendering the virtual AI screening phase is duplicated. Consider extracting this logic into a separate function to improve maintainability and reduce code duplication.

<PhaseInput
phase={{ name: AI_SCREENING_PHASE_NAME }}
readOnly
isVirtual
/>
)}
</React.Fragment>
))}
{showVirtualAiScreening && submissionIndex === -1 && (
<PhaseInput
phase={{ name: AI_SCREENING_PHASE_NAME }}
readOnly
isVirtual
/>
)}
</>
)
})()
}
</>
)}
Expand Down
48 changes: 33 additions & 15 deletions src/components/PhaseInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,39 @@ const inputDateFormat = 'MM/dd/yyyy'
const inputTimeFormat = 'HH:mm'
const MAX_LENGTH = 5

const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isVirtual }) => {
const { scheduledStartDate: startDate, scheduledEndDate: endDate, duration, isStartTimeActive, isDurationActive } = phase

const durationHoursMinutes = useMemo(() => getPhaseHoursMinutes(duration), [duration])
const endDateInputRef = useRef()

useEffect(() => {
if (!startDate && onUpdatePhase && !isVirtual) {
let startDate = moment().format(dateFormat)
let endDate = getPhaseEndDate(startDate, duration)
onUpdatePhase({
startDate,
endDate,
duration
})
}
}, [startDate])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The useEffect dependency array should include onUpdatePhase, isVirtual, and duration to ensure the effect runs correctly when these values change.


if (isVirtual && readOnly) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 readability]
The condition if (isVirtual && readOnly) could be more explicit by checking isVirtual === true && readOnly === true to avoid potential issues with truthy values.

return (
<div className={styles.container}>
<div className={styles.row}>
<div className={cn(styles.field, styles.col1, styles.phaseName)}>
<label>{phase.name} :</label>
</div>
<div className={cn(styles.field, styles.col2)}>
<span className={styles.title}>Automated (AI)</span>
</div>
</div>
</div>
)
}

const onStartDateChange = (e) => {
let startDate = moment(e).format(dateFormat)
let endDate = getPhaseEndDate(startDate, duration)
Expand All @@ -44,18 +71,6 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
}
}

useEffect(() => {
if (!startDate && onUpdatePhase) {
let startDate = moment().format(dateFormat)
let endDate = getPhaseEndDate(startDate, duration)
onUpdatePhase({
startDate,
endDate,
duration
})
}
}, [startDate])

const onDurationChange = (e, isBlur = false) => {
if (`${e}`.length > MAX_LENGTH) return null

Expand Down Expand Up @@ -144,13 +159,16 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {

PhaseInput.defaultProps = {
endDate: null,
readOnly: false
readOnly: false,
isVirtual: false,
phaseIndex: -1
}

PhaseInput.propTypes = {
phase: PropTypes.shape().isRequired,
onUpdatePhase: PropTypes.func,
readOnly: PropTypes.bool,
phaseIndex: PropTypes.number.isRequired
phaseIndex: PropTypes.number,
isVirtual: PropTypes.bool
}
export default PhaseInput
1 change: 1 addition & 0 deletions src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const SKILLS_OPTIONAL_BILLING_ACCOUNT_IDS = ['80000062']
*/
export const AI_WORKFLOW_POLL_INTERVAL = 1000 // 1 second in milliseconds
export const AI_WORKFLOW_POLL_TIMEOUT = 5 * 60000 // 5 * 60 seconds in milliseconds
export const AI_SCREENING_PHASE_NAME = 'AI Screening'

/**
* Filepicker config
Expand Down
Loading