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

FIX Add one to current colspan in fixColumns instead of resetting to 2 #1869

Open
wants to merge 1 commit into
base: 2.3
Choose a base branch
from

Conversation

Kevinn1109
Copy link

Description

In the old situation, the final column in each row would be hardcoded to colspan="2" if the function 'fixColumns' was called. This is required because this function adds an additional column to the table that needs to be filled in. This change removes the hardcoded number and instead adds one to the current colspan of the last cell. This fixes the bug that the 'No items found' row would be capped at two columns even if the table has more.

Manual testing steps

  1. Manually create a GridField for an has_many relation that contains no records, this should fullfill the check in needsColumnFix by default. The relation class should have at least 3 summary fields.
  2. Without this change, the 'No items found' row gets a colspan of 2. With this change, it should be 4.

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@Kevinn1109 Kevinn1109 force-pushed the bugfix/no-records-row-colspan branch 3 times, most recently from ee22a35 to ae3f7db Compare December 10, 2024 10:21
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

Thanks! Couple of small changes

@@ -176,7 +176,8 @@ $.entwine('ss', function($) {
this.find('.sortable-header').append('<th class="main col-Actions" />');
this.find('tbody tr').each(function () {
var cell = $(this).find('td:last');
cell.attr('colspan', 2);
var colspan = cell.attr("colspan") ?? 1;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var colspan = cell.attr("colspan") ?? 1;
var colspan = cell.attr('colspan') ?? 1;

What is the ?? 1 there for? What scenarios result in there not being a colspan attribute?

Copy link
Author

Choose a reason for hiding this comment

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

The colspan attribute is not set by default, I've not seen it in use other than in the case of an empty gridfield.

Copy link
Member

@GuySartorelli GuySartorelli Dec 16, 2024

Choose a reason for hiding this comment

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

Would colspan 2 always be correct when colspan wasn't already defined?

client/src/legacy/GridField.js Show resolved Hide resolved
client/src/legacy/GridField.js Show resolved Hide resolved
@@ -176,7 +176,8 @@ $.entwine('ss', function($) {
this.find('.sortable-header').append('<th class="main col-Actions" />');
this.find('tbody tr').each(function () {
var cell = $(this).find('td:last');
cell.attr('colspan', 2);
var colspan = cell.attr("colspan") ?? 1;
Copy link
Member

@GuySartorelli GuySartorelli Dec 16, 2024

Choose a reason for hiding this comment

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

Would colspan 2 always be correct when colspan wasn't already defined?

@Kevinn1109 Kevinn1109 force-pushed the bugfix/no-records-row-colspan branch from 8d14019 to 3d6b2d9 Compare December 17, 2024 08:20
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

#1869 (comment) hasn't been responded to. We're assuming if the colspan wasn't defined, it is already 1 and should become 2. Does that always hold true? Can we do something like count the number of columns in the table or something?

client/src/legacy/GridField.js Outdated Show resolved Hide resolved
client/src/legacy/GridField.js Outdated Show resolved Hide resolved
@Kevinn1109
Copy link
Author

#1869 (comment) hasn't been responded to. We're assuming if the colspan wasn't defined, it is already 1 and should become 2. Does that always hold true? Can we do something like count the number of columns in the table or something?

The calling function adds one column to the table, so a correctly set up table will always have rows with the number of columns minus that new column. My change changes a hardcoded 2 that disregards the existing colspan to something that takes it into account. Counting the number of columns isn't needed, the entire purpose of this function is to add one column. If this leads to a wrong number of columns, there's a near certainty that said table already has a wrong number of columns in the current release. As far as I can tell, the only native integration that's affected by this is the 'No items found' row.

In my eyes this is legacy code that should be removed altogether, but I'm not entirely sure if that comes with complications or not.

In the previous situation, the 'No items found' row would be hardcapped at colspan=2. This change ensures that that row always spans all columns in the table
@Kevinn1109 Kevinn1109 force-pushed the bugfix/no-records-row-colspan branch from 3d6b2d9 to c297bef Compare January 6, 2025 11:05
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.

2 participants