Skip to content
Merged
Show file tree
Hide file tree
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
@@ -1,6 +1,6 @@
<template>
<div class="flex w-full gap-3">
<div class="w-1/2">
<div class="w-5/12">
<el-select
v-model="form.organization"
filterable
Expand Down Expand Up @@ -49,7 +49,7 @@
</el-option>
</el-select>
</div>
<div class="w-1/2">
<div class="w-7/12">
<div class="flex items-center">
<el-date-picker
:model-value="!form.organization ? '' : form.dateStart"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,28 @@
v-model="form[ai]"
:contributor="props.contributor"
>
<lf-button
type="secondary-ghost"
class="ml-2"
:icon-only="true"
@click="form.splice(ai, 1)"
>
<lf-icon-old name="delete-bin-6-line" />
</lf-button>
<lf-dropdown placement="bottom-end" width="14rem">
<template #trigger>
<lf-button
type="secondary-ghost"
class="ml-2 my-1"
:icon-only="true"
>
<lf-icon-old name="more-fill" />
</lf-button>
</template>
<lf-dropdown-item
@click="copyToOtherProjects(ai)"
>
<lf-icon-old name="file-copy-line" /> Apply to all projects
</lf-dropdown-item>
<lf-dropdown-item
type="danger"
@click="form.splice(ai, 1)"
>
<lf-icon-old name="delete-bin-6-line" /> Delete affiliation
</lf-dropdown-item>
</lf-dropdown>
</lf-contributor-edit-affilations-item>
</template>
</template>
Expand Down Expand Up @@ -105,6 +119,8 @@ import LfContributorEditAffilationsItem
import useVuelidate from '@vuelidate/core';
import Message from '@/shared/message/message';
import moment from 'moment';
import LfDropdown from '@/ui-kit/dropdown/Dropdown.vue';
import LfDropdownItem from '@/ui-kit/dropdown/DropdownItem.vue';

const props = defineProps<{
modelValue: boolean,
Expand Down Expand Up @@ -177,6 +193,21 @@ const isProjectInvalid = (projectId: string) => form.value.some((affiliation) =>

const hasFormChanged = computed(() => JSON.stringify(form.value) !== JSON.stringify(initialForm.value));

const copyToOtherProjects = (index: number) => {
const affiliation = form.value[index];
const otherProjects = props.contributor.segments.filter((seg) => seg.id !== affiliation.segmentId);

otherProjects.forEach((project) => {
form.value.push({
segmentId: project.id,
organization: affiliation.organization,
dateStart: affiliation.dateStart,
dateEnd: affiliation.dateEnd,
currentlyAffiliated: affiliation.currentlyAffiliated,
});
});
};
Comment on lines +196 to +209
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add validation and error handling to copyToOtherProjects.

The method successfully copies affiliations but could benefit from additional safeguards:

  1. Validate if similar affiliations already exist in target projects
  2. Add error handling and loading state management
  3. Provide user feedback about the operation's success/failure

Here's a suggested implementation:

-const copyToOtherProjects = (index: number) => {
+const copyToOtherProjects = async (index: number) => {
+  try {
+    sending.value = true;
     const affiliation = form.value[index];
     const otherProjects = props.contributor.segments.filter((seg) => seg.id !== affiliation.segmentId);
 
+    // Check for existing similar affiliations
+    const duplicates = otherProjects.filter(project => 
+      form.value.some(existing => 
+        existing.segmentId === project.id && 
+        existing.organization === affiliation.organization &&
+        existing.dateStart === affiliation.dateStart
+      )
+    );
+
+    if (duplicates.length > 0) {
+      Message.warning(`Similar affiliations already exist in ${duplicates.length} project(s)`);
+      return;
+    }
+
     otherProjects.forEach((project) => {
       form.value.push({
         segmentId: project.id,
@@ -206,6 +223,13 @@
         currentlyAffiliated: affiliation.currentlyAffiliated,
       });
     });
+
+    Message.success(`Affiliation copied to ${otherProjects.length} project(s)`);
+  } catch (error) {
+    Message.error('Failed to copy affiliations');
+  } finally {
+    sending.value = false;
+  }
 };

Committable suggestion skipped: line range outside the PR's diff.


onMounted(() => {
form.value = props.contributor.affiliations.map((affiliation) => ({
segmentId: affiliation.segmentId || '',
Expand Down