From 6a8e16593d378ae556634905bf1628056dcdb350 Mon Sep 17 00:00:00 2001 From: C Dharmateja Date: Wed, 27 Jan 2021 12:00:22 +0000 Subject: [PATCH 1/3] fix project terms load and default terms in beta --- src/components/ChallengeEditor/index.js | 5 +++-- src/containers/ChallengeEditor/index.js | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/components/ChallengeEditor/index.js b/src/components/ChallengeEditor/index.js index 12c50035..a0b3d965 100644 --- a/src/components/ChallengeEditor/index.js +++ b/src/components/ChallengeEditor/index.js @@ -810,7 +810,8 @@ class ChallengeEditor extends Component { async createNewChallenge () { if (!this.props.isNew) return - const { metadata, createChallenge, projectDetail } = this.props + const { metadata, createChallenge, projectDetail, location } = this.props + const params = new URLSearchParams(location.search) const { name, trackId, typeId } = this.state.challenge const { timelineTemplates } = metadata const isDesignChallenge = trackId === DES_TRACK_ID @@ -839,7 +840,7 @@ class ChallengeEditor extends Component { terms: [{ id: DEFAULT_TERM_UUID, roleId: SUBMITTER_ROLE_UUID }] // prizeSets: this.getDefaultPrizeSets() } - if (projectDetail.terms) { + if (params.get('beta') === 'true' && projectDetail.terms) { const currTerms = new Set(newChallenge.terms.map(term => term.id)) newChallenge.terms.push( ...projectDetail.terms diff --git a/src/containers/ChallengeEditor/index.js b/src/containers/ChallengeEditor/index.js index 51ffaa26..ef20dc23 100644 --- a/src/containers/ChallengeEditor/index.js +++ b/src/containers/ChallengeEditor/index.js @@ -30,6 +30,8 @@ import { replaceResourceInRole } from '../../actions/challenges' +import { loadProject } from '../../actions/projects' + import { connect } from 'react-redux' import { SUBMITTER_ROLE_UUID, MESSAGE } from '../../config/constants' import { patchChallenge } from '../../services/challenges' @@ -74,7 +76,8 @@ class ChallengeEditor extends Component { loadGroups, loadResourceRoles, loadChallengeDetails, - loadResources + loadResources, + loadProject } = this.props loadTimelineTemplates() loadChallengePhases() @@ -85,6 +88,7 @@ class ChallengeEditor extends Component { // loadChallengeTerms() loadGroups() loadResourceRoles() + this.fetchProjectDetails(match, loadProject) this.fetchChallengeDetails(match, loadChallengeDetails, loadResources) // this.unlisten = this.props.history.listen(() => { @@ -112,6 +116,14 @@ class ChallengeEditor extends Component { } } + async fetchProjectDetails (newMatch, loadProject) { + let projectId = _.get(newMatch.params, 'projectId', null) + projectId = projectId ? parseInt(projectId) : null + if (projectId) { + await loadProject(projectId) + } + } + async fetchChallengeDetails (newMatch, loadChallengeDetails, loadResources) { let projectId = _.get(newMatch.params, 'projectId', null) projectId = projectId ? parseInt(projectId) : null @@ -413,7 +425,8 @@ ChallengeEditor.propTypes = { partiallyUpdateChallengeDetails: PropTypes.func.isRequired, createChallenge: PropTypes.func.isRequired, deleteChallenge: PropTypes.func.isRequired, - replaceResourceInRole: PropTypes.func + replaceResourceInRole: PropTypes.func, + loadProject: PropTypes.func // members: PropTypes.arrayOf(PropTypes.shape()) } @@ -450,7 +463,8 @@ const mapDispatchToProps = { partiallyUpdateChallengeDetails, deleteChallenge, createChallenge, - replaceResourceInRole + replaceResourceInRole, + loadProject } export default withRouter(connect(mapStateToProps, mapDispatchToProps)(ChallengeEditor)) From 46f6345aba8483c5969904cbd05b89e2c3063605 Mon Sep 17 00:00:00 2001 From: C Dharmateja Date: Wed, 27 Jan 2021 13:17:51 +0000 Subject: [PATCH 2/3] fix: load project details once --- src/containers/ChallengeEditor/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/containers/ChallengeEditor/index.js b/src/containers/ChallengeEditor/index.js index ef20dc23..5198c8da 100644 --- a/src/containers/ChallengeEditor/index.js +++ b/src/containers/ChallengeEditor/index.js @@ -77,7 +77,8 @@ class ChallengeEditor extends Component { loadResourceRoles, loadChallengeDetails, loadResources, - loadProject + loadProject, + projectDetail } = this.props loadTimelineTemplates() loadChallengePhases() @@ -88,7 +89,9 @@ class ChallengeEditor extends Component { // loadChallengeTerms() loadGroups() loadResourceRoles() - this.fetchProjectDetails(match, loadProject) + if (!projectDetail.terms) { + this.fetchProjectDetails(match, loadProject) + } this.fetchChallengeDetails(match, loadChallengeDetails, loadResources) // this.unlisten = this.props.history.listen(() => { From 58ef9bee986c0d279a5f7300ac6cf77abfa7b4cd Mon Sep 17 00:00:00 2001 From: C Dharmateja Date: Thu, 28 Jan 2021 07:04:11 +0000 Subject: [PATCH 3/3] fix 2nd load of project details --- src/containers/ChallengeEditor/index.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/containers/ChallengeEditor/index.js b/src/containers/ChallengeEditor/index.js index 5198c8da..910c2f01 100644 --- a/src/containers/ChallengeEditor/index.js +++ b/src/containers/ChallengeEditor/index.js @@ -61,6 +61,7 @@ class ChallengeEditor extends Component { this.closeSuccessModal = this.closeSuccessModal.bind(this) this.onCloseTask = this.onCloseTask.bind(this) this.closeTask = this.closeTask.bind(this) + this.fetchProjectDetails = this.fetchProjectDetails.bind(this) } componentDidMount () { @@ -76,9 +77,7 @@ class ChallengeEditor extends Component { loadGroups, loadResourceRoles, loadChallengeDetails, - loadResources, - loadProject, - projectDetail + loadResources } = this.props loadTimelineTemplates() loadChallengePhases() @@ -89,11 +88,7 @@ class ChallengeEditor extends Component { // loadChallengeTerms() loadGroups() loadResourceRoles() - if (!projectDetail.terms) { - this.fetchProjectDetails(match, loadProject) - } this.fetchChallengeDetails(match, loadChallengeDetails, loadResources) - // this.unlisten = this.props.history.listen(() => { // const { isLoading } = this.props // if (!isLoading) { @@ -119,11 +114,11 @@ class ChallengeEditor extends Component { } } - async fetchProjectDetails (newMatch, loadProject) { + async fetchProjectDetails (newMatch) { let projectId = _.get(newMatch.params, 'projectId', null) projectId = projectId ? parseInt(projectId) : null if (projectId) { - await loadProject(projectId) + await this.props.loadProject(projectId) } } @@ -133,6 +128,9 @@ class ChallengeEditor extends Component { const challengeId = _.get(newMatch.params, 'challengeId', null) await loadResources(challengeId) loadChallengeDetails(projectId, challengeId) + if (!challengeId) { + this.fetchProjectDetails(newMatch) + } } isEditable () {