Skip to content

Commit

Permalink
refactor: improve person / organization switching
Browse files Browse the repository at this point in the history
- fix bug in contributor serializer when submitting an organization with
  only a given name and no email
- use ROR affiliations search generate Contributor.given_name, should
  find a way to limit jsonAffiliations and ResearchOrgListField to a
  single entry
- add reset button to reset contributor entirely if we want to start
  over but needs additional work, see below

TODO: reset works fine for new contributors but should also offer a
pathway to allow resetting and starting over with an existing
contributor. perhaps needs a clean way to clear the disabled attributes
for the entire modal, maybe bubble an event up to the ContributorsPage
component?
  • Loading branch information
alee committed Jun 11, 2024
1 parent bb25c37 commit bcda087
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 27 deletions.
4 changes: 3 additions & 1 deletion django/library/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ def check_unique_users(self, contributors):
if raw_user:
username = raw_user["username"]
user_map[username].append(contributor)
else:
elif contributor["type"] == "person":
contributors_map[contributor["email"]].append(contributor)
else:
contributors_map[contributor["given_name"]].append(contributor)

error_messages = []
for username, related_contributors in user_map.items():
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/form/ResearchOrgListField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export interface ResearchOrgListFieldProps {
const props = defineProps<ResearchOrgListFieldProps>();
onMounted(() => {
// FIXME: see if we can change `value` to a more meaningful variable name, e.g., `organizations`
if (!value.value) {
// force initialize to empty array
value.value = [];
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/form/SelectField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<select
v-else
:id="id"
:disabled="disabled"
v-bind="attrs"
:class="{ 'form-select': true, 'is-invalid': error }"
@change="updateValue"
Expand Down Expand Up @@ -45,6 +46,7 @@ export interface SelectFieldProps {
help?: string;
placeholder?: string;
required?: boolean;
disabled?: boolean;
options: { value: any; label: string }[];
}
Expand Down
73 changes: 50 additions & 23 deletions frontend/src/components/releaseEditor/ContributorEditForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
class="mb-3"
name="type"
label="Contributor Type"
@change="changeContributorType"
:options="typeOptions"
:disabled="disableEditForm"
required
/>
<div class="card mb-3">
<div v-if="isPerson" class="card-header">
<UserSearch
label="Search for an Existing User"
label="Search for an existing User"
placeholder="Skip entering contributor details by searching for users already in our system"
:search-fn="search"
:errors="profileErrors"
Expand All @@ -30,13 +32,21 @@
style="z-index: 3"
></div>
<div class="card-body">
<TextField
v-if="!isPerson"
class="mb-3"
name="givenName"
label="Organization Name"
required
/>
<div v-if="!isPerson">
<ResearchOrgListField
name="jsonAffiliations"
placeholder="Type to find organizations"
@change="setOrganizationGivenName"
label="Research Organization Registry Lookup"
/>
<TextField
class="mb-3"
name="givenName"
label="Organization Name"
disabled
required
/>
</div>
<div v-else class="row">
<div class="col-4 pe-0">
<TextField
Expand Down Expand Up @@ -65,20 +75,21 @@
/>
</div>
</div>
<TextField
v-if="isPerson"
class="mb-3"
name="email"
label="Email"
required
:disabled="disableEditForm"
/>
<ResearchOrgListField
name="jsonAffiliations"
placeholder="Type to find organizations"
label="Affiliations"
:disabled="disableEditForm"
/>
<div v-if="isPerson">
<TextField
class="mb-3"
name="email"
label="Email"
required
:disabled="disableEditForm"
/>
<ResearchOrgListField
name="jsonAffiliations"
placeholder="Type to find organizations"
label="Affiliations"
:disabled="disableEditForm"
/>
</div>
</div>
</div>
</div>
Expand All @@ -95,11 +106,12 @@
required
:disabled="disableEditForm"
/>
<CheckboxField name="includeInCitation" label="Include in Citation?" />
<CheckboxField name="includeInCitation" label="Include in citation?" />
<FormAlert :validation-errors="Object.values(errors)" :server-errors="serverErrors" />
</form>
</div>
<div class="modal-footer border-0">
<button type="button" class="btn btn-outline-gray" @click="resetContributor">Reset</button>
<button
type="reset"
class="btn btn-outline-gray"
Expand Down Expand Up @@ -299,12 +311,27 @@ function populateFromContributor(contributor: Contributor | null) {
});
}
function hasPersonData() {
return values.user || values.givenName || values.familyName || values.email;
}
function changeContributorType() {
// reset contributors if we switch to an organization and there was a previous user set
if (values.type === "organization" && hasPersonData()) {
resetContributor();
}
}
function resetContributor() {
setValues(initialValues);
serverErrors.value = [];
handleReset();
}
function setOrganizationGivenName() {
values.givenName = (values as any).jsonAffiliations[0].name;
}
function populateFromUser(user: any) {
setValues({
...values,
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/releaseEditor/ContributorsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div>
<p>
Please list the contributors that should be included in a citation for this software release.
Ordering is important, as is the role of the contributor. You can change ordering by dragging
contributors in the list.
Ordering is important, as are the contributor's role(s). Change contributor ordering by
dragging them in the list.
</p>
<p>
By default, we will always add the submitter (you) as a release contributor. There must be at
Expand All @@ -14,7 +14,8 @@
<div v-if="reordered">
<div class="alert alert-warning px-1 py-0 mb-2">
<small class="">
<i class="fas fa-info-circle"></i> Please save your changes once finished re-ordering
<i class="fas fa-info-circle"></i> Please save your changes after you're finished
re-ordering
</small>
</div>
<div class="d-flex justify-content-end">
Expand Down

0 comments on commit bcda087

Please sign in to comment.