Skip to content

Commit

Permalink
fix: allow only one Organization to be set when adding an Organizatio…
Browse files Browse the repository at this point in the history
…n Contributor; hide "Reset" button when editing Contributor through prop.
  • Loading branch information
asuworks committed Jun 12, 2024
1 parent c415a31 commit 22789b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
21 changes: 19 additions & 2 deletions frontend/src/components/form/ResearchOrgListField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</template>

<script setup lang="ts">
import { inject, ref, onMounted, reactive, computed } from "vue";
import { inject, ref, onMounted, reactive, computed, watch } from "vue";
import { string } from "yup";
import { Sortable } from "sortablejs-vue3";
import type { SortableEvent } from "sortablejs";
Expand All @@ -119,16 +119,26 @@ export interface ResearchOrgListFieldProps {
placeholder?: string;
required?: boolean;
disabled?: boolean;
isContributorOrganization?: boolean;
}
const props = defineProps<ResearchOrgListFieldProps>();
const emit = defineEmits(["change"]);
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 = [];
}
// set givenName in the ContributorEditForm whenever value (selected organization) changes
watch(
() => value,
() => {
emit("change");
},
{ deep: true }
);
});
const showCustomInput = ref(false);
Expand Down Expand Up @@ -173,6 +183,13 @@ function createCustom() {
}
function create(organization: Organization) {
// only one organization is allowed if Contributor is Organization
if (props.isContributorOrganization && value.value.length > 0) {
value.value = [];
value.value.push(organization);
return;
}
if (!value.value.some(e => e.name === organization.name)) {
value.value.push(organization);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
id="add-contributor-form"
:show-custom-input="showCustomInput"
:disable-edit-form="disableEditForm"
:is-edit="false"
ref="editFormRef"
@success="() => editContributorModal?.hide()"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
name="jsonAffiliations"
placeholder="Type to find organizations"
@change="setOrganizationGivenName"
:is-contributor-organization="!isPerson"
label="Research Organization Registry Lookup"
/>
<TextField
Expand Down Expand Up @@ -111,7 +112,9 @@
</form>
</div>
<div class="modal-footer border-0">
<button v-if="!disableEditForm" type="button" class="btn btn-outline-gray" @click="resetContributor">Reset</button>
<button v-if="!isEdit" type="button" class="btn btn-outline-gray" @click="resetContributor">
Reset
</button>
<button
type="reset"
class="btn btn-outline-gray"
Expand Down Expand Up @@ -154,10 +157,12 @@ const props = withDefaults(
disableEditForm?: boolean;
contributor?: ReleaseContributor;
onSuccess?: () => void;
isEdit?: boolean;
}>(),
{
showCustomInput: false,
disableEditForm: true,
isEdit: true,
}
);
Expand Down

0 comments on commit 22789b1

Please sign in to comment.