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

[Fix] Video filtering #8765

Merged
merged 10 commits into from
Feb 7, 2025
Merged

[Fix] Video filtering #8765

merged 10 commits into from
Feb 7, 2025

Conversation

adkif
Copy link
Contributor

@adkif adkif commented Feb 7, 2025

PR

Please note: we will close your PR without comment if you do not check the boxes above and provide ALL requested information.


Summary by CodeRabbit

  • New Features
     • Introduced a video count feature that displays the total number of videos based on custom filters (such as date range and organization).
     • Launched a streamlined video update experience, allowing users to easily modify key details like title and description.

  • Enhancements
     • Adjusted video page filters by disabling options (log type, source, and activity level) for a cleaner, more focused search experience.
     • Refined video listing filters to better sort and display content based on selected criteria.

adkif added 10 commits February 7, 2025 18:30
Adds a new API endpoint to retrieve the count of videos.

Updates the video service to use the new API endpoint for checking video availability.  This improves performance by only retrieving the count instead of the entire list of videos.

Adds update video API endpoint to update video metadata.
Moves RxJS operators import to be with other RxJS imports.  This improves code readability and consistency.
- Updated `VideoService` in `video.service.ts` to refine selection logic, prioritizing `selectedOrganization` over `organizationId`.
- Enhanced `GetVideoCountQueryHandler` in `get-video-count.handler.ts` by introducing permission checks for `CHANGE_SELECTED_EMPLOYEE`, ensuring queries respect user permissions.
- Introduced `moment-timezone` for converting start and end dates to UTC.
- Updated query to dynamically filter videos based on provided `startDate`, `endDate`, and `timeZone`.
- Implemented dynamic WHERE clause with optional employee filtering using `TypeORM`'s `In` and `Between` utilities.
Modify the query to conditionally include the recordedAt filter
only when both startDate and endDate are provided. This change
enhances the query flexibility by avoiding unnecessary date filtering.
- Updated import statements for DTOs and models in videos.controller.ts
- Changed the Delete method to accept an optional IDeleteVideo parameter
- Updated the VideoEffects update logic for better state management
- Refactored UpdateVideoHandler to include description in video updates
- Modified UpdateVideoCommand and UpdateVideoDTO for simplified DTO structure
- Revised VideosController to adapt to new UpdateVideoCommand constructor
- Ensures that the video store is cleared before fetching new video data when the filter changes.
- Disable log type, source, and activity level filters in the video page filter component.
- This change simplifies the available filters for a streamlined user experience.
@adkif adkif requested review from evereq and rahul-rocket February 7, 2025 19:35
Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Walkthrough

The changes improve various aspects of the video modules by updating state management, UI behavior, service logic, and command–query flows. In the videos-ui package, the video state update now directly stores the updated video; video page components are modified to set filter properties and clear the video list on initialization; and routing has been adjusted. In the videos package, commands and DTOs have been refined to update only essential fields, and new query classes and handlers are added to support video counting along with controller endpoint updates.

Changes

File(s) Change Summary
packages/plugins/videos-ui/src/lib/…/(video.effect.ts, video-page.component.html, video-page.component.ts, video.service.ts, video-ui-routing.module.ts) Updated video state management and UI configuration: the updateVideo$ effect now includes a “video” property; added new filter input properties (all set to false); video list is reset on ngOnInit; Store dependency injected with a new getCount method; route’s date selector disabled and reuseRoute enabled.
packages/plugins/videos/src/lib/…/(commands/handlers/update-video.handler.ts, commands/update-video.command.ts, dto/update-video.dto.ts, dto/count-video.dto.ts, queries/get-video-count.query.ts, queries/handlers/get-video-count.handler.ts, queries/handlers/get-videos.handler.ts, queries/handlers/index.ts, videos.controller.ts) Streamlined video update and query logic: UpdateVideoHandler and UpdateVideoCommand now include an id and update only title/description; UpdateVideoDTO is simplified; a new CountVideoDTO is added for video counting; new GetVideoCountQuery and its handler are introduced with permission checks; GetVideosQueryHandler now applies refined date and employee filtering; VideosController adds endpoints for count and update while modifying delete parameters.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant VC as VideosController
    participant Q as GetVideoCountQuery
    participant QH as GetVideoCountQueryHandler
    participant VS as VideoService
    participant DB as Database

    C->>VC: GET /videos/count?options
    VC->>Q: Create GetVideoCountQuery(options)
    Q->>QH: Dispatch query
    QH->>VS: Call getCount(options)
    VS->>DB: Query video count
    DB-->>VS: Return count result
    VS-->>QH: Return count
    QH-->>VC: Return count
    VC-->>C: Send count response
Loading
sequenceDiagram
    participant C as Client
    participant VC as VideosController
    participant CMD as UpdateVideoCommand
    participant UH as UpdateVideoHandler
    participant VS as VideoService

    C->>VC: PUT /videos/{id} with update data
    VC->>CMD: Instantiate update command (id, input)
    CMD->>UH: Dispatch update command
    UH->>VS: Call update({...})
    VS-->>UH: Return updated video
    UH-->>VC: Return updated video
    VC-->>C: Send updated video response
Loading

Suggested reviewers

  • rahul-rocket
  • evereq

Poem

Oh, I’m a rabbit, quick on my feet,
Hopping through code with a joyful beat,
Filters and queries now dance in the light,
Videos updated smooth and bright,
With each change, my whiskers twitch in glee,
Celebrating updates—happy as can be!
🐰✨

✨ 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
Contributor

@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: 0

🧹 Nitpick comments (6)
packages/plugins/videos-ui/src/lib/shared/services/video.service.ts (2)

34-38: Method getCount lacks dedicated error handling.
Although the caller can catch errors, consider adding basic error handling here if other consumers call getCount directly. This helps ensure robust error propagation outside of the isAvailable$ flow.


41-52: Consider dynamic re-evaluation for isAvailable$.
The logic is straightforward, but be mindful that it only evaluates once when the getter is subscribed to. If the organization or tenant changes in the Store at runtime, re-subscribing or wrapping these lookups in real-time reactive streams (e.g., store.selectedOrganization$) could be beneficial to avoid stale data.

packages/plugins/videos/src/lib/queries/handlers/get-videos.handler.ts (2)

3-4: Evaluate choice of moment-timezone.
moment-timezone is widely used and reliable but can be large. Consider dayjs or date-fns if bundle size and performance with time zones become concerns.


33-57: Consider indexing and updating comment references.

  1. If the dataset grows large, ensure recordedAt is indexed in the DB for efficient range queries.
  2. The inline comment mentions “valueDate” but the code uses “recordedAt.” Update the comment to match the actual property or vice versa.
packages/plugins/videos/src/lib/queries/handlers/get-video-count.handler.ts (1)

19-34: Consider enhancing type safety for query options.

While the implementation is correct, the type safety could be improved.

Consider this improvement:

-  const { options } = query || {};
-  const { organizationId, tenantId } = options;
+  const { options = {} } = query;
+  const { organizationId, tenantId } = options;
+  
+  if (!organizationId || !tenantId) {
+    throw new Error('organizationId and tenantId are required');
+  }
packages/plugins/videos/src/lib/dto/count-video.dto.ts (1)

51-52: Consider adding date transformation.

While the date validation is correct, adding transformation would ensure consistent date handling.

Add Transform decorator to automatically convert string dates to Date objects:

+import { Transform } from 'class-transformer';

 @IsOptional()
 @IsISO8601({ strict: true }, { message: 'startDate must be a valid ISO 8601 date string' })
+@Transform(({ value }) => value ? new Date(value) : value)
-startDate: Date | string;
+startDate: Date;

 @IsOptional()
 @IsISO8601({ strict: true }, { message: 'endDate must be a valid ISO 8601 date string' })
+@Transform(({ value }) => value ? new Date(value) : value)
-endDate: Date | string;
+endDate: Date;

Also applies to: 68-69

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f0e05c2 and 92474d0.

