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

🌱 Add data attributes to table rows #1996

Merged
merged 2 commits into from
Jul 16, 2024
Merged

Conversation

sjd78
Copy link
Member

@sjd78 sjd78 commented Jul 3, 2024

To enable easier and safer selection of table rows by testing code, add some data attributes to the tr:

  • data-item-id - Holds the idProperty value of a table's items. This is typically the item's id number but may be a frontend generated ID in some cases.

  • data-item-name - If the table property dataNameProperty is provided, hold the name property of a table's item.

For any tables that use /use.?*TableControls\(/, add a dataNameProperty and if necessary, adjust the idProperty. A few tables for items without a good item id and name property were left with just the idProperty.

Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 42.21%. Comparing base (b654645) to head (dbb3509).
Report is 192 commits behind head on main.

Files Patch % Lines
...c/app/hooks/table-controls/useTableControlProps.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1996      +/-   ##
==========================================
+ Coverage   39.20%   42.21%   +3.01%     
==========================================
  Files         146      171      +25     
  Lines        4857     5477     +620     
  Branches     1164     1352     +188     
==========================================
+ Hits         1904     2312     +408     
- Misses       2939     3049     +110     
- Partials       14      116     +102     
Flag Coverage Δ
client 42.21% <0.00%> (+3.01%) ⬆️
server ?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Collaborator

@rszwajko rszwajko left a comment

Choose a reason for hiding this comment

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

Looks good!

@sjd78 sjd78 marked this pull request as ready for review July 3, 2024 21:37
@sjd78 sjd78 requested a review from ibolton336 as a code owner July 3, 2024 21:37
@@ -83,7 +83,8 @@ export const BusinessServices: React.FC = () => {

const tableControls = useLocalTableControls({
tableName: "business-services-table",
idProperty: "name",
idProperty: "id",
Copy link
Collaborator

Choose a reason for hiding this comment

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

good catch! please mention those fixes in the commit message (or extract to a small PR)?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch! please mention those fixes in the commit message (or extract to a small PR)?

I mentioned that kind of change in the description as "and if necessary, adjust the idProperty". Could be called out more explicitly.

Also interesting that it really didn't do anything bad or wrong with any behavior. Apparently the name on the entity is enforced unique so it worked just fine. But now both bits of info are available on the data attributes. :-)

@@ -74,6 +74,7 @@ export const ManageImportsDetails: React.FC = () => {
const tableControls = useLocalTableControls({
tableName: "manage-imports-details",
idProperty: "Application Name",
dataNameProperty: "Application Name",
Copy link
Collaborator

@mguetta1 mguetta1 Jul 10, 2024

Choose a reason for hiding this comment

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

I am probably missing something...
Shouldn't it be one of the columnNames value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah the original idProperty name didn't make much sense to me either. Tracing the code back, and the data is coming from:

export const getApplicationImports = (
importSummaryID: number,
isValid: boolean | string
): Promise<ApplicationImport[]> =>
axios
.get(`${APP_IMPORT}?importSummary.id=${importSummaryID}&isValid=${isValid}`)
.then((response) => response.data);

And the return type is:

export interface ApplicationImport {
"Application Name": string;
errorMessage: string;
isValid: boolean;
}

I haven't looked at the hub code to see if other data items are also returned with that endpoint. Working with what we already have, the only field that makes sense in the ApplicationImport to use for the idProperty and dataNameProperty is "Application Name".

I wouldn't touch this any further in the PR, but we can write an issue to re-evaluate it in the near future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, while the columnNames for the table properties often line up with the actual item field name, there is no requirement that it do so. In some tables, the columns are "UI synthetic" being derived from multiple data sources.

That's just a long way of saying the idProperty and dataNameProperty values do not need to have a corresponding entry in columnNames.

To enable easier and safer selection of table rows by
testing code, add some data attributes to the tr:

  - `data-item-id` - Holds the `idProperty` value of
    a table's items.  This is typically the item's id
    number but may be a frontend generated ID in some
    cases.

  - `data-item-name` - If the table property `dataNameProperty`
    is provided, hold the name property of a table's item.

Signed-off-by: Scott J Dickerson <[email protected]>
@sjd78 sjd78 merged commit 4a41417 into konveyor:main Jul 16, 2024
12 checks passed
@sjd78 sjd78 deleted the data-item-on-tables branch July 17, 2024 12:22
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