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

organizations: updated knownOrganizations to use id #1260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading