10000 fix(nc-gui): instead of rendering multiple lookup attachment cell render only 1 by rameshmane7218 · Pull Request #10518 · nocodb/nocodb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(nc-gui): instead of rendering multiple lookup attachment cell render only 1 #10518

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

Merged
merged 5 commits into from
Feb 18, 2025

Conversation

rameshmane7218
Copy link
Member

Change Summary

Provide summary of changes with issue number if any.

Change type

  • feat: (new feature for the user, not a new feature for build script)
  • fix: (bug fix for the user, not a fix to a build script)
  • docs: (changes to the documentation)
  • style: (formatting, missing semi colons, etc; no production code change)
  • refactor: (refactoring production code, eg. renaming a variable)
  • test: (adding missing tests, refactoring tests; no production code change)
  • chore: (updating grunt tasks etc; no production code change)

Test/ Verification

Provide summary of changes.

Additional information / screenshots (optional)

Anything for maintainers to be made aware of

@rameshmane7218 rameshmane7218 added the 🛑 Status: Do Not Merge Used in PR only. The PR cannot be merged due to some reasons. label Feb 17, 2025
@rameshmane7218 rameshmane7218 self-assigned this Feb 17, 2025
Copy link
Contributor
coderabbitai bot commented Feb 17, 2025
📝 Walkthrough

Walkthrough

The changes update the Lookup.vue component by enhancing how attachment types are handled and improving the dropdown rendering logic. The modifications now include array flattening and filtering when processing cellValue, as well as a simplified condition to determine when to display the LazySmartsheetCell for attachments. Additionally, the dropdown overlay rendering is now conditional on the presence of a valid lookupColumn. The Readonly.vue component's handling of modelValue is also improved with optional chaining, and the Attachment.ts file has been updated to include a new parameter for flexible alignment in the rendering method.

Changes

File Path Change Summary
packages/nc-gui/components/virtual-cell/Lookup.vue Updated the logic for computing arrValue to handle arrays by flattening and filtering out null values; simplified attachment rendering conditions and adjusted dropdown overlay rendering based on the existence of lookupColumn.
packages/nc-gui/components/cell/SingleSelect/Readonly.vue Modified the selectedOpt computed property to use optional chaining for safe handling of modelValue.
packages/nc-gui/components/smartsheet/grid/canvas/cells/Attachment.ts Updated the render method in AttachmentCellRenderer to include a textAlign parameter for flexible alignment options when rendering attachments.
packages/nc-gui/components/smartsheet/grid/canvas/cells/Lookup.ts Introduced a new function getArrValue to encapsulate logic for determining arrValue, enhancing modularity and readability; updated rendering properties based on lookupColumn.
packages/nc-gui/components/smartsheet/grid/canvas/index.vue Added a new CSS class .nc-attachment-image to apply a pointer cursor style on hover for attachment images.

Possibly related PRs

  • feat: Use lookup over attachment field as cover image in gallery & kanban view #8801: The changes in the main PR for Lookup.vue involve enhancements to the logic for handling attachment types and rendering dropdown values, while the retrieved PR also modifies Lookup.vue to adjust the height calculation based on attachment presence, indicating a direct relationship in their modifications to the same component.
  • Nc fix/grid view attachment cell icon size #9964: The changes in the main PR, specifically the enhancements to the Lookup.vue component for handling attachment types, are related to the modifications in the retrieved PR that involve the rendering of attachment icons, as both focus on improving the handling and display of attachments in the application.

Suggested labels

🐛 Type: Bug, 👓 Scope : View, size:L, lgtm

Suggested reviewers

  • dstala

📜 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 9abe9f0 and 8b05c72.

📒 Files selected for processing (5)
  • packages/nc-gui/components/cell/SingleSelect/Readonly.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/grid/canvas/cells/Attachment.ts (3 hunks)
  • packages/nc-gui/components/smartsheet/grid/canvas/cells/Lookup.ts (3 hunks)
  • packages/nc-gui/components/smartsheet/grid/canvas/index.vue (1 hunks)
  • packages/nc-gui/components/virtual-cell/Lookup.vue (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/nc-gui/components/cell/SingleSelect/Readonly.vue
  • packages/nc-gui/components/smartsheet/grid/canvas/cells/Lookup.ts
  • packages/nc-gui/components/smartsheet/grid/canvas/cells/Attachment.ts
  • packages/nc-gui/components/smartsheet/grid/canvas/index.vue
  • packages/nc-gui/components/virtual-cell/Lookup.vue
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: release-docker / buildx
  • GitHub Check: unit-tests-pg
  • GitHub Check: unit-tests

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.

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.

Copy link
Contributor
@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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 874b831 and ae741e9.

📒 Files selected for processing (1)
  • packages/nc-gui/components/virtual-cell/Lookup.vue (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: release-docker / buildx
  • GitHub Check: pre-build-for-playwright / playwright
  • GitHub Check: unit-tests-pg
  • GitHub Check: unit-tests
🔇 Additional comments (2)
packages/nc-gui/components/virtual-cell/Lookup.vue (2)

282-283: LGTM! Improved rendering conditions.

The changes improve the code by:

  • Simplifying the attachment cell rendering check
  • Adding a guard clause for the dropdown overlay

Also applies to: 352-353


484-488: LGTM! Well-structured CSS for attachment wrapper.

The new styles follow the project's CSS conventions and properly handle the attachment cell height in the lookup dropdown.

Copy link
Contributor
github-actions bot commented Feb 17, 2025

Uffizzi Preview deployment-61052 was deleted.

@o1lab o1lab force-pushed the nc-fix/lookup-attachments branch from ae741e9 to 5fbbc13 Compare February 18, 2025 05:52
Copy link
Contributor
@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)
packages/nc-gui/components/virtual-cell/Lookup.vue (2)

296-298: Simplify attachment rendering condition.

The condition for rendering attachments can be simplified by extracting the check into a computed property.

+const hasValidAttachment = computed(() => 
+  isAttachment(lookupColumn.value) && 
+  arrValue.value[0] && 
+  ncIsObject(arrValue.value[0])
+)

-<div v-if="isAttachment(lookupColumn) && arrValue[0] && ncIsObject(arrValue[0])">
+<div v-if="hasValidAttachment">

412-414: Reuse attachment rendering logic.

The attachment rendering logic is duplicated from the main template. Consider extracting it into a reusable component.

+<!-- AttachmentCell.vue -->
+<template>
+  <div class="nc-lookup-attachment-wrapper">
+    <LazySmartsheetCell 
+      :model-value="modelValue" 
+      :column="column" 
+      :edit-enabled="false" 
+      :read- 
+    />
+  </div>
+</template>

+<script setup lang="ts">
+defineProps({
+  modelValue: { type: Array, required: true },
+  column: { type: Object, required: true }
+})
+</script>

-<div v-if="isAttachment(lookupColumn) && arrValue[0] && ncIsObject(arrValue[0])" class="nc-lookup-attachment-wrapper">
-  <LazySmartsheetCell :model-value="arrValue" :column="lookupColumn" :edit-enabled="false" :read- />
-</div>
+<AttachmentCell 
+  v-if="hasValidAttachment"
+  :model-value="arrValue" 
+  :column="lookupColumn" 
+/>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ae741e9 and 5fbbc13.

📒 Files selected for processing (1)
  • packages/nc-gui/components/virtual-cell/Lookup.vue (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: release-docker / buildx
  • GitHub Check: pre-build-for-playwright / playwright
  • GitHub Check: unit-tests-pg
  • GitHub Check: unit-tests
🔇 Additional comments (2)
packages/nc-gui/components/virtual-cell/Lookup.vue (2)

80-105: Add missing imports and optimize array flattening.

The array handling logic could be improved in two ways:

  1. The utility functions ncIsArray, ncIsObject, and ncIsNull are used but not imported.

  2. The array flattening logic can be simplified using flatMap.

  3. Add the missing imports at the top of the file:

+import { ncIsArray, ncIsObject, ncIsNull } from 'nocodb-sdk'
  1. Simplify the array flattening logic:
-      return cellValue.value
-        .filter((v) => v !== null)
-        .reduce((acc, v) => {
-          acc.push(...v)
-
-          return acc
-        }, [])
+      return cellValue.value
+        .filter((v) => v !== null)
+        .flatMap((v) => v)

500-504: LGTM! New attachment wrapper styles.

The styles for the attachment wrapper ensure proper layout and appearance.

@rameshmane7218 rameshmane7218 removed the 🛑 Status: Do Not Merge Used in PR only. The PR cannot be merged due to some reasons. label Feb 18, 2025
@o1lab o1lab force-pushed the nc-fix/lookup-attachments branch from 5fbbc13 to 02acad1 Compare February 18, 2025 07:15
Copy link
Contributor
@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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5fbbc13 and 02acad1.

📒 Files selected for processing (4)
  • packages/nc-gui/components/cell/SingleSelect/Readonly.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/grid/canvas/cells/Attachment.ts (2 hunks)
  • packages/nc-gui/components/smartsheet/grid/canvas/cells/Lookup.ts (3 hunks)
  • packages/nc-gui/components/virtual-cell/Lookup.vue (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nc-gui/components/virtual-cell/Lookup.vue
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: release-docker / buildx
  • GitHub Check: pre-build-for-playwright / playwright
  • GitHub Check: unit-tests-pg
  • GitHub Check: unit-tests
🔇 Additional comments (5)
packages/nc-gui/components/cell/SingleSelect/Readonly.vue (1)

34-36: LGTM! Good defensive programming practice.

The introduction of optional chaining (?.) for modelValue.trim() is a good improvement that safely handles cases where modelValue is undefined, preventing potential runtime errors. This change aligns well with the component's Props interface where modelValue is defined as optional.

packages/nc-gui/components/smartsheet/grid/canvas/cells/Attachment.ts (2)

100-114: LGTM! The render method signature has been updated to support flexible alignment.

The addition of the textAlign parameter enhances the flexibility of attachment rendering, particularly for lookup cells.


188-191:

❓ Verification inconclusive

Verify the impact of left-aligned attachments on the UI.

The change allows for left-aligned attachments in lookup cells, which aligns with the PR objective. However, ensure that this change:

  1. Maintains visual consistency with other cell types
  2. Doesn't cause layout issues when attachments are too wide

🏁 Script executed:

#!/bin/bash
# Description: Search for other cell renderers that might be affected by this alignment change

# Search for other cell renderers that handle alignment
ast-grep --pattern 'class $_ implements CellRenderer {
  $$$
  render($_, $_) {
    $$$
    textAlign
    $$$
  }
  $$$
}'

# Search for lookup-related components that might need similar alignment handling
rg -g '*.{ts,vue}' -l 'isUnderLookup.*textAlign'

Length of output: 324


Action: Confirm UI Impact of Left-Aligned Attachments

The recent change in packages/nc-gui/components/smartsheet/grid/canvas/cells/Attachment.ts (lines 188–191) now permits left-aligned attachments in lookup cells. However, automated searches did not unveil similar cases in other cell renderers, so please manually verify the following:

  • That the new left alignment maintains visual consistency with other cell types.
  • That there are no layout issues (e.g., when attachments are wider than expected).

Please double-check these aspects to ensure the UI remains robust.

packages/nc-gui/components/smartsheet/grid/canvas/cells/Lookup.ts (2)

91-91: LGTM!

The assignment captures the return value from getArrValue correctly.


109-109: LGTM! Changes align with PR objectives.

The conditional height and text alignment for attachment cells improve the rendering:

  • Full height for attachments ensures proper display
  • Centered alignment for attachments enhances visual presentation

Also applies to: 119-119

@o1lab o1lab force-pushed the nc-fix/lookup-attachments branch from 02acad1 to 712df8b Compare February 18, 2025 09:36
Copy link
Contributor
@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)
packages/nc-gui/components/smartsheet/grid/canvas/cells/Lookup.ts (1)

54-89: Enhance type safety and simplify array flattening logic.

The function correctly addresses previous scoping issues, but could benefit from the following improvements:

  1. Add type annotations for better type safety
  2. Simplify the array flattening logic using flatMap
  3. Make the conditions more explicit with type guards
-const getArrValue = () => {
+const getArrValue = (): unknown[] => {
   if (!value) return []

   if (lookupColumn.uidt === UITypes.Attachment) {
     if ([RelationTypes.BELONGS_TO, RelationTypes.ONE_TO_ONE].includes(relatedColObj?.colOptions?.type)) {
       return [value]
     }

-    if (
-      ncIsArray(value) &&
-      value.every((v) => {
-        if (ncIsNull(v)) return true
-
-        if (ncIsArray(v)) {
-          return !v.length || ncIsObject(v[0])
-        }
-
-        return false
-      })
-    ) {
-      return value
-        .filter((v) => v !== null)
-        .reduce((acc, v) => {
-          acc.push(...v)
-
-          return acc
-        }, [])
-    }
+    if (ncIsArray(value)) {
+      const isNestedArray = value.every(v => 
+        ncIsNull(v) || (ncIsArray(v) && (!v.length || ncIsObject(v[0])))
+      )
+      if (isNestedArray) {
+        return value
+          .filter((v): v is unknown[] => ncIsArray(v))
+          .flatMap(v => v)
+      }
+    }
   }

   if (ncIsArray(value)) {
     return value.filter((v) => v !== null)
   }

   return [value]
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 02acad1 and 712df8b.

📒 Files selected for processing (4)
  • packages/nc-gui/components/cell/SingleSelect/Readonly.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/grid/canvas/cells/Attachment.ts (2 hunks)
  • packages/nc-gui/components/smartsheet/grid/canvas/cells/Lookup.ts (3 hunks)
  • packages/nc-gui/components/virtual-cell/Lookup.vue (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/nc-gui/components/cell/SingleSelect/Readonly.vue
  • packages/nc-gui/components/smartsheet/grid/canvas/cells/Attachment.ts
  • packages/nc-gui/components/virtual-cell/Lookup.vue
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: release-docker / buildx
  • GitHub Check: pre-build-for-playwright / playwright
  • GitHub Check: unit-tests
  • GitHub Check: unit-tests-pg
🔇 Additional comments (2)
packages/nc-gui/components/smartsheet/grid/canvas/cells/Lookup.ts (2)

91-93: LGTM!

The usage of getArrValue is clean and maintains proper validation of the result.


109-109: LGTM!

The conditional rendering properties for attachments are well-implemented and align with the PR's objective of fixing lookup attachment cell rendering.

Also applies to: 119-119

@o1lab o1lab force-pushed the nc-fix/lookup-attachments branch 2 times, most recently from d55e161 to 9abe9f0 Compare February 18, 2025 10:36
@o1lab o1lab force-pushed the nc-fix/lookup-attachments branch from 9abe9f0 to 8b05c72 Compare February 18, 2025 13:04
@mertmit mertmit merged commit 27ce4d8 into develop Feb 18, 2025
22 checks passed
@mertmit mertmit deleted the nc-fix/lookup-attachments branch February 18, 2025 13:38
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
0