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

Shutov/ #2582 [tech Admin/ Users] Added functionality to proccesses deleting of child`s data #2587

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from

Conversation

MarianS23
Copy link
Contributor

@MarianS23 MarianS23 commented Jun 25, 2024

also added modal window, translate, and enums for "deleting Parent`s data method" for further implementation

Summary by CodeRabbit

Release Notes

  • New Features

    • Added ability to conditionally display "Delete User" button based on user role
    • Introduced new confirmation modal type for deleting parent entities
  • Enhancements

    • Updated user list component to restrict delete functionality
    • Added optional pib property to child model
  • Bug Fixes

    • Implemented role-based access control for user deletion

MarianS23 and others added 9 commits July 6, 2024 11:53
…n' should contain the information about selection specified on the workshop page (#2584)

* Created 'getWorkshopCompetitiveSelectionDescriptionById' method in UserWorkshopService
Changed info-status template to show competitive selection description if user has applicationStatus AcceptedForSelection

* fix tests

* lint fix

* lint fix

* replaced 'toString' method with enum in 'if' statement

* fixed formatting of inside *ngIf
…ng fix (#2594)

* First version

* Dvorak / 2549 Burger menu, name of the menu tab and indicator positioning fix

* Minor update

* Changed camelCase to kebab-case
MarianS23 and others added 9 commits July 16, 2024 14:23
…parent already has 20 children (#2585)

* Disabled 'Add another child' button when the parent already has 20 children.
Added information button with pop-up message when the parent already has 20 children.

* error fix

* error fix

* Changed checking of children array length in template to a variable

* renamed 'has20Children' variable to 'isChildLimitReached'. Replaced comparing to 20 with CHILDREN_AMOUNT_MAX constant
* added method of unreadMessages in chat

* Removed question mark in translation

* Add applications count example endpoint, state, badges for cabinet

* Add provider.service tests

* Update chat.state.ts

* Update uk.json

* Changed endpoint, refactored application service docs, moved method to application service, add tests

* Made pendingApplications as search response, add role check

* Add null-safety for template

* Add test

* Add support icon & fixed notification badge style

* Add unreadNotificationsCount support

* Removed notifications-list amount test assertions since it's managed by notifications.component

* Add accepted for selection notification declination

* Fixed fetching of pending application after application update and badge empty bug

* Fixed changing notifications amount by tab navigation

* Test enhancement

* Resolved code review comments

* Removed unused imports in personal-cabinet.component

---------

Co-authored-by: doliinyk <[email protected]>
Co-authored-by: Denys Oliinyk <[email protected]>
* Fixed lint warnings

* Fixed Sonar issues

* Added lint-staged and pre-commit hook by husky

* Lint & Prettier fixes

* lintstagedrc config change

* Lint/prettier fix
Copy link

Copy link

Copy link

coderabbitai bot commented Jan 26, 2025

Walkthrough

This pull request introduces functionality to delete child users with role-based restrictions. The changes span multiple files, adding a new delete option for child users in the admin tools section. The implementation includes conditional rendering of the delete button, a new modal confirmation type, and methods to handle child user deletion with appropriate dialog and action dispatching.

Changes

File Change Summary
src/app/shared/components/users-list/users-list.component.html Added conditional rendering for delete button based on user role
src/app/shared/components/users-list/users-list.component.ts Imported UserTabsTitles and added as a public readonly property
src/app/shared/enum/modal-confirmation.ts Added new deleteParent enum values for modal confirmations
src/app/shared/models/child.model.ts Added optional pib property to Child class
src/app/shell/admin-tools/data/users/users.component.html Added (delete) event binding for child deletion
src/app/shell/admin-tools/data/users/users.component.ts Implemented onDeleteChild and deleteChild methods for child deletion

Sequence Diagram

sequenceDiagram
    participant User
    participant UsersListComponent
    participant UsersComponent
    participant DialogService
    participant Store

    User->>UsersListComponent: Click Delete Button
    UsersListComponent->>UsersComponent: Emit delete event
    UsersComponent->>DialogService: Open Confirmation Dialog
    DialogService-->>UsersComponent: Dialog Result
    alt Confirmed
        UsersComponent->>Store: Dispatch DeleteChildById Action
    else Cancelled
        UsersComponent->>UsersComponent: No Action
    end
Loading

Poem

🐰 A Rabbit's Deletion Tale 🗑️

With buttons that hide and roles that decide,
A child's delete dance, now carefully tried.
Confirmations pop up, with wisdom so neat,
Our admin tools now have a new, careful beat!
Delete with precision, no chaos in sight! 🎉

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 3

🧹 Nitpick comments (4)
src/app/shared/models/child.model.ts (1)

19-19: Consider using a more descriptive property name.

The property name pib is not self-descriptive. Consider renaming it to something more meaningful like displayName or fullName to better indicate its purpose in the UI.

-  pib?: string;
+  displayName?: string;
src/app/shell/admin-tools/data/users/users.component.ts (1)

127-129: Improve method documentation.

The current documentation is too basic. Add more details about the parameters and the confirmation flow.

 /**
- * This method delete child By Id
+ * Deletes a child after showing a confirmation dialog.
+ * @param child - The child entity to be deleted
+ * @throws {Error} When deletion fails
  */
src/app/shell/admin-tools/data/users/users.component.spec.ts (1)

224-234: Enhance mock data quality in tests.

The mock child object contains several empty strings and null values. Consider using meaningful test data to make the tests more realistic and maintainable.

 mockChild = {
   id: 'childId',
   firstName: 'John',
   lastName: 'Doe',
-  parentId: '',
-  dateOfBirth: '',
+  parentId: 'parent123',
+  dateOfBirth: '2010-01-01',
   gender: 0,
-  isParent: null,
-  placeOfStudy: '',
+  isParent: false,
+  placeOfStudy: 'School #1',
   pib: 'qwerty'
 };
src/app/shared/components/users-list/users-list.component.html (1)

136-136: Consider extracting the role check to a method.

The condition user.role === UserTabsTitles.child could be moved to a method in the component class for better reusability and testability.

  1. Add a method to the component class:
isChildUser(user: User): boolean {
  return user.role === UserTabsTitles.child;
}
  1. Update the template:
-<button *ngIf="user.role === UserTabsTitles.child" mat-menu-item (click)="delete.emit(user)">
+<button *ngIf="isChildUser(user)" mat-menu-item (click)="delete.emit(user)">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ba50be and b65d744.

⛔ Files ignored due to path filters (2)
  • src/assets/i18n/en.json is excluded by !src/assets/** and included by src/**
  • src/assets/i18n/uk.json is excluded by !src/assets/** and included by src/**
📒 Files selected for processing (7)
  • src/app/shared/components/users-list/users-list.component.html (1 hunks)
  • src/app/shared/components/users-list/users-list.component.ts (2 hunks)
  • src/app/shared/enum/modal-confirmation.ts (3 hunks)
  • src/app/shared/models/child.model.ts (1 hunks)
  • src/app/shell/admin-tools/data/users/users.component.html (1 hunks)
  • src/app/shell/admin-tools/data/users/users.component.spec.ts (2 hunks)
  • src/app/shell/admin-tools/data/users/users.component.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: SonarCloud
🔇 Additional comments (4)
src/app/shared/components/users-list/users-list.component.ts (1)

9-9: LGTM!

The addition of UserTabsTitles follows Angular best practices for component properties and supports role-based conditional rendering.

Also applies to: 38-38

src/app/shell/admin-tools/data/users/users.component.spec.ts (2)

254-264: LGTM! Comprehensive test coverage.

The test properly verifies that the deleteChild method is called with correct parameters upon confirmation.


242-246: Verify the modal width constant.

Add a test to verify that the Constants.MODAL_SMALL value matches the expected width for consistency across the application.

src/app/shell/admin-tools/data/users/users.component.html (1)

35-39: LGTM! Clean event binding implementation.

The delete event binding follows the established pattern and maintains consistency with other event bindings.

Comment on lines +204 to +206
private deleteChild(id: string, params: ChildrenParameters): void {
this.store.dispatch(new DeleteChildById(id, params));
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add return type for better error handling.

The deleteChild method should return the Observable from the store dispatch for proper error handling in the calling method.

-private deleteChild(id: string, params: ChildrenParameters): void {
-  this.store.dispatch(new DeleteChildById(id, params));
+private deleteChild(id: string, params: ChildrenParameters): Observable<any> {
+  return this.store.dispatch(new DeleteChildById(id, params));
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private deleteChild(id: string, params: ChildrenParameters): void {
this.store.dispatch(new DeleteChildById(id, params));
}
private deleteChild(id: string, params: ChildrenParameters): Observable<any> {
return this.store.dispatch(new DeleteChildById(id, params));
}

Comment on lines +127 to +144
/**
* This method delete child By Id
*/
public onDeleteChild(child: Child): void {
this.matDialog
.open(ConfirmationModalWindowComponent, {
width: Constants.MODAL_SMALL,
data: {
type: ModalConfirmationType.deleteChild,
property: child.pib
}
})
.afterClosed()
.pipe(filter(Boolean))
.subscribe(() => {
this.deleteChild(child.id, this.childrenParams);
});
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for the delete operation.

The delete operation should handle potential errors to provide feedback to the user when deletion fails.

 public onDeleteChild(child: Child): void {
   this.matDialog
     .open(ConfirmationModalWindowComponent, {
       width: Constants.MODAL_SMALL,
       data: {
         type: ModalConfirmationType.deleteChild,
         property: child.pib
       }
     })
     .afterClosed()
     .pipe(filter(Boolean))
     .subscribe(() => {
-      this.deleteChild(child.id, this.childrenParams);
+      this.deleteChild(child.id, this.childrenParams).pipe(
+        catchError(error => {
+          // Handle error (e.g., show error message)
+          console.error('Failed to delete child:', error);
+          return EMPTY;
+        })
+      ).subscribe();
     });
 }

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

@@ -33,6 +33,7 @@ export enum ModalConfirmationType {
updateEmployeeDeputy = 'updateEmployeeDeputy',
unBlockParent = 'unBlockParent',
blockParent = 'blockParent',
deleteParent = 'deleteParent',
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Remove unused deleteParent enum values

The deleteParent enum values are not used anywhere in the codebase. The PR implements child deletion functionality and consistently uses ModalConfirmationType.deleteChild. Remove these unused enum values to maintain code cleanliness:

  • deleteParent from ModalConfirmationType
  • deleteParent from ModalConfirmationTitle
  • deleteParent from ModalConfirmationText
🔗 Analysis chain

Verify if deleteParent enum is needed.

The PR objectives mention functionality for deleting child's data, but these changes add enum values for deleting parent. The code uses ModalConfirmationType.deleteChild. Please verify if the deleteParent enum values are necessary for this PR.

Also applies to: 64-64, 112-112

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of deleteParent in the codebase
rg "deleteParent" --type ts

Length of output: 335


Script:

#!/bin/bash
# Search for ModalConfirmationType and the translation keys
rg "ModalConfirmationType\.deleteParent" --type ts
rg "SERVICE_MESSAGES\.MODAL_CONFIRMATIONS\.TITLES\.DELETE_PARENT" --type ts
rg "SERVICE_MESSAGES\.MODAL_CONFIRMATIONS\.DELETE_PARENT" --type ts

# Search for any file that might be importing and using these enums
rg -l "modal-confirmation" --type ts

Length of output: 3557


Script:

#!/bin/bash
# Check parent-related components for delete functionality
echo "=== parent-applications.component.ts ==="
rg "delete" -A 5 -B 5 src/app/shell/personal-cabinet/parent/parent-applications/parent-applications.component.ts

echo -e "\n=== create-parent.component.ts ==="
rg "delete" -A 5 -B 5 src/app/shell/personal-cabinet/parent/create-parent/create-parent.component.ts

echo -e "\n=== children.component.ts ==="
rg "delete" -A 5 -B 5 src/app/shell/personal-cabinet/parent/children/children.component.ts

Length of output: 861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants