Skip to content

Commit c6836cd

Browse files
committed
solve conflicts
2 parents 210b0d7 + 54f3e48 commit c6836cd

File tree

8 files changed

+81
-30
lines changed

8 files changed

+81
-30
lines changed

api/environments/serializers.py

+10
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ def get_project(self, validated_data: dict = None) -> Project:
8686
)
8787

8888

89+
class EnvironmentRetrieveSerializerWithMetadata(EnvironmentSerializerWithMetadata):
90+
total_segment_overrides = serializers.IntegerField()
91+
92+
class Meta(EnvironmentSerializerWithMetadata.Meta):
93+
fields = EnvironmentSerializerWithMetadata.Meta.fields + (
94+
"total_segment_overrides",
95+
)
96+
read_only_fields = ("total_segment_overrides",)
97+
98+
8999
class CreateUpdateEnvironmentSerializer(
90100
ReadOnlyIfNotValidPlanMixin, EnvironmentSerializerWithMetadata
91101
):

api/environments/views.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import logging
55

6+
from django.db.models import Count
67
from django.utils.decorators import method_decorator
78
from drf_yasg import openapi
89
from drf_yasg.utils import swagger_auto_schema
@@ -41,6 +42,7 @@
4142
CloneEnvironmentSerializer,
4243
CreateUpdateEnvironmentSerializer,
4344
EnvironmentAPIKeySerializer,
45+
EnvironmentRetrieveSerializerWithMetadata,
4446
EnvironmentSerializerWithMetadata,
4547
WebhookSerializer,
4648
)
@@ -73,6 +75,8 @@ def get_serializer_class(self):
7375
return DeleteAllTraitKeysSerializer
7476
if self.action == "clone":
7577
return CloneEnvironmentSerializer
78+
if self.action == "retrieve":
79+
return EnvironmentRetrieveSerializerWithMetadata
7680
elif self.action in ("create", "update", "partial_update"):
7781
return CreateUpdateEnvironmentSerializer
7882
return EnvironmentSerializerWithMetadata
@@ -98,12 +102,20 @@ def get_queryset(self):
98102
return (
99103
self.request.master_api_key.organisation.projects.environments.all()
100104
)
105+
101106
return self.request.user.get_permitted_environments(
102107
"VIEW_ENVIRONMENT", project=project
103108
)
104109

105110
# Permission class handles validation of permissions for other actions
106-
return Environment.objects.all()
111+
queryset = Environment.objects.all()
112+
113+
if self.action == "retrieve":
114+
queryset = queryset.annotate(
115+
total_segment_overrides=Count("feature_segments")
116+
)
117+
118+
return queryset
107119

108120
def perform_create(self, serializer):
109121
environment = serializer.save()

api/projects/serializers.py

-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ class Meta:
3939
def get_migration_status(self, obj: Project) -> str:
4040
if not settings.PROJECT_METADATA_TABLE_NAME_DYNAMO:
4141
migration_status = ProjectIdentityMigrationStatus.NOT_APPLICABLE.value
42-
4342
elif obj.is_edge_project_by_default:
4443
migration_status = ProjectIdentityMigrationStatus.MIGRATION_COMPLETED.value
45-
4644
else:
4745
migration_status = IdentityMigrator(obj.id).migration_status.value
4846

api/projects/tests/test_serializers.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
from django.utils import timezone
55

66
from environments.dynamodb.types import ProjectIdentityMigrationStatus
7-
from projects.serializers import ProjectListSerializer
7+
from projects.serializers import (
8+
ProjectListSerializer,
9+
ProjectRetrieveSerializer,
10+
)
811

912

1013
def test_ProjectListSerializer_get_migration_status_returns_migration_not_applicable_if_not_configured(
@@ -86,3 +89,24 @@ def test_ProjectListSerializer_get_use_edge_identities(
8689

8790
# When/Then
8891
assert expected is serializer.get_use_edge_identities(project)
92+
93+
94+
@pytest.mark.parametrize(
95+
"migration_status, expected",
96+
[
97+
(ProjectIdentityMigrationStatus.MIGRATION_COMPLETED.value, True),
98+
(ProjectIdentityMigrationStatus.MIGRATION_IN_PROGRESS.value, False),
99+
(ProjectIdentityMigrationStatus.MIGRATION_NOT_STARTED.value, False),
100+
(ProjectIdentityMigrationStatus.NOT_APPLICABLE.value, False),
101+
],
102+
)
103+
def test_ProjectRetrieveSerializer_get_use_edge_identities(
104+
project, migration_status, expected
105+
):
106+
# Given
107+
serializer = ProjectRetrieveSerializer(
108+
context={"migration_status": migration_status}
109+
)
110+
111+
# When/Then
112+
assert expected is serializer.get_use_edge_identities(project)

api/tests/unit/projects/test_unit_projects_views.py

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def test_get_project_data_by_id(client, organisation, project):
7171

7272
# When
7373
response = client.get(url)
74-
print("DEBUG: response:", response.json())
7574

7675
# Then
7776
assert response.status_code == status.HTTP_200_OK

frontend/web/components/modals/CreateSegment.tsx

+31-18
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import JSONReference from 'components/JSONReference'
3636
import { cloneDeep } from 'lodash'
3737
import ErrorMessage from 'components/ErrorMessage'
3838
import ProjectStore from 'common/stores/project-store'
39+
import Icon from 'components/Icon'
3940

4041
type PageType = {
4142
number: number
@@ -135,20 +136,13 @@ const CreateSegment: FC<CreateSegmentType> = ({
135136

136137
const isError = createError || updateError
137138
const isLimitReached =
138-
ProjectStore.getTotalSegments() >= ProjectStore.getMaxFeaturesAllowed()
139+
ProjectStore.getTotalSegments() >= ProjectStore.getMaxSegmentsAllowed()
139140

140141
const THRESHOLD = 90
141142
const segmentsLimitAlert = Utils.calculateRemainingLimitsPercentage(
142143
ProjectStore.getTotalSegments(),
143-
ProjectStore.getMaxFeaturesAllowed(),
144-
THRESHOLD,
145-
)
146-
147-
console.log(
148-
'DEBUG: ProjectStore.getTotalSegments()c:',
149-
ProjectStore.getTotalSegments(),
150-
'ProjectStore.getMaxSegmentsAllowed()c:',
151144
ProjectStore.getMaxSegmentsAllowed(),
145+
THRESHOLD,
152146
)
153147

154148
const addRule = (type = 'ANY') => {
@@ -526,6 +520,7 @@ const CreateSegment: FC<CreateSegmentType> = ({
526520
title='Environment'
527521
component={
528522
<EnvironmentSelect
523+
projectId={`${projectId}`}
529524
value={environmentId}
530525
onChange={(environmentId: string) => {
531526
setEnvironmentId(environmentId)
@@ -600,17 +595,35 @@ const CreateSegment: FC<CreateSegmentType> = ({
600595
<div className='font-weight-medium'>
601596
{identifier}
602597
</div>
603-
<div
604-
className={`${
605-
inSegment
606-
? 'font-weight-medium text-primary'
607-
: 'text-muted fs-small lh-sm'
598+
<Row
599+
className={`font-weight-medium fs-small lh-sm ${
600+
inSegment ? 'text-primary' : 'faint'
608601
}`}
609602
>
610-
{inSegment
611-
? 'User in segment'
612-
: 'Not in segment'}
613-
</div>
603+
{inSegment ? (
604+
<>
605+
<Icon
606+
name='checkmark-circle'
607+
width={20}
608+
fill='#6837FC'
609+
/>
610+
<span className='ml-1'>
611+
User in segment
612+
</span>
613+
</>
614+
) : (
615+
<>
616+
<Icon
617+
name='minus-circle'
618+
width={20}
619+
fill='#9DA4AE'
620+
/>
621+
<span className='ml-1'>
622+
Not in segment
623+
</span>
624+
</>
625+
)}
626+
</Row>
614627
</Row>
615628
)
616629
}}

frontend/web/components/pages/FeaturesPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const FeaturesPage = class extends Component {
174174
const isLoading = !FeatureListStore.hasLoaded
175175
const THRESHOLD = 90
176176
const featureLimitAlert = Utils.calculateRemainingLimitsPercentage(
177-
100,
177+
totalFeatures,
178178
maxFeaturesAllowed,
179179
THRESHOLD,
180180
)

frontend/web/components/pages/SegmentsPage.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,7 @@ const SegmentsPage: FC<SegmentsPageType> = (props) => {
7676
ProjectStore.getMaxSegmentsAllowed(),
7777
THRESHOLD,
7878
)
79-
console.log(
80-
'DEBUG: ProjectStore.getTotalSegments():',
81-
ProjectStore.getTotalSegments(),
82-
'ProjectStore.getMaxSegmentsAllowed():',
83-
ProjectStore.getMaxSegmentsAllowed(),
84-
)
79+
8580
useEffect(() => {
8681
API.trackPage(Constants.pages.FEATURES)
8782
}, [])

0 commit comments

Comments
 (0)