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

Minor fixes #107

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Minor fixes #107

wants to merge 3 commits into from

Conversation

BMartinos
Copy link
Collaborator

@BMartinos BMartinos commented Oct 23, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a toggle button in the Patient Summary Viewer to show/hide additional information.
    • Enhanced Docker image build and push process with conditional tagging based on branch context.
  • Bug Fixes

    • Improved error handling for accessing performer references in the Immunization component.
  • Chores

    • Updated CI/CD pipeline for Docker images to support multiple platforms and tagging strategies.

Immunization threw an undefined error
Added option to view generated composition
Copy link

coderabbitai bot commented Oct 23, 2024

Walkthrough

The pull request introduces modifications to the GitHub Actions workflow for building and pushing Docker images, adding steps based on the branch context. It also updates the PatientSummaryViewer components, enhancing the toggle functionality in the Composition component and refining the reference access in the Immunization component. These changes improve the CI/CD pipeline's flexibility and the functionality of the patient summary viewer.

Changes

File Path Change Summary
.github/workflows/tests-build-push.yml Added two new steps to the build-and-push job: Build and push latest for the main branch and Build and push tag for non-main branches. Modified the Login to DockerHub step by commenting out its conditional execution.
src/app/components/PatientSummaryViewer/resources/Composition/index.tsx Added a new row with a toggle button for displaying additional information, including a new toggleInfo function.
src/app/components/PatientSummaryViewer/resources/Immunization/index.tsx Modified the reference access pattern for performer to include an additional optional chaining operator for safety.

Possibly related PRs

  • Fix broken Production build #40: The changes in the .github/workflows/docker-publish.yml file relate to the build-and-push job, which is also modified in the main PR's .github/workflows/tests-build-push.yml, indicating a connection in the CI/CD processes for Docker images.
  • Verify build fix with prisma field encryption inclusion #65: The modifications in the .github/workflows/tests-build-push.yml file to enhance the build process are relevant to the changes made in this PR, which also addresses build issues related to environment variables necessary for the build process.
  • update: apply ui/ux enhancements #96: The modifications in the Header.tsx file include improvements to the user interface, aligning with the overall goal of enhancing the CI/CD pipeline and user experience as indicated in the main PR's changes to the workflow.
  • FE : UI Enhancements #100: The refactoring of the Header.tsx and LinksTable.tsx components to improve user interface elements is relevant to the main PR's focus on enhancing the build and push process, as both aim to improve the overall functionality and user experience of the application.

Suggested reviewers

  • yassinedorbozgithub

🐇 In the garden, changes bloom,
New steps added, dispelling gloom.
Toggle buttons, a click away,
Patient summaries brightening the day!
Docker images, built with care,
CI/CD magic fills the air.
Hooray for updates, let’s hop and play! 🥕✨


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

🧹 Outside diff range and nitpick comments (2)
src/app/components/PatientSummaryViewer/resources/Immunization/index.tsx (1)

Based on the gathered information, I can now provide a final response:

The data origin field should be implemented using the FHIR Immunization.primarySource attribute

From the code analysis, we can see that:

  1. The commented code shows a hardcoded 'non-primary source' value, which is incorrect as it should be dynamically determined from the resource data
  2. The Immunization component is using FHIR resource types, but the primarySource field is not currently being utilized
  3. No other components in the codebase are handling primarySource, suggesting this is a missing implementation

To properly implement this:

  • Remove the TODO comment
  • Uncomment and modify the row configuration to use the primarySource field from the FHIR resource
  • The value should be dynamically set based on the primarySource boolean field, not hardcoded

Example implementation:

{
  type: 'row',
  config: {
    label: 'Data origin',
    render: ({ primarySource }) =>
      primarySource ? 'primary source' : 'non-primary source',
  },
}
🔗 Analysis chain

Line range hint 47-51: Verify the data origin logic and update the TODO comment.

The commented code and TODO note suggest that verification is needed for the data origin field logic. This should be addressed to ensure the component correctly handles immunization source information according to FHIR specifications.

Let's check the FHIR specification and codebase for similar patterns:

Would you like me to help investigate the correct implementation for the data origin field or create an issue to track this verification task?


Let me gather more information about the Immunization resource type and its usage in the codebase.


Let me check the FHIR resource definitions and implementations to understand how primarySource is handled.


Let me check one more thing to understand how the Immunization type is defined and used in the codebase.


Let me check one final thing about the FHIR types and interfaces to understand how primarySource should be handled.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other components handling primarySource or similar fields
rg -g '*.tsx' -g '*.ts' 'primarySource|dataOrigin' --type-add 'tsx:*.tsx'

# Look for FHIR Immunization handling patterns
ast-grep --pattern 'type TImmunization = $_'

Length of output: 249


Script:

#!/bin/bash
# Search for the TType and EResource definitions
rg -g '*.ts*' 'export (type TType|enum EResource)'

# Search for Immunization-related types and interfaces
rg -g '*.ts*' 'interface.*Immunization|type.*Immunization'

# Look for actual usage of primarySource in the codebase
rg -g '*.ts*' -B 2 -A 2 'primarySource'

# Check if there are any test files related to Immunization
fd -g '*immunization*.test.*'

Length of output: 453


Script:

#!/bin/bash
# Check the FHIR resource interfaces
rg -g '*.ts*' -A 10 'interface IResource'

# Look for any Immunization-related mappings or transformations
rg -g '*.ts*' -B 2 -A 2 'Immunization.*\{|\.primarySource'

# Check for any configuration or mapping files
fd -g '*immunization*.{json,ts,tsx}'

# Look for any resource transformation utilities
rg -g '*.ts*' 'transform.*Immunization|map.*Immunization'

Length of output: 2359


Script:

#!/bin/bash
# Look for Immunization type imports and the actual type definition
rg -g '*.ts*' 'import.*Immunization|type Immunization'

# Check the content of the file containing the Immunization component
cat src/app/components/PatientSummaryViewer/resources/Immunization/index.tsx

# Look for any configuration related to immunization data display
rg -g '*.ts*' -B 5 -A 5 'rows.*=.*\[.*Immunization'

Length of output: 1949


Script:

#!/bin/bash
# Look for the actual FHIR type definitions
rg -g '*.ts*' -A 15 'type (Immunization|Patient) =|interface (Immunization|Patient) '

# Check for any FHIR-related utility functions or transformations
rg -g '*.ts*' 'getFHIR|transformFHIR|mapFHIR'

# Look for any documentation files related to FHIR resources
fd -g 'README*' -x grep -l 'FHIR'

Length of output: 169

.github/workflows/tests-build-push.yml (1)

Line range hint 56-72: Consider adding image scanning for security vulnerabilities.

Since we're building and pushing Docker images, it would be beneficial to add a security scanning step before pushing to DockerHub.

Consider adding Trivy or Snyk container scanning:

      - name: Run Trivy vulnerability scanner
        uses: aquasecurity/trivy-action@master
        with:
          image-ref: 'jembi/smart-health-links-portal:${{ github.sha }}'
          format: 'table'
          exit-code: '1'
          ignore-unfixed: true
          vuln-type: 'os,library'
          severity: 'CRITICAL,HIGH'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 94e94de and 3caba78.

📒 Files selected for processing (3)
  • .github/workflows/tests-build-push.yml (2 hunks)
  • src/app/components/PatientSummaryViewer/resources/Composition/index.tsx (2 hunks)
  • src/app/components/PatientSummaryViewer/resources/Immunization/index.tsx (1 hunks)
🧰 Additional context used
🪛 Biome
src/app/components/PatientSummaryViewer/resources/Composition/index.tsx

[error] 566-566: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

🔇 Additional comments (4)
src/app/components/PatientSummaryViewer/resources/Immunization/index.tsx (1)

40-40: LGTM! Improved null safety with optional chaining.

The addition of optional chaining for the actor property is a good defensive programming practice that prevents potential runtime errors when accessing nested FHIR resource properties.

.github/workflows/tests-build-push.yml (2)

Line range hint 56-64: LGTM: Main branch build configuration is well structured.

The configuration correctly handles the main branch case with appropriate platform targets and tagging strategy.


65-72: ⚠️ Potential issue

Verify Docker credentials for non-main branch pushes.

The workflow attempts to push images for non-main branches, but the Docker login step only runs for the main branch. This could lead to authentication failures.

Apply this diff to fix the authentication issue:

      - name: Login to DockerHub
-       if: ${{ github.ref_name == 'main' }}
+       if: ${{ github.ref_name == 'main' || github.event_name == 'pull_request' }}
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
src/app/components/PatientSummaryViewer/resources/Composition/index.tsx (1)

1-1: LGTM: Import statements are appropriate.

The new imports for Box and StyledButton are correctly added and align with the new toggle functionality being implemented.

Also applies to: 4-4

Comment on lines 65 to 72
- name: Build and push latest - tag
if: ${{ github.ref_name != 'main' }}
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
file: docker/production/Dockerfile
tags: jembi/smart-health-links-portal:hotfix
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Reconsider the use of 'hotfix' as a static tag.

Using a static 'hotfix' tag for all non-main branches could lead to confusion and potential deployment issues. Consider using a more specific tag format that includes:

  • Branch name or PR number
  • Commit SHA
  • Timestamp

This would provide better traceability and prevent tag conflicts.

Here's a suggested modification:

-          tags: jembi/smart-health-links-portal:hotfix
+          tags: jembi/smart-health-links-portal:pr-${{ github.event.pull_request.number }}-${{ github.sha }}
📝 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
- name: Build and push latest - tag
if: ${{ github.ref_name != 'main' }}
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
file: docker/production/Dockerfile
tags: jembi/smart-health-links-portal:hotfix
- name: Build and push latest - tag
if: ${{ github.ref_name != 'main' }}
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
file: docker/production/Dockerfile
tags: jembi/smart-health-links-portal:pr-${{ github.event.pull_request.number }}-${{ github.sha }}

Comment on lines +546 to +561
<Box
sx={{
padding: '20px 0px',
width: '100%',
'& table': {
width: '100%',
borderCollapse: 'collapse',
marginBottom: '20px',
'& th, & td': {
border: '1px solid gray',
padding: '8px',
textAlign: 'left',
},
},
}}
>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Extract styles to a styled component.

Inline styles should be moved to styled components for better maintainability and reusability.

Consider creating a styled component:

const StyledBox = styled(Box)(({ theme }) => ({
  padding: '20px 0px',
  width: '100%',
  '& table': {
    width: '100%',
    borderCollapse: 'collapse',
    marginBottom: '20px',
    '& th, & td': {
      border: '1px solid gray',
      padding: '8px',
      textAlign: 'left',
    },
  },
}));

Then use it in your component:

-<Box
-  sx={{
-    padding: '20px 0px',
-    width: '100%',
-    '& table': {
-      width: '100%',
-      borderCollapse: 'collapse',
-      marginBottom: '20px',
-      '& th, & td': {
-        border: '1px solid gray',
-        padding: '8px',
-        textAlign: 'left',
-      },
-    },
-  }}
->
+<StyledBox>

Comment on lines +562 to +564
<StyledButton size="small" variant="contained" onClick={toggleInfo}>
Toggle Generated
</StyledButton>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Enhance button accessibility.

The toggle button lacks proper accessibility attributes.

Add ARIA attributes to improve accessibility:

-<StyledButton size="small" variant="contained" onClick={toggleInfo}>
+<StyledButton
+  size="small"
+  variant="contained"
+  onClick={toggleInfo}
+  aria-expanded={isVisible}
+  aria-controls="composition-generated"
+>
   Toggle Generated
 </StyledButton>

Committable suggestion was skipped due to low confidence.

Comment on lines +530 to +543
const toggleInfo = () => {
const infoDiv = document.getElementById('composition-generated');

if (!infoDiv) {
return null;
}

if (infoDiv.style.display === 'none') {
infoDiv.style.display = 'block';
} else {
infoDiv.style.display = 'none';
}
return null;
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace DOM manipulation with React state management.

The current implementation uses direct DOM manipulation which goes against React's principles and could lead to synchronization issues.

Consider using React's useState hook:

-const toggleInfo = () => {
-  const infoDiv = document.getElementById('composition-generated');
-
-  if (!infoDiv) {
-    return null;
-  }
-
-  if (infoDiv.style.display === 'none') {
-    infoDiv.style.display = 'block';
-  } else {
-    infoDiv.style.display = 'none';
-  }
-  return null;
-};
+const [isVisible, setIsVisible] = useState(false);
+const toggleInfo = () => setIsVisible(!isVisible);

Committable suggestion was skipped due to low confidence.

Comment on lines +565 to +570
<div
dangerouslySetInnerHTML={{ __html: text.div }}
className="extra-info"
id="composition-generated"
style={{ display: 'none' }}
/>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security Risk: Unsafe HTML rendering.

Using dangerouslySetInnerHTML with unsanitized content exposes the application to XSS attacks.

Consider using a sanitization library like DOMPurify:

+import DOMPurify from 'dompurify';

-<div
-  dangerouslySetInnerHTML={{ __html: text.div }}
-  className="extra-info"
-  id="composition-generated"
-  style={{ display: 'none' }}
-/>
+<div
+  dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(text.div) }}
+  className="extra-info"
+  id="composition-generated"
+  style={{ display: isVisible ? 'block' : 'none' }}
+/>

Would you like me to help set up DOMPurify in your project?

Committable suggestion was skipped due to low confidence.

🧰 Tools
🪛 Biome

[error] 566-566: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3caba78 and 1e49db6.

📒 Files selected for processing (1)
  • .github/workflows/tests-build-push.yml (2 hunks)
🧰 Additional context used
🔇 Additional comments (2)
.github/workflows/tests-build-push.yml (2)

Line range hint 56-64: LGTM! Well-configured multi-platform build for main branch.

The step correctly handles:

  • Branch condition
  • Multi-platform build
  • Appropriate tagging strategy

65-72: The 'hotfix' tag issue remains unaddressed

The static 'hotfix' tag issue raised in the previous review is still applicable. Using a static tag for all non-main branches could lead to tag conflicts and traceability issues.

Let's verify if this tag is being used elsewhere in the codebase:

#!/bin/bash
# Search for other occurrences of the hotfix tag
rg -i "hotfix" --type yaml

Comment on lines +50 to +55
# if: ${{ github.ref_name == 'main' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize DockerHub login condition

The login step should only execute when we need to push images. Consider using this condition instead:

-        # if: ${{ github.ref_name == 'main' }}
+        if: ${{ github.ref_name == 'main' || github.event_name == 'pull_request' }}
📝 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
# if: ${{ github.ref_name == 'main' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
if: ${{ github.ref_name == 'main' || github.event_name == 'pull_request' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

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.

1 participant