Skip to content

Conversation

dsanz
Copy link
Collaborator

@dsanz dsanz commented Oct 7, 2025

Context: https://liferay.atlassian.net/browse/LPD-24670

Goal is to check selected item has no visualization modes, to render it differently

How it looks like
With this commit, a Data Set with no visualization mode appears with a warning icon:
image

Problem: in the case of list visualization, we need to mutate item as ClayList.Item does not take any prop we can remap.

Proposal to handle this case for list views, which we can use in all views:

  • Extend api to allow a setItemProps function that returns a modified item to be consumed by views.
  • Use it from views as follows (example with List):
const ListItem = forwardRef<HTMLLIElement, any>(
	(
		{
			className,
			item: originalItem,
			...
		}: {
			...
		},
		ref
	) => {
...

		const item = {...originalItem, activeView.setItemProps?.({originalItem})}		

		// use item normally
		const itemId = getObjectValueFromPath({
			object: item,
			path: selectedItemsKey,
		});

...

		return (
			<ClayList.Item
				{...props}
				{...(activeView.setItemComponentProps?.({item, props}) ?? {})}
				ref={ref}
			>

This came from a quick peer session with @chestofwonders

cc @markocikos as you designed this solution, pls chime in and share yout thougths

… case of list we need to mutate item as ClayList.Item does not take any prop we can remap.
@liferay-continuous-integration
Copy link
Collaborator

CI is automatically triggering the following test suites:

  •     ci:test:sf

@liferay-continuous-integration
Copy link
Collaborator

Test suite sf has been triggered on http://test-1-32

@liferay-continuous-integration
Copy link
Collaborator

✔️ ci:test:sf - 1 out of 1 jobs passed in 3 minutes

Ran com.liferay.source.formatter at released version 1.0.1543.
*The latest version has not been released.

Click here for more details.

Base Branch:

Branch Name: master
Branch GIT ID: ba9d2ba803a68c8d511640bc697f5266cada47d8

Sender Branch:

Branch Name: LPD-24670
Branch GIT ID: 9b587ce85528b7eb6969c2f9f9d18525b86975ef

1 out of 1 jobs PASSED
1 Successful Jobs:
For more details click here.

@liferay-continuous-integration
Copy link
Collaborator

Jenkins Report:jenkins-report.html
Jenkins Suite:sf
Testray Routine:EE Pull Request
Testray Build ID:334418936

…ormer to the parent component. This assumes it makes no sense to manage <ClayList.Item> props directly
@dsanz
Copy link
Collaborator Author

dsanz commented Oct 9, 2025

@markocikos I've added an extra commit that solves the item mutation issue, but changes a bit the application of setItemComponentProps in List.

markocikos

This comment was marked as outdated.

Copy link
Collaborator

@markocikos markocikos left a comment

Choose a reason for hiding this comment

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

@dsanz @chestofwonders please see comment inline

Comment on lines +38 to +45
return {
...props, // we need to avoid item mutation
item: {
...item,
symbol: 'warning',
tooltip: 'perico'
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

My first feeling about this was that it wasn't right, because API was intended to modify props of component implementing the item, <ClayList.Item>. It does make sense to shift target of customization to <ListItem>, our own wrapper of the component. It makes customization of our implementation more flexible. But. it's a tradeoff. We lose future-proof aspect of the solution, where devs would automatically be able to modify future props of <ClayList.Item>. It might make sense to add a prop specifically for that purpose. Something like

const props = {
		className,
		clayListItemProps, // new prop
		item,
		items,
		onItemSelectionChange,
		ref:dropRef,
		schema,
	};

<ListItem
		{...props}
		{...(activeView.setItemComponentProps?.({item, props}) ?? {})}

that ends up in

<ClayList.Item
	className={classNames(className, {
		active: selectedItemsValue?.includes(itemId),
	})}
	flex
	{...clayListItemProps}
>

In general, mutating item is not good practice, but I think it's acceptable this close to leaf usage.

What do you think?

Copy link
Collaborator Author

@dsanz dsanz Oct 10, 2025

Choose a reason for hiding this comment

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

Doing this shift makes item not mutated indeed.

Note how first commit does item.foo = bar whereas second one just provides a different item. So no internal FDS state is mutated.

It's true that we are changing the item we pass to the child component. I believe there's a slight difference between this and mutating the item.

And yes, what you say makes sense to me, we need to open the possibility to drill down props in the "real" target component here. @chestofwonders pls add this to #5122 so that devs have access to the underlying <ClayList.Item> so that we get the best of both worlds

Thank you @markocikos !

@dsanz
Copy link
Collaborator Author

dsanz commented Oct 10, 2025

Pls see #5122

@dsanz dsanz closed this Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants