Skip to content

Commit 0005985

Browse files
committed
shows info message after creating a new change request
1 parent 3bc2893 commit 0005985

File tree

2 files changed

+75
-33
lines changed

2 files changed

+75
-33
lines changed

frontend/web/components/ExistingChangeRequestAlert.tsx

+18-31
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,35 @@
1-
import { FC, useRef } from 'react'
2-
import { useGetChangeRequestsQuery } from 'common/services/useChangeRequest'
3-
import moment from 'moment'
1+
import { FC } from 'react'
42
import InfoMessage from './InfoMessage'
53
import { RouterChildContext } from 'react-router-dom'
64
import Button from './base/forms/Button'
5+
import { ChangeRequestSummary } from 'common/types/responses'
76

87
type ExistingChangeRequestAlertType = {
8+
changeRequests: ChangeRequestSummary[]
9+
editingChangeRequest?: ChangeRequestSummary
10+
scheduledChangeRequests: ChangeRequestSummary[]
911
projectId: number | string
1012
environmentId: string
11-
featureId: number
1213
className?: string
1314
history: RouterChildContext['router']['history']
1415
}
1516

1617
const ExistingChangeRequestAlert: FC<ExistingChangeRequestAlertType> = ({
18+
changeRequests,
1719
className,
20+
editingChangeRequest,
1821
environmentId,
19-
featureId,
2022
history,
2123
projectId,
24+
scheduledChangeRequests,
2225
}) => {
23-
const date = useRef(moment().toISOString())
24-
25-
const { data: changeRequests } = useGetChangeRequestsQuery(
26-
{
27-
committed: false,
28-
environmentId,
29-
feature_id: featureId,
30-
},
31-
{ refetchOnMountOrArgChange: true },
32-
)
33-
34-
const { data: scheduledChangeRequests } = useGetChangeRequestsQuery(
35-
{
36-
environmentId,
37-
feature_id: featureId,
38-
live_from_after: date.current,
39-
},
40-
{ refetchOnMountOrArgChange: true },
41-
)
42-
4326
const handleNavigate = () => {
44-
const changes = scheduledChangeRequests?.results?.length
45-
? scheduledChangeRequests?.results
46-
: changeRequests?.results
47-
const latestChangeRequest = changes?.at(-1)?.id
27+
const changes = scheduledChangeRequests?.length
28+
? scheduledChangeRequests
29+
: changeRequests
30+
const latestChangeRequest = !editingChangeRequest?.id
31+
? changes?.at(-1)?.id
32+
: editingChangeRequest?.id
4833
closeModal()
4934
history.push(
5035
`/project/${projectId}/environment/${environmentId}/change-requests/${latestChangeRequest}`,
@@ -71,10 +56,12 @@ const ExistingChangeRequestAlert: FC<ExistingChangeRequestAlertType> = ({
7156
}
7257

7358
const requestChangeInfoText = getRequestChangeInfoText(
74-
!!scheduledChangeRequests?.results?.length,
75-
!!changeRequests?.results?.length,
59+
!!scheduledChangeRequests?.length,
60+
!!changeRequests?.length,
7661
)
7762

63+
console.log({ requestChangeInfoText })
64+
7865
if (!requestChangeInfoText?.length) {
7966
return null
8067
}

frontend/web/components/modals/CreateFlag.js

+57-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { Component } from 'react'
22
import withSegmentOverrides from 'common/providers/withSegmentOverrides'
3+
import moment from 'moment'
34
import Constants from 'common/constants'
45
import data from 'common/data/base/_data'
56
import ProjectStore from 'common/stores/project-store'
@@ -47,6 +48,7 @@ import PlanBasedBanner from 'components/PlanBasedAccess'
4748
import FeatureHistory from 'components/FeatureHistory'
4849
import WarningMessage from 'components/WarningMessage'
4950
import { getPermission } from 'common/services/usePermission'
51+
import { getChangeRequests } from 'common/services/useChangeRequest'
5052

5153
const CreateFlag = class extends Component {
5254
static displayName = 'CreateFlag'
@@ -78,6 +80,7 @@ const CreateFlag = class extends Component {
7880
}
7981
this.state = {
8082
allowEditDescription,
83+
changeRequests: [],
8184
default_enabled: enabled,
8285
description,
8386
enabledIndentity: false,
@@ -106,6 +109,7 @@ const CreateFlag = class extends Component {
106109
multivariate_options: _.cloneDeep(multivariate_options),
107110
name,
108111
period: 30,
112+
scheduledChangeRequests: [],
109113
selectedIdentity: null,
110114
tags: tags?.filter((tag) => !hideTags.includes(tag)) || [],
111115
}
@@ -201,6 +205,9 @@ const CreateFlag = class extends Component {
201205
})
202206
}
203207

208+
this.fetchChangeRequests()
209+
this.fetchScheduledChangeRequests()
210+
204211
getGithubIntegration(getStore(), {
205212
organisation_id: AccountStore.getOrganisation().id,
206213
}).then((res) => {
@@ -543,6 +550,43 @@ const CreateFlag = class extends Component {
543550
this.forceUpdate()
544551
}
545552

553+
fetchChangeRequests = (forceRefetch) => {
554+
const { environmentId, projectFlag } = this.props
555+
if (!projectFlag?.id) return
556+
557+
getChangeRequests(
558+
getStore(),
559+
{
560+
committed: false,
561+
environmentId,
562+
feature_id: projectFlag?.id,
563+
},
564+
{ forceRefetch },
565+
).then((res) => {
566+
this.setState({ changeRequests: res.data?.results })
567+
})
568+
}
569+
570+
fetchScheduledChangeRequests = (forceRefetch) => {
571+
const { environmentId, projectFlag } = this.props
572+
if (!projectFlag?.id) return
573+
574+
const date = moment().toISOString()
575+
576+
console.log('data', date)
577+
getChangeRequests(
578+
getStore(),
579+
{
580+
environmentId,
581+
feature_id: projectFlag.id,
582+
live_from_after: date,
583+
},
584+
{ forceRefetch },
585+
).then((res) => {
586+
this.setState({ scheduledChangeRequests: res.data?.results })
587+
})
588+
}
589+
546590
render() {
547591
const {
548592
default_enabled,
@@ -579,6 +623,9 @@ const CreateFlag = class extends Component {
579623
let regexValid = true
580624
const metadataEnable = Utils.getPlansPermission('METADATA')
581625

626+
const { changeRequests, scheduledChangeRequests } = this.state
627+
console.log({ changeRequests, out: true, scheduledChangeRequests })
628+
582629
try {
583630
if (!isEdit && name && regex) {
584631
regexValid = name.match(new RegExp(regex))
@@ -745,15 +792,18 @@ const CreateFlag = class extends Component {
745792

746793
const Value = (error, projectAdmin, createFeature, hideValue) => {
747794
const { featureError, featureWarning } = this.parseError(error)
795+
const { changeRequests, scheduledChangeRequests } = this.state
748796
return (
749797
<>
750-
{!!isEdit && (
798+
{!!isEdit && !identity && (
751799
<ExistingChangeRequestAlert
752800
className='mb-4'
801+
editingChangeRequest={this.props.changeRequest}
753802
projectId={this.props.projectId}
754-
featureId={projectFlag.id}
755803
environmentId={this.props.environmentId}
756804
history={this.props.history}
805+
changeRequests={changeRequests}
806+
scheduledChangeRequests={scheduledChangeRequests}
757807
/>
758808
)}
759809
{!isEdit && (
@@ -888,6 +938,11 @@ const CreateFlag = class extends Component {
888938
this.props.projectId,
889939
this.props.environmentId,
890940
)
941+
942+
if (is4Eyes && !identity) {
943+
this.fetchChangeRequests(true)
944+
this.fetchScheduledChangeRequests(true)
945+
}
891946
}}
892947
>
893948
{(

0 commit comments

Comments
 (0)