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
1 change: 0 additions & 1 deletion .local-ssl-proxy.pid

This file was deleted.

55 changes: 47 additions & 8 deletions src/components/ChallengeEditor/ChallengeReviewer-Field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,47 @@ const ResourceToPhaseNameMap = {
'Checkpoint Screener': 'Checkpoint Screening'
}

// Keep track filters aligned with the scorecards API regardless of legacy values
const SCORECARD_TRACK_ALIASES = {
DEVELOP: 'DEVELOPMENT',
DEV: 'DEVELOPMENT',
QA: 'QUALITY_ASSURANCE',
QUALITY_ASSURANCE: 'QUALITY_ASSURANCE',
QUALITYASSURANCE: 'QUALITY_ASSURANCE',
DES: 'DESIGN',
DESIGN: 'DESIGN',
DS: 'DATA_SCIENCE',
DATA_SCIENCE: 'DATA_SCIENCE',
DATASCIENCE: 'DATA_SCIENCE'
}

const normalizeTrackForScorecards = (challenge, metadata) => {
const normalize = (value) => {
if (!value) return null
const normalized = value.toString().trim().toUpperCase().replace(/\s+/g, '_')
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
The use of replace(/\s+/g, '_') could lead to unexpected behavior if the input contains multiple spaces. Consider using replace(/\s+/g, '_') to ensure consistent normalization.

return SCORECARD_TRACK_ALIASES[normalized] || normalized
}

if (!challenge) return null

if (challenge.trackId && metadata && Array.isArray(metadata.challengeTracks)) {
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
The function normalizeTrackForScorecards returns null if challenge is falsy, but this might not be the desired behavior if metadata is provided. Consider handling the case where metadata is valid even if challenge is not.

const trackFromMetadata = metadata.challengeTracks.find(t => t.id === challenge.trackId)
if (trackFromMetadata) {
return normalize(trackFromMetadata.track || trackFromMetadata.name || trackFromMetadata.abbreviation)
}
}

const { track } = challenge
if (typeof track === 'string') {
return normalize(track)
}
if (track && typeof track === 'object') {
return normalize(track.track || track.name || track.abbreviation)
}

return null
}

class ChallengeReviewerField extends Component {
constructor (props) {
super(props)
Expand Down Expand Up @@ -327,19 +368,16 @@ class ChallengeReviewerField extends Component {
}

loadScorecards () {
const { challenge, loadScorecards } = this.props
const { challenge, loadScorecards, metadata } = this.props
Copy link

Choose a reason for hiding this comment

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

[❗❗ correctness]
The loadScorecards function now depends on metadata, but it doesn't check if metadata is defined before using it. Consider adding a check to ensure metadata is not undefined to avoid potential runtime errors.


const filters = {
status: 'ACTIVE'
}

// Add challenge track if available
if (challenge.track) {
if (typeof challenge.track === 'string') {
filters.challengeTrack = challenge.track.toUpperCase().replace(' ', '_')
} else if (challenge.track.track) {
filters.challengeTrack = challenge.track.track
}
const normalizedTrack = normalizeTrackForScorecards(challenge, metadata)
if (normalizedTrack) {
filters.challengeTrack = normalizedTrack
}

// Add challenge type if available
Expand Down Expand Up @@ -1013,7 +1051,8 @@ ChallengeReviewerField.propTypes = {
scorecards: PropTypes.array,
defaultReviewers: PropTypes.array,
workflows: PropTypes.array,
resourceRoles: PropTypes.array
resourceRoles: PropTypes.array,
challengeTracks: PropTypes.array
Copy link

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The addition of challengeTracks to PropTypes suggests that it is used in the component, but there is no validation for its presence when used in normalizeTrackForScorecards. Consider adding validation to ensure challengeTracks is provided when expected.

}),
isLoading: PropTypes.bool,
readOnly: PropTypes.bool,
Expand Down