Skip to content

core&ui: add contest language limit (#1007) - #1014

Merged
undefined-moe merged 5 commits into
masterfrom
contest-langs
Jul 15, 2025
Merged

core&ui: add contest language limit (#1007)#1014
undefined-moe merged 5 commits into
masterfrom
contest-langs

Conversation

@undefined-moe

@undefined-moe undefined-moe commented Jul 11, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added language selection fields to contest and homework edit forms for setting submission language limits.
    • Introduced a new language selection autocomplete component with multi-selection support and enhanced UI.
    • Enabled language selection on domain and contest edit pages using the updated autocomplete component.
  • Improvements

    • Updated problem configuration forms to utilize the new language selection component for a streamlined experience.
    • Improved autocomplete dropdown rendering to avoid empty list items.
    • Simplified autocomplete components by removing internal state wrappers and delegating rendering to base components.
    • Enhanced autocomplete class with stronger typing, multi-select support, and customizable component rendering.
    • Expanded build configuration to include TypeScript JSX files.
    • Added explicit React import in relevant UI files for consistency.
  • Localization

    • Added Chinese translations for "Select All", "Select None", and "Submission language limit".

@coderabbitai

coderabbitai Bot commented Jul 11, 2025

Copy link
Copy Markdown

Walkthrough

This set of changes introduces support for configuring and selecting allowed programming languages across contest, homework, and problem configuration interfaces. Backend handler methods for contest and homework editing (postUpdate) now accept and process an optional langs parameter, and the Tdoc interface is extended to include an optional langs array. The frontend adds new language selection autocomplete components, replacing previous manual language key filtering and selection logic with unified React-based components. Language selection fields are added to contest and homework edit forms, and related UI pages are updated to use the new autocomplete widgets. The autocomplete base class was enhanced to support generic multi-selection and internal React state management. Additional improvements include refactoring various autocomplete components to delegate rendering directly to their React functional components, removing redundant wrapper components and manual state handling. The Chinese locale is expanded with new translation keys related to selection options. The build script was updated to include .tsx files in its configuration. No existing public API signatures are removed; new parameters and components are added.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/ui-default/components/autocomplete/DomainSelectAutoComplete.tsx

Oops! Something went wrong! :(

ESLint: 9.31.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@hydrooj/eslint-config' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:202:49)

packages/ui-default/components/autocomplete/UserSelectAutoComplete.tsx

Oops! Something went wrong! :(

ESLint: 9.31.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@hydrooj/eslint-config' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:202:49)

packages/ui-default/pages/home_domain.page.tsx

Oops! Something went wrong! :(

ESLint: 9.31.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@hydrooj/eslint-config' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:202:49)


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6bb8c70 and f1618d1.

📒 Files selected for processing (3)
  • packages/ui-default/components/autocomplete/DomainSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/autocomplete/UserSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/pages/home_domain.page.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/ui-default/pages/home_domain.page.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/ui-default/components/autocomplete/DomainSelectAutoComplete.tsx
  • packages/ui-default/components/autocomplete/UserSelectAutoComplete.tsx
⏰ 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). (3)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
packages/ui-default/templates/homework_edit.html (1)

100-107: LGTM! Form field implementation is correct.

The new submission language limit form field is properly implemented using the form helper macro. The field configuration, positioning, and default value handling are all appropriate.

Consider using a more specific placeholder like _("Language codes separated by commas, e.g., cpp,java,python") to provide better user guidance.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0699e17 and b189f75.

📒 Files selected for processing (15)
  • packages/components/frontend/autocomplete/AutoComplete.tsx (1 hunks)
  • packages/hydrooj/src/handler/contest.ts (2 hunks)
  • packages/hydrooj/src/handler/homework.ts (2 hunks)
  • packages/hydrooj/src/handler/problem.ts (1 hunks)
  • packages/hydrooj/src/interface.ts (1 hunks)
  • packages/ui-default/components/autocomplete/LanguageSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/autocomplete/components/LanguageSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/problemconfig/BasicForm.tsx (2 hunks)
  • packages/ui-default/components/problemconfig/ProblemConfigForm.tsx (2 hunks)
  • packages/ui-default/locales/zh.yaml (2 hunks)
  • packages/ui-default/pages/contest_edit.page.ts (2 hunks)
  • packages/ui-default/pages/domain_edit.page.ts (0 hunks)
  • packages/ui-default/pages/domain_edit.page.tsx (1 hunks)
  • packages/ui-default/templates/contest_edit.html (1 hunks)
  • packages/ui-default/templates/homework_edit.html (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/ui-default/pages/domain_edit.page.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/ui-default/pages/contest_edit.page.ts (1)
packages/ui-default/components/autocomplete/LanguageSelectAutoComplete.tsx (1)
  • LanguageSelectAutoComplete (27-54)
packages/ui-default/pages/domain_edit.page.tsx (2)
packages/ui-default/misc/Page.ts (1)
  • NamedPage (37-37)
packages/ui-default/components/autocomplete/LanguageSelectAutoComplete.tsx (1)
  • LanguageSelectAutoComplete (27-54)
packages/hydrooj/src/handler/contest.ts (2)
framework/framework/decorators.ts (1)
  • param (111-111)
packages/hydrooj/src/model/setting.ts (1)
  • langs (358-358)
⏰ 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). (3)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (20)
packages/hydrooj/src/handler/problem.ts (1)

307-307: LGTM! Correct integration of contest language limits.

The addition of this.tdoc?.langs to the language filtering array follows the existing pattern and correctly integrates contest-level language restrictions with domain and problem-level restrictions. The optional chaining ensures safe access.

packages/hydrooj/src/interface.ts (1)

272-272: LGTM! Appropriate interface extension.

The addition of the optional langs?: string[] property to the Tdoc interface correctly supports the new language limit feature while maintaining backward compatibility.

packages/ui-default/pages/contest_edit.page.ts (2)

3-3: LGTM! Correct import addition.

The import of LanguageSelectAutoComplete follows the existing import pattern in the file.


13-13: LGTM! Consistent autocomplete initialization.

The initialization of LanguageSelectAutoComplete follows the same pattern as other autocomplete components in the file and correctly enables multi-selection for language limits.

packages/ui-default/templates/contest_edit.html (1)

135-142: LGTM! Well-integrated form field addition.

The new "Submission language limit" field is properly integrated into the Contest Settings section. The field name langs correctly matches the JavaScript initialization, and the value binding with tdoc.langs|default('') handles both new and existing contests appropriately.

packages/ui-default/pages/domain_edit.page.tsx (1)

1-8: LGTM! Excellent refactoring to use centralized component.

This new implementation is much cleaner and simpler than the previous manual language selection logic. Using the LanguageSelectAutoComplete component reduces code duplication and centralizes language selection functionality, which is a good architectural improvement.

packages/ui-default/locales/zh.yaml (2)

824-826: LGTM! Translation additions look correct.

The Chinese translations for "Select All" and "Select None" are accurate and appropriately placed in the locale file.


889-889: LGTM! Submission language limit translation is appropriate.

The Chinese translation "提交语言限制" for "Submission language limit" is accurate and follows the existing translation patterns in the file.

packages/hydrooj/src/handler/contest.ts (2)

313-313: LGTM! Parameter implementation is correct.

The langs parameter is properly integrated into the function signature with an appropriate default value and correctly passed to the contest.edit call. The implementation follows existing patterns in the codebase.

Also applies to: 354-354


308-308: langs Parameter Integration Approved; Typo Consistent Across Codebase

The langs parameter is declared, typed, and passed correctly, following existing patterns. The spelling “CommaSeperatedArray” appears consistently in multiple handlers and in the framework’s Types definition and tests, so this PR doesn’t introduce the typo—no changes required here.

packages/components/frontend/autocomplete/AutoComplete.tsx (1)

313-326: LGTM! Excellent defensive programming improvement.

The updated rendering logic properly handles cases where renderItem returns falsy values by skipping those items instead of rendering empty list elements. This prevents potential UI issues and makes the component more robust.

The addition of the wrapping <div> around the inner content maintains consistency with the existing structure while providing the necessary container for the rendered item.

packages/ui-default/components/problemconfig/ProblemConfigForm.tsx (2)

76-81: LGTM! Component usage is simplified and cleaner.

The update to use LanguageSelectAutoComplete simplifies the component by removing manual data processing and filtering logic. The direct use of the langs array from state and simplified onChange handler is cleaner and more maintainable.

The placeholder logic is also improved, providing clear feedback about the current state (unlimited vs. specific languages selected).


9-9: Import path validated. The LanguageSelectAutoComplete component is present at

  • packages/ui-default/components/autocomplete/components/LanguageSelectAutoComplete.tsx

No further changes needed.

packages/ui-default/components/problemconfig/BasicForm.tsx (1)

5-5: LGTM: Import change aligns with new component architecture.

The import change to the new LanguageSelectAutoComplete component is consistent with the centralized language selection implementation.

packages/ui-default/components/autocomplete/components/LanguageSelectAutoComplete.tsx (1)

5-8: Language processing logic looks robust.

The prefix extraction and data transformation logic correctly separates prefixed languages from their base forms and creates display names with hierarchical structure.

packages/hydrooj/src/handler/homework.ts (3)

194-194: Parameter decoration follows established pattern.

The @param decorator for langs correctly uses Types.CommaSeperatedArray which is consistent with the assign parameter handling.


199-199: Method signature update is consistent.

The parameter addition with default empty array follows the same pattern as other optional array parameters in the method.


230-230: contest.edit already supports the langs field
The Tdoc interface in packages/hydrooj/src/interface.ts defines

    langs?: string[];

and contest.edit in packages/hydrooj/src/model/contest.ts (around line 813) accepts a Partial<Tdoc>, so any langs property passed in $set will be persisted via document.set. No further changes are needed.

packages/ui-default/components/autocomplete/LanguageSelectAutoComplete.tsx (2)

10-25: State management in Component wrapper looks good.

The React component properly manages internal state and handles both array and string values for selectedKeys conversion.


42-53: Component initialization and ref handling is well implemented.

The attach method properly initializes the React component with the DOM value and sets up the ref callback for value access.

Comment thread packages/ui-default/components/problemconfig/BasicForm.tsx
Comment on lines +16 to +22
onChange={(val) => {
let value = val.split(',');
const active = new Set(value.filter((i) => i.includes('.')).map((i) => i.split('.')[0]));
value = value.filter((i) => !prefixes.has(i) || active.has(i));
for (const i of active) if (!value.includes(i)) value.push(i);
props.onChange(value);
}}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Complex onChange logic may have edge cases.

The logic handles prefixed language relationships but has potential issues:

  1. Line 17: val.split(',') assumes val is always a string, but it could be an array in some cases
  2. Line 20: The loop adds base languages but doesn't validate if they exist in the original value

Consider adding type guards and validation:

 onChange={(val) => {
-  let value = val.split(',');
+  let value = Array.isArray(val) ? val : val.split(',');
   const active = new Set(value.filter((i) => i.includes('.')).map((i) => i.split('.')[0]));
   value = value.filter((i) => !prefixes.has(i) || active.has(i));
-  for (const i of active) if (!value.includes(i)) value.push(i);
+  for (const i of active) {
+    if (!value.includes(i) && Object.prototype.hasOwnProperty.call(window.LANGS, i)) {
+      value.push(i);
+    }
+  }
   props.onChange(value);
 }}
🤖 Prompt for AI Agents
In
packages/ui-default/components/autocomplete/components/LanguageSelectAutoComplete.tsx
around lines 16 to 22, the onChange handler assumes val is always a string and
splits it, which can cause errors if val is an array. Add a type check to handle
both string and array inputs properly. Also, before adding base languages in the
loop, validate that they exist in the original input to avoid adding unintended
values. Adjust the logic to safely process val and ensure only valid base
languages are included before calling props.onChange.

Comment thread packages/ui-default/components/autocomplete/LanguageSelectAutoComplete.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
packages/ui-default/components/autocomplete/UserSelectAutoComplete.tsx (1)

19-22: Action Required: Implement or Forward getSelectedItemKeys and getSelectedItems on the AutoComplete ref

The base AutoComplete class correctly assigns your component’s ref (ref = null; and ref={(ref) => { this.ref = ref; }}), but I didn’t find getSelectedItemKeys or getSelectedItems defined or forwarded in UserSelectAutoComplete.tsx. Without those methods on this.ref, value() will throw at runtime.

Please update UserSelectAutoCompleteFC to expose those instance methods—either by:

  • Defining them directly on the class or functional component via useImperativeHandle (for forwardRef).
  • Forwarding the ref to an underlying component that already implements them.

For example, if you’re wrapping a library Select that has these methods, you can:

- const UserSelectAutoCompleteFC = (props) => { … }
+ const UserSelectAutoCompleteFC = forwardRef<YourRefType, Props>((props, ref) => {
+   const innerRef = useRef<YourRefType>(null);
+   useImperativeHandle(ref, () => ({
+     getSelectedItemKeys: () => innerRef.current!.getSelectedItemKeys(),
+     getSelectedItems:   () => innerRef.current!.getSelectedItems(),
+   }));
+   return <Select ref={innerRef} {...props} />;
+ });

• File: packages/ui-default/components/autocomplete/components/UserSelectAutoComplete.tsx
• Location: around the export/definition of your component

Once those methods are available on this.ref, the value() implementation will work as intended.

🧹 Nitpick comments (1)
packages/ui-default/components/autocomplete/index.tsx (1)

22-22: Consider using Record<string, any> instead of {}

The static analysis correctly flags the use of {} as a type. For better clarity and type safety, consider using Record<string, any> as the default type parameter.

-export default class AutoComplete<Options extends Record<string, any> = {}, Multi extends boolean = boolean> extends DOMAttachedObject {
+export default class AutoComplete<Options extends Record<string, any> = Record<string, any>, Multi extends boolean = boolean> extends DOMAttachedObject {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b189f75 and 519fa72.

📒 Files selected for processing (7)
  • packages/ui-default/components/autocomplete/CustomSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/autocomplete/DomainSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/autocomplete/FileSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/autocomplete/LanguageSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/autocomplete/ProblemSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/autocomplete/UserSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/autocomplete/index.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/ui-default/components/autocomplete/LanguageSelectAutoComplete.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/ui-default/components/autocomplete/index.tsx (2)
packages/ui-default/components/DOMAttachedObject.ts (1)
  • DOMAttachedObject (26-129)
packages/ui-default/components/autocomplete/UserSelectAutoComplete.tsx (1)
  • value (19-22)
🪛 Biome (1.9.4)
packages/ui-default/components/autocomplete/index.tsx

[error] 22-22: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

⏰ 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). (3)
  • GitHub Check: build
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build
🔇 Additional comments (5)
packages/ui-default/components/autocomplete/ProblemSelectAutoComplete.tsx (1)

10-14: LGTM! Consistent with the refactoring pattern.

The changes properly delegate component rendering to the base AutoComplete class by passing the functional component and its props.

packages/ui-default/components/autocomplete/DomainSelectAutoComplete.tsx (1)

10-14: LGTM! Follows the established refactoring pattern.

The changes correctly pass the component and props to the base class. The fixed height of '34px' appears appropriate for domain selection UI consistency.

packages/ui-default/components/autocomplete/CustomSelectAutoComplete.tsx (1)

14-19: LGTM! Proper implementation with type safety.

The changes correctly implement the refactoring pattern while maintaining type safety through the generic Multi parameter. The data prop is properly passed to support custom selection options.

packages/ui-default/components/autocomplete/FileSelectAutoComplete.tsx (1)

17-22: Component and props configuration looks good.

The refactoring correctly passes the component and required props including the typed data prop.

packages/ui-default/components/autocomplete/UserSelectAutoComplete.tsx (1)

10-14: LGTM! Consistent refactoring implementation.

The changes properly delegate rendering to the base class following the established pattern.

Comment thread packages/ui-default/components/autocomplete/FileSelectAutoComplete.tsx Outdated
Comment thread packages/ui-default/components/autocomplete/index.tsx Outdated
render: () => '',
text: () => null,
multi: false,
multi: false as Multi,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove type assertion for the multi option

The type assertion false as Multi can cause type inconsistencies. Let TypeScript infer the correct type from the passed options.

-      multi: false as Multi,
+      multi: false,
📝 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
multi: false as Multi,
multi: false,
🤖 Prompt for AI Agents
In packages/ui-default/components/autocomplete/index.tsx at line 38, remove the
type assertion "false as Multi" from the "multi" option. Instead, just assign
the value false directly and let TypeScript infer the type automatically to
avoid type inconsistencies.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
packages/ui-default/components/autocomplete/index.tsx (2)

38-38: Remove type assertion for the multi option.

The type assertion false as Multi can cause type inconsistencies. Let TypeScript infer the correct type from the passed options.

-      multi: false as Multi,
+      multi: false,

94-97: Fix return type consistency in the value method.

The multi-select case should return an array of numbers to match the type signature and be consistent with other implementations like UserSelectAutoComplete.

   value(): Multi extends true ? (string | number)[] : string {
-    if (this.options.multi) return this.ref?.getSelectedItemKeys() ?? this.$dom.val();
+    if (this.options.multi) return this.ref?.getSelectedItemKeys()?.map((i) => +i) ?? [];
     return this.ref?.getSelectedItems()[0] ?? null;
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 519fa72 and d9f8e9e.

📒 Files selected for processing (5)
  • build/prepare.js (1 hunks)
  • packages/ui-default/components/autocomplete/FileSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/autocomplete/components/LanguageSelectAutoComplete.tsx (1 hunks)
  • packages/ui-default/components/autocomplete/index.tsx (4 hunks)
  • packages/ui-default/components/problemconfig/BasicForm.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/ui-default/components/problemconfig/BasicForm.tsx
  • packages/ui-default/components/autocomplete/components/LanguageSelectAutoComplete.tsx
  • packages/ui-default/components/autocomplete/FileSelectAutoComplete.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ui-default/components/autocomplete/index.tsx

[error] 22-22: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

⏰ 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). (3)
  • GitHub Check: build
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build
🔇 Additional comments (3)
build/prepare.js (1)

63-63: LGTM! Necessary change to support TSX files.

This change correctly expands the build configuration to include TypeScript JSX files (.tsx) alongside TypeScript files (.ts), which is essential for the new React components being added to the codebase.

packages/ui-default/components/autocomplete/index.tsx (2)

2-2: LGTM: React import correctly added.

The explicit React import is necessary for the JSX syntax used in the refactored attach method.


67-81: LGTM: React wrapper pattern is well-implemented.

The refactored attach method effectively creates a React wrapper that:

  • Manages internal state with useState
  • Handles component flexibility via the component option
  • Correctly processes selectedKeys with proper string splitting and trimming
  • Maintains backward compatibility while enabling new features

This pattern centralizes React rendering logic and eliminates the need for subclasses to implement their own React wrappers.

}

export default class AutoComplete<Options extends Record<string, any> = {}> extends DOMAttachedObject {
export default class AutoComplete<Options extends Record<string, any> = {}, Multi extends boolean = boolean> extends DOMAttachedObject {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace {} type with explicit object type.

The static analysis tool correctly flags the use of {} as a type. This type means "any non-nullable value" which is overly broad and can lead to type safety issues.

-export default class AutoComplete<Options extends Record<string, any> = {}, Multi extends boolean = boolean> extends DOMAttachedObject {
+export default class AutoComplete<Options extends Record<string, any> = Record<string, any>, Multi extends boolean = boolean> extends DOMAttachedObject {
🧰 Tools
🪛 Biome (1.9.4)

[error] 22-22: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🤖 Prompt for AI Agents
In packages/ui-default/components/autocomplete/index.tsx at line 22, replace the
generic type parameter default from {} to a more explicit object type such as
Record<string, unknown> or a defined interface to improve type safety and avoid
the overly broad {} type. Update the declaration of Options to use this explicit
object type instead of {}.

@pandadtdyy pandadtdyy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@undefined-moe
undefined-moe merged commit 4165e9b into master Jul 15, 2025
6 checks passed
@undefined-moe
undefined-moe deleted the contest-langs branch July 15, 2025 22:54
if (this.pdoc.config.langs) t.push(this.pdoc.config.langs);
if (ddoc.langs) t.push(ddoc.langs.split(',').map((i) => i.trim()).filter((i) => i));
if (this.domain.langs) t.push(this.domain.langs.split(',').map((i) => i.trim()).filter((i) => i));
if (this.tdoc?.langs) t.push(this.tdoc.langs);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also need check if tdoc.langs.length > 0, or none language can be submited.

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