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

Clean Refactor Scribe as MFE | Support for Questionnaires #9636

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

Conversation

shivankacker
Copy link
Member

@shivankacker shivankacker commented Jan 1, 2025

Requires ohcnetwork/care_scribe_fe#9

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • Configuration

    • Updated environment variable to enable a specific application
    • Modified Vite configuration to support custom remote module URLs
  • Localization

    • Removed several localization keys related to transcription and review processes
  • Component Updates

    • Simplified state management in several components
    • Removed custom value injection observer hook
    • Added plugin component integration to Questionnaire Form
    • Enhanced HTML structure by adding question ID data attributes
  • Type Updates

    • Enhanced ScribeComponentType with state management capabilities

@shivankacker shivankacker requested a review from a team as a code owner January 1, 2025 16:16
Copy link
Contributor

coderabbitai bot commented Jan 1, 2025

Walkthrough

This pull request encompasses several modifications across different files in a React application. The changes primarily involve removing the useValueInjectionObserver hook from multiple components, updating localization files, modifying environment configurations, and introducing a plugin system for questionnaire forms. The modifications aim to streamline component interactions, simplify state management, and enhance the overall architecture of the application.

Changes

File Change Summary
.env Updated REACT_ENABLED_APPS from empty string to specific URL
package.json Minor formatting change with newline addition
public/locale/en.json Removed several localization keys related to transcription and review
src/Utils/useValueInjectionObserver.tsx Completely removed custom hook
src/components/Common/DateInputV2.tsx Removed useValueInjectionObserver and related refs
src/components/Form/FormFields/Autocomplete.tsx Removed DOM value injection logic
src/components/Form/SelectMenuV2.tsx Simplified component by removing refs and value injection
src/components/Questionnaire/QuestionnaireForm.tsx Added plugin component and exported interface
src/pluginTypes.ts Updated ScribeComponentType with new state management props
vite.config.mts Updated remote module configuration comments and logic
scripts/setup-care-apps.ts Enhanced package name extraction logic

Possibly related PRs

Suggested Reviewers

  • rithviknishad
  • Jacobjeevan
  • bodhish

Poem

🐰 Hooks hop away, clean and light,
Components dance with newfound might
Plugin magic weaves its spell
Refactoring code, all is well!
A rabbit's code, sleek and bright 🌟


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

cloudflare-workers-and-pages bot commented Jan 1, 2025

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 38b5a2a
Status: ✅  Deploy successful!
Preview URL: https://fa06db9a.care-fe.pages.dev
Branch Preview URL: https://scribe-exit.care-fe.pages.dev

View logs

@shivankacker shivankacker marked this pull request as draft January 2, 2025 08:54
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 2, 2025
Copy link

github-actions bot commented Jan 2, 2025

👋 Hi, @shivankacker,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Jan 2, 2025
Copy link

netlify bot commented Jan 7, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 38b5a2a
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/677e3769d7494000085d310b
😎 Deploy Preview https://deploy-preview-9636--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added Deploy-Failed Deplyment is not showing preview merge conflict pull requests with merge conflict and removed merge conflict pull requests with merge conflict labels Jan 7, 2025
Copy link

github-actions bot commented Jan 7, 2025

👋 Hi, @shivankacker,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Jan 7, 2025
Copy link

cypress bot commented Jan 7, 2025

CARE    Run #4192

Run Properties:  status check passed Passed #4192  •  git commit 38b5a2ab48: Clean Refactor Scribe as MFE | Support for Questionnaires
Project CARE
Branch Review scribe-exit
Run status status check passed Passed #4192
Run duration 01m 15s
Commit git commit 38b5a2ab48: Clean Refactor Scribe as MFE | Support for Questionnaires
Committer Shivank Kacker
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 4
View all changes introduced in this branch ↗︎

@shivankacker shivankacker removed the Deploy-Failed Deplyment is not showing preview label Jan 7, 2025
@shivankacker shivankacker marked this pull request as ready for review January 7, 2025 23:36
@gigincg gigincg mentioned this pull request Jan 8, 2025
6 tasks
@gigincg gigincg changed the title Rid FE of Scribe Prompts Clean Refactor Scribe as MFE | Support for Questionnaires Jan 8, 2025
Copy link
Member

@gigincg gigincg left a comment

Choose a reason for hiding this comment

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

Requesting minor clarifications, Looks good for the most part.

@shivankacker Please get the Deployment fixed so that @nihal467 can test it out. @tellmeY18 Can you set up Github Pages for the Scribe MFE

Copy link

github-actions bot commented Jan 8, 2025

Reminder: To add the "needs testing" label, comment "ready for testing" on this PR.

@github-actions github-actions bot added the Deploy-Failed Deplyment is not showing preview label Jan 8, 2025
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

🔭 Outside diff range comments (1)
vite.config.mts (1)

Line range hint 137-140: Enforce HTTPS in production

The remote URL is always constructed with HTTP protocol, which is insecure for production environments.

Add environment-based protocol selection:

- const remoteUrl = `"http://${host}/assets/remoteEntry.js"`;
+ const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
+ const remoteUrl = `"${protocol}://${host}/assets/remoteEntry.js"`;
🧹 Nitpick comments (6)
src/components/Form/SelectMenuV2.tsx (1)

93-96: LGTM! Consider improving type safety in the onChange handler.

The component correctly handles value updates, but the type assertion in onChange could be more specific.

-        onChange={(selection: any) => props.onChange(selection.value)}
+        onChange={(selection: typeof value) => props.onChange(selection.value)}
src/components/Form/FormFields/Autocomplete.tsx (2)

8-8: Remove unused import.

The useEffect import is already included in the destructured import from 'react'.

-import { ReactNode, useEffect, useState } from "react";
+import { ReactNode, useState } from "react";

Line range hint 171-173: Improve type safety in the Combobox value prop.

The type assertion to T could lead to runtime errors. Consider using a more specific type that matches the option structure.

-        value={(value ?? props.placeholder ?? "Select") as T}
+        value={value ?? { label: props.placeholder ?? "Select", value: undefined }}
src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx (2)

92-99: Improve type safety in the questionnaire response handling.

The type assertion to any could be replaced with a more specific type.

-    const formStateValue = (questionnaireResponse.values[0]?.value as any)?.[0];
+    const formStateValue = (questionnaireResponse.values[0]?.value as EncounterEditRequest[])?.[0];

88-88: Improve type safety in the encounter data handling.

The type assertion to unknown followed by EncounterEditRequest could be simplified.

-      handleUpdateEncounter(encounterData as unknown as EncounterEditRequest);
+      handleUpdateEncounter(encounterData as EncounterEditRequest);
src/pluginTypes.ts (1)

11-11: LGTM! Well-typed plugin interface.

The ScribeComponentType is properly typed with the necessary props for form state management. This ensures type safety when implementing the Scribe plugin.

However, consider adding JSDoc comments to document the purpose and usage of these props:

 export type ScribeComponentType = React.FC<{
+  /** Array of questionnaire form states to be managed by the plugin */
   formState: QuestionnaireFormState[];
+  /** Callback to update the questionnaire form states */
   setFormState: React.Dispatch<React.SetStateAction<QuestionnaireFormState[]>>;
 }>;

Also applies to: 22-25

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ca65ceb and c972f4a.

📒 Files selected for processing (12)
  • .env (1 hunks)
  • package.json (1 hunks)
  • public/locale/en.json (0 hunks)
  • src/Utils/useValueInjectionObserver.tsx (0 hunks)
  • src/components/Common/DateInputV2.tsx (0 hunks)
  • src/components/Form/FormFields/Autocomplete.tsx (1 hunks)
  • src/components/Form/SelectMenuV2.tsx (2 hunks)
  • src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx (1 hunks)
  • src/components/Questionnaire/QuestionTypes/QuestionInput.tsx (1 hunks)
  • src/components/Questionnaire/QuestionnaireForm.tsx (3 hunks)
  • src/pluginTypes.ts (2 hunks)
  • vite.config.mts (2 hunks)
💤 Files with no reviewable changes (3)
  • src/components/Common/DateInputV2.tsx
  • public/locale/en.json
  • src/Utils/useValueInjectionObserver.tsx
✅ Files skipped from review due to trivial changes (2)
  • src/components/Questionnaire/QuestionTypes/QuestionInput.tsx
  • package.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: care-fe
🔇 Additional comments (3)
src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx (1)

65-82: LGTM! Initial state is well-structured.

The encounter state is properly initialized with all required fields and appropriate default values.

src/components/Questionnaire/QuestionnaireForm.tsx (2)

14-14: LGTM! Good practice exporting the interface for reuse.

The export of QuestionnaireFormState interface makes it properly reusable across the application, which is essential for type safety when working with questionnaire forms.

Also applies to: 33-37


298-302: Verify plugin component integration.

The integration with the plugin system looks correct, but we should ensure that the Scribe plugin properly handles the form state updates.

Let's verify the plugin integration:

✅ Verification successful

Plugin integration is correctly implemented

The Scribe plugin integration is properly typed and follows the plugin system's design patterns. The component receives correctly typed form state props that match the ScribeComponentType interface definition.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Scribe plugin implementation and usage
# Check if the Scribe plugin component exists and implements the correct interface

# Search for Scribe plugin component definition
echo "Searching for Scribe plugin component implementation..."
ast-grep --pattern 'export const Scribe: ScribeComponentType = $_'

# Check for other usages of PLUGIN_Component with Scribe
echo "Checking for other usages of PLUGIN_Component with Scribe..."
rg -l "PLUGIN_Component.*__name=\"Scribe\""

Length of output: 364


Script:

#!/bin/bash
# Search for plugin-related files and Scribe implementations
echo "Searching for plugin-related files..."
fd -e ts -e tsx . | grep -i "plugin"

echo "Searching for Scribe-related files..."
fd . -t f | grep -i "scribe"

echo "Searching for plugin type definitions..."
rg "type.*Plugin" -A 3

echo "Looking for PLUGIN_Component definition..."
rg "PLUGIN_Component" -A 2

Length of output: 3352


Script:

#!/bin/bash
# Search for ScribeComponentType definition and usage
echo "Searching for ScribeComponentType definition..."
rg "ScribeComponentType" -B 2 -A 5

echo "Checking for any Scribe-related interfaces..."
rg "interface.*Scribe" -A 5

Length of output: 1204

vite.config.mts Outdated Show resolved Hide resolved
.env Outdated Show resolved Hide resolved
@shivankacker shivankacker added needs testing needs review and removed Deploy-Failed Deplyment is not showing preview labels Jan 8, 2025
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: 1

🧹 Nitpick comments (2)
scripts/setup-care-apps.ts (2)

47-47: Enhance generated code formatting.

While the added newline improves readability, consider standardizing the spacing between different sections of the generated code.

Consider this improved template structure:

-const pluginMapContent = `// Use type assertion for the static import\n${plugins
+const pluginMapContent = `// Use type assertion for the static import
+
+${plugins
   .map(
     (plugin) =>
       `// @ts-expect-error Remote module will be available at runtime\nimport ${plugin.camelCaseName}Manifest from "${plugin.repo}/manifest";`,
   )
-  .join("\n")}
+  .join("\n")}\n
 import type { PluginManifest } from "./pluginTypes";
 
+// Plugin manifest array
 const pluginMap: PluginManifest[] = [${plugins.map((plugin) => `${plugin.camelCaseName}Manifest as PluginManifest`).join(",\n  ")}];
 
 export { pluginMap };
`;

Line range hint 1-58: Document the new plugin configuration format and provide migration guidance.

The script now supports a new URL-based plugin format, which is a significant architectural change that affects how plugins are configured.

Consider:

  1. Updating documentation to explain the new format: url|package[@version]
  2. Providing migration guidance for existing plugin configurations
  3. Adding examples in .env.example or similar documentation
  4. Creating a validation schema for the plugin configuration format

Would you like me to help create this documentation or open an issue to track this task?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c972f4a and 38b5a2a.

📒 Files selected for processing (3)
  • .env (1 hunks)
  • scripts/setup-care-apps.ts (2 hunks)
  • vite.config.mts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .env
  • vite.config.mts

Comment on lines +23 to +26
const package_ = app.includes("|")
? app.split("|")[1].split("@")[0]
: app.split("@")[0];
console.log(package_);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add input validation and error handling for the new URL format.

The new package extraction logic supports URLs with pipe-separated format but lacks validation and error handling. This could lead to runtime issues with malformed input.

Consider applying these improvements:

-        const package_ = app.includes("|")
-          ? app.split("|")[1].split("@")[0]
-          : app.split("@")[0];
-        console.log(package_);
+        let package_: string;
+        if (app.includes("|")) {
+          const [url, pkgIdentifier] = app.split("|");
+          if (!url || !pkgIdentifier) {
+            throw new Error(`Invalid app format: ${app}. Expected format: "url|package[@version]"`);
+          }
+          package_ = pkgIdentifier.split("@")[0];
+        } else {
+          package_ = app.split("@")[0];
+        }

Also, consider removing or conditionally enabling the debug log based on NODE_ENV.

📝 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
const package_ = app.includes("|")
? app.split("|")[1].split("@")[0]
: app.split("@")[0];
console.log(package_);
let package_: string;
if (app.includes("|")) {
const [url, pkgIdentifier] = app.split("|");
if (!url || !pkgIdentifier) {
throw new Error(`Invalid app format: ${app}. Expected format: "url|package[@version]"`);
}
package_ = pkgIdentifier.split("@")[0];
} else {
package_ = app.split("@")[0];
}

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

Successfully merging this pull request may close these issues.

2 participants