Skip to content

Conversation

@akanshaaa19
Copy link
Member

@akanshaaa19 akanshaaa19 commented Aug 8, 2025

target issue is glific/glific-frontend#3425

Summary by CodeRabbit

  • New Features

    • Dialogs support a configurable Home tab label and only add the Home tab when user tabs exist.
    • Translation UI now shows a category-focused tab and uses rule translations as the default pane when applicable.
  • Bug Fixes

    • Active-tab initialization refined so Home becomes the default only when appropriate; Home is hidden when no user tabs exist.
  • Chores

    • Package version bumped.

@coderabbitai
Copy link

coderabbitai bot commented Aug 8, 2025

Walkthrough

Added an optional Dialog prop homeTabName?: string and changed Dialog to append a "Home" tab (label from homeTabName || 'Home') only when user-provided tabs exist; activeTab initializes to props.tabs.length. RouterLocalizationForm updates Dialog usage to homeTabName="Rule Translations" and swaps which translation view is shown by default.

Changes

Cohort / File(s) Change Summary
Dialog: homeTabName & home-tab behavior
src/components/dialog/Dialog.tsx
Added optional homeTabName?: string to DialogProps. Home tab label uses `this.props.homeTabName
RouterLocalizationForm: default body swap & Dialog usage
src/components/flow/routers/localization/RouterLocalizationForm.tsx
Introduced ruleTranslationsTab and categoryTranslationsTab fragments; selected defaultTabBody conditionally (ruleTranslationsTab when cases have arguments, else categoryTranslationsTab). Replaced defaultTab={defaultTab} with homeTabName="Rule Translations" and render {defaultTabBody} as Dialog body; updated tabs list to include Category Translations (and adjusted scroll lengths to use state.categories.length vs state.cases.length).
Version bump
package.json
Bumped package version from 1.26.3-29 to 1.26.3-30. No other dependency or script changes.

Sequence Diagram(s)

sequenceDiagram
    participant RouterForm as RouterLocalizationForm
    participant Dialog as Dialog

    RouterForm->>Dialog: render(props including tabs?, homeTabName="Rule Translations")
    Dialog->>Dialog: set activeTab = props.tabs ? props.tabs.length : -1
    alt props.tabs && props.tabs.length > 0
        Dialog->>Dialog: create homeTab { label: props.homeTabName || "Home", body: children }
        Dialog->>Dialog: append homeTab to tabs
    else
        Dialog->>Dialog: do not append homeTab
    end
    RouterForm->>Dialog: pass defaultTabBody as children (rule or category view)
    Dialog->>RouterForm: render UI showing tabs and active content
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Poem

I hopped into the tab parade,
A home with name by choice is made.
If user tabs are on the floor,
Home springs up and leads once more.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/wait_for_response

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

@akanshaaa19 akanshaaa19 requested a review from kurund August 8, 2025 16:51
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: 3

🧹 Nitpick comments (1)
src/components/dialog/Dialog.tsx (1)

45-45: Avoid duplicating showHomeTab in state (derived from props)

Storing showHomeTab in state invites drift and edge cases (e.g., when tabs are initially empty). Prefer deriving it from props during render/initialization. If you keep it in state, ensure it’s set in both constructor branches and synced in componentDidUpdate.

Possible simplification:

  • Remove showHomeTab from DialogState.
  • In render, compute const showHomeTab = this.props.showHomeTab !== false; and use that.
  • In constructor, only compute activeTab (using the revised logic above).

Also applies to: 50-50

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bb6d6dc and 61a6d13.

⛔ Files ignored due to path filters (2)
  • src/components/flow/routers/localization/__snapshots__/RouterLocalizationForm.test.ts.snap is excluded by !**/*.snap
  • src/components/flow/routers/subflow/__snapshots__/SubflowRouterForm.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/components/dialog/Dialog.tsx (4 hunks)
  • src/components/flow/routers/localization/RouterLocalizationForm.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
src/components/flow/routers/localization/RouterLocalizationForm.tsx (1)

250-250: LGTM: Home tab explicitly disabled for this dialog

Passing showHomeTab={false} matches the intent for this flow and prevents showing the extra “Home” tab.

@akanshaaa19 akanshaaa19 changed the title Add showHomeTab prop to Dialog component and update related tests Made rule translation the default tab and added category translations Aug 11, 2025
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

🔭 Outside diff range comments (1)
src/components/flow/routers/localization/RouterLocalizationForm.tsx (1)

216-216: Fix ESLint build error: remove unused defaultTab.

defaultTab is assigned but never used; it breaks the build. Dialog now manages the active tab internally, so delete this vestigial code.

Apply this diff:

-    let defaultTab;
@@
-      defaultTab = 0;

Also applies to: 240-240

🧹 Nitpick comments (5)
src/components/flow/routers/localization/RouterLocalizationForm.tsx (5)

220-222: Localize the new tab label.

Hardcoded "Category Translations" should use i18n for consistency.

-        name: 'Category Translations',
+        name: i18n.t('tabs.category_translations', 'Category Translations'),

223-226: Localize the new instructions for the Category tab.

These are new user-visible strings; prefer i18n.t.

-            <p data-spec="instructions">
-              When category names are referenced later in the flow, the appropriate language for the
-              category will be used. If no translation is provided, the original text will be used.
-            </p>
+            <p data-spec="instructions">
+              {i18n.t(
+                'forms.routerLocalization.category_instructions',
+                'When category names are referenced later in the flow, the appropriate language for the category will be used. If no translation is provided, the original text will be used.'
+              )}
+            </p>

231-233: Avoid magic number duplication for scroll threshold.

The threshold 5 is duplicated for categories and cases; factor it into a constant to keep behavior consistent.

Example:

// near top of render()
const SCROLL_THRESHOLD = 5;

// then:
(this.state.categories.length > SCROLL_THRESHOLD ? styles.scrolling : '')
(this.state.cases.length > SCROLL_THRESHOLD ? styles.scrolling : '')

Also applies to: 259-260


252-254: Localize the new instructions for the Home tab.

Wrap with i18n.t for translation.

-        <p data-spec="instructions">
-          Sometimes languages need special rules to route things properly. If a translation is not
-          provided, the original rule will be used.
-        </p>
+        <p data-spec="instructions">
+          {i18n.t(
+            'forms.routerLocalization.rule_instructions',
+            'Sometimes languages need special rules to route things properly. If a translation is not provided, the original rule will be used.'
+          )}
+        </p>

208-214: Nit: variable name typo.

orginalCase → originalCase. Improves readability.

-      const orginalCase = getOriginalCase(this.props.nodeSettings, kase.uuid) as Case;
+      const originalCase = getOriginalCase(this.props.nodeSettings, kase.uuid) as Case;
       return (
-        orginalCase.arguments &&
-        orginalCase.arguments.length > 0 &&
-        orginalCase.type !== Operators.has_number_between
+        originalCase.arguments &&
+        originalCase.arguments.length > 0 &&
+        originalCase.type !== Operators.has_number_between
       );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 61a6d13 and 1b59a6d.

⛔ Files ignored due to path filters (1)
  • src/components/flow/routers/localization/__snapshots__/RouterLocalizationForm.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/components/dialog/Dialog.tsx (2 hunks)
  • src/components/flow/routers/localization/RouterLocalizationForm.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/dialog/Dialog.tsx
🧰 Additional context used
🪛 GitHub Actions: Build
src/components/flow/routers/localization/RouterLocalizationForm.tsx

[error] 216-216: yarn build failed due to ESLint error: 'defaultTab' is assigned a value but never used. (no-unused-vars)

🔇 Additional comments (2)
src/components/flow/routers/localization/RouterLocalizationForm.tsx (2)

235-236: Render helper swap looks correct.

Using renderCategories() within the Category tab aligns with the tab’s purpose.


263-264: Render helper remains correct for the Home tab.

Using renderCases() under the "Rule Translations" Home tab matches the intent.

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

♻️ Duplicate comments (1)
src/components/flow/routers/localization/RouterLocalizationForm.tsx (1)

269-269: Localize the home tab label "Rule Translations"

Use the new Dialog prop with a translated label instead of a hardcoded string. Update snapshots accordingly.

-        homeTabName="Rule Translations"
+        homeTabName={i18n.t('tabs.rule_translations', 'Rule Translations')}

Also refresh the snapshot:

  • src/components/flow/routers/localization/snapshots/RouterLocalizationForm.test.ts.snap
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1b59a6d and 918b382.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/components/flow/routers/localization/RouterLocalizationForm.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/components/flow/routers/localization/RouterLocalizationForm.tsx (1)
src/components/dialog/Dialog.tsx (1)
  • Dialog (55-268)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Coverage
  • GitHub Check: Tests (12.x)
🔇 Additional comments (2)
src/components/flow/routers/localization/RouterLocalizationForm.tsx (2)

261-262: LGTM: default body logic matches the PR objective

Selecting ruleTranslationsTab as the default body when cases with arguments exist makes “Rule Translations” the default view. This aligns with the stated goal.


271-271: LGTM: render default body via Dialog children

Rendering {defaultTabBody} as Dialog children correctly feeds the “Home” tab content. Works with and without additional tabs.

Comment on lines +207 to +225
const ruleTranslationsTab = (
<>
<p data-spec="instructions">
Sometimes languages need special rules to route things properly. If a translation is not
provided, the original rule will be used.
</p>
<div
className={
styles.translating_list_container +
' ' +
(this.state.cases.length > 5 ? styles.scrolling : '')
}
tabIndex={0}
>
<div className={styles.translating_item_list}>{this.renderCases()}</div>
</div>
</>
);

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Localize the Rule Translations instructions text

Wrap the instructions paragraph in i18n to avoid hardcoded English.

-        <p data-spec="instructions">
-          Sometimes languages need special rules to route things properly. If a translation is not
-          provided, the original rule will be used.
-        </p>
+        <p data-spec="instructions">
+          {i18n.t(
+            'forms.router_localization.rule_instructions',
+            'Sometimes languages need special rules to route things properly. If a translation is not provided, the original rule will be used.'
+          )}
+        </p>
📝 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
const ruleTranslationsTab = (
<>
<p data-spec="instructions">
Sometimes languages need special rules to route things properly. If a translation is not
provided, the original rule will be used.
</p>
<div
className={
styles.translating_list_container +
' ' +
(this.state.cases.length > 5 ? styles.scrolling : '')
}
tabIndex={0}
>
<div className={styles.translating_item_list}>{this.renderCases()}</div>
</div>
</>
);
const ruleTranslationsTab = (
<>
<p data-spec="instructions">
{i18n.t(
'forms.router_localization.rule_instructions',
'Sometimes languages need special rules to route things properly. If a translation is not provided, the original rule will be used.'
)}
</p>
<div
className={
styles.translating_list_container +
' ' +
(this.state.cases.length > 5 ? styles.scrolling : '')
}
tabIndex={0}
>
<div className={styles.translating_item_list}>{this.renderCases()}</div>
</div>
</>
);
🤖 Prompt for AI Agents
In src/components/flow/routers/localization/RouterLocalizationForm.tsx around
lines 207 to 225, the instructions paragraph is hardcoded in English; replace
that plain text with your project's internationalization API (e.g., wrap the
string in the translation function or use the Trans/Translation component your
app uses), preserving the <p data-spec="instructions"> element, punctuation and
intent, and ensure the translated key/string is added to the appropriate locale
files; keep the surrounding JSX structure and classNames unchanged.

Comment on lines +226 to +243
const categoryTranslationsTab = (
<>
<p data-spec="instructions">
When category names are referenced later in the flow, the appropriate language for the
category will be used. If no translation is provided, the original text will be used.
</p>
<div
className={
styles.translating_list_container +
' ' +
(this.state.categories.length > 5 ? styles.scrolling : '')
}
tabIndex={0}
>
<div className={styles.translating_item_list}>{this.renderCategories()}</div>
</div>
</>
);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Localize the Category Translations instructions text

Same as above—please i18n-ize the prose.

-        <p data-spec="instructions">
-          When category names are referenced later in the flow, the appropriate language for the
-          category will be used. If no translation is provided, the original text will be used.
-        </p>
+        <p data-spec="instructions">
+          {i18n.t(
+            'forms.router_localization.category_instructions',
+            'When category names are referenced later in the flow, the appropriate language for the category will be used. If no translation is provided, the original text will be used.'
+          )}
+        </p>
📝 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
const categoryTranslationsTab = (
<>
<p data-spec="instructions">
When category names are referenced later in the flow, the appropriate language for the
category will be used. If no translation is provided, the original text will be used.
</p>
<div
className={
styles.translating_list_container +
' ' +
(this.state.categories.length > 5 ? styles.scrolling : '')
}
tabIndex={0}
>
<div className={styles.translating_item_list}>{this.renderCategories()}</div>
</div>
</>
);
const categoryTranslationsTab = (
<>
<p data-spec="instructions">
{i18n.t(
'forms.router_localization.category_instructions',
'When category names are referenced later in the flow, the appropriate language for the category will be used. If no translation is provided, the original text will be used.'
)}
</p>
<div
className={
styles.translating_list_container +
' ' +
(this.state.categories.length > 5 ? styles.scrolling : '')
}
tabIndex={0}
>
<div className={styles.translating_item_list}>{this.renderCategories()}</div>
</div>
</>
);
🤖 Prompt for AI Agents
In src/components/flow/routers/localization/RouterLocalizationForm.tsx around
lines 226 to 243, the explanatory paragraph text is hardcoded English and must
be internationalized; replace the literal string with a call to the project's
i18n helper (e.g., t('...') or intl.formatMessage) using a clear translation key
like 'routerLocalization.categoryTranslations.instructions' and include the
original text as the default message, import the i18n helper at the top of the
file if not already present, and add the new key and default text to the locale
files so translators can provide translations.

Comment on lines +256 to 258
name: 'Category Translations',
body: categoryTranslationsTab
});
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Localize the tab label "Category Translations"

Avoid hardcoded labels in tabs; use i18n with a sensible key.

-      tabs.push({
-        name: 'Category Translations',
-        body: categoryTranslationsTab
-      });
+      tabs.push({
+        name: i18n.t('tabs.category_translations', 'Category Translations'),
+        body: categoryTranslationsTab
+      });
📝 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
name: 'Category Translations',
body: categoryTranslationsTab
});
tabs.push({
name: i18n.t('tabs.category_translations', 'Category Translations'),
body: categoryTranslationsTab
});
🤖 Prompt for AI Agents
In src/components/flow/routers/localization/RouterLocalizationForm.tsx around
lines 256 to 258, the tab label is hardcoded as "Category Translations"; replace
it with a call to the i18n translator (e.g. useTranslation hook) and a sensible
key such as 'router.tabs.categoryTranslations' (or
'flow.tabs.categoryTranslations') so the label is localizable; ensure you
import/use the hook at the top of the component, call
t('router.tabs.categoryTranslations') when building the tab object, and keep a
readable default/fallback in your translation files.

Copy link

@kurund kurund left a comment

Choose a reason for hiding this comment

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

@akanshaaa19

Functionality-wise wise it's working fine.

Few comments:

  • Can we please not mix multiple functionalities in the same PR? It can be confusing when it's being reviewed. It's ok for this PR.
  • We should create a separate base branch for 1.26.x series. v1.26.x and use that for release etc. Currently, this is raised against glific-master

@akanshaaa19 akanshaaa19 changed the base branch from glific-master to v1.26.3-x August 12, 2025 03:30
@akanshaaa19 akanshaaa19 merged commit 7fb5d8e into v1.26.3-x Aug 12, 2025
7 checks passed
@akanshaaa19 akanshaaa19 deleted the fix/wait_for_response branch August 12, 2025 10:53
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.

3 participants