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

Enhanced Styling Updates: Conditional 'Completed' Tags and Export Button Design #9499

Conversation

ashwinpraveengo
Copy link
Contributor

@ashwinpraveengo ashwinpraveengo commented Dec 19, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Updated Design

image

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

  • New Features

    • Enhanced visual feedback for the ExportButton with a tooltip displaying the current board's name.
    • Conditional styling for the Kanban section header, improving the representation of completed sections.
  • Bug Fixes

    • Improved drag-and-drop functionality by preventing unnecessary navigation when items are dropped in the same location.

@ashwinpraveengo ashwinpraveengo requested a review from a team as a code owner December 19, 2024 15:58
Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Walkthrough

The pull request introduces visual enhancements across multiple components, focusing on improving the representation of completed states and export button interactions. Changes span four components: Export.tsx, Board.tsx, ResourceBoard.tsx, and ShiftingBoard.tsx. The modifications primarily involve adding tooltips to export buttons, conditionally styling completed sections with green backgrounds, and refining drag-and-drop interactions to provide more intuitive user feedback.

Changes

File Change Summary
src/components/Common/Export.tsx Added isCompleted variable to conditionally style export button text color
src/components/Kanban/Board.tsx Updated section header styling for "COMPLETED" sections with green border and bold white text
src/components/Resource/ResourceBoard.tsx Added board name tooltip to ExportButton for improved context
src/components/Shifting/ShiftingBoard.tsx Added board-specific tooltip to ExportButton and refined drag-and-drop navigation logic

Assessment against linked issues

Objective Addressed Explanation
Improve Visibility of 'Completed' Tag [#9417]
Use Green Text/Background for Completed State

Possibly related PRs

Suggested Labels

needs review, tested

Suggested Reviewers

  • rithviknishad
  • Jacobjeevan
  • bodhish

Poem

🐰 A rabbit's tale of code so bright,
Green borders dancing with delight,
Tooltips whisper, buttons gleam,
Completed tasks now reign supreme,
Coding magic takes its flight! 🚀


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

netlify bot commented Dec 19, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit b6ec446
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67656265bc95a40008bf7a02
😎 Deploy Preview https://deploy-preview-9499--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.

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

🔭 Outside diff range comments (1)
src/components/Shifting/ShiftingBoard.tsx (1)

Line range hint 176-182: Enhance drag-and-drop user experience

The current implementation could benefit from better error handling and user feedback.

Consider these improvements:

           onDragEnd={(result) => {
-            if (result.source.droppableId !== result.destination?.droppableId)
+            if (result.source.droppableId !== result.destination?.droppableId) {
+              const updateStatus = async () => {
+                try {
+                  // Show loading state
+                  setIsUpdating(true);
                   navigate(
                     `/shifting/${result.draggableId}/update?status=${result.destination?.droppableId}`,
                   );
+                } catch (error) {
+                  // Show error notification
+                  showErrorNotification(t('status_update_failed'));
+                } finally {
+                  setIsUpdating(false);
+                }
+              };
+              updateStatus();
+            }
           }}

Also consider adding visual feedback during drag operations using the isDragging prop from the drag context.

🧹 Nitpick comments (5)
src/components/Common/Export.tsx (1)

133-137: Simplify conditional class names using template literals

The current nested ternary expression could be simplified for better readability.

- className={`tooltip mx-2 p-4 text-lg ${
-   isCompleted
-     ? "text-white"
-     : "text-secondary-800 disabled:bg-transparent disabled:text-secondary-500"
- }`}
+ className={`tooltip mx-2 p-4 text-lg ${
+   isCompleted ? "text-white" : "text-secondary-800"
+ } disabled:bg-transparent disabled:text-secondary-500`}
src/components/Resource/ResourceBoard.tsx (1)

Line range hint 119-131: Consider caching the export action callback

The export action callback is recreated on every render. Consider memoizing it for better performance.

+ const getExportAction = useCallback((board: string) => async () => {
+   const { data } = await request(routes.downloadResourceRequests, {
+     query: {
+       ...formatFilter({ ...qParams, status: board }),
+       csv: true,
+     },
+   });
+   return data ?? null;
+ }, [qParams]);

- action={async () => {
-   const { data } = await request(routes.downloadResourceRequests, {
-     query: {
-       ...formatFilter({ ...qParams, status: board }),
-       csv: true,
-     },
-   });
-   return data ?? null;
- }}
+ action={getExportAction(board)}
src/components/Shifting/ShiftingBoard.tsx (3)

150-150: Enhance tooltip accessibility and internationalization

The tooltip text should be translated and more descriptive to improve user experience.

Consider applying this change:

-                  tooltip={`${board.text}`}
+                  tooltip={t('export_shifts_for_status', { status: t(board.text.toLowerCase()) })}

Line range hint 54-69: Consider extracting status configuration

The wartime/peacetime status configuration could be more maintainable and type-safe.

Consider creating a dedicated configuration module:

// src/config/shiftingStatus.ts
export interface ShiftingStatusConfig {
  completed: string[];
  active: string[];
  isCompleted: (status: string) => boolean;
}

export const getShiftingStatusConfig = (isWartime: boolean): ShiftingStatusConfig => ({
  completed: isWartime 
    ? ["COMPLETED", "REJECTED", "CANCELLED", "DESTINATION REJECTED", "PATIENT EXPIRED"]
    : ["CANCELLED", "PATIENT EXPIRED"],
  active: [...], // Define active statuses
  isCompleted: (status: string) => completed.includes(status)
});

Line range hint 36-201: Consider component decomposition and performance optimization

The BoardView component handles multiple responsibilities and could benefit from decomposition and optimization.

Consider these improvements:

  1. Extract the status management logic into a custom hook:
// useShiftingStatus.ts
export const useShiftingStatus = (isWartime: boolean) => {
  const [activeFilter, setActiveFilter] = useState<boolean>(true);
  const statusConfig = useMemo(() => getShiftingStatusConfig(isWartime), [isWartime]);
  const currentBoards = useMemo(() => 
    activeFilter ? statusConfig.active : statusConfig.completed,
    [activeFilter, statusConfig]
  );
  return { currentBoards, setActiveFilter, statusConfig };
};
  1. Extract the header section into a separate component:
const ShiftingBoardHeader: React.FC<{
  onViewChange: () => void;
  onSearch: (value: string) => void;
  onFilterChange: () => void;
}> = memo(({ onViewChange, onSearch, onFilterChange }) => {
  // Header rendering logic
});
  1. Memoize callbacks and derived state:
+  const handleSearch = useCallback((e) => 
+    updateQuery({ [e.name]: e.value }), 
+    [updateQuery]
+  );

+  const exportAction = useCallback(async () => {
+    const { data } = await request(routes.downloadShiftRequests, {
+      query: { ...formatFilter(qParams), csv: true },
+    });
+    return data ?? null;
+  }, [qParams]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 213e114 and 7a383b3.

📒 Files selected for processing (4)
  • src/components/Common/Export.tsx (2 hunks)
  • src/components/Kanban/Board.tsx (1 hunks)
  • src/components/Resource/ResourceBoard.tsx (1 hunks)
  • src/components/Shifting/ShiftingBoard.tsx (1 hunks)
🔇 Additional comments (1)
src/components/Shifting/ShiftingBoard.tsx (1)

Line range hint 11-11: Request for additional context

The changes to ExportButton component in Export.tsx were mentioned in the AI summary but the file is not provided for review. Please provide the Export.tsx file to ensure the tooltip implementation is consistent with the changes made there.

✅ Verification successful

No changes needed in other files

The Export.tsx file shows that the ExportButton component already has proper tooltip implementation with the tooltipClassName prop and tooltip text display. The changes in ShiftingBoard.tsx are consistent with the existing implementation in Export.tsx. No other files need modifications as they are already using the same component interface.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for recent changes to Export.tsx
git log -p -- src/components/Common/Export.tsx

Length of output: 0


Script:

#!/bin/bash
# Search for Export.tsx files in the repository
fd -e tsx -e ts "Export"

# Search for ExportButton component usage
rg -l "ExportButton|Export\.tsx" --type ts --type tsx

Length of output: 165


Script:

#!/bin/bash
# Check the content of Export.tsx
cat src/components/Common/Export.tsx

# Search for ExportButton usage with correct file type
rg -t ts "ExportButton"

Length of output: 5742

@@ -113,7 +113,7 @@ export const ExportButton = ({
...props
}: ExportButtonProps) => {
const { isExporting, exportFile } = useExport();

const isCompleted = props.tooltip?.toLowerCase() === "completed";
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

Consider using a dedicated prop for completion status

Using the tooltip text to determine completion status mixes presentation with business logic. This approach is fragile and could break if tooltip text changes.

Consider adding a dedicated prop:

- const isCompleted = props.tooltip?.toLowerCase() === "completed";
+ interface ExportButtonProps {
+   // ... existing props
+   isCompleted?: boolean;
+ }
+ 
+ export const ExportButton = ({
+   isCompleted = false,
+   // ... other props
+ }: ExportButtonProps)

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

Comment on lines +153 to +166
<div
className={`mx-2 flex items-center justify-between rounded-lg border p-4 ${
section.id === "COMPLETED"
? "border-green-500 bg-green-500 "
: "border-secondary-300 bg-white"
}`}
>
<div>
{section.id === "COMPLETED" ? (
<span className="font-bold text-white">{section.title}</span>
) : (
section.title
)}
</div>
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

Extract status constants and simplify conditional rendering

The current implementation has several areas for improvement:

  1. Hardcoded "COMPLETED" string
  2. Complex nested conditional rendering
  3. Multiple nested divs

Consider this refactor:

+ const SECTION_STATUS = {
+   COMPLETED: 'COMPLETED'
+ } as const;
+
+ const getSectionHeaderClass = (status: string) => 
+   status === SECTION_STATUS.COMPLETED
+     ? "border-green-500 bg-green-500"
+     : "border-secondary-300 bg-white";

- <div
-   className={`mx-2 flex items-center justify-between rounded-lg border p-4 ${
-     section.id === "COMPLETED"
-       ? "border-green-500 bg-green-500 "
-       : "border-secondary-300 bg-white"
-   }`}
- >
-   <div>
-     {section.id === "COMPLETED" ? (
-       <span className="font-bold text-white">{section.title}</span>
-     ) : (
-       section.title
-     )}
-   </div>
+ <div className={`mx-2 flex items-center justify-between rounded-lg border p-4 ${getSectionHeaderClass(section.id)}`}>
+   <span className={section.id === SECTION_STATUS.COMPLETED ? "font-bold text-white" : ""}>
+     {section.title}
+   </span>
📝 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
<div
className={`mx-2 flex items-center justify-between rounded-lg border p-4 ${
section.id === "COMPLETED"
? "border-green-500 bg-green-500 "
: "border-secondary-300 bg-white"
}`}
>
<div>
{section.id === "COMPLETED" ? (
<span className="font-bold text-white">{section.title}</span>
) : (
section.title
)}
</div>
const SECTION_STATUS = {
COMPLETED: 'COMPLETED'
} as const;
const getSectionHeaderClass = (status: string) =>
status === SECTION_STATUS.COMPLETED
? "border-green-500 bg-green-500"
: "border-secondary-300 bg-white";
<div className={`mx-2 flex items-center justify-between rounded-lg border p-4 ${getSectionHeaderClass(section.id)}`}>
<span className={section.id === SECTION_STATUS.COMPLETED ? "font-bold text-white" : ""}>
{section.title}
</span>

@@ -116,6 +116,7 @@ export default function BoardView() {
<h3 className="flex h-8 items-center text-xs">
{board}{" "}
<ExportButton
tooltip={`${board}`}
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 translation and improve accessibility for tooltips

The tooltip text should be translated and accessible.

- tooltip={`${board}`}
+ tooltip={t(`resource_board_export_tooltip`, { board: t(board.toLowerCase()) })}
+ aria-label={t(`resource_board_export_aria_label`, { board: t(board.toLowerCase()) })}

Also, ensure these translation keys are added to your i18n files:

{
  "resource_board_export_tooltip": "Export {{board}} resources",
  "resource_board_export_aria_label": "Export resources from {{board}} board"
}

@bodhish
Copy link
Member

bodhish commented Dec 22, 2024

#9417 (comment)

@bodhish bodhish closed this Dec 22, 2024
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.

Enhancement Request: Improve Visibility of the 'Completed' Tag in Shifting and Resource Section
2 participants