From 66fe89bd358d442903abda88771800e2aa67172a Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Wed, 5 Jun 2024 23:32:19 +0100 Subject: [PATCH 1/4] Use version live from --- frontend/web/components/pages/ChangeRequestPage.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/web/components/pages/ChangeRequestPage.js b/frontend/web/components/pages/ChangeRequestPage.js index 9d69cbfc97e6..3ae000a87934 100644 --- a/frontend/web/components/pages/ChangeRequestPage.js +++ b/frontend/web/components/pages/ChangeRequestPage.js @@ -154,7 +154,9 @@ const ChangeRequestsPage = class extends Component { const isScheduled = new Date(changeRequest.feature_states[0].live_from).valueOf() > new Date().valueOf() - const scheduledDate = moment(changeRequest.feature_states[0].live_from) + const scheduledDate = changeRequest.feature_states + ? moment(changeRequest.feature_states[0].live_from) + : moment(changeRequest.environment_feature_versions[0].live_from) openConfirm({ body: ( @@ -256,7 +258,9 @@ const ChangeRequestsPage = class extends Component { new Date(changeRequest.feature_states[0].live_from).valueOf() > new Date().valueOf() - const scheduledDate = moment(changeRequest.feature_states[0].live_from) + const scheduledDate = changeRequest.feature_states + ? moment(changeRequest.feature_states[0].live_from) + : moment(changeRequest.environment_feature_versions[0].live_from) const approval = changeRequest && From 486a62096abc405ce42a60671dbe23c3bfeecd9b Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Thu, 6 Jun 2024 00:04:32 +0100 Subject: [PATCH 2/4] Update isScheduled --- .../web/components/pages/ChangeRequestPage.js | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/frontend/web/components/pages/ChangeRequestPage.js b/frontend/web/components/pages/ChangeRequestPage.js index 3ae000a87934..4d7495e7b02f 100644 --- a/frontend/web/components/pages/ChangeRequestPage.js +++ b/frontend/web/components/pages/ChangeRequestPage.js @@ -151,12 +151,10 @@ const ChangeRequestsPage = class extends Component { publishChangeRequest = () => { const id = this.props.match.params.id const changeRequest = ChangeRequestStore.model[id] - const isScheduled = - new Date(changeRequest.feature_states[0].live_from).valueOf() > - new Date().valueOf() - const scheduledDate = changeRequest.feature_states - ? moment(changeRequest.feature_states[0].live_from) - : moment(changeRequest.environment_feature_versions[0].live_from) + const scheduledDate = changeRequest.environment_feature_versions + ? moment(changeRequest.environment_feature_versions[0].live_from) + : moment(changeRequest.feature_states[0].live_from) + const isScheduled = scheduledDate > moment() openConfirm({ body: ( @@ -254,13 +252,11 @@ const ChangeRequestsPage = class extends Component { orgUsers && orgUsers.find((v) => v.id === changeRequest.committed_by)) || {} - const isScheduled = - new Date(changeRequest.feature_states[0].live_from).valueOf() > - new Date().valueOf() + const scheduledDate = changeRequest.environment_feature_versions + ? moment(changeRequest.environment_feature_versions[0].live_from) + : moment(changeRequest.feature_states[0].live_from) - const scheduledDate = changeRequest.feature_states - ? moment(changeRequest.feature_states[0].live_from) - : moment(changeRequest.environment_feature_versions[0].live_from) + const isScheduled = scheduledDate > moment() const approval = changeRequest && From 7f390a3a380f3ea60175444af490b8b656d84537 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Thu, 6 Jun 2024 00:30:21 +0100 Subject: [PATCH 3/4] Fix issue with existing scheduled changes --- frontend/web/components/pages/ChangeRequestPage.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/web/components/pages/ChangeRequestPage.js b/frontend/web/components/pages/ChangeRequestPage.js index 4d7495e7b02f..ec66fa1e6d59 100644 --- a/frontend/web/components/pages/ChangeRequestPage.js +++ b/frontend/web/components/pages/ChangeRequestPage.js @@ -151,9 +151,10 @@ const ChangeRequestsPage = class extends Component { publishChangeRequest = () => { const id = this.props.match.params.id const changeRequest = ChangeRequestStore.model[id] - const scheduledDate = changeRequest.environment_feature_versions - ? moment(changeRequest.environment_feature_versions[0].live_from) - : moment(changeRequest.feature_states[0].live_from) + const scheduledDate = + changeRequest.environment_feature_versions.length > 0 + ? moment(changeRequest.environment_feature_versions[0].live_from) + : moment(changeRequest.feature_states[0].live_from) const isScheduled = scheduledDate > moment() openConfirm({ @@ -252,9 +253,10 @@ const ChangeRequestsPage = class extends Component { orgUsers && orgUsers.find((v) => v.id === changeRequest.committed_by)) || {} - const scheduledDate = changeRequest.environment_feature_versions - ? moment(changeRequest.environment_feature_versions[0].live_from) - : moment(changeRequest.feature_states[0].live_from) + const scheduledDate = + changeRequest.environment_feature_versions.length > 0 + ? moment(changeRequest.environment_feature_versions[0].live_from) + : moment(changeRequest.feature_states[0].live_from) const isScheduled = scheduledDate > moment() From 052bcf5ead780f8a7600ba4f07b35063735d4396 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Thu, 6 Jun 2024 00:34:21 +0100 Subject: [PATCH 4/4] Remove code duplication --- .../web/components/pages/ChangeRequestPage.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/web/components/pages/ChangeRequestPage.js b/frontend/web/components/pages/ChangeRequestPage.js index ec66fa1e6d59..579b3cc6c581 100644 --- a/frontend/web/components/pages/ChangeRequestPage.js +++ b/frontend/web/components/pages/ChangeRequestPage.js @@ -148,13 +148,16 @@ const ChangeRequestsPage = class extends Component { AppActions.actionChangeRequest(this.props.match.params.id, 'approve') } + getScheduledDate = (changeRequest) => { + return changeRequest.environment_feature_versions.length > 0 + ? moment(changeRequest.environment_feature_versions[0].live_from) + : moment(changeRequest.feature_states[0].live_from) + } + publishChangeRequest = () => { const id = this.props.match.params.id const changeRequest = ChangeRequestStore.model[id] - const scheduledDate = - changeRequest.environment_feature_versions.length > 0 - ? moment(changeRequest.environment_feature_versions[0].live_from) - : moment(changeRequest.feature_states[0].live_from) + const scheduledDate = this.getScheduledDate(changeRequest) const isScheduled = scheduledDate > moment() openConfirm({ @@ -253,11 +256,8 @@ const ChangeRequestsPage = class extends Component { orgUsers && orgUsers.find((v) => v.id === changeRequest.committed_by)) || {} - const scheduledDate = - changeRequest.environment_feature_versions.length > 0 - ? moment(changeRequest.environment_feature_versions[0].live_from) - : moment(changeRequest.feature_states[0].live_from) + const scheduledDate = this.getScheduledDate(changeRequest) const isScheduled = scheduledDate > moment() const approval =