📒 Files selected for processing (14)
  • packages/plugins/videos-ui/src/lib/+state/video.effect.ts (1 hunks)
  • packages/plugins/videos-ui/src/lib/pages/video-page/video-page.component.html (1 hunks)
  • packages/plugins/videos-ui/src/lib/pages/video-page/video-page.component.ts (1 hunks)
  • packages/plugins/videos-ui/src/lib/shared/services/video.service.ts (2 hunks)
  • packages/plugins/videos-ui/src/lib/video-ui-routing.module.ts (1 hunks)
  • packages/plugins/videos/src/lib/commands/handlers/update-video.handler.ts (1 hunks)
  • packages/plugins/videos/src/lib/commands/update-video.command.ts (1 hunks)
  • packages/plugins/videos/src/lib/dto/count-video.dto.ts (1 hunks)
  • packages/plugins/videos/src/lib/dto/update-video.dto.ts (1 hunks)
  • packages/plugins/videos/src/lib/queries/get-video-count.query.ts (1 hunks)
  • packages/plugins/videos/src/lib/queries/handlers/get-video-count.handler.ts (1 hunks)
  • packages/plugins/videos/src/lib/queries/handlers/get-videos.handler.ts (2 hunks)
  • packages/plugins/videos/src/lib/queries/handlers/index.ts (1 hunks)
  • packages/plugins/videos/src/lib/videos.controller.ts (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (19)
packages/plugins/videos-ui/src/lib/shared/services/video.service.ts (2)

5-6: Smooth integration of new imports.
No concerns with the additional imports of Store and rxjs operators. This cleanly aligns with Angular best practices for state management and observables.


14-14: Validate Store injection.
While injecting the Store is appropriate, ensure that the module providing Store is properly configured and that the Store object is guaranteed to be defined at runtime.

packages/plugins/videos/src/lib/queries/handlers/get-videos.handler.ts (2)

6-6: New IVideo import appears correct.
No issues with referencing the IVideo interface in this context.


25-31: Destructuring filter parameters is clear and concise.
The default values for employeeIds and timeZone are a nice touch. This makes the handler resilient to undefined inputs.

packages/plugins/videos/src/lib/dto/update-video.dto.ts (1)

3-3: Confirm removal of ID and file fields.
This DTO no longer contains the previously declared properties (id, file). Verify that no other parts of the code rely on them.

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search the codebase for references to removed fields in UpdateVideoDTO
rg -A 5 'UpdateVideoDTO' 

Length of output: 2086


Verification of removed "id" and "file" fields in UpdateVideoDTO

The search confirms that the UpdateVideoDTO now extends BaseVideoDTO without including the removed properties. The only reference to an "id" comes from UpdateVideoCommand—which accepts the id as a separate constructor argument—and there is no evidence that any part of the system is still relying on UpdateVideoDTO to contain id or file fields.

packages/plugins/videos/src/lib/queries/get-video-count.query.ts (1)

1-8: LGTM! Well-structured query implementation.

The implementation follows CQRS pattern best practices with clear type definition and proper encapsulation of query parameters.

packages/plugins/videos/src/lib/queries/handlers/index.ts (1)

1-1: LGTM! Consistent handler registration.

The GetVideoCountQueryHandler is properly registered alongside existing handlers.

Also applies to: 5-5

packages/plugins/videos/src/lib/commands/update-video.command.ts (1)

3-3: LGTM! Improved type safety with explicit ID parameter.

The command structure is enhanced by requiring an explicit ID parameter, making the command more type-safe and self-documenting.

Also applies to: 7-7

packages/plugins/videos/src/lib/commands/handlers/update-video.handler.ts (2)

10-18: LGTM! Clear and helpful documentation.

The JSDoc comments effectively document the purpose and behavior of the execute method.


21-30: Verify the intentional removal of size, file, and duration fields.

The update operation has been simplified to only update title and description. Please confirm if this is intentional and that size, file, and duration fields are no longer needed for updates.

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search for usages of removed fields in the codebase
echo "Searching for references to removed fields..."
rg -A 5 "size|file|duration" packages/plugins/videos/

Length of output: 21243


UPDATE HANDLER: Confirmed Simplified Update is Intentional

The search results indicate that the fields (size, file, and duration) are still present and used in other parts of the videos feature (such as during creation and entity validation), but they are omitted from the update command. This suggests that the update operation is intentionally limited to modifying only the title and description, while keeping the original file and its metadata intact.

packages/plugins/videos/src/lib/queries/handlers/get-video-count.handler.ts (1)

11-18: LGTM! Well-documented method.

The documentation clearly describes the purpose, parameters, and return type of the execute method.

packages/plugins/videos-ui/src/lib/video-ui-routing.module.ts (1)

39-39: LGTM! Routing configuration changes look good.

The changes to disable the date selector and enable route reuse for the video detail page are appropriate.

Also applies to: 51-51

packages/plugins/videos/src/lib/dto/count-video.dto.ts (1)

4-70: LGTM! Well-structured DTO with comprehensive validation.

The DTO is well-documented with proper validation rules and API property decorators.

packages/plugins/videos-ui/src/lib/pages/video-page/video-page.component.ts (1)

56-56: LGTM! Clean state management.

Resetting the videos array before fetching new data ensures a clean state and prevents stale data issues.

packages/plugins/videos-ui/src/lib/+state/video.effect.ts (1)

108-109: LGTM! Good improvement to state management.

The addition of the video property to the state update ensures consistency between the list and individual video states.

packages/plugins/videos/src/lib/videos.controller.ts (3)

174-195: LGTM! Well-structured count endpoint.

The implementation includes:

  • Comprehensive API documentation
  • Proper validation using ValidationPipe
  • Clear error responses

207-232: LGTM! Well-implemented update endpoint.

The implementation includes:

  • Comprehensive API documentation
  • Input validation
  • UUID validation for the ID parameter

292-292: LGTM! Improved delete endpoint signature.

Making the options parameter optional with proper typing improves the API's flexibility.

packages/plugins/videos-ui/src/lib/pages/video-page/video-page.component.html (1)

10-12: LGTM! Improved filter configuration.

Disabling irrelevant filters (log type, source, and activity level) streamlines the UI for video filtering.

Copy link

nx-cloud bot commented Feb 7, 2025

View your CI Pipeline Execution ↗ for commit 92474d0.

Command Status Duration Result
nx build gauzy -c=production --prod --verbose ✅ Succeeded 3m 57s View ↗
nx build api -c=production --prod ✅ Succeeded 1m View ↗
nx build desktop-ui-lib --configuration=develop... ✅ Succeeded 30s View ↗
nx build plugin-integration-wakatime ✅ Succeeded <1s View ↗
nx build desktop-lib ✅ Succeeded <1s View ↗
nx build desktop-window ✅ Succeeded <1s View ↗
nx build desktop-core ✅ Succeeded <1s View ↗
nx build plugin-videos ✅ Succeeded <1s View ↗
Additional runs (52) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-02-07 20:15:07 UTC

@evereq evereq merged commit 619b664 into develop Feb 7, 2025
15 of 16 checks passed
@evereq evereq deleted the fix/video-filtering branch February 7, 2025 20:35
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.

2 participants