|
1 | 1 | import React, { Component } from 'react'
|
2 | 2 | import withSegmentOverrides from 'common/providers/withSegmentOverrides'
|
| 3 | +import moment from 'moment' |
3 | 4 | import Constants from 'common/constants'
|
4 | 5 | import data from 'common/data/base/_data'
|
5 | 6 | import ProjectStore from 'common/stores/project-store'
|
@@ -47,6 +48,7 @@ import PlanBasedBanner from 'components/PlanBasedAccess'
|
47 | 48 | import FeatureHistory from 'components/FeatureHistory'
|
48 | 49 | import WarningMessage from 'components/WarningMessage'
|
49 | 50 | import { getPermission } from 'common/services/usePermission'
|
| 51 | +import { getChangeRequests } from 'common/services/useChangeRequest' |
50 | 52 |
|
51 | 53 | const CreateFlag = class extends Component {
|
52 | 54 | static displayName = 'CreateFlag'
|
@@ -78,6 +80,7 @@ const CreateFlag = class extends Component {
|
78 | 80 | }
|
79 | 81 | this.state = {
|
80 | 82 | allowEditDescription,
|
| 83 | + changeRequests: [], |
81 | 84 | default_enabled: enabled,
|
82 | 85 | description,
|
83 | 86 | enabledIndentity: false,
|
@@ -106,6 +109,7 @@ const CreateFlag = class extends Component {
|
106 | 109 | multivariate_options: _.cloneDeep(multivariate_options),
|
107 | 110 | name,
|
108 | 111 | period: 30,
|
| 112 | + scheduledChangeRequests: [], |
109 | 113 | selectedIdentity: null,
|
110 | 114 | tags: tags?.filter((tag) => !hideTags.includes(tag)) || [],
|
111 | 115 | }
|
@@ -201,6 +205,9 @@ const CreateFlag = class extends Component {
|
201 | 205 | })
|
202 | 206 | }
|
203 | 207 |
|
| 208 | + this.fetchChangeRequests() |
| 209 | + this.fetchScheduledChangeRequests() |
| 210 | + |
204 | 211 | getGithubIntegration(getStore(), {
|
205 | 212 | organisation_id: AccountStore.getOrganisation().id,
|
206 | 213 | }).then((res) => {
|
@@ -543,6 +550,43 @@ const CreateFlag = class extends Component {
|
543 | 550 | this.forceUpdate()
|
544 | 551 | }
|
545 | 552 |
|
| 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 | + |
546 | 590 | render() {
|
547 | 591 | const {
|
548 | 592 | default_enabled,
|
@@ -579,6 +623,9 @@ const CreateFlag = class extends Component {
|
579 | 623 | let regexValid = true
|
580 | 624 | const metadataEnable = Utils.getPlansPermission('METADATA')
|
581 | 625 |
|
| 626 | + const { changeRequests, scheduledChangeRequests } = this.state |
| 627 | + console.log({ changeRequests, out: true, scheduledChangeRequests }) |
| 628 | + |
582 | 629 | try {
|
583 | 630 | if (!isEdit && name && regex) {
|
584 | 631 | regexValid = name.match(new RegExp(regex))
|
@@ -745,15 +792,18 @@ const CreateFlag = class extends Component {
|
745 | 792 |
|
746 | 793 | const Value = (error, projectAdmin, createFeature, hideValue) => {
|
747 | 794 | const { featureError, featureWarning } = this.parseError(error)
|
| 795 | + const { changeRequests, scheduledChangeRequests } = this.state |
748 | 796 | return (
|
749 | 797 | <>
|
750 |
| - {!!isEdit && ( |
| 798 | + {!!isEdit && !identity && ( |
751 | 799 | <ExistingChangeRequestAlert
|
752 | 800 | className='mb-4'
|
| 801 | + editingChangeRequest={this.props.changeRequest} |
753 | 802 | projectId={this.props.projectId}
|
754 |
| - featureId={projectFlag.id} |
755 | 803 | environmentId={this.props.environmentId}
|
756 | 804 | history={this.props.history}
|
| 805 | + changeRequests={changeRequests} |
| 806 | + scheduledChangeRequests={scheduledChangeRequests} |
757 | 807 | />
|
758 | 808 | )}
|
759 | 809 | {!isEdit && (
|
@@ -888,6 +938,11 @@ const CreateFlag = class extends Component {
|
888 | 938 | this.props.projectId,
|
889 | 939 | this.props.environmentId,
|
890 | 940 | )
|
| 941 | + |
| 942 | + if (is4Eyes && !identity) { |
| 943 | + this.fetchChangeRequests(true) |
| 944 | + this.fetchScheduledChangeRequests(true) |
| 945 | + } |
891 | 946 | }}
|
892 | 947 | >
|
893 | 948 | {(
|
|
0 commit comments