Skip to content

Commit 6cf0b6d

Browse files
committed
Merge remote-tracking branch 'github/main' into fix/metrics-availability
2 parents 1c6f557 + fcae6b4 commit 6cf0b6d

4 files changed

Lines changed: 94 additions & 91 deletions

File tree

frontend/web/components/CompareEnvironments.js

Lines changed: 73 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class CompareEnvironments extends Component {
4444
}
4545

4646
fetch = () => {
47+
if (!this.state.environmentLeft || !this.state.environmentRight) {
48+
return
49+
}
4750
this.setState({ isLoading: true })
4851
return Promise.all([
4952
data.get(
@@ -66,70 +69,76 @@ class CompareEnvironments extends Component {
6669
data.get(
6770
`${Project.api}environments/${this.state.environmentRight}/featurestates/?page_size=999`,
6871
),
69-
]).then(
70-
([
71-
environmentLeftProjectFlags,
72-
environmentRightProjectFlags,
73-
environmentLeftFlags,
74-
environmentRightFlags,
75-
]) => {
76-
const changes = []
77-
const same = []
78-
_.each(
79-
_.sortBy(environmentLeftProjectFlags.results, (p) => p.name),
80-
(projectFlagLeft) => {
81-
const projectFlagRight = environmentRightProjectFlags.results?.find(
82-
(projectFlagRight) => projectFlagRight.id === projectFlagLeft.id,
83-
)
84-
const leftSide = environmentLeftFlags.results.find(
85-
(v) => v.feature === projectFlagLeft.id,
86-
)
87-
const rightSide = environmentRightFlags.results.find(
88-
(v) => v.feature === projectFlagLeft.id,
89-
)
90-
const change = {
91-
leftEnabled: leftSide.enabled,
92-
leftEnvironmentFlag: leftSide,
93-
leftValue: leftSide.feature_state_value,
94-
projectFlagLeft,
95-
projectFlagRight,
96-
rightEnabled: rightSide.enabled,
97-
rightEnvironmentFlag: rightSide,
98-
rightValue: rightSide.feature_state_value,
99-
}
100-
change.enabledChanged = change.rightEnabled !== change.leftEnabled
101-
change.valueChanged = change.rightValue !== change.leftValue
102-
if (
103-
change.enabledChanged ||
104-
change.valueChanged ||
105-
projectFlagLeft.num_identity_overrides ||
106-
projectFlagLeft.num_segment_overrides ||
107-
projectFlagRight.num_identity_overrides ||
108-
projectFlagRight.num_segment_overrides
109-
) {
110-
changes.push(change)
111-
} else {
112-
same.push(change)
113-
}
114-
},
115-
)
116-
this.setState({
117-
changes,
118-
environmentLeftFlags: _.keyBy(
119-
environmentLeftFlags.results,
120-
'feature',
121-
),
122-
environmentRightFlags: _.keyBy(
123-
environmentRightFlags.results,
124-
'feature',
125-
),
126-
isLoading: false,
127-
projectFlagsLeft: environmentLeftProjectFlags.results,
128-
projectFlagsRight: environmentLeftProjectFlags.results,
129-
same,
130-
})
131-
},
132-
)
72+
])
73+
.then(
74+
([
75+
environmentLeftProjectFlags,
76+
environmentRightProjectFlags,
77+
environmentLeftFlags,
78+
environmentRightFlags,
79+
]) => {
80+
const changes = []
81+
const same = []
82+
_.each(
83+
_.sortBy(environmentLeftProjectFlags.results, (p) => p.name),
84+
(projectFlagLeft) => {
85+
const projectFlagRight =
86+
environmentRightProjectFlags.results?.find(
87+
(projectFlagRight) =>
88+
projectFlagRight.id === projectFlagLeft.id,
89+
)
90+
const leftSide = environmentLeftFlags.results.find(
91+
(v) => v.feature === projectFlagLeft.id,
92+
)
93+
const rightSide = environmentRightFlags.results.find(
94+
(v) => v.feature === projectFlagLeft.id,
95+
)
96+
const change = {
97+
leftEnabled: leftSide.enabled,
98+
leftEnvironmentFlag: leftSide,
99+
leftValue: leftSide.feature_state_value,
100+
projectFlagLeft,
101+
projectFlagRight,
102+
rightEnabled: rightSide.enabled,
103+
rightEnvironmentFlag: rightSide,
104+
rightValue: rightSide.feature_state_value,
105+
}
106+
change.enabledChanged = change.rightEnabled !== change.leftEnabled
107+
change.valueChanged = change.rightValue !== change.leftValue
108+
if (
109+
change.enabledChanged ||
110+
change.valueChanged ||
111+
projectFlagLeft.num_identity_overrides ||
112+
projectFlagLeft.num_segment_overrides ||
113+
projectFlagRight.num_identity_overrides ||
114+
projectFlagRight.num_segment_overrides
115+
) {
116+
changes.push(change)
117+
} else {
118+
same.push(change)
119+
}
120+
},
121+
)
122+
this.setState({
123+
changes,
124+
environmentLeftFlags: _.keyBy(
125+
environmentLeftFlags.results,
126+
'feature',
127+
),
128+
environmentRightFlags: _.keyBy(
129+
environmentRightFlags.results,
130+
'feature',
131+
),
132+
isLoading: false,
133+
projectFlagsLeft: environmentLeftProjectFlags.results,
134+
projectFlagsRight: environmentLeftProjectFlags.results,
135+
same,
136+
})
137+
},
138+
)
139+
.catch(() => {
140+
this.setState({ isLoading: false })
141+
})
133142
}
134143

