Skip to content

Commit 6fbdc3c

Browse files
committed
refactor: put logic into class methods
1 parent 4ae4f00 commit 6fbdc3c

File tree

1 file changed

+69
-84
lines changed

1 file changed

+69
-84
lines changed

src/projects/create/containers/CreateContainer.jsx

Lines changed: 69 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ class CreateContainer extends React.Component {
8484
this.onLeave = this.onLeave.bind(this)
8585
this.closeWizard = this.closeWizard.bind(this)
8686
this.prepareProjectForCreation = this.prepareProjectForCreation.bind(this)
87-
this.createContainerView = this.createContainerView.bind(this)
8887
this.addProjectAttachment = this.addProjectAttachment.bind(this)
8988
this.removeProjectAttachment = this.removeProjectAttachment.bind(this)
9089
this.updatePendingAttachment = this.updatePendingAttachment.bind(this)
90+
this.handleProjectUpdate = this.handleProjectUpdate.bind(this)
91+
this.handleWizardStepChange = this.handleWizardStepChange.bind(this)
9192

9293
if (!props.userRoles || props.userRoles.length <= 0) {
9394
window.location = `${ACCOUNTS_APP_LOGIN_URL}?retUrl=${window.location.href}`
@@ -295,90 +296,59 @@ class CreateContainer extends React.Component {
295296
}
296297
}
297298

298-
createContainerView() {
299+
handleWizardStepChange(wizardStep, updatedProject) {
299300
const { templates: { projectTemplates, projectTypes }, orgConfig } = this.props
301+
const projectTypeKey = _.get(updatedProject, 'type', null)
300302

301-
return (
302-
<EnhancedCreateView
303-
{...this.props}
304-
createProject={ this.createProject }
305-
processing={ this.state.creatingProject}
306-
createdProject={ this.state.createdProject }
307-
projectId={ this.state.projectId }
308-
showModal
309-
closeModal={ this.closeWizard }
310-
onStepChange={ (wizardStep, updatedProject) => {
311-
const projectTypeKey = _.get(updatedProject, 'type', null)
312-
let projectType = getProjectTypeByKey(projectTypes, projectTypeKey)
313-
if (!projectType) {
314-
projectType = getProjectTypeByAlias(projectTypes, projectTypeKey)
315-
}
316-
317-
const typeAlias = _.get(projectType, 'aliases[0]')
318-
319-
const projectTemplateId = _.get(updatedProject, 'templateId', null)
320-
const projectTemplate = _.find(projectTemplates, pt => pt.id === projectTemplateId)
321-
const templateAlias = _.get(projectTemplate, 'aliases[0]')
322-
323-
let link
324-
if (wizardStep === ProjectWizard.Steps.WZ_STEP_INCOMP_PROJ_CONF) {
325-
let productUrl = templateAlias ? ('/' + templateAlias) : ''
326-
productUrl = !templateAlias && typeAlias ? ('/' + typeAlias) : productUrl
327-
this.props.history.push(NEW_PROJECT_PATH + productUrl + '/incomplete' + window.location.search)
328-
}
329-
330-
if (wizardStep === ProjectWizard.Steps.WZ_STEP_SELECT_PROJ_TYPE) {
331-
link = getNewProjectLink(orgConfig)
332-
if(/^https?:\/\//.test(link)) {
333-
window.location = link
334-
} else {
335-
this.props.history.push(link + '/' + window.location.search)
336-
}
337-
}
338-
339-
if (typeAlias && wizardStep === ProjectWizard.Steps.WZ_STEP_SELECT_PROJ_TEMPLATE) {
340-
this.props.history.push(NEW_PROJECT_PATH + '/' + typeAlias + window.location.search)
341-
}
342-
343-
if (typeAlias && templateAlias && wizardStep === ProjectWizard.Steps.WZ_STEP_FILL_PROJ_DETAILS) {
344-
this.props.history.push(NEW_PROJECT_PATH + '/' + templateAlias + window.location.search)
345-
}
346-
347-
if (typeAlias && templateAlias && wizardStep === ProjectWizard.Steps.WZ_STEP_PROJECT_SUBMITTED) {
348-
this.props.history.push(NEW_PROJECT_PATH + '/' + 'submitted' + window.location.search)
349-
}
350-
351-
this.setState({
352-
wizardStep,
353-
})
354-
}
355-
}
356-
onProjectUpdate={ (updatedProject, dirty=true) => {
357-
// const projectType = _.get(this.state.updatedProject, 'type', null)
358-
const prevProduct = _.get(this.state.updatedProject, 'templateId', null)
359-
const product = _.get(updatedProject, 'templateId', null)
360-
// compares updated product with previous product to know if user has updated the product
361-
if (prevProduct !== product) {
362-
if (product) {
363-
// intentionally commented because now it should not be require as we handling all URL changes in onStepChange
364-
// earlier we were not getting updated project in onStepChange handler, hence it was required here
365-
// still leaving it here for next few release, in case we find any issue because of commenting this line
366-
// this.props.history.push(NEW_PROJECT_PATH + '/' + product + window.location.search)
367-
}
368-
}
369-
this.setState({
370-
isProjectDirty: dirty,
371-
updatedProject
372-
})
373-
}
374-
}
375-
projectTemplates={this.props.templates.projectTemplates}
376-
projectTypes={this.props.templates.projectTypes}
377-
addAttachment={this.addProjectAttachment}
378-
updateAttachment={this.updatePendingAttachment}
379-
removeAttachment={this.removeProjectAttachment}
380-
/>
381-
)
303+
let projectType = getProjectTypeByKey(projectTypes, projectTypeKey)
304+
if (!projectType) {
305+
projectType = getProjectTypeByAlias(projectTypes, projectTypeKey)
306+
}
307+
308+
const typeAlias = _.get(projectType, 'aliases[0]')
309+
310+
const projectTemplateId = _.get(updatedProject, 'templateId', null)
311+
const projectTemplate = _.find(projectTemplates, pt => pt.id === projectTemplateId)
312+
const templateAlias = _.get(projectTemplate, 'aliases[0]')
313+
314+
let link
315+
if (wizardStep === ProjectWizard.Steps.WZ_STEP_INCOMP_PROJ_CONF) {
316+
let productUrl = templateAlias ? ('/' + templateAlias) : ''
317+
productUrl = !templateAlias && typeAlias ? ('/' + typeAlias) : productUrl
318+
this.props.history.push(NEW_PROJECT_PATH + productUrl + '/incomplete' + window.location.search)
319+
}
320+
321+
if (wizardStep === ProjectWizard.Steps.WZ_STEP_SELECT_PROJ_TYPE) {
322+
link = getNewProjectLink(orgConfig)
323+
if(/^https?:\/\//.test(link)) {
324+
window.location = link
325+
} else {
326+
this.props.history.push(link + '/' + window.location.search)
327+
}
328+
}
329+
330+
if (typeAlias && wizardStep === ProjectWizard.Steps.WZ_STEP_SELECT_PROJ_TEMPLATE) {
331+
this.props.history.push(NEW_PROJECT_PATH + '/' + typeAlias + window.location.search)
332+
}
333+
334+
if (typeAlias && templateAlias && wizardStep === ProjectWizard.Steps.WZ_STEP_FILL_PROJ_DETAILS) {
335+
this.props.history.push(NEW_PROJECT_PATH + '/' + templateAlias + window.location.search)
336+
}
337+
338+
if (typeAlias && templateAlias && wizardStep === ProjectWizard.Steps.WZ_STEP_PROJECT_SUBMITTED) {
339+
this.props.history.push(NEW_PROJECT_PATH + '/' + 'submitted' + window.location.search)
340+
}
341+
342+
this.setState({
343+
wizardStep,
344+
})
345+
}
346+
347+
handleProjectUpdate(updatedProject, dirty=true) {
348+
this.setState({
349+
isProjectDirty: dirty,
350+
updatedProject
351+
})
382352
}
383353

384354
addProjectAttachment(attachment) {
@@ -412,7 +382,22 @@ class CreateContainer extends React.Component {
412382

413383
return (
414384
<WizardWrapper className="WizardCreateProject" type={type}>
415-
{ this.createContainerView() }
385+
<EnhancedCreateView
386+
{...this.props}
387+
createProject={this.createProject}
388+
processing={this.state.creatingProject}
389+
createdProject={this.state.createdProject}
390+
projectId={this.state.projectId}
391+
showModal
392+
closeModal={this.closeWizard}
393+
onStepChange={this.handleWizardStepChange}
394+
onProjectUpdate={this.handleProjectUpdate}
395+
projectTemplates={this.props.templates.projectTemplates}
396+
projectTypes={this.props.templates.projectTypes}
397+
addAttachment={this.addProjectAttachment}
398+
updateAttachment={this.updatePendingAttachment}
399+
removeAttachment={this.removeProjectAttachment}
400+
/>
416401
</WizardWrapper>
417402
)
418403
}

0 commit comments

Comments
 (0)