Skip to content

fix: survey list spacing and loading#4003

Merged
jobenjada merged 1 commit intomainfrom
fix-survey-overview
Oct 23, 2024
Merged

fix: survey list spacing and loading#4003
jobenjada merged 1 commit intomainfrom
fix-survey-overview

Conversation

@jobenjada
Copy link
Member

@jobenjada jobenjada commented Oct 23, 2024

fix: survey list spacing and loading

Summary by CodeRabbit

  • New Features

    • Enhanced layout and styling for the SurveyCard component for improved visual clarity.
    • Improved duplication process in SurveyDropdownMenu for better survey management.
    • Adjusted grid layout in SurveyList for enhanced visibility of survey names.
    • Updated loading representation in SurveyLoading for a streamlined user experience.
  • Bug Fixes

    • Retained error handling in survey actions for consistent user feedback.
  • Chores

    • Consolidated import statements for better code organization.

@vercel
Copy link

vercel bot commented Oct 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Oct 23, 2024 7:36pm
formbricks-docs ⬜️ Ignored (Inspect) Oct 23, 2024 7:36pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

Walkthrough

The pull request introduces structural and styling modifications to several components related to surveys. Key changes include updates to the SurveyCard, SurveyDropdownMenu, SurveyList, and SurveyLoading components, focusing on layout enhancements, visual clarity, and user interaction improvements. The SurveyDropdownMenu also sees an enhancement in the survey duplication logic. Overall, these changes aim to refine the user interface while maintaining core functionalities.

Changes

File Path Change Summary
apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyCard.tsx Structural modifications to the SurveyCard component, including a grid layout for child elements, simplified Link className, adjusted column spans, modified hover effects, and repositioned dropdown menu.
apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyDropdownMenu.tsx Consolidated import statements, enhanced duplicateSurveyAndRefresh function to include getSurveyAction, and modified dropdown trigger background color. Error handling remains intact.
apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyList.tsx Adjusted grid layout with increased column span for "Name" header and modified padding. No changes to logic or functionality.
apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyLoading.tsx Simplified JSX structure, reduced height of inner divs, modified widths and background colors, and added new divs for loading representation.
packages/lib/time.ts Consolidated import statement for date-fns functions and updated convertDateString to use short month format. Other functions remain unchanged.

Possibly related PRs

Suggested labels

bug, enhancement, 🕹️ oss.gg, 🕹️ 150 points

Suggested reviewers

  • Dhruwang

Poem

In the land of surveys, bright and fair,
Cards and menus dance with flair.
Grids align, and dropdowns gleam,
Loading states now flow like a dream.
With each click, a joy to find,
A rabbit's hop, so well designed! 🐇✨


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.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2024

Thank you for following the naming conventions for pull request titles! 🙏

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 and nitpick comments (9)
apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyLoading.tsx (2)

5-21: LGTM! Consider reducing placeholder elements for better performance.

The layout changes and styling improvements look good. The simplified grid layout and reduced height create a cleaner loading state. However, rendering 5 identical loading placeholders with 7 elements each (35 total) might impact performance during frequent loading states.

Consider reducing the number of placeholder items to 3 for a better balance between visual feedback and performance:

- {[1, 2, 3, 4, 5].map((i) => {
+ {[1, 2, 3].map((i) => {

5-5: Add ARIA attributes for better accessibility.

Loading states should be properly announced to screen readers.

Add appropriate ARIA attributes to the container:

- <div className="grid h-full w-full animate-pulse place-content-stretch gap-4">
+ <div 
+   role="status"
+   aria-label="Loading surveys"
+   className="grid h-full w-full animate-pulse place-content-stretch gap-4">
apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyCard.tsx (4)

76-78: Consider adding a tooltip for truncated survey names.

When survey names are truncated, users can't see the full name. Consider adding a tooltip to improve usability.

-          <div className="w-full truncate">{survey.name}</div>
+          <div className="w-full truncate" title={survey.name}>{survey.name}</div>

90-92: Add number formatting for response count.

Large numbers would be more readable with thousand separators.

-          {survey.responseCount}
+          {survey.responseCount.toLocaleString()}

93-95: Simplify survey type indicator container.

The flex container with justify-between is unnecessary for a single child element.

-        <div className="col-span-1 flex justify-between">
+        <div className="col-span-1">

Line range hint 107-121: Consider using CSS custom properties for positioning values.

The magic numbers in positioning could be converted to CSS custom properties for better maintainability.

+// Add to your CSS variables
+:root {
+  --survey-card-dropdown-right: 0.75rem; /* 3 */
+  --survey-card-dropdown-top: 0.875rem; /* 3.5 */
+}

-      <div className="absolute right-3 top-3.5">
+      <div className="absolute right-[var(--survey-card-dropdown-right)] top-[var(--survey-card-dropdown-top)]">
apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyList.tsx (1)

140-140: Consider using consistent padding.

The grid has asymmetric padding (px-6 pr-8). Consider using consistent padding on both sides for better visual balance.

-<div className="mt-6 grid w-full grid-cols-8 place-items-center gap-3 px-6 pr-8 text-sm text-slate-800">
+<div className="mt-6 grid w-full grid-cols-8 place-items-center gap-3 px-8 text-sm text-slate-800">
apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyDropdownMenu.tsx (2)

Line range hint 82-98: Consider adding retry logic for survey data fetch.

While the enhanced duplication logic is good, there might be a race condition if the duplicated survey data isn't immediately available. Consider adding a small delay or retry mechanism before fetching the survey data.

 if (duplicatedSurveyResponse?.data) {
+  // Add a small delay to ensure data consistency
+  await new Promise((resolve) => setTimeout(resolve, 500));
   const transformedDuplicatedSurvey = await getSurveyAction({
     surveyId: duplicatedSurveyResponse.data.id,
   });
   if (transformedDuplicatedSurvey?.data) duplicateSurvey(transformedDuplicatedSurvey.data);
   toast.success("Survey duplicated successfully.");

Line range hint 109-113: Consider using theme-aware background color.

While the white background looks clean, consider using a theme-aware background color for better dark mode compatibility.

-          <div className="rounded-lg border bg-white p-2 hover:bg-slate-50">
+          <div className="rounded-lg border bg-background p-2 hover:bg-muted">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9465bd1 and bfd4c99.

📒 Files selected for processing (5)
  • apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyCard.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyDropdownMenu.tsx (2 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyList.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyLoading.tsx (1 hunks)
  • packages/lib/time.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (7)
packages/lib/time.ts (2)

1-1: LGTM! Clean import consolidation.

The consolidated import statement improves code organization while maintaining the same functionality.


12-12: Verify the month format consistency across the application.

The change from "long" to "short" month format in convertDateString creates an inconsistency with other date formatting functions in this file that use "long" format. While this change might help with spacing issues, please verify:

  1. The intentional difference in format is documented
  2. The UI maintains a consistent appearance where these different formats are used

Let's check where this function is used:

✅ Verification successful

Let me try different commands to verify the usage of this function.


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

The month format change in convertDateString is appropriate and doesn't create inconsistency

The search results show that convertDateString is only used in SurveyCard.tsx to display survey creation dates. The other date formatting functions serve different purposes:

  • convertDateTimeString and convertDateTimeStringShort include time components
  • formatDate is used in a different context (load segment modal)
  • Each function's format choice matches its specific use case

The "short" month format in convertDateString is suitable for the survey card context where space might be limited, while the "long" format is maintained in other functions where full date-time details are needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find usage of convertDateString to understand the impact
# Expected results: Files where the function is used, particularly in survey-related components

# Search for direct usage of convertDateString
echo "Direct usage of convertDateString:"
rg "convertDateString" --type ts --type tsx -A 2

# Search for imported usage from the time utility
echo -e "\nImports of time utility:"
rg "from.*['\"].*time['\"]" --type ts --type tsx -A 2

Length of output: 308


Script:

#!/bin/bash
# Search for direct usage of convertDateString without file type restrictions
echo "Direct usage of convertDateString:"
rg "convertDateString"

# Search for imports from time utility without file type restrictions
echo -e "\nImports from time utility:"
rg "from.*['\"].*time['\"]"

# Let's also look at the time.ts file to understand the context better
echo -e "\nContent of time.ts:"
find . -name "time.ts" -exec cat {} \;

Length of output: 8601

apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyCard.tsx (1)

74-75: LGTM! Clean and well-structured layout implementation.

The grid layout and styling provide a clear visual hierarchy with appropriate spacing and hover effects.

apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyList.tsx (2)

140-141: LGTM: Grid layout improvements enhance readability.

The column span adjustment for the "Name" header (col-span-2) provides better space distribution and aligns with the survey list's visual hierarchy.


140-141: Verify grid layout consistency with SurveyCard component.

Let's ensure the grid layout changes are consistent with the SurveyCard component's implementation.

✅ Verification successful

Based on the results, I can now generate the final response since I have enough information to verify the grid layout consistency.

Grid layout is consistent between header and card components

The grid layouts are perfectly aligned:

  • Both components use grid-cols-8 for the main container
  • Both have a col-span-2 for the name column at the start
  • The remaining columns each use col-span-1, maintaining consistent spacing
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if SurveyCard's grid layout matches the header's column structure

# Test: Search for grid-related classes in SurveyCard
rg -A 5 "grid-cols-8|col-span-[12]" "apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyCard.tsx"

Length of output: 1945

apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyDropdownMenu.tsx (2)

6-6: LGTM! Clean import organization.

The consolidation of icon imports and addition of getSurveyAction improves code maintainability.

Also applies to: 9-17


6-6: Verify integration with related components.

Let's verify the integration of these changes:

Also applies to: 109-109

✅ Verification successful

Let me generate new shell scripts with the correct syntax to verify the usage of getSurveyAction.

The previous command failed because of incorrect file type specification. Let's try with basic ripgrep and also examine the specific file to understand the context better. This will help us verify:

  1. Where getSurveyAction is used across the codebase
  2. How it's being used in the current file context

Based on the results, I can now generate the final response as we have sufficient information about the usage of getSurveyAction.

The import and usage of getSurveyAction is correctly integrated

The verification shows that getSurveyAction is:

  • Properly exported from actions.ts in the same directory
  • Used correctly within SurveyDropdownMenu.tsx for fetching survey data after duplication
  • Only used in a contained way within the surveys feature, with no unexpected usage elsewhere in the codebase

The theme-related styles (bg-white) are also properly scoped to the component's dropdown trigger and don't require changes in other components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check usage of getSurveyAction and theme-related styles
echo "Checking getSurveyAction usage:"
rg "getSurveyAction" --type typescript

echo -e "\nChecking theme-related background styles:"
rg "bg-white" --type typescript

Length of output: 312


Script:

#!/bin/bash
# Check usage of getSurveyAction across the codebase
echo "Checking getSurveyAction usage:"
rg "getSurveyAction"

# Check the specific file to understand the context
echo -e "\nChecking the specific file content:"
cat "apps/web/app/(app)/environments/[environmentId]/surveys/components/SurveyDropdownMenu.tsx"

Length of output: 8740

Comment on lines +97 to +105
<div className="col-span-1 max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-sm text-slate-600">
{convertDateString(survey.createdAt.toString())}
</div>
<div className="col-span-1 max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-sm text-slate-600">
{timeSince(survey.updatedAt.toString())}
</div>
<div className="col-span-1 max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-sm text-slate-600">
{survey.creator ? survey.creator.name : "-"}
</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

Optimize metadata sections and consider live updates.

Two suggestions for improvement:

  1. Extract duplicate styles into a shared class
  2. Consider using a hook for live updates of relative times
+const MetadataCell = ({ children }) => (
+  <div className="col-span-1 max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-sm text-slate-600">
+    {children}
+  </div>
+);

-        <div className="col-span-1 max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-sm text-slate-600">
+        <MetadataCell>
           {convertDateString(survey.createdAt.toString())}
-        </div>
+        </MetadataCell>

Also consider adding a custom hook for live updates:

function useRelativeTime(timestamp: string) {
  const [time, setTime] = useState(() => timeSince(timestamp));
  
  useEffect(() => {
    const timer = setInterval(() => {
      setTime(timeSince(timestamp));
    }, 60000); // Update every minute
    
    return () => clearInterval(timer);
  }, [timestamp]);
  
  return time;
}

Comment on lines +79 to +89
<div
className={cn(
"col-span-1 flex w-fit items-center gap-2 whitespace-nowrap rounded-full py-1 pl-1 pr-2 text-sm text-slate-800",
surveyStatusLabel === "Scheduled" && "bg-slate-200",
surveyStatusLabel === "In Progress" && "bg-emerald-50",
surveyStatusLabel === "Completed" && "bg-slate-200",
surveyStatusLabel === "Draft" && "bg-slate-100",
surveyStatusLabel === "Paused" && "bg-slate-100"
)}>
<SurveyStatusIndicator status={survey.status} /> {surveyStatusLabel}{" "}
</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

Simplify status indicator styling logic.

The conditional styling could be simplified using a mapping object to reduce repetition and improve maintainability.

+const statusStyles = {
+  scheduled: "bg-slate-200",
+  inProgress: "bg-emerald-50",
+  completed: "bg-slate-200",
+  draft: "bg-slate-100",
+  paused: "bg-slate-100",
+};

-          className={cn(
-            "col-span-1 flex w-fit items-center gap-2 whitespace-nowrap rounded-full py-1 pl-1 pr-2 text-sm text-slate-800",
-            surveyStatusLabel === "Scheduled" && "bg-slate-200",
-            surveyStatusLabel === "In Progress" && "bg-emerald-50",
-            surveyStatusLabel === "Completed" && "bg-slate-200",
-            surveyStatusLabel === "Draft" && "bg-slate-100",
-            surveyStatusLabel === "Paused" && "bg-slate-100"
-          )}>
+          className={cn(
+            "col-span-1 flex w-fit items-center gap-2 whitespace-nowrap rounded-full py-1 pl-1 pr-2 text-sm text-slate-800",
+            statusStyles[survey.status]
+          )}>

Committable suggestion was skipped due to low confidence.

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