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

Remove numeric class from columns #739

Conversation

DilwoarH
Copy link
Contributor

@DilwoarH DilwoarH commented Dec 12, 2024

Preview link: https://submit-pr-739.herokuapp.com/organisations/local-authority:WAE/brownfield-land/data

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

This makes all columns consistent. The GOVUK Design system documentation also suggests using this class only when comparing columns of numbers:

When comparing columns of numbers, align the numbers to the right in table cells.

#679

Related Tickets & Documents

QA Instructions, Screenshots, Recordings

Before

Screenshot 2024-12-12 at 3 38 46 pm

After

Screenshot 2024-12-12 at 3 39 09 pm

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above.

  • Yes
  • No, and this is why: Please replace this line with details on why tests have not been included
  • I need help with writing tests

QA sign off

  • Code has been checked and approved
  • Design has been checked and approved
  • Product and business logic has been checked and proved

[optional] Are there any post-deployment tasks we need to perform?

[optional] Are there any dependencies on other PRs or Work?

Summary by CodeRabbit

  • New Features

    • Simplified logic for constructing table parameters, enhancing clarity and efficiency.
    • Streamlined HTML link generation for URLs.
  • Bug Fixes

    • Adjusted class assignments for numeric and date fields in table rendering, potentially affecting styling.
  • Tests

    • Updated test cases to reflect changes in class assignments for numeric and date fields.

@DilwoarH DilwoarH linked an issue Dec 12, 2024 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The pull request introduces modifications to the dataview.middleware.js and table.html files, focusing on simplifying the logic in the constructTableParams function and the static definition of column classes in the table component. The changes remove unnecessary conditional checks for numeric and date values, streamline HTML link generation, and alter the column definitions in the HTML to eliminate dynamic class assignments. Corresponding test cases have also been updated to reflect these changes.

Changes

File Change Summary
src/middleware/dataview.middleware.js Simplified logic in constructTableParams, removed checks for numeric/date values, streamlined HTML link generation.
src/views/components/table.html Altered <col> elements in <colgroup> to static definitions, removed conditional class assignments for numeric columns.
test/unit/middleware/dataview.middleware.test.js Updated tests for constructTableParams to reflect changes in class assignments for numeric and date fields.

Assessment against linked issues

Objective Addressed Explanation
Consistent way of displaying numerical data/dates in table component (#679) The changes remove the govuk-table__cell--numeric class from numeric and date columns.

Possibly related PRs

  • fix: a few type errors #589: This PR modifies the dataview.middleware.js file, which is directly related to the changes made in the constructTableParams function in the main PR, as both involve handling parameters for table construction.
  • Add issue table view #691: This PR introduces a new issue table view and modifies the issueTable.middleware.js, which is relevant because it also deals with the construction and management of table parameters, similar to the changes in the constructTableParams function.
  • 684 issue details fetch data from all active resources #707: This PR updates the issue details page and includes changes to the entityIssueDetails.middleware.js, which may relate to how issues are displayed in tables, connecting to the overall theme of managing data presentation in tables as seen in the main PR.

Suggested labels

bug, enhancement

Suggested reviewers

  • GeorgeGoodall-GovUk
  • rosado

🐰 In the meadow, changes bloom,
Simplifying logic, clearing the room.
Columns once dressed, now plain and bright,
A table of data, a clearer sight!
Hopping along, we celebrate,
Efficiency gained, oh, isn’t it great? 🌼


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. (Experiment)
  • @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.

This makes all columns consistent. The GOVUK Design system documentation also suggests using this class only when comparing columns of numbers:

When comparing columns of numbers, align the numbers to the right in table cells.

#679
@DilwoarH DilwoarH force-pushed the 679-consistent-way-of-displaying-numerical-datadates-in-table-component branch from e4b53a9 to d3a3821 Compare December 12, 2024 15:40
@DilwoarH DilwoarH requested a review from alextea December 12, 2024 15:40
Copy link

github-actions bot commented Dec 12, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 70.48% 5201 / 7379
🔵 Statements 70.48% 5201 / 7379
🔵 Functions 68.72% 211 / 307
🔵 Branches 83.09% 683 / 822
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/middleware/dataview.middleware.js 100% 88.88% 50% 100%
Generated in workflow #506 for commit 809377b by the Vitest Coverage Report Action

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

🧹 Outside diff range and nitpick comments (1)
src/middleware/dataview.middleware.js (1)

47-49: Consider adding text-align CSS class for URL columns

Whilst removing the numeric class is correct, consider whether URL columns need specific alignment for better readability. The GOVUK Design System suggests considering alignment based on content type.

 if (urlRegex.test(entity[field])) {
   html = `<a href='${entity[field]}' target='_blank' rel='noopener noreferrer' aria-label='${entity[field]} (opens in new tab)'>${entity[field]}</a>`
   value = undefined
+  classes = 'govuk-table__cell--left'
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a0b54a8 and d3a3821.

📒 Files selected for processing (3)
  • src/middleware/dataview.middleware.js (1 hunks)
  • src/views/components/table.html (1 hunks)
  • test/unit/middleware/dataview.middleware.test.js (1 hunks)
🔇 Additional comments (3)
src/middleware/dataview.middleware.js (1)

42-43: LGTM: Removal of numeric class aligns with GOVUK Design System

The removal of numeric class assignment aligns with the GOVUK Design System guidance, which specifies that numeric classes should only be used when comparing columns of numbers.

test/unit/middleware/dataview.middleware.test.js (1)

95-96: LGTM: Test cases correctly validate removal of numeric classes

The test assertions have been properly updated to expect empty classes for both numeric and date fields, which aligns with the changes in the middleware and GOVUK Design System guidance.

Also applies to: 101-102

src/views/components/table.html (1)

42-42: LGTM: Simplified column definition aligns with GOVUK Design System

The removal of conditional class assignment from col elements aligns with the GOVUK Design System guidance and simplifies the template logic.

Let's verify that no other templates are expecting these classes:

✅ Verification successful

Simplified column definition is safe and maintains styling

The removal of class assignments from the col element is safe as:

  • No numeric classes are used anywhere in the views
  • Table styling is maintained through the proper GOV.UK Design System classes (govuk-table, govuk-table__cell, etc.)
  • Custom styling is handled via the .dl-table classes which don't rely on column-specific classes
  • Cell-level styling is still possible through the columnData.classes parameter
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining numeric class usage in templates
# This helps ensure we've caught all instances where the class might have been expected

rg -l "govuk-table__cell--numeric" "src/views/"

Length of output: 45


Script:

#!/bin/bash
# Let's broaden our search to check for any numeric class usage across the codebase
# and also look for related table styling patterns

# Check for any numeric class patterns in the codebase
rg -i "numeric" "src/views/" -A 2

# Look for table-related class usage
rg "govuk-table" "src/views/" -A 2

# Check for any table-related styling in SCSS files
fd -e scss -x rg "table" {} -A 2

Length of output: 7460

@DilwoarH DilwoarH temporarily deployed to submit-pr-739 December 16, 2024 15:04 Inactive
@DilwoarH DilwoarH merged commit b261a0b into main Dec 16, 2024
5 checks passed
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.

Consistent way of displaying numerical data/dates in table component
3 participants