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

fix(web): improve project import #1199

Merged
merged 6 commits into from
Oct 29, 2024
Merged

fix(web): improve project import #1199

merged 6 commits into from
Oct 29, 2024

Conversation

mkumbobeaty
Copy link
Contributor

@mkumbobeaty mkumbobeaty commented Oct 25, 2024

Overview

  • Add teamId in project import mutation input

What I've done

What I haven't done

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features
    • Enhanced project import functionality by allowing imports with both teamId and file.
    • Updated export options to "Export (Experimental)" and "Import (Experimental)" to indicate these features are in a testing phase.
    • Added new translation keys for improved localization in Japanese, including "新規プロジェクト," "Workspace," and "Workspace Name."
  • Bug Fixes
    • Simplified error handling for project export operations, improving user feedback.
  • Documentation
    • Updated translations for import and export functionalities in both English and Japanese to reflect the new terminology.

Copy link

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes in this pull request primarily focus on the handleExportProject and handleImportProject functions within the Projects component. The handleExportProject function has been simplified by removing conditional logging of export results, while the handleImportProject function has been updated to accept an object containing both teamId and file, altering its parameter structure. Additionally, the useImportProject function has been modified to accommodate these changes. The overall functionality of the component remains intact, with no alterations to props or state management.

Changes

File Path Change Summary
web/src/beta/features/Dashboard/ContentsContainer/Projects/hooks.ts - handleExportProject: Removed conditional logging of export results.
- handleImportProject: Updated to accept an object with teamId and file.
web/src/services/api/projectApi.ts - useImportProject: Updated to accept an ImportProjectInput object instead of a single File parameter.
- Added new type ImportProjectInput.
web/src/services/gql/queries/project.ts - IMPORT_PROJECT mutation: Updated to require teamId alongside file parameter.
web/src/beta/features/Dashboard/ContentsContainer/Projects/index.tsx - Updated button title for importing projects from "Import" to "Import (Experimental).
- Updated button title for exporting projects from "Export" to "Export (Experimental)".
web/src/services/i18n/translations/en.yml - Updated translation keys for "Import" and "Export" to "Import (Experimental)" and "Export (Experimental)".
web/src/services/i18n/translations/ja.yml - Updated translation keys for "Import" and "Export" to "Import (Experimental)" and "Export (Experimental)".
- Added new keys for "Workspace" and "Workspace Name".
web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/ProjectGridViewItem.tsx - Removed commented-out code related to export modal, including variables and JSX block.
web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/ProjectListViewItem.tsx - Removed commented-out code related to export modal, including variables.

Possibly related PRs

Suggested labels

server

Suggested reviewers

  • pyshx

Poem

🐇 In the garden of code, changes bloom bright,
Export and import, now simpler in sight.
With team IDs added, our projects align,
A hop and a skip, all functions combine.
So let’s celebrate, with a joyful cheer,
For smoother imports, let’s give a big ear! 🎉


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dc27703 and 80ca34c.

📒 Files selected for processing (6)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/ProjectGridViewItem.tsx (0 hunks)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/ProjectListViewItem.tsx (0 hunks)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/hooks.ts (2 hunks)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/index.tsx (1 hunks)
  • web/src/services/i18n/translations/en.yml (2 hunks)
  • web/src/services/i18n/translations/ja.yml (2 hunks)
💤 Files with no reviewable changes (2)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/ProjectGridViewItem.tsx
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/ProjectListViewItem.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/hooks.ts
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/index.tsx
  • web/src/services/i18n/translations/en.yml
  • web/src/services/i18n/translations/ja.yml

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.

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 Oct 25, 2024

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit 80ca34c
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/6720350a15253600089fb58e
😎 Deploy Preview https://deploy-preview-1199--reearth-web.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.

@mkumbobeaty mkumbobeaty marked this pull request as ready for review October 25, 2024 14:55
@mkumbobeaty mkumbobeaty requested a review from airslice as a code owner October 25, 2024 14:55
@github-actions github-actions bot requested a review from m-abe-dev October 25, 2024 14:55
Copy link

codecov bot commented Oct 25, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 18.80%. Comparing base (e33d88e) to head (06ff0a2).
Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
...ures/Dashboard/ContentsContainer/Projects/hooks.ts 0.00% 5 Missing ⚠️
web/src/services/api/projectApi.ts 40.00% 3 Missing ⚠️
...hboard/ContentsContainer/Projects/Project/hooks.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1199      +/-   ##
==========================================
+ Coverage   13.85%   18.80%   +4.95%     
==========================================
  Files         595      597       +2     
  Lines       64056    65186    +1130     
  Branches      660      601      -59     
==========================================
+ Hits         8873    12259    +3386     
+ Misses      55183    52927    -2256     
Flag Coverage Δ
web 18.80% <50.00%> (+4.95%) ⬆️
web-beta 18.80% <50.00%> (+4.95%) ⬆️
web-classic 18.80% <50.00%> (+4.95%) ⬆️
web-utils 18.80% <50.00%> (+4.95%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
web/src/services/gql/__gen__/gql.ts 100.00% <100.00%> (ø)
web/src/services/gql/__gen__/graphql.ts 100.00% <100.00%> (ø)
web/src/services/gql/queries/project.ts 100.00% <100.00%> (ø)
...hboard/ContentsContainer/Projects/Project/hooks.ts 0.00% <0.00%> (ø)
web/src/services/api/projectApi.ts 8.40% <40.00%> (-0.42%) ⬇️
...ures/Dashboard/ContentsContainer/Projects/hooks.ts 0.00% <0.00%> (ø)

... and 119 files with indirect coverage changes

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

🧹 Outside diff range and nitpick comments (1)
web/src/services/api/projectApi.ts (1)

531-532: Enhance input validation

The current check if (!input) only validates if the input object exists. Consider adding specific validation for required fields:

-if (!input) return { status: "error" };
+if (!input?.teamId || !input?.file) {
+  console.log("GraphQL: Missing required fields for project import");
+  return { status: "error" };
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cfbf54b and 06ff0a2.

⛔ Files ignored due to path filters (2)
  • web/src/services/gql/__gen__/gql.ts is excluded by !**/__gen__/**
  • web/src/services/gql/__gen__/graphql.ts is excluded by !**/__gen__/**
📒 Files selected for processing (4)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/hooks.ts (1 hunks)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/hooks.ts (1 hunks)
  • web/src/services/api/projectApi.ts (2 hunks)
  • web/src/services/gql/queries/project.ts (1 hunks)
🔇 Additional comments (8)
web/src/services/gql/queries/project.ts (1)

222-223: LGTM! Verify mutation usage across the codebase.

The addition of the required teamId parameter is implemented correctly and follows the established patterns in the codebase. The mutation syntax and types are properly defined.

Let's verify that all consumers of this mutation have been updated with the new parameter:

✅ Verification successful

Let's examine the actual usage of the mutation in the identified files to ensure all consumers are properly updated.


All mutation consumers are properly updated with the new teamId parameter

The verification shows that the implementation is consistent across all consumers:

  • The GraphQL mutation is correctly defined in project.ts
  • The API implementation in projectApi.ts uses spread operator with the complete input type ({...input})
  • Generated types in __gen__ files are up to date
  • No instances of incomplete mutation calls were found
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any direct usage of IMPORT_PROJECT mutation or importProject API calls
# that might need updates for the new teamId parameter

# Look for direct mutation usage
echo "Checking for direct IMPORT_PROJECT mutation usage:"
rg -l "IMPORT_PROJECT|importProject" --type ts

# Look for potential mutation calls that might be missing teamId
echo -e "\nChecking for potential incomplete mutation calls:"
ast-grep --pattern 'importProject({ file: $_ })'

Length of output: 476


Script:

#!/bin/bash
# Check the implementation in projectApi.ts
echo "Content of projectApi.ts implementation:"
rg -A 5 "importProject" web/src/services/api/projectApi.ts

# Check for any direct mutation calls
echo -e "\nChecking for direct mutation calls in all TypeScript files:"
rg "importProject\(" --type ts -A 3

Length of output: 3457

web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/hooks.ts (1)

Line range hint 1-200: Verify the import functionality changes.

While this file shows changes to export functionality, the PR objectives mention adding teamId to project import. However, the import-related changes are not visible in this file.

Let's verify the import-related changes:

web/src/beta/features/Dashboard/ContentsContainer/Projects/hooks.ts (3)

242-245: LGTM! Changes align with PR objectives.

The modification to include teamId in the import function matches the PR's goal of improving project import functionality.


251-251: LGTM! Dependency array is correctly updated.

The addition of workspaceId to the dependency array is correct as it's used within the callback.


242-245: Verify API contract for empty teamId.

The code falls back to an empty string when workspaceId is undefined. Let's verify if the API properly handles this case.

✅ Verification successful

Let me search for more specific information about the import project mutation and its implementation.


Based on the search results and the learning from user feedback that states "when teamId is undefined, passing an empty string "" as teamId to the GraphQL query is correct because the API requires a string and handles empty strings appropriately", I can now provide a final response:

Empty string fallback for teamId is the correct approach

The current implementation aligns with the API contract. The GraphQL mutation expects teamId as an ID! type, and falling back to an empty string when workspaceId is undefined is the established pattern that the API properly handles.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the IMPORT_PROJECT mutation definition and its usage
ast-grep --pattern 'mutation IMPORT_PROJECT($teamId: String!, $file: Upload!) {
  $$$
}'

# Search for other implementations handling teamId
rg -g '*.{ts,tsx,graphql}' 'teamId.*String!'

Length of output: 4001


Script:

#!/bin/bash
# Search for IMPORT_PROJECT mutation in graphql files
rg -g '*.graphql' 'IMPORT_PROJECT'

# Search for import project related code
rg -g '*.{ts,tsx}' 'importProject|IMPORT_PROJECT' -A 3

# Search specifically for the useImportProject hook implementation
ast-grep --pattern 'const useImportProject = $_'

Length of output: 43120

web/src/services/api/projectApi.ts (3)

17-18: LGTM: Import changes are well-structured

The addition of ImportProjectInput type is aligned with the PR objective of enhancing project import functionality.


Line range hint 531-558: LGTM: Function implementation is well-structured

The changes to useImportProject are well-implemented:

  • Type-safe with ImportProjectInput
  • Proper error handling with user notifications
  • Consistent with GraphQL mutation structure

Line range hint 531-558: Verify integration with callers

Let's ensure all callers of useImportProject have been updated to provide both teamId and file.

✅ Verification successful

Let me verify the GraphQL mutation definition to ensure it's properly defined before making a conclusion.


Let me try a different approach to find the GraphQL mutation definition.


Let me try one last search without file type restrictions.


Based on the search results, I can now generate the final response:

Integration with callers is properly implemented

The codebase analysis shows:

  • The useImportProject hook is correctly used in web/src/beta/features/Dashboard/ContentsContainer/Projects/hooks.ts with both required parameters:
    • teamId (as workspaceId)
    • file
  • The GraphQL mutation is properly defined in server/gql/project.graphql with the correct input type ImportProjectInput requiring both fields
  • The server-side implementation in server/internal/adapter/gql/resolver_mutation_project.go handles the input correctly
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for useImportProject usage
rg "useImportProject" -A 5

Length of output: 2437


Script:

#!/bin/bash
# Search for importProject mutation definition
ast-grep --pattern 'mutation importProject'

# Also search for ImportProjectInput type definition
ast-grep --pattern 'type ImportProjectInput'

Length of output: 92


Script:

#!/bin/bash
# Search for importProject in GraphQL files
rg "importProject" --type graphql -A 5

# Also search for ImportProjectInput in TypeScript files
rg "ImportProjectInput" --type typescript -A 3

Length of output: 152


Script:

#!/bin/bash
# Search for importProject mutation and input type definitions
rg "importProject|ImportProjectInput" -A 5

# Also search for .graphql files to ensure we're not missing any
fd ".graphql$"

Length of output: 88792

@mulengawilfred
Copy link
Contributor

Implementation is good. I have two questions added and I think we would also require backend changes in this repo to support the new input property.

@mkumbobeaty
Copy link
Contributor Author

Implementation is good. I have two questions added and I think we would also require backend changes in this repo to support the new input property.

@mulengawilfred actually the backend already handled this input that why I updated on front-end

@mkumbobeaty mkumbobeaty reopened this Oct 28, 2024
@github-actions github-actions bot requested a review from pyshx October 28, 2024 06:32
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: 2

🧹 Outside diff range and nitpick comments (2)
web/src/beta/features/Dashboard/ContentsContainer/Projects/index.tsx (1)

Line range hint 93-102: Consider enhancing the import UX.

Since this is an experimental feature, consider the following improvements:

  1. Add a loading state during import
  2. Provide user feedback for successful/failed imports
  3. Add a tooltip explaining the experimental nature and any limitations

Example implementation:

<ManagerHeaderButton
  key={"import-project"}
  title={t("Import Experimental")}
  managerSize="large"
  icon="signIn"
  appearance="secondary"
  onClick={() => fileInputRef.current?.click()}
  tooltip={t("This is an experimental feature. Some limitations may apply.")}
  disabled={isImporting}
/>
{isImporting && <Loading />}
web/src/services/i18n/translations/en.yml (1)

40-40: Consider adding explanatory text for "Experimental" features.

To improve user experience, consider adding translation keys for tooltip or help text that explains what "Experimental" means (e.g., beta features, potential instability, etc.).

Example additions:

Import Experimental: ''
+Import Experimental Tooltip: 'This feature is in beta and may be subject to changes'
Export Experimental: ''
+Export Experimental Tooltip: 'This feature is in beta and may be subject to changes'

Also applies to: 49-49

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 06ff0a2 and b78301f.

📒 Files selected for processing (4)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/hooks.ts (2 hunks)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/index.tsx (1 hunks)
  • web/src/services/i18n/translations/en.yml (2 hunks)
  • web/src/services/i18n/translations/ja.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/beta/features/Dashboard/ContentsContainer/Projects/Project/hooks.ts
🔇 Additional comments (3)
web/src/beta/features/Dashboard/ContentsContainer/Projects/index.tsx (1)

93-93: LGTM! Verify import handler implementation.

The title change to "Import Experimental" appropriately indicates this is a feature in testing. However, we should verify that the import handler correctly implements the new teamId parameter as per the PR objective.

Let's verify the implementation of handleImportProject:

✅ Verification successful

Import functionality correctly implements teamId parameter

The verification confirms that:

  • The GraphQL mutation IMPORT_PROJECT properly accepts and requires teamId as a parameter
  • The import handler in hooks.ts correctly passes workspaceId as teamId to useImportProject
  • The mutation implementation in projectApi.ts properly forwards all input parameters to the GraphQL mutation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of handleImportProject and its integration with teamId

# Test 1: Check the hooks implementation
echo "Checking hooks implementation..."
rg -A 10 "handleImportProject" "web/src/beta/features/Dashboard/ContentsContainer/Projects/hooks.ts"

# Test 2: Check the import project mutation
echo "Checking import project mutation..."
rg "IMPORT_PROJECT" --type ts

Length of output: 1129


Script:

#!/bin/bash
# Let's check the implementation details of the import project mutation and its usage

# Check the mutation definition
echo "Checking IMPORT_PROJECT mutation definition..."
rg -A 10 "IMPORT_PROJECT = gql" "web/src/services/gql/queries/project.ts"

# Check the mutation usage in projectApi
echo "Checking mutation usage in projectApi..."
rg -A 10 "importProjectMutation" "web/src/services/api/projectApi.ts"

# Check if there are any other usages of useImportProject
echo "Checking useImportProject usages..."
rg "useImportProject"

Length of output: 2026

web/src/services/i18n/translations/en.yml (1)

40-40: LGTM! Consistent labeling of experimental features.

The addition of "Experimental" to both Import and Export features helps set proper user expectations while these features are being enhanced with new capabilities like teamId support.

Also applies to: 49-49

web/src/services/i18n/translations/ja.yml (1)

40-41: Verify translation key usage and consistency.

Let's ensure these new experimental import/export keys are used consistently across the codebase and other language files.

Also applies to: 48-49

✅ Verification successful

Translation keys are properly used and consistent across language files

The verification shows that:

  • Both translation keys "Import Experimental" and "All projects" are present in both en.yml and ja.yml translation files
  • The keys are actively used in the codebase, particularly in:
    • Dashboard project components (web/src/beta/features/Dashboard/ContentsContainer/Projects/)
    • Plugin installation components (web/src/beta/features/ProjectSettings/innerPages/PluginSettings/)

The empty string values ('') in both language files indicate these are new keys awaiting translation, which is a valid approach for gradual localization.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check translation key usage and consistency

# Test 1: Check if these keys are used in the codebase
echo "Checking usage of Import/Export Experimental keys..."
rg -l "Import Experimental|Export Experimental" --type ts --type tsx

# Test 2: Check if other language files have these keys
echo "Checking other language files for these keys..."
fd -e yml -e yaml . src/services/i18n/translations --exec grep -l "Import Experimental\|Export Experimental" {} \;

Length of output: 556


Script:

#!/bin/bash
# Let's first find the correct paths and file types

# Find all translation files
echo "Finding translation files..."
fd -e yml -e yaml

# Find all TypeScript/JavaScript files
echo "Finding TypeScript/JavaScript files..."
fd -e ts -e tsx -e js -e jsx

# Check for "Import" and "All projects" strings in code files
echo "Checking usage of translation keys..."
rg -l "Import|All projects" -g "*.{ts,tsx,js,jsx}"

# Check these strings in translation files
echo "Checking translations..."
fd -e yml -e yaml --exec grep -H "Import\|All projects" {} \;

Length of output: 43659

web/src/services/i18n/translations/ja.yml Outdated Show resolved Hide resolved
web/src/services/i18n/translations/ja.yml Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants