Skip to content

[518] Added Table widget - #98

Merged
Anton-88 merged 3 commits into
mainfrom
518-create-partnership-table-widget
May 21, 2025
Merged

[518] Added Table widget#98
Anton-88 merged 3 commits into
mainfrom
518-create-partnership-table-widget

Conversation

@Anton-88

Copy link
Copy Markdown
Contributor

Added new Table widget

@Anton-88
Anton-88 requested a review from killev as a code owner May 18, 2025 14:33
@coderabbitai

coderabbitai Bot commented May 18, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@killev has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 10 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 994ad92 and 2e06576.

📒 Files selected for processing (1)
  • website/app.js (1 hunks)
📝 Walkthrough

"""

Walkthrough

The changes introduce a new "Table Widget" feature to the ApostropheCMS application. This includes registering the widget module, updating main widget configurations, adding its SCSS styles, and providing both the server-side module definition and its corresponding HTML template for rendering. No existing logic or exported entities were modified.

Changes

File(s) Change Summary
website/app.js Registered the table-widget module in the ApostropheCMS modules configuration.
website/lib/mainWidgets.js Added the table widget to the basic group in the exported widgets configuration.
website/modules/asset/ui/src/index.scss Imported the new _table-widget.scss partial to include table widget styles in the main UI stylesheet.
website/modules/asset/ui/src/scss/_table-widget.scss Added a new SCSS partial with styles for the table widget, including layout, typography, and responsive design for widget components.
website/modules/table-widget/index.js Introduced a new ApostropheCMS widget module defining the "Table Widget" with schema, options, and rich-text toolbar configurations.
website/modules/table-widget/views/widget.html Added a new HTML template for rendering the table widget, including conditional rendering for intro, rows, and link logic based on row data.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ApostropheCMS
    participant TableWidgetModule
    participant UI

    User->>ApostropheCMS: Requests page with table widget
    ApostropheCMS->>TableWidgetModule: Fetch widget data (intro, rows, links)
    TableWidgetModule->>ApostropheCMS: Returns widget data
    ApostropheCMS->>UI: Renders widget.html with widget data
    UI-->>User: Displays styled table widget with intro, rows, and links
Loading

Suggested reviewers

  • IhorMasechko
  • killev
    """
✨ 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
Contributor

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 (14)
website/modules/asset/ui/src/scss/_table-widget.scss (6)

1-12: Consider centering the intro block.

You’ve set a max-width: 800px on .sf-table-intro, but without horizontal centering it will always hug the left edge.
Suggestion: add margin: 0 auto; to center within its container.


14-23: Leverage CSS gap for flexbox items.

Instead of manual margins or wrapping logic at the medium breakpoint, you can simplify spacing between rows by using gap. For example:

.sf-table {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;

  @include breakpoint-medium {
    flex-direction: row;
  }
}

This eliminates the need for negative margins and manual spacing adjustments.


25-55: Simplify redundant nth-child selectors.

You’ve applied three selectors to remove the top border on break-row items:

&:nth-child(3n+6),
&:nth-child(4n),
&:nth-child(n+4) {
  border-top: none;
}

The single rule &:nth-child(n+4) already matches every item from the 4th onward. Consider dropping the other two for clarity and maintainability.


57-65: Unify title-cell typography styling.

Both .sf-table-cell-title and .sf-table-title apply font-weight: 700 and adjust font-size at the same breakpoint. You can merge these into a single shared mixin or move the typography rules to one class to eliminate duplication.


67-76: Avoid duplicate breakpoint font-size rules.

.sf-table-title bumps from 18px→22px at medium, while .sf-table-cell-title goes 14px→22px. Given they converge at 22px, consider deriving both from a shared base, or adjust mobile sizes for a clearer hierarchy.


96-112: Consolidate link styling and class usage.

You’re styling links via .sf-table-link a but your template also adds a sf-link class to each <a>. Consider removing the extra class and relying solely on the parent selector for consistency:

- <a href="{{ linkUrl }}" class="sf-link" …>
+ <a href="{{ linkUrl }}" …>

Or, if sf-link is needed elsewhere, update your SCSS to target .sf-link directly.

website/modules/asset/ui/src/index.scss (1)

23-23: Maintain import naming consistency.

Other partials include the .scss extension (_cases.scss, _container.scss). For consistency, consider:

- @import './scss/_table-widget';
+ @import './scss/_table-widget.scss';

This makes it clear at a glance that you’re importing an SCSS file.

website/lib/mainWidgets.js (1)

22-22: Optional: Alphabetize widget list.

You’ve added 'table': {} inline—consider sorting the widgets keys alphabetically to make future maintenance and diff reviews easier.

website/modules/table-widget/views/widget.html (2)

1-6: Enhance accessibility with ARIA roles.

Because you’re using div for tabular data, consider adding ARIA roles to improve screen-reader support:

<section class="sf-section" data-table-widget role="table">
  {% if data.widget.intro %}
    <div class="sf-table-intro" role="rowgroup"></div>
  {% endif %}
  …
</section>

Or evaluate using a semantic <table> if that better fits your content.


8-37: Consider semantic markup for tabular data.

This structure is visually a table, but you’re using flexbox. For improved semantics and keyboard navigation, you could switch to:

<table class="sf-table">
  <thead>…intro…</thead>
  <tbody>
    {% for row in data.widget.rows %}
      <tr>
        <th scope="row">{{ row.title }}</th>
        <td>{% area row, 'description' %}{% if linkUrl %}<a href="{{ linkUrl }}"></a>{% endif %}</td>
      </tr>
    {% endfor %}
  </tbody>
</table>

This brings native accessibility benefits without extra ARIA roles.

website/modules/table-widget/index.js (4)

49-102: Consider adding conditional validation for link fields

While the linkType field is optional, if a user selects a link type, there's no validation to ensure they complete the corresponding link field (page, file, or custom URL).

Consider adding validation or making the corresponding fields required when a link type is selected:

 _page: {
   label: 'Link to page',
   type: 'relationship',
   withType: '@apostrophecms/page',
   max: 1,
   builders: {
     project: {
       title: 1,
       _url: 1,
     },
   },
   if: {
     linkType: 'page',
   },
+  required: true,
 },

Similar changes could be applied to _file and customUrl fields.


87-95: Consider adding projection to file relationship

The _page relationship includes a projection to limit the fields fetched, but the _file relationship doesn't have a similar optimization.

For consistency and performance, consider adding a projection to the file relationship:

 _file: {
   label: 'Link to file',
   type: 'relationship',
   withType: '@apostrophecms/file',
   max: 1,
+  builders: {
+    project: {
+      title: 1,
+      attachment: 1,
+    },
+  },
   if: {
     linkType: 'file',
   },
 },

103-112: Consider showing target option only when a link is defined

Currently, the "Open in a new tab" option appears regardless of whether a link is defined, which might confuse users.

Consider showing this field only when a link type is selected:

 target: {
   label: 'Will the link open a new browser tab?',
   type: 'checkboxes',
+  if: {
+    $or: [
+      { linkType: 'page' },
+      { linkType: 'file' },
+      { linkType: 'custom' }
+    ]
+  },
   choices: [
     {
       label: 'Open in a new tab',
       value: '_blank',
     },
   ],
 },

1-118: Consider adding JSDoc comments for better documentation

While the code is clear, adding JSDoc comments would improve maintainability and help other developers understand the widget's purpose and structure.

For example, at the top of the file:

/**
 * Table Widget module for ApostropheCMS
 * 
 * This widget displays information in a table format with optional intro text.
 * Each row can have a title, rich text description, and optional link.
 */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1da45b9 and 89e94a5.

