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

Affiliation apply to all projects #2673

Merged
merged 1 commit into from
Nov 5, 2024
Merged

Conversation

gaspergrom
Copy link
Contributor

@gaspergrom gaspergrom commented Nov 5, 2024

Changes proposed ✍️

What

copilot:summary

copilot:poem

Why

How

copilot:walkthrough

Checklist ✅

  • Label appropriately with Feature, Improvement, or Bug.
  • Add screenshots to the PR description for relevant FE changes
  • New backend functionality has been unit-tested.
  • API documentation has been updated (if necessary) (see docs on API documentation).
  • Quality standards are met.

Summary by CodeRabbit

  • New Features

    • Introduced a dropdown menu for managing affiliations with options to "Apply to all projects" and "Delete affiliation."
    • Added functionality to copy an affiliation to other projects.
  • Style

    • Adjusted layout widths for improved visual structure of the affiliations editing component.
  • Bug Fixes

    • Enhanced logic for handling affiliations while maintaining existing error handling and validation processes.

@gaspergrom gaspergrom added the Improvement Created by Linear-GitHub Sync label Nov 5, 2024
@gaspergrom gaspergrom self-assigned this Nov 5, 2024
Copy link

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes involve structural modifications to the layout of the contributor-affilations-edit-item.vue file, adjusting the widths of specific components. Additionally, the contributor-affilations-edit.vue file has been updated to replace a direct delete button with a dropdown menu for managing affiliations, which includes options for applying to all projects or deleting an affiliation. A new method for copying affiliations to other projects has also been introduced, enhancing the functionality while maintaining existing validation and error handling.

Changes

File Change Summary
frontend/src/modules/contributor/components/edit/affilations/contributor-affilations-edit-item.vue Adjusted widths of <div> elements for layout: first <div> from w-1/2 to w-5/12, second <div> from w-1/2 to w-7/12. No changes to logic or props.
frontend/src/modules/contributor/components/edit/affilations/contributor-affilations-edit.vue Replaced delete button with a dropdown for managing affiliations. Added method copyToOtherProjects. Imported LfDropdown and LfDropdownItem.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Dropdown
    participant AffiliationManager

    User->>Dropdown: Click "more" icon
    Dropdown->>User: Show options ("Apply to all projects", "Delete affiliation")
    User->>Dropdown: Select "Apply to all projects"
    Dropdown->>AffiliationManager: Call copyToOtherProjects()
    AffiliationManager-->>Dropdown: Update affiliations
Loading

🐰 "In the fields where bunnies play,
A dropdown blooms, brightening the day.
No more a button, just options to choose,
Affiliations managed, no more to lose!
With widths adjusted, the layout's a treat,
Hopping along, our work is complete!" 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
frontend/src/modules/contributor/components/edit/affilations/contributor-affilations-edit-item.vue (4)

Line range hint 67-71: Fix incorrect validation binding for end date picker.

The end date picker's error class is incorrectly bound to the start date's validation state:

:class="$v.dateStart.$invalid && $v.dateStart.$dirty ? 'is-error' : ''"

Apply this fix:

-:class="$v.dateStart.$invalid && $v.dateStart.$dirty ? 'is-error' : ''"
+:class="$v.dateEnd.$invalid && $v.dateEnd.$dirty ? 'is-error' : ''"

Line range hint 93-98: Consider externalizing validation messages for i18n support.

The hardcoded error messages should be moved to a translation system for better maintainability and internationalization support.

Consider using Vue i18n:

-:error-messages="{
-  required: 'This field is required',
-  minDate: 'This date range is not valid',
-}"
+:error-messages="{
+  required: $t('validation.required'),
+  minDate: $t('validation.dateRange.invalid'),
+}"

Line range hint 115-121: Enhance type safety for form interface.

The AffilationForm interface could be improved with more specific types and required fields.

Consider this enhancement:

 export interface AffilationForm {
-  segmentId: string;
-  organization: string | null,
-  dateStart: string;
-  dateEnd: string;
-  currentlyAffiliated: boolean;
+  segmentId: string;
+  organization: string | null;
+  dateStart: string;  // Consider using Date type
+  dateEnd: string | null;  // Optional when currentlyAffiliated is true
+  currentlyAffiliated: boolean;
+  readonly id?: string;  // For existing affiliations
 }

Line range hint 61-71: Consider making date format configurable.

The date format is hardcoded as "MMM YYYY". Consider making it configurable to support different format preferences.

Consider adding a prop:

+const props = defineProps<{
+  modelValue: AffilationForm,
+  contributor: Contributor,
+  dateFormat?: string,  // Add format prop
+}>();

 <el-date-picker
   ...
-  format="MMM YYYY"
+  :format="props.dateFormat || 'MMM YYYY'"
   ...
 />
frontend/src/modules/contributor/components/edit/affilations/contributor-affilations-edit.vue (1)

57-78: Consider adding confirmation dialogs and loading states.

The dropdown menu implementation looks good, but consider these UX improvements:

  1. Add a confirmation dialog for the delete action to prevent accidental deletions
  2. Add loading states to buttons during operations

Example implementation:

 <lf-dropdown-item
   type="danger"
+  :disabled="isLoading"
   @click="form.splice(ai, 1)"
 >
   <lf-icon-old name="delete-bin-6-line" /> Delete affiliation
 </lf-dropdown-item>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1d194bd and d79dbe9.

📒 Files selected for processing (2)
  • frontend/src/modules/contributor/components/edit/affilations/contributor-affilations-edit-item.vue (2 hunks)
  • frontend/src/modules/contributor/components/edit/affilations/contributor-affilations-edit.vue (3 hunks)
🔇 Additional comments (2)
frontend/src/modules/contributor/components/edit/affilations/contributor-affilations-edit-item.vue (1)

3-3: LGTM! Width adjustments improve the layout balance.

The asymmetric width distribution (5/12 for organization selector, 7/12 for date pickers) provides better space utilization, giving more room for the date picker controls which typically need more horizontal space.

Also applies to: 52-52

frontend/src/modules/contributor/components/edit/affilations/contributor-affilations-edit.vue (1)

122-123: LGTM!

The dropdown component imports follow the project's conventions and are properly organized.

Comment on lines +196 to +209
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,
});
});
};
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.

@gaspergrom gaspergrom merged commit 15e81f6 into main Nov 5, 2024
6 checks passed
@gaspergrom gaspergrom deleted the improvement/affiliations-copy branch November 5, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants