Skip to content
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

If image doesn't exist, show value #92

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/components/DataTable/SWRDataTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,19 @@ export const renderDataTableCell = ({ filters, column, row, selectedRows }) => {
case "actions":
return <DataTableRowActions row={row} column={column} />;
case "image":
if (!row.getValue("image")?.url) return null;
return (
<img
className="aspect-ratio-1 size-16 rounded-sm object-contain"
src={row.getValue("image").url}
alt={row.getValue("name")}
/>
);
// eslint-disable-next-line no-case-declarations
const image = row.getValue("image") || value;
Copy link

Choose a reason for hiding this comment

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

Scope the image declaration to the case block.

The image variable declaration should be wrapped in a block to restrict its access to the "image" case only. This avoids potential issues with other switch cases accessing it.

    case "image": {
      const image = row.getValue("image") || value;
      if (image?.url) {
        return (
          <img
            className="aspect-ratio-1 size-16 rounded-sm object-contain"
            src={image.url}
            alt={image.alt_text}
          />
        );
      } 
      return <div className="max-w-[400px] truncate">{value}</div>;
    }
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 image = row.getValue("image") || value;
case "image": {
const image = row.getValue("image") || value;
if (image?.url) {
return (
<img
className="aspect-ratio-1 size-16 rounded-sm object-contain"
src={image.url}
alt={image.alt_text}
/>
);
}
return <div className="max-w-[400px] truncate">{value}</div>;
}
Tools
Biome

[error] 118-118: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

GitHub Check: Run Type Check & Linters

[failure] 118-118:
Unexpected lexical declaration in case block

if (image?.url) {
return (
<img
className="aspect-ratio-1 size-16 rounded-sm object-contain"
src={image.url}
alt={image.alt_text}
/>
);
}
return <div className="max-w-[400px] truncate">{value}</div>;
Copy link
Contributor

@ribeirojose ribeirojose Aug 21, 2024

Choose a reason for hiding this comment

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

why not simply show the alt_text? where does value come from?


case "link":
// eslint-disable-next-line no-case-declarations
const url = row.getValue("details_url");
Expand Down