Skip to content

Prod Update - multiple fixes #962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 10, 2020
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
4 changes: 3 additions & 1 deletion src/actions/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ export function replaceResourceInRole (challengeId, roleId, newMember, oldMember
}
}
}
await dispatch(createResource(challengeId, roleId, newMember))
if (newMember) {
await dispatch(createResource(challengeId, roleId, newMember))
}
}
}
80 changes: 47 additions & 33 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ChallengeEditor extends Component {
this.onUpdateMetadata = this.onUpdateMetadata.bind(this)
this.getTemplatePhases = this.getTemplatePhases.bind(this)
this.getAvailableTimelineTemplates = this.getAvailableTimelineTemplates.bind(this)
this.autoUpdateChallengeThrottled = _.throttle(this.autoUpdateChallenge.bind(this), 3000) // 3s
this.autoUpdateChallengeThrottled = _.throttle(this.validateAndAutoUpdateChallenge.bind(this), 3000) // 3s
this.updateResource = this.updateResource.bind(this)
}

Expand All @@ -128,6 +128,18 @@ class ChallengeEditor extends Component {
this.resetChallengeData(this.setState.bind(this))
}

/**
* Validates challenge and if its valid calling an autosave method
*
* @param {string} changedField changed field
* @param {any} prevValue previous value
*/
async validateAndAutoUpdateChallenge (changedField, prevValue) {
if (this.validateChallenge()) {
this.autoUpdateChallenge(changedField, prevValue)
}
}

async resetChallengeData (setState = () => {}) {
const { isNew, challengeDetails, metadata, attachments, challengeId, assignedMemberDetails } = this.props
if (
Expand Down Expand Up @@ -922,35 +934,38 @@ class ChallengeEditor extends Component {
async updateAllChallengeInfo (status, cb = () => {}) {
const { updateChallengeDetails, assignedMemberDetails: oldAssignedMember } = this.props
if (this.state.isSaving) return
this.setState({ isSaving: true })
const challenge = this.collectChallengeData(status)
let newChallenge = _.cloneDeep(this.state.challenge)
newChallenge.status = status
try {
const challengeId = this.getCurrentChallengeId()
const action = await updateChallengeDetails(challengeId, challenge)
const { copilot: previousCopilot, reviewer: previousReviewer } = this.state.draftChallenge.data
const { challenge: { copilot, reviewer }, assignedMemberDetails: assignedMember } = this.state
if (copilot) await this.updateResource(challengeId, 'Copilot', copilot, previousCopilot)
if (reviewer) await this.updateResource(challengeId, 'Reviewer', reviewer, previousReviewer)
const oldMemberHandle = _.get(oldAssignedMember, 'handle')
// assigned member has been updated
if (assignedMember && assignedMember.handle !== oldMemberHandle) {
await this.updateResource(challengeId, 'Submitter', assignedMember.handle, oldMemberHandle)
}
this.setState({ isSaving: true }, async () => {
const challenge = this.collectChallengeData(status)
let newChallenge = _.cloneDeep(this.state.challenge)
newChallenge.status = status
try {
const challengeId = this.getCurrentChallengeId()
// state can have updated assigned member (in cases where user changes assignments without refreshing the page)
const { challenge: { copilot, reviewer }, assignedMemberDetails: assignedMember } = this.state
const oldMemberHandle = _.get(oldAssignedMember, 'handle')
const assignedMemberHandle = _.get(assignedMember, 'handle')
// assigned member has been updated
if (assignedMemberHandle !== oldMemberHandle) {
await this.updateResource(challengeId, 'Submitter', assignedMemberHandle, oldMemberHandle)
}
const action = await updateChallengeDetails(challengeId, challenge)
const { copilot: previousCopilot, reviewer: previousReviewer } = this.state.draftChallenge.data
if (copilot !== previousCopilot) await this.updateResource(challengeId, 'Copilot', copilot, previousCopilot)
if (reviewer !== previousReviewer) await this.updateResource(challengeId, 'Reviewer', reviewer, previousReviewer)

const draftChallenge = { data: action.challengeDetails }
draftChallenge.data.copilot = copilot
draftChallenge.data.reviewer = reviewer
this.setState({ isLaunch: true,
isConfirm: newChallenge.id,
draftChallenge,
challenge: newChallenge,
isSaving: false }, cb)
} catch (e) {
const error = _.get(e, 'response.data.message', `Unable to update the challenge to status ${status}`)
this.setState({ isSaving: false, error }, cb)
}
const draftChallenge = { data: action.challengeDetails }
draftChallenge.data.copilot = copilot
draftChallenge.data.reviewer = reviewer
this.setState({ isLaunch: true,
isConfirm: newChallenge.id,
draftChallenge,
challenge: newChallenge,
isSaving: false }, cb)
} catch (e) {
const error = _.get(e, 'response.data.message', `Unable to update the challenge to status ${status}`)
this.setState({ isSaving: false, error }, cb)
}
})
}

async onActiveChallenge () {
Expand Down Expand Up @@ -1043,7 +1058,6 @@ class ChallengeEditor extends Component {
return <div>Error loading challenge</div>
}
const isTask = _.get(challenge, 'task.isTask', false)
console.log(this.props.assignedMemberDetails)
const { assignedMemberDetails, error } = this.state
let isActive = false
let isDraft = false
Expand Down Expand Up @@ -1194,7 +1208,7 @@ class ChallengeEditor extends Component {
<OutlineButton text={isSaving ? 'Saving...' : 'Save'} type={'success'} onClick={this.onSaveChallenge} />
</div> */}
<div className={styles.button}>
<PrimaryButton text={'Save Draft'} type={'info'} onClick={this.createDraftHandler} />
<PrimaryButton text={isSaving ? 'Saving...' : 'Save Draft'} type={'info'} onClick={this.createDraftHandler} />
</div>
{isDraft && (
<div className={styles.button}>
Expand All @@ -1210,9 +1224,9 @@ class ChallengeEditor extends Component {
)}
</div>}
{!isLoading && isActive && <div className={styles.buttonContainer}>
{/* <div className={styles.button}>
<div className={styles.button}>
<OutlineButton text={isSaving ? 'Saving...' : 'Save'} type={'success'} onClick={this.onSaveChallenge} />
</div> */}
</div>
{isTask && (
<div className={styles.button}>
<PrimaryButton text={'Close Task'} type={'danger'} onClick={this.openCloseTaskConfirmation} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/Sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const Sidebar = ({
<div className={styles.title}>Work Manager</div>
<Link to='/'>
<div className={cn(styles.homeLink, { [styles.active]: !projectId })} onClick={resetSidebarActiveParams}>
Active challenges
All Work
</div>
</Link>
<a href='https://forms.gle/CsaVawSDkdR5E92B8' target='_blank' rel='noopener noreferrer' className='chameleon-feedback'>
<a href='https://github.com/topcoder-platform/work-manager/issues/newsid' target='_blank' rel='noopener noreferrer' className='chameleon-feedback'>
<div className={cn(styles.homeLink, { [styles.active]: !projectId })}>
Give Application Feedback
</div>
Expand Down