📒 Files selected for processing (6)
  • website/app.js (1 hunks)
  • website/lib/mainWidgets.js (1 hunks)
  • website/modules/asset/ui/src/index.scss (1 hunks)
  • website/modules/asset/ui/src/scss/_table-widget.scss (1 hunks)
  • website/modules/table-widget/index.js (1 hunks)
  • website/modules/table-widget/views/widget.html (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
website/modules/table-widget/index.js (1)
website/lib/mainWidgets.js (1)
  • headingToolbar (1-1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: unit-tests
  • GitHub Check: lint
  • GitHub Check: e2e-tests
  • GitHub Check: security-scan
🔇 Additional comments (6)
website/modules/asset/ui/src/scss/_table-widget.scss (1)

78-93: Mobile-first description styling looks good.

The font-weight, sizing, and adaptive min-height on medium breakpoints are well thought out. This block is straightforward and aligns with the design.

website/app.js (1)

122-122: Widget module registered correctly.

The addition of 'table-widget': {} in modules ensures the new Table Widget is loaded by Apostrophe. No action needed here.

website/modules/table-widget/index.js (4)

1-3: Imports look good

The imports for extendedToolbar and headingToolbar are correctly structured and consistent with other parts of the codebase.


4-9: Widget configuration is clear and follows best practices

The module correctly extends the base widget type with appropriate label and icon properties.


10-24: Intro field configuration looks good

The optional intro field is well configured with appropriate constraints and toolbar options.


25-48: Table rows structure is well-defined

The table rows configuration with required title and description fields provides a solid foundation for the widget.

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 18, 2025
@github-actions

github-actions Bot commented May 18, 2025

Copy link
Copy Markdown

🔍 Vulnerabilities of apostrophe-cms:test

📦 Image Reference apostrophe-cms:test
digestsha256:90dda227c64b59dce2a79a7d79ab7f8d5fc2d87e51d84e01a6f57a808abf2b75
vulnerabilitiescritical: 0 high: 2 medium: 0 low: 0
platformlinux/amd64
size284 MB
packages935
📦 Base Image node:23-alpine
also known as
  • 23-alpine3.21
  • 23.11-alpine
  • 23.11-alpine3.21
  • 23.11.1-alpine
  • 23.11.1-alpine3.21
digestsha256:169ee1b69bd3f5c7c8508a9919e8b367bba9dc7fa9a03097ec9f85d2e8179631
vulnerabilitiescritical: 0 high: 0 medium: 0 low: 0
critical: 0 high: 1 medium: 0 low: 0 async 0.9.2 (npm)

pkg:npm/async@0.9.2

high 7.8: CVE--2021--43138 OWASP Top Ten 2017 Category A9 - Using Components with Known Vulnerabilities

Affected range<2.6.4
Fixed version2.6.4, 3.2.2
CVSS Score7.8
CVSS VectorCVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score1.061%
EPSS Percentile77th percentile
Description

A vulnerability exists in Async through 3.2.1 (fixed in 3.2.2), which could let a malicious user obtain privileges via the mapValues() method.

critical: 0 high: 1 medium: 0 low: 0 async 1.5.2 (npm)

pkg:npm/async@1.5.2

high 7.8: CVE--2021--43138 OWASP Top Ten 2017 Category A9 - Using Components with Known Vulnerabilities

Affected range<2.6.4
Fixed version2.6.4, 3.2.2
CVSS Score7.8
CVSS VectorCVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score1.061%
EPSS Percentile77th percentile
Description

A vulnerability exists in Async through 3.2.1 (fixed in 3.2.2), which could let a malicious user obtain privileges via the mapValues() method.

@Anton-88 Anton-88 self-assigned this May 18, 2025

@yuramax yuramax left a comment

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.

LGTM! 👍

@sonarqubecloud

Copy link
Copy Markdown

@IhorMasechko IhorMasechko left a comment

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.

LGTM

@VitalyyP VitalyyP left a comment

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.

LGTM

@killev killev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good

@Anton-88
Anton-88 merged commit 154b95b into main May 21, 2025
@Anton-88
Anton-88 deleted the 518-create-partnership-table-widget branch May 21, 2025 06:40
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.

5 participants