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

chore(ui5-table): remove selection import & rename key #9300

Merged
merged 5 commits into from
Jul 4, 2024

Conversation

DonkeyCo
Copy link
Member

Table.ts imported TableSelection.ts, although it is not a base functionality.
Therefore, the selection has been removed as import and the code has been refactored to accomodate for that.

Additionaly, key is a reserved keyword in React, which is why the row key has been renamed to row-id.

@DonkeyCo DonkeyCo changed the title chore: remove selection import & rename key chore(ui5-table): remove selection import & rename key Jun 25, 2024
@@ -17,9 +17,14 @@ const findRowInPath = (composedPath: Array<EventTarget>) => {
return composedPath.find((el: EventTarget) => el instanceof HTMLElement && el.hasAttribute("ui5-table-row")) as TableRow;
};

const isFeature = <T>(element: any, identifier: string): element is T => {
Copy link
Member

@ilhan007 ilhan007 Jun 25, 2024

Choose a reason for hiding this comment

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

Probably we can integrate the existing mechanism

// TableSelection.ts
import { registerFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";

registerFeature("TableSelection", TableSelection);

When someone imports the TableSelection.ts module, the feature is registered, then the Table can call getFeature to check if the feature is enabeled:

import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";

const TableSelection = getFeature<typeof TableSelection>("TableSelection");

See Input.ts, InputSuggestions.ts for reference, the suggestions are like plug-in feature on top, don't come built in with the Input by default but only when someone imports the InputSuggestions module explicitly.
This is I guess the same with the Table and TableSelection.

Copy link
Member Author

@DonkeyCo DonkeyCo Jun 26, 2024

Choose a reason for hiding this comment

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

Is it the same though?
In case of Input.ts and InputSuggestions.ts, when the import for InputSuggestions exist, the Input will create a new instance of it.

While in the Table.ts, even if you have TableSelection imported, you need to explicitly slot it into features slot of the table. This would allow you to have multiple tables with one having selection and the other not.

So even if I check whether the feature has been imported:

// Table.ts
const TableSelection = getFeature<typeof TableSelection>("TableSelection");
if (!TableSelection) { return; }
...

I still need to check, if the features slot contains a feature, that is of instance TableSelection like:

// Table.ts
const TableSelection = getFeature<typeof TableSelection>("TableSelection");
if (!TableSelection) { return; }

this.features.find(feature => feature instanceof TableSelection);

So there is no real benefit from registering the feature, isn't it?
This isFeature check still needs to be done to 100% determine that the feature is of type TableSelection (as to avoid this instanceof check)

So as far as I understand, this feature registration is quite nice for features that are then created by the component themselves (e.g. Input creates a new instance of InputSuggestion), but not really applicable, if the "feature" comes from the application.

Or am I misunderstanding something here?

packages/main/src/Table.ts Show resolved Hide resolved
packages/main/src/TableSelection.ts Outdated Show resolved Hide resolved
packages/main/src/TableSelection.ts Outdated Show resolved Hide resolved
@DonkeyCo DonkeyCo requested a review from aborjinik July 2, 2024 07:05
@@ -26,7 +26,7 @@ import { isSelectionCheckbox, isHeaderSelector, findRowInPath } from "./TableUti
* * Multiple - select multiple rows.
* * None - no selection active.
*
* As the selection is key-based, `ui5-table-row` components need to define a unique `key` property.
* As the selection is key-based, `ui5-table-row` components need to define a unique `row-key` property.
Copy link
Contributor

Choose a reason for hiding this comment

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

like F6 handling we should document the TableSelection import. better in the "features" slot documentation of the table as general suggestion and here in the TableSelection.ts

Copy link
Contributor

Choose a reason for hiding this comment

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

it would be great to mention the import again in the documentation of the TableSelection

@DonkeyCo DonkeyCo requested a review from aborjinik July 2, 2024 11:56
@DonkeyCo
Copy link
Member Author

DonkeyCo commented Jul 2, 2024

@aborjinik if you could review this PR, it would be great

@DonkeyCo DonkeyCo requested a review from ilhan007 July 3, 2024 08:08
@DonkeyCo
Copy link
Member Author

DonkeyCo commented Jul 3, 2024

@ilhan007: @aborjinik is unavailable today (d-com), if we need to merge today, I'd need a +2 from you.
We had a private discussion already and the current state is good to be merged


/**
* Interface for components that can be slotted inside the <code>features</code> slot of the <code>ui5-table</code>.
*
* @public
*/
interface ITableFeature extends UI5Element {
readonly identifier: string;
Copy link
Contributor

@aborjinik aborjinik Jul 4, 2024

Choose a reason for hiding this comment

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

It would be nice to document what this is necessary for.

@@ -80,6 +82,7 @@ type TableRowClickEventDetail = {
*
* The `ui5-table` can be enhanced in its functionalities by applying different features.
* Features can be slotted into the `features` slot, to enable them in the component.
* Features need to be imported separately, as they are not enabled by default.
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to give a sample here
e.g. in order to use the selection functionality, you need to import the following module:
import "@ui5/webcomponents/blabla"

@@ -26,7 +26,7 @@ import { isSelectionCheckbox, isHeaderSelector, findRowInPath } from "./TableUti
* * Multiple - select multiple rows.
* * None - no selection active.
*
* As the selection is key-based, `ui5-table-row` components need to define a unique `key` property.
* As the selection is key-based, `ui5-table-row` components need to define a unique `row-key` property.
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be great to mention the import again in the documentation of the TableSelection

Copy link
Contributor

@aborjinik aborjinik left a comment

Choose a reason for hiding this comment

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

Please see the comments you can align the docu later

@DonkeyCo DonkeyCo merged commit 7901f7a into main Jul 4, 2024
10 checks passed
@DonkeyCo DonkeyCo deleted the chore-selection branch July 4, 2024 20:55
@DonkeyCo
Copy link
Member Author

DonkeyCo commented Jul 4, 2024

Please see the comments you can align the docu later

Will do this tomorrow

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