Skip to content

Commit

Permalink
organizations: updated knownOrganizations to use id
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 committed Dec 9, 2024
1 parent dcc8682 commit 3f8e1b2
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ class CommunityProfileForm extends Component {
// create a map with all organizations that are not custom (part of the
// vocabulary), so that on form submission, newly custom organization input
// by the user can be identified and correctly sent to the backend.
const organizationsNames = initialValues.metadata.organizations.map((org) => {
const organizations = initialValues.metadata.organizations.map((org) => {
const isNonCustomOrganization = org.id;
if (isNonCustomOrganization) {
this.knownOrganizations[org.name] = org.id;
this.knownOrganizations[org.id] = org.name;
return org.id; // For known organizations, return the id
} else {
return org.name; // For custom organizations, return the name
}
return org.name;
});

_unset(initialValues, "metadata.type.title");
Expand Down Expand Up @@ -206,7 +208,7 @@ class CommunityProfileForm extends Component {
...initialValues,
metadata: {
...initialValues.metadata,
organizations: organizationsNames,
organizations: organizations,
funding,
},
};
Expand Down Expand Up @@ -270,13 +272,11 @@ class CommunityProfileForm extends Component {
// Serialize organisations. If it is known and has an id, serialize a pair 'id/name'. Otherwise use 'name' only
const organizations = submittedCommunity.metadata.organizations.map(
(organization) => {
const orgID = this.knownOrganizations[organization];
return {
...(orgID && { id: orgID }),
name: organization,
};
const orgName = this.knownOrganizations[organization];
return orgName ? { id: organization, name: orgName } : { name: organization };
}
);

// Serialize each funding record, award being optional.
const funding = submittedCommunity.metadata?.funding?.map((fund) => {
return {
Expand Down Expand Up @@ -474,12 +474,12 @@ class CommunityProfileForm extends Component {
organizations.forEach((organization) => {
// eslint-disable-next-line no-prototype-builtins
const isKnownOrg = this.knownOrganizations.hasOwnProperty(
organization.name
organization.id
);
if (!isKnownOrg) {
this.knownOrganizations = {
...this.knownOrganizations,
[organization.name]: organization.id,
[organization.id]: organization.name,
};
}
});
Expand Down

0 comments on commit 3f8e1b2

Please sign in to comment.