Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined featureFlagSegmentInclusion and featureFlagSegmentExclusion errors #1833

Merged
merged 7 commits into from
Aug 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ const reducer = createReducer(
const existingFlag = state.entities[featureFlag?.id];

if (existingFlag) {
const updatedInclusions = existingFlag.featureFlagSegmentInclusion.map((inclusion) =>
inclusion.segment.id === listResponse.segment.id ? listResponse : inclusion
);
const updatedInclusions =
existingFlag.featureFlagSegmentInclusion?.map((inclusion) =>
inclusion.segment.id === listResponse.segment.id ? listResponse : inclusion
) ?? [];

return adapter.updateOne(
{
Expand All @@ -174,14 +175,13 @@ const reducer = createReducer(
on(FeatureFlagsActions.actionDeleteFeatureFlagInclusionListSuccess, (state, { segmentId }) => {
const updatedState = { ...state, isLoadingUpsertPrivateSegmentList: false };
const flagId = Object.keys(state.entities).find((id) =>
state.entities[id].featureFlagSegmentInclusion.some((inclusion) => inclusion.segment.id === segmentId)
state.entities[id].featureFlagSegmentInclusion?.some((inclusion) => inclusion.segment.id === segmentId)
);

if (flagId) {
const flag = state.entities[flagId];
const updatedInclusions = flag.featureFlagSegmentInclusion.filter(
(inclusion) => inclusion.segment.id !== segmentId
);
const updatedInclusions =
flag.featureFlagSegmentInclusion?.filter((inclusion) => inclusion.segment.id !== segmentId) ?? [];

return adapter.updateOne(
{
Expand Down Expand Up @@ -226,9 +226,10 @@ const reducer = createReducer(
const existingFlag = state.entities[featureFlag?.id];

if (existingFlag) {
const updatedExclusions = existingFlag.featureFlagSegmentExclusion.map((exclusion) =>
exclusion.segment.id === listResponse.segment.id ? listResponse : exclusion
);
const updatedExclusions =
existingFlag.featureFlagSegmentExclusion?.map((exclusion) =>
exclusion.segment.id === listResponse.segment.id ? listResponse : exclusion
) ?? [];

return adapter.updateOne(
{
Expand All @@ -250,14 +251,13 @@ const reducer = createReducer(
on(FeatureFlagsActions.actionDeleteFeatureFlagExclusionListSuccess, (state, { segmentId }) => {
const updatedState = { ...state, isLoadingUpsertPrivateSegmentList: false };
const flagId = Object.keys(state.entities).find((id) =>
state.entities[id].featureFlagSegmentExclusion.some((exclusion) => exclusion.segment.id === segmentId)
state.entities[id].featureFlagSegmentExclusion?.some((exclusion) => exclusion.segment.id === segmentId)
);

if (flagId) {
const flag = state.entities[flagId];
const updatedExclusions = flag.featureFlagSegmentExclusion.filter(
(exclusion) => exclusion.segment.id !== segmentId
);
const updatedExclusions =
flag.featureFlagSegmentExclusion?.filter((exclusion) => exclusion.segment.id !== segmentId) ?? [];

return adapter.updateOne(
{
Expand Down
Loading