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): custom domain form #1369

Merged
merged 2 commits into from
Jan 24, 2025
Merged

fix(web): custom domain form #1369

merged 2 commits into from
Jan 24, 2025

Conversation

hexaforce
Copy link
Contributor

@hexaforce hexaforce commented Jan 23, 2025

Overview

Fixes an issue where custom domain extension components were not loading correctly.

What I've done

The typename referenced in the separation of Project and Story was not being recognized correctly.

What I haven't done

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • Refactor

    • Removed optional typename properties from multiple type definitions across different files
    • Updated PublicSettingsDetail component with new function prop for Google Analytics settings
  • Chores

    • Simplified type structures in project settings and API-related files

@hexaforce hexaforce self-assigned this Jan 23, 2025
Copy link

coderabbitai bot commented Jan 23, 2025

Walkthrough

This pull request involves removing optional typename properties from several TypeScript types across different files in the web application. The changes primarily affect type definitions in project settings, storytelling API utilities, and publication extension configurations. The modifications aim to streamline type structures by eliminating unnecessary type identification properties, potentially simplifying type handling and reducing potential type-related complexities.

Changes

File Change Summary
web/src/beta/features/ProjectSettings/.../{PublicSettingsDetail.tsx, index.tsx} Removed optional typename property from SettingsProject type, updated component props to include onUpdateGA function
web/src/services/api/storytellingApi/utils.ts Removed optional typename?: "Story" from Story type
web/src/services/config/extensions.ts Removed typename from ProjectPublicationExtensionProps and StoryPublicationExtensionProps types

Possibly related PRs

Suggested labels

web

Suggested reviewers

  • mkumbobeaty
  • m-abe-dev
  • airslice

Poem

🐰 Type cleanup, oh so neat
Removing typename, a coding feat
Streamlined types, no extra fluff
Our code now looks clean enough!
Rabbit's refactor, simple 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.

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 github-actions bot added the web label Jan 23, 2025
Copy link

netlify bot commented Jan 23, 2025

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit 08648d4
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/679304f289e89c0008bc2486
😎 Deploy Preview https://deploy-preview-1369--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.

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

🔭 Outside diff range comments (1)
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (1)

Line range hint 125-133: Consider improving type safety and error handling in ExtensionComponent.

The current implementation could benefit from the following improvements:

  1. Add type guards to handle the union type props safely
  2. Add validation for empty typename
  3. Wrap the extension component in an error boundary

Here's a suggested implementation:

-  const ExtensionComponent = (props: ExtensionComponentProps) => {
-    const type = props.typename.toLocaleLowerCase();
-    const extensionId = `custom-${type}-domain`;
-    const Component = extensions?.find((e) => e.id === extensionId)?.component;
-    if (!Component) {
-      return null;
-    }
-    return <Component {...props} />;
+  const ExtensionComponent = (props: ExtensionComponentProps) => {
+    const type = props.typename?.trim().toLowerCase();
+    if (!type) return null;
+    
+    const extensionId = `custom-${type}-domain`;
+    const Component = extensions?.find((e) => e.id === extensionId)?.component;
+    if (!Component) return null;
+    
+    return (
+      <ErrorBoundary fallback={<div>Extension failed to load</div>}>
+        <Component
+          {...(props.typename === "Project"
+            ? (props as ProjectPublicationExtensionProps)
+            : (props as StoryPublicationExtensionProps)
+          )}
+        />
+      </ErrorBoundary>
+    );
+  };
🧹 Nitpick comments (1)
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (1)

264-284: Consider improving error handling and user experience in extension rendering.

The current implementation could benefit from the following improvements:

  1. Add a loading state while the access token is being fetched
  2. Add a fallback UI when extensions are not available
  3. Add null checks for typename access

Here's a suggested implementation:

-      {extensions && extensions.length > 0 && accessToken && (
+      {extensions?.length > 0 ? (
+        accessToken ? (
         <Collapse title={t("Custom Domain")} size="large">
           <ExtensionComponent
-            typename={settingsItem.__typename || ""}
+            typename={settingsItem.__typename ?? ""}
             {...(settingsItem.__typename === "Project"
               ? {
                   projectId: settingsItem.id,
                   projectAlias: settingsItem.alias
                 }
               : {
                   storyId: settingsItem.id,
                   storyAlias: settingsItem.alias
                 })}
             lang={currentLang}
             theme={currentTheme}
             accessToken={accessToken}
             onNotificationChange={onNotificationChange}
             version="visualizer"
           />
         </Collapse>
+        ) : (
+          <LoadingSpinner />
+        )
+      ) : (
+        <EmptyState message={t("No custom domain extensions available")} />
       )}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1141a0c and 4f5f20e.

📒 Files selected for processing (4)
  • web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (3 hunks)
  • web/src/beta/features/ProjectSettings/innerPages/PublicSettings/index.tsx (0 hunks)
  • web/src/services/api/storytellingApi/utils.ts (0 hunks)
  • web/src/services/config/extensions.ts (0 hunks)
💤 Files with no reviewable changes (3)
  • web/src/services/config/extensions.ts
  • web/src/services/api/storytellingApi/utils.ts
  • web/src/beta/features/ProjectSettings/innerPages/PublicSettings/index.tsx
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: ci-server / ci-server-lint
  • GitHub Check: ci-server / ci-server-test
  • GitHub Check: ci-web / ci
  • GitHub Check: Redirect rules - reearth-web
  • GitHub Check: Header rules - reearth-web
  • GitHub Check: Pages changed - reearth-web
🔇 Additional comments (3)
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (3)

31-37: LGTM! Well-structured type definitions.

The new type definitions follow TypeScript best practices and properly handle the optional __typename property using type composition.


39-45: LGTM! Props interface is well-defined.

The props interface properly handles both project and story settings with appropriate type safety.


46-52: LGTM! Extension props type is well-structured.

The type definition properly handles both project and story publication extensions while ensuring type safety with the required typename property.

Copy link

codecov bot commented Jan 24, 2025

Codecov Report

Attention: Patch coverage is 0% with 37 lines in your changes missing coverage. Please review.

Project coverage is 22.62%. Comparing base (1141a0c) to head (08648d4).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...innerPages/PublicSettings/PublicSettingsDetail.tsx 0.00% 37 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1369      +/-   ##
==========================================
- Coverage   22.79%   22.62%   -0.17%     
==========================================
  Files        1052     1061       +9     
  Lines      109347   110306     +959     
  Branches      669      677       +8     
==========================================
+ Hits        24924    24959      +35     
- Misses      83161    84084     +923     
- Partials     1262     1263       +1     
Flag Coverage Δ
server 31.51% <ø> (ø)
web 17.64% <0.00%> (-0.20%) ⬇️
web-beta 17.64% <0.00%> (-0.20%) ⬇️
web-classic 17.64% <0.00%> (-0.20%) ⬇️
web-utils 17.64% <0.00%> (-0.20%) ⬇️

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

Files with missing lines Coverage Δ
...rojectSettings/innerPages/PublicSettings/index.tsx 0.00% <ø> (ø)
web/src/services/api/storytellingApi/utils.ts 62.33% <ø> (ø)
web/src/services/config/extensions.ts 66.14% <ø> (+2.58%) ⬆️
...innerPages/PublicSettings/PublicSettingsDetail.tsx 0.00% <0.00%> (ø)

... and 24 files with indirect coverage changes

@hexaforce hexaforce merged commit 2066548 into main Jan 24, 2025
20 checks passed
@hexaforce hexaforce deleted the fix/custom-domain-error branch January 24, 2025 03:21
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.

2 participants