-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix: cmdk improvements #9575
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: cmdk improvements #9575
Conversation
Signed-off-by: mertmit <mertmit99@gmail.com>
📝 Walkthrough📝 WalkthroughWalkthroughThe changes primarily enhance the command palette functionality across various components by introducing a debounced input mechanism, improving UI responsiveness, and refining command handling logic. The updates include a new computed property for workspace commands, modifications to import services for better model handling, and improvements to logging within the command palette service. Additionally, minor textual adjustments were made in utility functions for grammatical accuracy. Changes
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (3)
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 (
|
Signed-off-by: mertmit <mertmit99@gmail.com>
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: 4
🧹 Outside diff range and nitpick comments (14)
tests/playwright/pages/Dashboard/Command/CmdKPage.ts (1)
Line range hint
27-35: Improve visibility check methods.The current implementation uses element count as a proxy for visibility. Playwright provides more explicit and reliable APIs for checking visibility.
Consider refactoring both methods:
async isCmdKVisible() { - const isVisible = this.get(); - return await isVisible.count(); + return await this.get().isVisible(); } async isCmdKNotVisible() { - const isNotVisible = this.get(); - return await isNotVisible.count(); + return await this.get().isHidden(); }This approach:
- Is more explicit about what's being checked
- Handles edge cases better (element exists but is hidden)
- Follows Playwright best practices
packages/nocodb/src/helpers/commandPaletteHelpers.ts (2)
Line range hint
16-63: Consider documentation and code organization improvementsWhile the current changes look good, here are some suggestions for future improvements:
- The SQL query is complex with multiple joins. Consider adding documentation explaining the purpose and logic of each join.
- The sorting logic at the end of the function could be extracted into a separate helper function for better readability and reusability.
Example refactor for the sorting logic:
function sortCommandPaletteData(data: any[]) { return data.sort((a, b) => { if (a.base_order !== b.base_order) { return (a.base_order ?? Infinity) - (b.base_order ?? Infinity); } if (a.table_order !== b.table_order) { return (a.table_order ?? Infinity) - (b.table_order ?? Infinity); } if (a.view_order !== b.view_order) { return (a.view_order ?? Infinity) - (b.view_order ?? Infinity); } return 0; }); }
Discrepancy Between PR Description and Code Changes
The PR description mentions implementing virtual scrolling for cmdk, but the changes in this PR are limited to replacing string literals with enum constants. There are no modifications or implementations related to virtual scrolling.
Please consider:
- Updating the PR description to accurately reflect the changes made.
- If virtual scrolling implementation is intended, ensure that all relevant files are included in this PR.
🔗 Analysis chain
Line range hint
1-93: Verify alignment with PR objectivesThe PR description mentions implementing virtual scrolling for cmdk, but the changes in this file are limited to replacing a string literal with an enum constant. This seems unrelated to virtual scrolling implementation.
Could you please clarify:
- Are there other files implementing the virtual scrolling that should be part of this review?
- If not, should the PR description be updated to reflect the actual changes?
Let's check if there are other relevant files:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for files that might contain virtual scrolling implementation echo "Searching for potential virtual scrolling related files..." rg -l --type-add 'frontend:*.{vue,ts,js,jsx,tsx}' --type frontend -i 'virtualscroll|virtual-scroll|virtual scroll' echo "Searching for other files modified in this PR..." git diff --name-only HEAD~1Length of output: 978
packages/nocodb/src/services/command-palette.service.ts (2)
Line range hint
19-144: Consider refactoring for improved maintainabilityThe
commandPalettemethod is quite long and handles multiple responsibilities. Consider breaking it down into smaller, focused functions for improved maintainability and testability. Here are some suggestions:
Extract data processing logic into separate methods:
processBaseDataprocessTableDataprocessViewDataConsider using TypeScript interfaces for the data structures:
interface BaseItem { id: string; title: string; meta: any; // Consider being more specific about meta type } interface TableItem extends BaseItem { base_id: string; type: string; } interface ViewItem extends TableItem { is_default: boolean; }Consider using a more functional approach with array methods instead of for...of loops
Would you like me to provide a detailed refactoring example implementing these suggestions?
PR Description Does Not Match Implemented Changes
The modifications in
packages/nocodb/src/services/command-palette.service.tsfocus on logging improvements and do not implement virtual scrolling for cmdk as described in the PR. Additionally, no virtual scrolling implementations were found in other parts of the codebase.Please update the PR description to accurately reflect the changes made or include the virtual scrolling implementation if it was intended.
🔗 Analysis chain
Line range hint
1-144: Verify alignment with PR objectivesThe PR description mentions implementing virtual scrolling for cmdk, but the changes in this file only relate to logging improvements. Could you clarify:
- Is this change part of a larger set of changes for implementing virtual scrolling?
- Are there other files where the virtual scrolling implementation exists?
- If not, should the PR description be updated to reflect the actual changes?
Let's check for other related changes:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Look for other files that might contain virtual scrolling implementation rg --type typescript -i "virtualscroll|virtual.scroll|virtual-scroll" # Look for cmdk-related files fd -e ts -e vue cmdkLength of output: 236
packages/nc-gui/composables/useCommandPalette/index.ts (3)
39-57: Good implementation, consider adding error handlingThe new
workspacesCmdcomputed property effectively generates workspace navigation commands. The implementation is clean and consistent.Consider adding error handling for potentially undefined workspace properties:
const workspacesCmd = computed(() => (workspacesList.value || []).map((workspace: { id: string; title: string; meta?: { color: string } }) => ({ - id: `ws-nav-${workspace.id}`, - title: workspace.title, + id: workspace.id ? `ws-nav-${workspace.id}` : `ws-nav-unknown`, + title: workspace.title || 'Unnamed Workspace', icon: 'workspace', iconColor: workspace.meta?.color, section: 'Workspaces', scopePayload: { - scope: `ws-${workspace.id}`, + scope: workspace.id ? `ws-${workspace.id}` : 'ws-unknown', data: { - workspace_id: workspace.id, + workspace_id: workspace.id || '', }, }, handler: processHandler({ type: 'navigate', - payload: `/${workspace.id}/settings`, + payload: workspace.id ? `/${workspace.id}/settings` : '/', }), })),
193-194: Fix indentation for consistencyThe
refreshCommandPalette.trigger()call is correctly added to refresh commands when workspace changes.Fix the indentation to match the surrounding code:
- - refreshCommandPalette.trigger() + refreshCommandPalette.trigger()
Line range hint
1-217: Clarify PR objectives vs. actual changesThe changes in this file focus on improving workspace command handling by:
- Introducing a new
workspacesCmdcomputed property- Simplifying
staticDatausage- Ensuring command palette refresh on workspace changes
However, the PR objective mentions implementing virtual scrolling for cmdk, which isn't addressed in these changes. Consider:
- Updating the PR description to match the actual changes
- Or, implementing the virtual scrolling as originally intended
If you decide to implement virtual scrolling:
- Consider using a virtual scrolling library like
vue-virtual-scroller- Implement pagination or lazy loading for command results
- Add a scroll container with fixed height to the command palette
packages/nc-gui/components/cmd-k/index.vue (4)
43-44: Improved search performance with debounced inputGood implementation of debounced input handling. This will help reduce unnecessary re-renders and improve performance when users are typing quickly.
A few suggestions to consider:
- The debounce delay of 100ms is reasonable, but you might want to make it configurable via props for flexibility.
- Consider adding a loading indicator when the debounced input is different from the actual input to provide visual feedback.
+ const props = defineProps<{ + debounceDelay?: number + }>() - const updateDebouncedInput = useDebounceFn(() => { + const updateDebouncedInput = useDebounceFn(() => { debouncedCmdInput.value = cmdInput.value nextTick(() => { cmdInputEl.value?.focus() }) - }, 100) + }, props.debounceDelay ?? 100)Also applies to: 296-310
49-58: Effective implementation of virtual scrollingGood job implementing virtual scrolling using the
useVirtualListcomposable. This will significantly improve performance when dealing with large lists of actions.A few observations:
- The
ACTION_HEIGHTandWRAPPER_HEIGHTconstants are well-defined and used consistently.- The
actionListNormalizedcomputed property effectively organizes the list with section headers.Consider adding a comment explaining the structure of
actionListNormalizedfor better maintainability:+ // Normalize the action list by inserting section headers + // Structure: [{ sectionTitle: string } | CmdAction] const actionListNormalized = computed(() => { const rt: (CmdAction | { sectionTitle: string })[] = [] visibleSections.value.forEach((el) => { rt.push({ sectionTitle: el || 'default' }) rt.push(...searchedActionList.value.filter((el2) => el2.section === el)) }) return rt })Also applies to: 174-186
473-558: Well-structured virtual list templateThe template implementation for the virtual list is well-structured and handles both section headers and action items appropriately.
A few suggestions:
- Consider extracting the action item template into a separate component for better maintainability.
- The keyboard shortcut display could be simplified using a computed property.
<!-- ActionItem.vue --> <template> <div :ref="isSelected ? 'cmdkActionSelectedRef' : undefined" :key="`${action.id}-${isSelected}`" v-e="['a:cmdk:action']" class="cmdk-action group flex items-center" :style="{ height: `${ACTION_HEIGHT}px`, }" :class="{ selected: isSelected }" @mouseenter="$emit('select', action.id)" @click="$emit('execute', action)" > <div class="cmdk-action-content w-full"> <ActionIcon :action="action" /> <ActionTitle :title="action.title" /> <KeyboardShortcut v-if="isSelected" /> </div> </div> </template> <script setup lang="ts"> defineProps<{ action: CmdAction isSelected: boolean ACTION_HEIGHT: number }>() defineEmits<{ (e: 'select', id: string): void (e: 'execute', action: CmdAction): void }>() </script>Then in the main component:
- <div - :ref="item.data.id === selected ? 'cmdkActionSelectedRef' : undefined" - :key="`${item.data.id}-${item.data.id === selected}`" - v-e="['a:cmdk:action']" - class="cmdk-action group flex items-center" - :style="{ - height: `${ACTION_HEIGHT}px`, - }" - :class="{ selected: selected === item.data.id }" - @mouseenter="setAction(item.data.id)" - @click="fireAction(item.data)" - > - <!-- ... --> - </div> + <ActionItem + :action="item.data" + :is-selected="selected === item.data.id" + :ACTION_HEIGHT="ACTION_HEIGHT" + @select="setAction" + @execute="fireAction" + />
Line range hint
719-731: Good styling for section headersThe CSS implementation for section headers is clean and consistent with the overall design.
Consider adding a transition for smoother visual feedback:
.cmdk-action-section-header { display: flex; align-items: center; padding: 8px 16px; font-size: 14px; color: #6a7184; + transition: background-color 0.2s ease; + &:hover { + background-color: rgba(0, 0, 0, 0.02); + } }packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts (2)
Line range hint
1-1: Overall assessment: Valuable improvements, but possibly misplacedThe changes in this file represent significant improvements to the import functionality:
- Enhanced flexibility in handling existing models
- Thorough implementation with proper edge case handling
- Consistent with the existing codebase style and patterns
However, these improvements seem unrelated to the PR's stated objective of implementing virtual scrolling for cmdk. While the changes are valuable, consider:
- Moving these import service improvements to a separate PR
- Updating the PR description to accurately reflect all changes
- Adding comments explaining why these import changes are necessary for the cmdk feature (if they are)
Clarification needed: File changes vs PR objective
The changes in
packages/nocodb/src/modules/jobs/jobs/export-import/import.service.tsappear to focus on improving and fixing bugs in the data import functionality, particularly around handling existing models and table creation. However, the PR objective states that it's implementing virtual scrolling for cmdk. Could you please clarify:
- How do these import service changes relate to the cmdk virtual scrolling implementation?
- Are these changes necessary prerequisites for the scrolling feature?
- Should these import service improvements be in a separate PR?
🔗 Analysis chain
Line range hint
1-1: Clarification needed: File changes vs PR objectiveThe changes in this file appear to be focused on improving and fixing bugs in the data import functionality, particularly around handling existing models and table creation. However, the PR objective states that it's implementing virtual scrolling for cmdk. Could you please clarify:
- How do these import service changes relate to the cmdk virtual scrolling implementation?
- Are these changes necessary prerequisites for the scrolling feature?
- Should these import service improvements be in a separate PR?
Let's check if there are any cmdk-related changes in the codebase:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for cmdk-related changes rg --type typescript "cmdk" -B 2 -A 2Length of output: 72
Script:
#!/bin/bash # Search for cmdk-related changes in TypeScript files rg --type ts "cmdk" -B 2 -A 2Length of output: 1661
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
packages/nocodb/src/services/api-docs/swaggerV2/swagger-base.jsonis excluded by!**/*.json
📒 Files selected for processing (7)
- packages/nc-gui/components/cmd-k/index.vue (10 hunks)
- packages/nc-gui/composables/useCommandPalette/index.ts (3 hunks)
- packages/nc-gui/utils/filterUtils.ts (1 hunks)
- packages/nocodb/src/helpers/commandPaletteHelpers.ts (2 hunks)
- packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts (1 hunks)
- packages/nocodb/src/services/command-palette.service.ts (3 hunks)
- tests/playwright/pages/Dashboard/Command/CmdKPage.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/nc-gui/utils/filterUtils.ts
🔇 Additional comments (7)
tests/playwright/pages/Dashboard/Command/CmdKPage.ts (2)
Line range hint
1-35: Verify virtual scrolling implementation.The PR objective mentions implementing virtual scrolling, but this test file doesn't appear to verify that functionality.
Let's check if there are other test files that might be testing virtual scrolling:
Consider adding tests specifically for virtual scrolling:
- Test with a large number of items
- Verify that only visible items are rendered
- Test scrolling and verify that new items are loaded
- Test search within a large list of items
Would you like me to provide example test cases for these scenarios?
23-24:⚠️ Potential issueClarify the need for double Enter press.
The method presses Enter twice without explanation. This could be masking an underlying issue in the component's keyboard handling.
Let's verify if both Enter presses are necessary:
Consider:
- Adding a comment explaining why two Enter presses are needed
- Investigating if this is masking a bug in the component
- If only one Enter is needed, update the code:
- await this.rootPage.keyboard.press('Enter'); - await this.rootPage.keyboard.press('Enter'); + await this.rootPage.keyboard.press('Enter');packages/nocodb/src/helpers/commandPaletteHelpers.ts (2)
1-1: Good use of ProjectRoles enumAdding the ProjectRoles import and using it instead of string literals improves code maintainability and reduces the risk of typos.
49-49: Improved code robustnessReplacing the string literal with
ProjectRoles.NO_ACCESSmakes the code more maintainable and less prone to errors. This change ensures consistency across the codebase when referring to project roles.packages/nocodb/src/services/command-palette.service.ts (2)
1-1: LGTM: Logger import added correctlyThe addition of the Logger import from @nestjs/common aligns with NestJS best practices for structured logging.
17-17: LGTM: Logger instance properly initializedThe logger is correctly instantiated with the class name as context, following NestJS best practices.
packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts (1)
Line range hint
179-192: Improved flexibility by supporting existing model reuseThis change enhances the import functionality by allowing the reuse of an existing model when creating tables. This is a valuable improvement as it:
- Enables importing data into existing tables
- Prevents unnecessary table duplication
- Provides more flexibility in data import scenarios
The implementation correctly handles both cases - using an existing model or creating a new one.
|
Uffizzi Preview |
Change Summary
Change type