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

Add keyboard support for esc and seek for imavid #4726

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

CamronStaley
Copy link
Contributor

@CamronStaley CamronStaley commented Aug 25, 2024

What changes are proposed in this pull request?

Some of the keyboard controls offered in video datasets were not support for imavid so I am adding them here (also fixing an issue where you could go above the size of the video dataset when seeking).

Controls added:

  • esc key to exit (and reset state)
  • Num keys to seek through the video to certain frames

2024-08-25 00 23 56

How is this patch tested? If it is not, please explain why.

Local server

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

In imavid datasets you can now use esc to exit and number keys to seek through the videos

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Enhanced video controls to support a new state type, allowing for improved handling of video frame data.
    • Adapted seekTo and videoEscape controls to manage various video states more effectively.
  • Bug Fixes

    • Improved robustness of actions in response to user inputs by better managing state transitions.

Copy link
Contributor

coderabbitai bot commented Aug 25, 2024

Walkthrough

The modifications enhance the seekTo and videoEscape controls in the actions.ts file by integrating a new state type, ImaVidState, alongside the existing VideoState. The action methods for both controls are updated to accept either state type, enabling improved handling of frame data and overall control flow.

Changes

Files Change Summary
app/packages/looker/src/elements/common/actions.ts Updated seekTo and videoEscape controls to accept ImaVidState in addition to VideoState, enhancing frame data handling and control logic.

Poem

In the land of frames, where bunnies hop,
Changes are made, and we can’t stop!
With states intertwined, like a dance in the sun,
Seeking and escaping, oh what fun!
With each little tweak, our journey's aglow,
Hopping along with a joyful "Hello!" 🐇✨

Tip

New review model

We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.


New features

Walkthrough comment now includes:

  • Possibly related PRs: A list of potentially related PRs to help you recall past context.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs. You can also provide custom labeling instructions in the UI or configuration file.

Notes:

  • Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 76cdadf and 8cd62f4.

Files selected for processing (1)
  • app/packages/looker/src/elements/common/actions.ts (3 hunks)
Additional context used
Path-based instructions (1)
app/packages/looker/src/elements/common/actions.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Additional comments not posted (3)
app/packages/looker/src/elements/common/actions.ts (3)

556-590: Verify frame calculation logic in seekTo.

The function now handles both VideoState and ImaVidState. Ensure that the frame calculation logic correctly computes the frame positions based on the state type and updates the frame number accordingly.

#!/bin/bash
# Description: Verify the frame calculation logic for correctness and efficiency.
# Test: Search for similar logic in other parts of the codebase. Expect: Consistent and efficient frame calculation.

rg --type typescript -A 5 $'frame calculation logic'

615-678: Simplify and verify new logic in videoEscape.

The function has been adjusted to handle ImaVidState alongside VideoState, increasing its complexity. Consider simplifying the logic and verify that it correctly handles different scenarios based on the state type.

#!/bin/bash
# Description: Verify the new logic for handling different scenarios based on the state type.
# Test: Search for similar state handling logic in other parts of the codebase. Expect: Consistent and correct state handling.

rg --type typescript -A 5 $'state handling logic'

Line range hint 5-678: Ensure TypeScript and React best practices are followed.

Review the entire file to ensure that TypeScript typing is accurate and React concepts are properly utilized, especially in the context of the changes made for handling ImaVidState and VideoState.

#!/bin/bash
# Description: Verify TypeScript and React best practices.
# Test: Search for TypeScript and React best practices in the codebase. Expect: Proper typing, use of hooks, and component lifecycle management.

rg --type typescript -A 5 $'TypeScript and React best practices'

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: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8cd62f4 and 445899f.

Files selected for processing (1)
  • app/packages/looker/src/elements/common/actions.ts (3 hunks)
Additional context used
Path-based instructions (1)
app/packages/looker/src/elements/common/actions.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Comment on lines +557 to +591
const seekTo: Control<VideoState | ImaVidState> = {
title: "Seek to",
detail: "Seek to 0%, 10%, 20%... of the video",
shortcut: "0-9",
eventKeys: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
action: (update, dispatchEvent, eventKey) => {
update(({ duration, config: { frameRate, support }, lockedToSupport }) => {
const frameCount = getFrameNumber(duration, duration, frameRate);
const total = lockedToSupport ? support[1] - support[0] : frameCount;
const base = lockedToSupport ? support[0] : 1;

update((state: ImaVidState | VideoState) => {
const isImavid = (state.config as ImaVidConfig)
.frameStoreController as ImaVidFramesController;
const frameName = isImavid ? "currentFrameNumber" : "frameNumber";
let total = 0;
let base = 0;
if (isImavid) {
const {
config: {
frameStoreController: { totalFrameCount },
},
currentFrameNumber,
} = state as ImaVidState;
total = totalFrameCount;
base = currentFrameNumber < totalFrameCount ? currentFrameNumber : 1;
} else {
const {
lockedToSupport,
config: { support, frameRate },
duration,
} = state as VideoState;
const frameCount = getFrameNumber(duration, duration, frameRate);
total = lockedToSupport ? support[1] - support[0] : frameCount;
base = lockedToSupport ? support[0] : 1;
}
const position = Math.round((parseInt(eventKey, 10) / 10) * total) + base;
dispatchEvent("options", { showJSON: false });
return {
frameNumber: Math.max(
1,
Math.round((parseInt(eventKey, 10) / 10) * total) + base
),
[frameName]: Math.min(total, Math.max(1, position)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Approve the seekTo control changes with a suggestion for readability.

The modifications to the seekTo control are well-aligned with the PR objectives and enhance the functionality by supporting both VideoState and ImaVidState. The logic to handle different state types and compute frame numbers based on the state is correctly implemented.

Suggestion for Improvement:
Consider adding comments within the action function to explain the logic, especially the calculations and conditions, to improve readability and maintainability.

Comment on lines +616 to +679
detail: "Escape the current context",
alwaysHandle: true,
action: (update, dispatchEvent, eventKey) => {
update(
({
action: (update, dispatchEvent) => {
update((state: ImaVidState | VideoState) => {
const isImavid = (state.config as ImaVidConfig)
.frameStoreController as ImaVidFramesController;

const frameName = isImavid ? "currentFrameNumber" : "frameNumber";

const {
hasDefaultZoom,
showOptions,
frameNumber,
config: { support },
options: { showHelp, showJSON, selectedLabels },
lockedToSupport,
}) => {
if (showHelp) {
dispatchEvent("panels", { showHelp: "close" });
return { showHelp: "close" };
}
} = state as VideoState;

if (showOptions) {
return { showOptions: false };
}
if (showHelp) {
dispatchEvent("panels", { showHelp: "close" });
return { showHelp: "close" };
}

if (showJSON) {
dispatchEvent("panels", { showJSON: "close" });
dispatchEvent("options", { showJSON: false });
return { options: { showJSON: false } };
}
if (showOptions) {
return { showOptions: false };
}

if (!lockedToSupport && Boolean(support)) {
return {
frameNumber: support[0],
lockedToSupport: true,
};
}
if (showJSON) {
dispatchEvent("panels", { showJSON: "close" });
dispatchEvent("options", { showJSON: false });
return { options: { showJSON: false } };
}

if (!hasDefaultZoom) {
return {
setZoom: true,
};
}
if (!lockedToSupport && Boolean(support) && !isImavid) {
return {
frameNumber: support[0],
lockedToSupport: true,
};
}

if (frameNumber !== 1) {
return {
frameNumber: 1,
playing: false,
};
}
if (!hasDefaultZoom) {
return {
setZoom: true,
};
}

if (selectedLabels.length) {
dispatchEvent("clear");
return {};
}
if (state[frameName] !== 1) {
return {
[frameName]: 1,
playing: false,
};
}

dispatchEvent("close");
if (selectedLabels.length) {
dispatchEvent("clear");
return {};
}
);

dispatchEvent("close");
return {};
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Approve the videoEscape control changes with a suggestion for consistency.

The modifications to the videoEscape control enhance its functionality by supporting both VideoState and ImaVidState, allowing users to exit video playback and reset the state using the esc key. The comprehensive logic covers various scenarios and conditions, ensuring robust functionality.

Suggestion for Improvement:
Ensure consistency in the handling of different states and conditions. For example, the handling of showJSON could be streamlined to reduce redundancy in dispatching events and updating state.

Copy link
Contributor

@sashankaryal sashankaryal left a comment

Choose a reason for hiding this comment

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

lgtm!!

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 445899f and 6a1c5e1.

Files selected for processing (1)
  • app/packages/looker/src/elements/common/actions.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/packages/looker/src/elements/common/actions.ts

@CamronStaley CamronStaley merged commit f53cbb9 into develop Sep 10, 2024
12 checks passed
@CamronStaley CamronStaley deleted the imavid/controls branch September 10, 2024 03:27
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