Skip to content

Conversation

@pan-kot
Copy link
Member

@pan-kot pan-kot commented Feb 27, 2025

Description

This PR introduces a new API property for the table component, the: cellVerticalAlign?: "middle" | "top". This property will complement the existing columnDefinitions.verticalAlign?: "middle" | "top" property, but is applicable for the entire table, including the selection column. When both properties are set, the columnDefinitions.verticalAlign takes precedence.

On the screenshot you can see how selection checkboxes are aligned to the cell's top when cellVerticalAlign = "top". The last column alignment is overridden by setting the columnDefinitions.verticalAlign = "middle".

Screenshot 2025-02-27 at 17 46 38

Rel: AWSUI-59979

How has this been tested?

  • Existing screenshot tests
Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.44%. Comparing base (47c19bf) to head (36d1aba).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3318      +/-   ##
==========================================
+ Coverage   96.42%   96.44%   +0.01%     
==========================================
  Files         791      795       +4     
  Lines       22616    22711      +95     
  Branches     7820     7848      +28     
==========================================
+ Hits        21808    21903      +95     
  Misses        754      754              
  Partials       54       54              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pan-kot pan-kot force-pushed the table-all-cell-align branch from 00391bc to dce402f Compare March 6, 2025 17:33
@pan-kot pan-kot marked this pull request as ready for review March 10, 2025 07:49
@pan-kot pan-kot requested a review from a team as a code owner March 10, 2025 07:49
@pan-kot pan-kot requested review from orangevolon and removed request for a team March 10, 2025 07:49
* Determines the alignment of the content inside table cells.
* This property affects all cells, including the ones in the selection column.
* To target individual cells use `columnDefinitions.verticalAlign`.
*/
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be a good idea to mention which one takes precedence here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the columnDefinitions.verticalAlign taking precedence is the only reasonable assumption because otherwise it won't work at all if cellVerticalAlign is set.

Copy link
Member

Choose a reason for hiding this comment

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

I think that's reasonable to assume but making it explicit and clear would be even better in my opinion.

import headerCellStyles from '../../../lib/components/table/header-cell/styles.css.js';
import styles from '../../../lib/components/table/styles.css.js';

const useBaseComponentSpy = jest.spyOn(baseComponentHooks, 'default');
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to mock the dependencies (e.g. useComponentMetrics and useComponentMetadata) rather than an internal hook? The reason for this is that if we break something inside the internal hook this test will not be catching the regression.

Copy link
Member Author

Choose a reason for hiding this comment

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

This test is not intended to capture possible issues inside the useBaseComponent, but only the props that we pass to it from the table. If we mock the inner hooks instead, that would be a violation of the hook's encapsulation. Instead, we treat it as a black box.

Copy link
Member

Choose a reason for hiding this comment

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

This mock does not only apply to your new tests, but for all tests in this file, which may lead to coverage issues.

If you want to test metrics reporting specifically, extract this into a separate table-metrics.test.tsx, do not do this into the main test file

orangevolon
orangevolon previously approved these changes Mar 13, 2025
Comment on lines 11 to 13
jest.mock('../../../lib/components/internal/hooks/use-mobile', () => ({
useMobile: jest.fn(),
}));
Copy link
Member

Choose a reason for hiding this comment

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

Why is this mock needed?

Evergreen rule – less mocks, better tests

See this PR for an example why mocks are bad: #3277

Copy link
Member Author

Choose a reason for hiding this comment

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

That was a copy-paste artifact from the table tests file, it is not needed for the metrics tests - removed.

@pan-kot pan-kot added this pull request to the merge queue Mar 14, 2025
Merged via the queue into main with commit 9298076 Mar 14, 2025
38 checks passed
@pan-kot pan-kot deleted the table-all-cell-align branch March 14, 2025 10:46
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