From 2194af0e6fb6bfac82816df1d863dd2cccb28272 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Tue, 10 Oct 2017 13:22:25 +0530 Subject: [PATCH 1/5] =?UTF-8?q?Github=20issue#1104,=20"Create=20a=20new=20?= =?UTF-8?q?project"=20action=20should=20consider=20the=20product=20from=20?= =?UTF-8?q?the=20URL=20=E2=80=94=20Added=20logic=20to=20direct=20user=20di?= =?UTF-8?q?rectly=20to=20the=20form=20details=20page=20when=20the=20deep?= =?UTF-8?q?=20link=20is=20for=20the=20same=20product=20as=20of=20the=20sav?= =?UTF-8?q?e=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/projects/create/components/ProjectWizard.jsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/projects/create/components/ProjectWizard.jsx b/src/projects/create/components/ProjectWizard.jsx index db5f264c0..8a2670308 100644 --- a/src/projects/create/components/ProjectWizard.jsx +++ b/src/projects/create/components/ProjectWizard.jsx @@ -48,10 +48,21 @@ class ProjectWizard extends Component { const incompleteProjectStr = window.localStorage.getItem(LS_INCOMPLETE_PROJECT) if(incompleteProjectStr) { const incompleteProject = JSON.parse(incompleteProjectStr) + // const incompleteProjectType = _.get(incompleteProject, 'type') + const incompleteProduct = _.get(incompleteProject, 'details.products[0]') + let wizardStep = WZ_STEP_INCOMP_PROJ_CONF + if (incompleteProduct && params && params.product) { + // assumes the params.product to be id of a product because incomplete project is set only + // after user selects a particular product + const product = findProduct(params.product, true) + if (product && product.id === incompleteProduct) { + wizardStep = WZ_STEP_FILL_PROJ_DETAILS + } + } this.setState({ project: update(this.state.project, {$merge : incompleteProject}), dirtyProject: update(this.state.dirtyProject, {$merge : incompleteProject}), - wizardStep: WZ_STEP_INCOMP_PROJ_CONF, + wizardStep: wizardStep, isProjectDirty: false }, () => { typeof onStepChange === 'function' && onStepChange(this.state.wizardStep) From cb0a5572abe2efde88011ed958c60d34fcc2a020 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Tue, 10 Oct 2017 13:24:06 +0530 Subject: [PATCH 2/5] =?UTF-8?q?Github=20issue#1104,=20"Create=20a=20new=20?= =?UTF-8?q?project"=20action=20should=20consider=20the=20product=20from=20?= =?UTF-8?q?the=20URL=20=E2=80=94=20Reverted=20the=20changes=20made=20for?= =?UTF-8?q?=20https://github.com/appirio-tech/connect-app/issues/1114=20be?= =?UTF-8?q?cause=20is=20creating=20more=20issues=20than=20solving=20a=20ra?= =?UTF-8?q?re=20problem.=20We=20need=20to=20fix=20it=20again=20using=20som?= =?UTF-8?q?e=20other=20approach.=20With=20this=20change,=20it=20is=20now?= =?UTF-8?q?=20saving=20the=20incomplete=20project=20only=20when=20the=20pr?= =?UTF-8?q?oject=20is=20dirty.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/projects/create/containers/CreateContainer.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/projects/create/containers/CreateContainer.jsx b/src/projects/create/containers/CreateContainer.jsx index 718607789..a73cb8a1f 100644 --- a/src/projects/create/containers/CreateContainer.jsx +++ b/src/projects/create/containers/CreateContainer.jsx @@ -108,9 +108,9 @@ class CreateConainer extends React.Component { // stores the incomplete project in local storage onLeave(e) {// eslint-disable-line no-unused-vars - const { wizardStep } = this.state - if (wizardStep === ProjectWizard.Steps.WZ_STEP_FILL_PROJ_DETAILS) {// Project Details step - console.log('saving incomplete project') + const { wizardStep, isProjectDirty } = this.state + if (wizardStep === ProjectWizard.Steps.WZ_STEP_FILL_PROJ_DETAILS && isProjectDirty) {// Project Details step + console.log('saving incomplete project', this.state.updatedProject) window.localStorage.setItem(LS_INCOMPLETE_PROJECT, JSON.stringify(this.state.updatedProject)) } // commenting alerts for the page unload and route change hooks as discussed From 752bb65252622af0c94e7c74f848342d590fde28 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Tue, 10 Oct 2017 14:15:06 +0530 Subject: [PATCH 3/5] =?UTF-8?q?Github=20issue#1104,=20"Create=20a=20new=20?= =?UTF-8?q?project"=20action=20should=20consider=20the=20product=20from=20?= =?UTF-8?q?the=20URL=20=E2=80=94=20added=20inline=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/projects/create/components/ProjectWizard.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/projects/create/components/ProjectWizard.jsx b/src/projects/create/components/ProjectWizard.jsx index 8a2670308..89436b4c8 100644 --- a/src/projects/create/components/ProjectWizard.jsx +++ b/src/projects/create/components/ProjectWizard.jsx @@ -55,6 +55,7 @@ class ProjectWizard extends Component { // assumes the params.product to be id of a product because incomplete project is set only // after user selects a particular product const product = findProduct(params.product, true) + // load project detais page directly if product of save project and deep link are the same if (product && product.id === incompleteProduct) { wizardStep = WZ_STEP_FILL_PROJ_DETAILS } From fd75dcd7b2664c04ab4729c69596a5a7cb7a1629 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Tue, 10 Oct 2017 18:03:17 +0530 Subject: [PATCH 4/5] =?UTF-8?q?Github=20issue#1235,=20Deep=20link=20doesn'?= =?UTF-8?q?t=20open=20proper=20page=20if=20a=20project=20was=20not=20compl?= =?UTF-8?q?eted=20and=20user=20clicks=20"Create=20New=20Project"=20?= =?UTF-8?q?=E2=80=94=20Preserving=20the=20project=E2=80=99s=20product=20wh?= =?UTF-8?q?ile=20creating=20new=20project=20from=20incomplete=20project=20?= =?UTF-8?q?screen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../create/components/ProjectWizard.jsx | 91 +++++++++++-------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/src/projects/create/components/ProjectWizard.jsx b/src/projects/create/components/ProjectWizard.jsx index 89436b4c8..58f8becc4 100644 --- a/src/projects/create/components/ProjectWizard.jsx +++ b/src/projects/create/components/ProjectWizard.jsx @@ -40,6 +40,7 @@ class ProjectWizard extends Component { this.handleStepChange = this.handleStepChange.bind(this) this.restoreCommonDetails = this.restoreCommonDetails.bind(this) this.handleWizardCancel = this.handleWizardCancel.bind(this) + this.loadProjectAndProductFromURL = this.loadProjectAndProductFromURL.bind(this) } componentDidMount() { @@ -48,16 +49,21 @@ class ProjectWizard extends Component { const incompleteProjectStr = window.localStorage.getItem(LS_INCOMPLETE_PROJECT) if(incompleteProjectStr) { const incompleteProject = JSON.parse(incompleteProjectStr) - // const incompleteProjectType = _.get(incompleteProject, 'type') const incompleteProduct = _.get(incompleteProject, 'details.products[0]') let wizardStep = WZ_STEP_INCOMP_PROJ_CONF if (incompleteProduct && params && params.product) { // assumes the params.product to be id of a product because incomplete project is set only // after user selects a particular product const product = findProduct(params.product, true) - // load project detais page directly if product of save project and deep link are the same - if (product && product.id === incompleteProduct) { - wizardStep = WZ_STEP_FILL_PROJ_DETAILS + if (product) { + // load project detais page directly if product of save project and deep link are the same + if (product.id === incompleteProduct) { + wizardStep = WZ_STEP_FILL_PROJ_DETAILS + } else { // for different product type, update local state with URL params + const projectType = findProductCategory(params.product) + _.set(incompleteProject, 'type', projectType.id) + _.set(incompleteProject, 'details.products[0]', product.id) + } } } this.setState({ @@ -73,20 +79,7 @@ class ProjectWizard extends Component { const updateQuery = {} let wizardStep = WZ_STEP_SELECT_PROJ_TYPE if (params && params.product) { - // first try the path param to be a project category - let projectType = findCategory(params.product, true) - if (projectType) {// if its a category - updateQuery['type'] = { $set : projectType.id } - wizardStep = WZ_STEP_SELECT_PROD_TYPE - } else { - // if it is not a category, it should be a product and we should be able to find a category for it - projectType = findProductCategory(params.product, true) - // finds product object from product alias - const product = findProduct(params.product, true) - updateQuery['type'] = { $set : projectType.id } - updateQuery['details'] = { products : { $set: [product.id] } } - wizardStep = WZ_STEP_FILL_PROJ_DETAILS - } + wizardStep = this.loadProjectAndProductFromURL(params.product, updateQuery) } // retrieve refCode from query param // TODO give warning after truncating @@ -118,22 +111,7 @@ class ProjectWizard extends Component { let wizardStep = type && product ? WZ_STEP_FILL_PROJ_DETAILS : null const updateQuery = {} if (params && params.product) { // if there exists product path param - // first try the path param to be a project category - let projectType = findCategory(params.product, true) - if (projectType) {// if its a category - updateQuery['type'] = { $set : projectType.id } - wizardStep = WZ_STEP_SELECT_PROD_TYPE - } else { - // if it is not a category, it should be a product and we should be able to find a category for it - projectType = findProductCategory(params.product, true) - // finds product object from product alias - const product = findProduct(params.product, true) - if (projectType) {// we can have `incomplete` as params.product - updateQuery['type'] = { $set : projectType.id } - updateQuery['details'] = { products : { $set: [product.id] } } - wizardStep = WZ_STEP_FILL_PROJ_DETAILS - } - } + wizardStep = this.loadProjectAndProductFromURL(params.product, updateQuery) } else { // if there is not product path param, it should be first step of the wizard updateQuery['type'] = { $set : null } updateQuery['details'] = { products : { $set: [] } } @@ -151,6 +129,33 @@ class ProjectWizard extends Component { } } + /** + * Loads project type and product from the given URL parameter. + * + * @param {string} urlParam URL parameter value which represents either project type or product + * @param {object} updateQuery query object which would be updated according to parsed project type and product + * + * @return {number} step where wizard should move after parsing the URL param + */ + loadProjectAndProductFromURL(urlParam, updateQuery) { + // first try the path param to be a project category + let projectType = findCategory(urlParam, true) + if (projectType) {// if its a category + updateQuery['type'] = { $set : projectType.id } + return WZ_STEP_SELECT_PROD_TYPE + } else { + // if it is not a category, it should be a product and we should be able to find a category for it + projectType = findProductCategory(urlParam, true) + // finds product object from product alias + const product = findProduct(urlParam, true) + if (projectType) {// we can have `incomplete` as params.product + updateQuery['type'] = { $set : projectType.id } + updateQuery['details'] = { products : { $set: [product.id] } } + return WZ_STEP_FILL_PROJ_DETAILS + } + } + } + /** * Loads incomplete project from the local storage and populates the state from that project. * It also moves the wizard to the project details step if there exists an incomplete project. @@ -175,14 +180,22 @@ class ProjectWizard extends Component { * Removed incomplete project from the local storage and resets the state. Also, moves wizard to the first step. */ removeIncompleteProject() { - const { onStepChange } = this.props + const { onStepChange, params, onProjectUpdate } = this.props + // remove incomplete project from local storage window.localStorage.removeItem(LS_INCOMPLETE_PROJECT) + const projectType = _.get(this.state.project, 'type') + const product = _.get(this.state.project, 'details.products[0]') + let wizardStep = WZ_STEP_SELECT_PROJ_TYPE + if (product) { + wizardStep = WZ_STEP_FILL_PROJ_DETAILS + } else if (projectType) { + wizardStep = WZ_STEP_SELECT_PROD_TYPE + } this.setState({ - project: { details: {} }, - dirtyProject: { details: {} }, - wizardStep: WZ_STEP_SELECT_PROJ_TYPE + wizardStep: wizardStep }, () => { - typeof onStepChange === 'function' && onStepChange(this.state.wizardStep) + typeof onProjectUpdate === 'function' && onProjectUpdate(this.state.dirtyProject, true) + typeof onStepChange === 'function' && onStepChange(this.state.wizardStep, this.state.project) }) } From 16f6985f7ecab5558895dd8dbbdd9d1068ee7406 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Wed, 11 Oct 2017 11:47:53 +0530 Subject: [PATCH 5/5] Fixed lint error --- src/projects/create/components/ProjectWizard.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/projects/create/components/ProjectWizard.jsx b/src/projects/create/components/ProjectWizard.jsx index 58f8becc4..e2e4a0526 100644 --- a/src/projects/create/components/ProjectWizard.jsx +++ b/src/projects/create/components/ProjectWizard.jsx @@ -180,7 +180,7 @@ class ProjectWizard extends Component { * Removed incomplete project from the local storage and resets the state. Also, moves wizard to the first step. */ removeIncompleteProject() { - const { onStepChange, params, onProjectUpdate } = this.props + const { onStepChange, onProjectUpdate } = this.props // remove incomplete project from local storage window.localStorage.removeItem(LS_INCOMPLETE_PROJECT) const projectType = _.get(this.state.project, 'type')