135144
onSave = () => this.fetch()

frontend/web/components/CompareIdentities.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ const CompareIdentities: FC<CompareIdentitiesType> = ({
5959
}) => {
6060
const [leftId, setLeftId] = useState<IdentitySelectType['value']>()
6161
const [rightId, setRightId] = useState<IdentitySelectType['value']>()
62-
const { data: projectFlags, refetch } = useGetProjectFlagsQuery({
63-
environment: ProjectStore.getEnvironmentIdFromKey(_environmentId),
64-
project: projectId,
65-
})
62+
const envId = ProjectStore.getEnvironmentIdFromKey(_environmentId)
63+
const { data: projectFlags, refetch } = useGetProjectFlagsQuery(
64+
{
65+
environment: envId,
66+
project: projectId,
67+
},
68+
{ skip: !envId || !projectId },
69+
)
6670
const [environmentId, setEnvironmentId] = useState(_environmentId)
6771
const [showArchived, setShowArchived] = useState(false)
6872

@@ -74,11 +78,11 @@ const CompareIdentities: FC<CompareIdentitiesType> = ({
7478

7579
const { data: leftUser } = useGetIdentityFeatureStatesAllQuery(
7680
{ environment: environmentId, user: `${leftId?.value}` },
77-
{ skip: !leftId },
81+
{ skip: !leftId || !environmentId },
7882
)
7983
const { data: rightUser } = useGetIdentityFeatureStatesAllQuery(
8084
{ environment: environmentId, user: `${rightId?.value}` },
81-
{ skip: !rightId },
85+
{ skip: !rightId || !environmentId },
8286
)
8387
const [createCloneIdentityFeatureStates] =
8488
useCreateCloneIdentityFeatureStatesMutation()

frontend/web/components/IdentitySelect.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ const IdentitySelect: FC<IdentitySelectType> = ({
2828
const { data, isLoading, loadMore, searchItems } = useInfiniteScroll<
2929
Req['getIdentities'],
3030
Res['identities']
31-
>(useGetIdentitiesQuery, {
32-
environmentId,
33-
isEdge,
34-
page_size: 10,
35-
})
31+
>(
32+
useGetIdentitiesQuery,
33+
{
34+
environmentId,
35+
isEdge,
36+
page_size: 10,
37+
},
38+
500,
39+
{ skip: !environmentId },
40+
)
3641
const identityOptions = useMemo(() => {
3742
return filter(
3843
data?.results,

frontend/web/components/modals/create-feature/index.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -775,22 +775,7 @@ const Index = class extends Component {
775775
this.props.changeRequest.id,
776776
ignore_conflicts,
777777
live_from,
778-
multivariate_options: this.props
779-
.multivariate_options
780-
? this.props.multivariate_options.map((v) => {
781-
const matching =
782-
projectFlag.multivariate_options.find(
783-
(m) =>
784-
m.id ===
785-
v.multivariate_feature_option,
786-
)
787-
return {
788-
...v,
789-
percentage_allocation:
790-
matching.default_percentage_allocation,
791-
}
792-
})
793-
: projectFlag.multivariate_options,
778+
multivariate_options: flag.multivariate_options,
794779
title,
795780
},
796781
!is4Eyes,

0 commit comments

Comments
 (0)