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

feat(web): update story custom domain extension #1361

Merged
merged 5 commits into from
Jan 21, 2025

Conversation

hexaforce
Copy link
Contributor

@hexaforce hexaforce commented Jan 20, 2025

Overview

Added custom domain for stories.

What I've done

I have added a new extension to reearth-cloud.js.
https://github.com/eukarya-inc/reearth-cloud/pull/95/files#diff-a4fc01cb110b1ca5c89a7624b5c8a4a455f52bd40eddfc554632625665b61ae4

As a result, it is necessary to update the extension of reearth-visualizer:

{
  type: "publication",
-  id: "custom-domain",
+  id: "custom-project-domain",
  component: CustomDomainSection,
},
+{
+  type: "publication",
+  id: "custom-story-domain",
+  component: CustomStoryDomainSection,
+},

Currently, both use the custom-domain extension, but I have modified it so that the custom-story-domain is used for stories.

What I haven't done

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced support for project and story type extensions in publication settings.
    • Improved type-specific rendering of extension components.
  • Improvements

    • Added typename property to support more precise type identification.
    • Refined conditional rendering logic for publication settings.
    • Increased flexibility in handling different types of publication extensions.

@hexaforce hexaforce self-assigned this Jan 20, 2025
@github-actions github-actions bot added the web label Jan 20, 2025
@github-actions github-actions bot requested a review from m-abe-dev January 20, 2025 03:44
Copy link

coderabbitai bot commented Jan 20, 2025

Walkthrough

The pull request introduces modifications to handle project and story types more dynamically across multiple files. The changes primarily focus on adding a typename property to various type definitions and enhancing the rendering logic for extensions in the PublicSettingsDetail.tsx component. The modifications improve type-specific handling of project and story settings, allowing for more flexible and precise rendering of extension components based on their specific type.

Changes

File Change Summary
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx Added ExtensionComponent for type-specific extension rendering using ProjectPublicationExtensionProps and StoryPublicationExtensionProps. Enhanced rendering logic based on typename.
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/index.tsx Added optional typename?: "Project" to SettingsProject type.
web/src/services/api/storytellingApi/utils.ts Added optional typename?: "Story" to Story type.
web/src/services/config/extensions.ts Introduced StoryPublicationExtensionProps and updated publication property in ExtensionProps to accept both ProjectPublicationExtensionProps and StoryPublicationExtensionProps.

Possibly related PRs

Suggested reviewers

  • mkumbobeaty
  • airslice
  • OpeDada
  • pyshx

Poem

🐰 Hop, hop, through types so bright,
Extensions dancing left and right,
typename leads the way,
Rendering magic on display,
Code rabbit's tale of type delight! 🌈


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.

Copy link

netlify bot commented Jan 20, 2025

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit 946ebc1
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/678f36f68e8b36000888a61e
😎 Deploy Preview https://deploy-preview-1361--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: 1

🧹 Nitpick comments (5)
web/src/services/api/storytellingApi/utils.ts (1)

46-46: Consider making __typename optional.

The __typename property should be marked as optional with ? modifier since it's typically added by GraphQL automatically and may not always be present when creating Story objects manually.

-  __typename: string;
+  __typename?: string;
web/src/services/config/extensions.ts (1)

32-39: Extract common fields into a base type.

Both ProjectPublicationExtensionProps and StoryPublicationExtensionProps share common fields. Consider extracting these into a base type to reduce duplication and improve maintainability.

+type BasePublicationExtensionProps = {
+  publishDisabled?: boolean;
+  typename: string;
+} & SharedExtensionProps;

-export type ProjectPublicationExtensionProps = {
+export type ProjectPublicationExtensionProps = BasePublicationExtensionProps & {
   projectId: string;
   projectAlias?: string;
-  publishDisabled?: boolean;
-  typename: string;
-} & SharedExtensionProps;
};

-export type StoryPublicationExtensionProps = {
+export type StoryPublicationExtensionProps = BasePublicationExtensionProps & {
   storyId: string;
   storyAlias?: string;
-  publishDisabled?: boolean;
-  typename: string;
-} & SharedExtensionProps;
};
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/index.tsx (1)

55-55: Consider making __typename optional.

Similar to the Story type, the __typename property should be marked as optional with ? modifier since it may not always be present when creating SettingsProject objects manually.

-  __typename: string;
+  __typename?: string;
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (2)

111-121: Consider making the extension ID more configurable.

The extensionId is currently hardcoded as custom-${type}-domain. Consider making it more flexible by accepting it as a prop or configuration.

-    const extensionId = `custom-${type}-domain`;
+    const extensionId = props.extensionId ?? `custom-${type}-domain`;

267-267: Consider making the version configurable.

The version is hardcoded as "visualizer". Consider making it configurable through environment variables or props.

-                version={"visualizer"}
+                version={process.env.REACT_APP_VERSION ?? "visualizer"}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 79e3792 and 7cb5d5a.

📒 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 (1 hunks)
  • web/src/services/api/storytellingApi/utils.ts (1 hunks)
  • web/src/services/config/extensions.ts (2 hunks)

Comment on lines 252 to 284
{extensions &&
extensions.length > 0 &&
settingsItem.__typename &&
accessToken && (
<Collapse title={t("Custom Domain")} size="large">
{settingsItem.__typename === "Project" && (
<ExtensionComponent
typename={settingsItem.__typename}
key={settingsItem.id}
projectId={settingsItem.id}
projectAlias={settingsItem.alias}
lang={currentLang}
theme={currentTheme}
accessToken={accessToken}
onNotificationChange={() => onNotificationChange}
version={"visualizer"}
/>
)}
{settingsItem.__typename === "Story" && (
<ExtensionComponent
typename={settingsItem.__typename}
key={settingsItem.id}
storyId={settingsItem.id}
storyAlias={settingsItem.alias}
lang={currentLang}
theme={currentTheme}
accessToken={accessToken}
onNotificationChange={() => onNotificationChange}
version={"visualizer"}
/>
)}
</Collapse>
)}
Copy link

@coderabbitai coderabbitai bot Jan 20, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect callback and reduce code duplication.

  1. The onNotificationChange prop is incorrectly passed as a function that returns a function.
  2. There's significant duplication between Project and Story extension components.

