Skip to content

Commit 8dc92c3

Browse files
Zaimwa9pre-commit-ci[bot]
andauthored
feat: MetadataModelRequirement uses organisation ID as objectID (✅ relies on #5325 - deployed) (#5326)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4c5043d commit 8dc92c3

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

api/tests/unit/metadata/test_serializers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ def test_metadata_serializer_validate_validates_field_value_type_correctly(
7272
"project",
7373
False,
7474
"The requirement organisation does not match the field organisation",
75-
lambda **kwargs: kwargs["metadata_field"].organisation.id,
75+
lambda **kwargs: 9999,
7676
),
7777
(
7878
"organisation",
7979
False,
8080
"The requirement organisation does not match the field organisation",
81-
lambda **kwargs: kwargs["project"].id,
81+
lambda **kwargs: 9999,
8282
),
8383
],
8484
)
@@ -99,7 +99,7 @@ def test_metadata_model_field_serializer_validation(
9999
else project_content_type
100100
)
101101
object_id = get_object_id(project=project, metadata_field=a_metadata_field)
102-
102+
print(f"Metadata field org_id: {a_metadata_field.organisation.id}")
103103
# Given
104104
data: Dict[str, Any] = {
105105
"field": a_metadata_field.id,

frontend/web/components/metadata/MetadataPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type MetadataPageType = {
1818
organisationId: string
1919
projectId: string
2020
}
21+
2122
type MergeMetadata = {
2223
content_type_fields: MetadataModelField[]
2324
id: number
@@ -48,7 +49,7 @@ const MetadataPage: FC<MetadataPageType> = ({ organisationId, projectId }) => {
4849
...item1,
4950
content_type_fields: matchingItems2,
5051
}
51-
})
52+
})?.sort((a, b) => a.id - b.id)
5253
}
5354
return null
5455
}, [metadataFieldList, MetadataModelFieldList])
@@ -63,7 +64,6 @@ const MetadataPage: FC<MetadataPageType> = ({ organisationId, projectId }) => {
6364
<CreateMetadataField
6465
onComplete={metadataCreatedToast}
6566
organisationId={organisationId}
66-
projectId={projectId}
6767
isEdit={false}
6868
/>,
6969
'side-modal create-feature-modal',
@@ -80,7 +80,6 @@ const MetadataPage: FC<MetadataPageType> = ({ organisationId, projectId }) => {
8080
onComplete={() => {
8181
toast('Custom Field Updated')
8282
}}
83-
projectId={projectId}
8483
organisationId={organisationId}
8584
/>,
8685
'side-modal create-feature-modal',
@@ -179,6 +178,7 @@ const MetadataPage: FC<MetadataPageType> = ({ organisationId, projectId }) => {
179178
}
180179
/>
181180
</FormGroup>
181+
182182
</PlanBasedBanner>
183183
)
184184
}

frontend/web/components/modals/CreateMetadataField.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ type CreateMetadataFieldType = {
3232
metadataModelFieldList?: MetadataModelField[]
3333
onComplete?: () => void
3434
organisationId: string
35-
projectId: string
3635
}
3736

3837
type QueryBody = Omit<MetadataModelField, 'id'>
@@ -54,13 +53,17 @@ type metadataFieldUpdatedSelectListType = MetadataModelField & {
5453
new: boolean
5554
}
5655

56+
export enum MetadataContentType {
57+
ORGANISATION = 'organisation',
58+
PROJECT = 'project',
59+
}
60+
5761
const CreateMetadataField: FC<CreateMetadataFieldType> = ({
5862
id,
5963
isEdit,
6064
metadataModelFieldList,
6165
onComplete,
6266
organisationId,
63-
projectId,
6467
}) => {
6568
const metadataTypes: MetadataType[] = [
6669
{ id: 1, label: 'int', value: 'int' },
@@ -88,9 +91,10 @@ const CreateMetadataField: FC<CreateMetadataFieldType> = ({
8891
const [updateMetadataModelField] = useUpdateMetadataModelFieldMutation()
8992

9093
const [deleteMetadataModelField] = useDeleteMetadataModelFieldMutation()
91-
const projectContentType: ContentType =
92-
supportedContentTypes &&
93-
Utils.getContentType(supportedContentTypes, 'model', 'project')
94+
const metadataContentType: ContentType =
95+
supportedContentTypes &&
96+
Utils.getContentType(supportedContentTypes, 'model', MetadataContentType.ORGANISATION)
97+
9498
useEffect(() => {
9599
if (data && !isLoading) {
96100
setName(data.name)
@@ -142,8 +146,8 @@ const CreateMetadataField: FC<CreateMetadataFieldType> = ({
142146
is_required_for: isRequiredFor
143147
? ([
144148
{
145-
content_type: projectContentType.id,
146-
object_id: parseInt(projectId),
149+
content_type: metadataContentType.id,
150+
object_id: parseInt(organisationId),
147151
} as isRequiredFor,
148152
] as isRequiredFor[])
149153
: [],
@@ -191,8 +195,8 @@ const CreateMetadataField: FC<CreateMetadataFieldType> = ({
191195
const query = generateDataQuery(
192196
m.content_type,
193197
m.field,
194-
m.is_required_for,
195-
m.id,
198+
!!m.is_required_for,
199+
parseInt(m.id),
196200
m.new,
197201
)
198202
if (!m.removed && !m.new) {

0 commit comments

Comments
 (0)