-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat: N Components #10082
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: N Components #10082
Conversation
📝 WalkthroughWalkthroughThis pull request introduces a comprehensive enhancement to the Changes
Sequence DiagramsequenceDiagram
participant User
participant NSelect
participant Store
participant ViewsStore
participant TablesStore
User->>NSelect: Interact with Select
NSelect->>Store: Request data
alt Table Selection
Store->>TablesStore: Fetch tables
TablesStore-->>NSelect: Return tables
else View Selection
Store->>ViewsStore: Load views
ViewsStore-->>NSelect: Return views
end
NSelect->>User: Display options
Possibly related PRs
Suggested Labels
Suggested Reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
🧹 Nitpick comments (7)
packages/nc-gui/components/n/Select/View.vue (2)
1-5: Use explicit naming conventions for better clarity
Line 1 sets up a Vue component using the Composition API in TypeScript. While the code is valid, it might be helpful to run through your naming conventions and ensure that the file name (“View.vue”) precisely describes its domain or purpose, such as “NViewSelect.vue,” to distinguish it from more general “View” components in the codebase.
53-73: Provide fallback or custom messages for empty views
The rendering loop uses viewsRef to populate the select options. If no views are found, the dropdown will be empty. Consider providing a fallback text or a loading state to inform users.packages/nc-gui/components/n/Select/index.vue (2)
14-22: Consolidate the onChange and selectValue logic
The onChange method and selectValue method are closely related. They could be combined or invoked in a consistent approach to prevent event duplication or confusion.
28-60: Leverage built-in size classes or theme tokens
You define extensive custom SCSS rules for the select. While it’s valid, consider whether Ant Design Vue’s built-in classes or theme customization tokens are enough to achieve a similar design, reducing the complexity of custom definitions.packages/nc-gui/components/n/Select/types.d.ts (1)
8-27: Expand or refine doc comments for clarity
You do have doc comments for some fields, but consider adding them systematically for each property. This helps future maintainers understand the purpose and usage of each prop.packages/nc-gui/components/n/Select/Table.vue (2)
1-9: Hang documentation for new props
Similar to View.vue, you introduced baseId, forceLoadBaseTables, and filterTable. A short doc comment or usage note can help guide users.
32-51: Support “No tables found” scenario
When tablesRef is empty, you might show a fallback placeholder in the select dropdown or no results message to guide users.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
packages/nc-gui/components/n/README.md(1 hunks)packages/nc-gui/components/n/Select/Table.vue(1 hunks)packages/nc-gui/components/n/Select/View.vue(1 hunks)packages/nc-gui/components/n/Select/index.vue(1 hunks)packages/nc-gui/components/n/Select/types.d.ts(1 hunks)packages/nc-gui/store/views.ts(1 hunks)packages/nc-gui/utils/iconUtils.ts(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/nc-gui/components/n/README.md
🔇 Additional comments (7)
packages/nc-gui/components/n/Select/View.vue (2)
6-13: Avoid excessive optional props
Props like tableId, ignoreLoading, forceFetchViews, filterView, labelDefaultViewAsDefault can produce a highly configurable but also more complex API. While it’s not inherently incorrect to offer many optional props, consider whether some can be combined or if they’re truly necessary for your component’s primary use cases.
27-47: Ensure watch triggers only when necessary
Here, the watcher is watching props.tableId, props.ignoreLoading, and props.forceFetchViews. This is correct if you intend to refetch views every time any of these parameters change. However, such watchers can cause frequent network requests if triggered too often. Confirm whether any throttling or memoization is needed.
✅ Verification successful
Based on the analysis of the code, I can now generate the final response:
Watch dependencies are appropriate for this component
The watcher's dependencies (tableId, ignoreLoading, forceFetchViews) are correctly chosen as they represent the key parameters that should trigger a view reload. The immediate execution ensures views are loaded when the component mounts. Since these parameters are unlikely to change frequently and each change legitimately requires fresh data, no throttling is needed. The network request is already optimized through the store's loadViews method which handles caching.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Searching for watch usage within this component to confirm if there's any alternative watchers or additional watchers that might cause multiple triggers.
ast-grep --pattern $'watch($_) {\n $$$\n}'
Length of output: 42
Script:
#!/bin/bash
# Let's try a different pattern to search for watch usage
ast-grep --pattern 'watch($$$)'
# Also search for the file content to understand the complete component structure
cat "packages/nc-gui/components/n/Select/View.vue"
# Let's also check if there are any debounce or throttle utilities being used
rg "debounce|throttle" "packages/nc-gui/components/n/Select/View.vue"
Length of output: 61889
packages/nc-gui/components/n/Select/index.vue (2)
1-9: Validate default prop assignments
The provided defaults (e.g., placeholder, showSearch, suffixIcon) match typical usage patterns, but verify that “arrowDown” is accessible as an icon and that the placeholder aligns with your design guidelines.
10-13: Double-check emits usage
You define emits for 'update:modelValue' and 'change'. Ensure they integrate consistently with the Ant Design Vue’s events. Sometimes change events get triggered differently by underlying components.
✅ Verification successful
Based on the analysis of the code and search results, I can now provide a final response:
The emits implementation is correct and consistent with Ant Design Vue
The current implementation correctly uses both update:modelValue and change events which aligns with Ant Design Vue's v-model and @change patterns. The code shows:
- The component properly implements v-model through
update:modelValuefor two-way binding - The
changeevent is correctly emitted after value changes, following Ant Design Vue's Select component pattern - The implementation uses
useVModeland properly handles both events in theselectValuemethod
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Checking for usage of 'update:modelValue' and 'change' in the codebase to confirm consistent usage
rg -A 3 "emits\(.*update:modelValue.*change"
Length of output: 46
Script:
#!/bin/bash
# Let's check the Select component implementation and its event handling
cat "packages/nc-gui/components/n/Select/index.vue"
Length of output: 3402
Script:
#!/bin/bash
# Let's also search for other Select components' usage to understand event patterns
rg -l "n-select|NcSelect" --type vue
Length of output: 66
Script:
#!/bin/bash
# Search for any update:modelValue and change events separately
rg "('|\")update:modelValue('|\")" --type vue
rg "('|\")change('|\")" --type vue
Length of output: 148
Script:
#!/bin/bash
# Check Ant Design Vue's select component usage in the codebase
rg "@change|v-model" --type vue | grep -i "select"
Length of output: 78
Script:
#!/bin/bash
# Let's try without file type specification
rg -l "NcSelect|n-select"
Length of output: 2049
Script:
#!/bin/bash
# Search for update:modelValue and change events without file type
rg "('|\")update:modelValue('|\")"
Length of output: 12447
Script:
#!/bin/bash
# Check a-select usage patterns
rg "a-select.*@change|v-model:value"
Length of output: 65575
Script:
#!/bin/bash
# Let's check if there's any documentation or type definitions
fd "Select" --extension ts --extension vue
Length of output: 1351
packages/nc-gui/components/n/Select/types.d.ts (1)
1-3: Confirm that these imports match installed library versions
You’re importing from 'ant-design-vue/lib/vc-select/Select' and 'ant-design-vue/lib/select'. Confirm your ant-design-vue version supports these entry points without a mismatch in types or library changes.
packages/nc-gui/store/views.ts (1)
141-141: LGTM! Improved null safety
The addition of the null coalescing operator (??) enhances code robustness by providing a fallback empty array when viewsByTable.value.get(tableId) returns undefined, preventing potential runtime errors.
packages/nc-gui/utils/iconUtils.ts (1)
3791-3792: LGTM! Enhanced type safety
The addition of the IconMapKey type improves type safety by ensuring that only valid keys from the iconMap object can be used when accessing icons. This is a TypeScript best practice that helps catch potential errors at compile time.
| if (NSelectComponent.value) { | ||
| let selectedView = viewsList.find((v) => v.is_default) | ||
| if (!selectedView) { | ||
| selectedView = viewsList[0] | ||
| } | ||
| NSelectComponent.value.selectValue(selectedView?.id) | ||
| } | ||
| viewsRef.value = viewsList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Check for race conditions in asynchronous watch logic
If multiple changes happen in quick succession, you might have overlapping fetch requests from loadViews. Ensure that the store can handle concurrent requests or that the requests are canceled/debounced when a new request starts.
| const tablesRef = computedAsync<TableType[]>(async () => { | ||
| let tables: TableType[] | ||
| if (props.baseId) { | ||
| await tableStore.loadProjectTables(props.baseId, props.forceLoadBaseTables) | ||
| tables = baseTables.value.get(props.baseId) | ||
| } else { | ||
| tables = activeTables.value | ||
| } | ||
| if (props.filterTable) { | ||
| return tables.filter(props.filterTable) | ||
| } | ||
| return tables | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle async errors gracefully
Within computedAsync, if the store’s loadProjectTables fails or returns an undefined result, the code might break. Consider wrapping the call in try/catch logic or a safer fallback.
|
Uffizzi Preview |
Change Summary
N Components
Change type