Consider this refactoring:

      {extensions &&
        extensions.length > 0 &&
        settingsItem.__typename &&
        accessToken && (
          <Collapse title={t("Custom Domain")} size="large">
-            {settingsItem.__typename === "Project" && (
-              <ExtensionComponent
-                typename={settingsItem.__typename}
-                key={settingsItem.id}
-                projectId={settingsItem.id}
-                projectAlias={settingsItem.alias}
-                lang={currentLang}
-                theme={currentTheme}
-                accessToken={accessToken}
-                onNotificationChange={() => onNotificationChange}
-                version={"visualizer"}
-              />
-            )}
-            {settingsItem.__typename === "Story" && (
-              <ExtensionComponent
-                typename={settingsItem.__typename}
-                key={settingsItem.id}
-                storyId={settingsItem.id}
-                storyAlias={settingsItem.alias}
-                lang={currentLang}
-                theme={currentTheme}
-                accessToken={accessToken}
-                onNotificationChange={() => onNotificationChange}
-                version={"visualizer"}
-              />
-            )}
+            <ExtensionComponent
+              typename={settingsItem.__typename}
+              key={settingsItem.id}
+              {...(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>
        )}
📝 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
{extensions &&
extensions.length > 0 &&
settingsItem.__typename &&
accessToken && (
<Collapse title={t("Custom Domain")} size="large">
{settingsItem.__typename === "Project" && (
<ExtensionComponent
typename={settingsItem.__typename}
key={settingsItem.id}
projectId={settingsItem.id}
projectAlias={settingsItem.alias}
lang={currentLang}
theme={currentTheme}
accessToken={accessToken}
onNotificationChange={() => onNotificationChange}
version={"visualizer"}
/>
)}
{settingsItem.__typename === "Story" && (
<ExtensionComponent
typename={settingsItem.__typename}
key={settingsItem.id}
storyId={settingsItem.id}
storyAlias={settingsItem.alias}
lang={currentLang}
theme={currentTheme}
accessToken={accessToken}
onNotificationChange={() => onNotificationChange}
version={"visualizer"}
/>
)}
</Collapse>
)}
{extensions &&
extensions.length > 0 &&
settingsItem.__typename &&
accessToken && (
<Collapse title={t("Custom Domain")} size="large">
<ExtensionComponent
typename={settingsItem.__typename}
key={settingsItem.id}
{...(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>
)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix

Copy link

Choose a reason for hiding this comment

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

@hexaforce Thanks for confirming! I'll mark this as resolved.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

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

🧹 Nitpick comments (2)
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (2)

111-121: Consider enhancing type safety for the extension component.

While the implementation is correct, we can improve type safety:

   const ExtensionComponent = (
     props: ProjectPublicationExtensionProps | StoryPublicationExtensionProps
   ) => {
-    const type = props.typename.toLocaleLowerCase();
+    const type = props.typename.toLowerCase() === 'project' ? 'project' : 'story';
     const extensionId = `custom-${type}-domain`;
     const Component = extensions?.find((e) => e.id === extensionId)?.component;
     if (!Component) {
       return null;
     }
     return <Component {...props} />;
   };

This change ensures that only valid types ('project' or 'story') are used in the extension ID.


273-273: Consider making the version configurable.

The version is hardcoded as "visualizer". Consider making it configurable through props or environment variables for better flexibility.

-              version="visualizer"
+              version={process.env.REACT_APP_VISUALIZER_VERSION ?? "visualizer"}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7cb5d5a and dcf48c7.

📒 Files selected for processing (1)
  • web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Redirect rules - reearth-web
  • GitHub Check: Header rules - reearth-web
  • GitHub Check: Pages changed - reearth-web
  • GitHub Check: ci-server / ci-server-lint
  • GitHub Check: ci-server / ci-server-test
🔇 Additional comments (2)
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (2)

8-11: LGTM! Clean import structure.

The new type imports are well-organized and provide proper type safety for the extension components.


252-276: Great implementation following previous review suggestions!

The code successfully implements the recommended approach for reducing duplication while maintaining type safety.

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

🧹 Nitpick comments (1)
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (1)

273-273: Consider making the version configurable.

The version is hardcoded as "visualizer". Consider making it configurable through props or environment variables for better flexibility.

-              version="visualizer"
+              version={process.env.REACT_APP_VISUALIZER_VERSION ?? "visualizer"}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 19a9401 and f4c1e9d.

📒 Files selected for processing (3)
  • web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (3 hunks)
  • web/src/beta/features/ProjectSettings/innerPages/PublicSettings/index.tsx (1 hunks)
  • web/src/services/api/storytellingApi/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/src/beta/features/ProjectSettings/innerPages/PublicSettings/index.tsx
  • web/src/services/api/storytellingApi/utils.ts
🔇 Additional comments (3)
web/src/beta/features/ProjectSettings/innerPages/PublicSettings/PublicSettingsDetail.tsx (3)

8-11: LGTM! Clean import structure.

The new imports for extension types properly separate project and story publication props, aligning with the PR objectives.


111-121: Well-structured component implementation!

The ExtensionComponent elegantly handles both project and story extensions with proper null checks and dynamic component resolution.


252-276: Clean implementation resolving previous duplication issues!

The conditional rendering and type-safe props spreading effectively addresses the code duplication mentioned in previous reviews.

@hexaforce hexaforce requested a review from airslice January 20, 2025 08:51
@hexaforce hexaforce merged commit 2d1d0ac into main Jan 21, 2025
17 checks passed
@hexaforce hexaforce deleted the feat/story-custom-domain-extension branch January 21, 2025 06:02
hexaforce added a commit that referenced this pull request Jan 22, 2025
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