Reusable components without expliciting type of component

Dear Bubble forum,

I am currently working on a very basic feature of my app to display data from diverse databases such as (contact, location, contract …). To display contact, location, contract or whatever it is, I will use a repeating group.

I would like to have one unique repeating group that will display the table that is selected by the user because all my tables will share properties that are defined at the repeating group level such as the number of rows for example.

Is there a way to not explicit the type of content, so I can display different tables using the same repeating group ? If it is not possible is there another way of factorizing the code ?

I would like to avoid having 5 different repeating groups for 5 different tables.

Thanks

Quentin

No, a repeating group must have a defined content-type, and that has to be defined in the main property editor for the RG (it can’t be et conditionally)…

If it is not possible is there another way of factorizing the code ?
I would like to avoid having 5 different repeating groups for 5 different tables.

You could create an additional data-type, which links to any of the 5 other datatypes, and use that as the content type of the RG, with conditions on the elements inside the cell to display the relevant data from the correct linked datatype…

But it might be simpler just create 5 separate RGs, each with a different content-type, and use conditions to decide which one to display (is there a particular reason you don’t want to do that?).

1 Like

Thanks for the help.
The reason why I don’t want to create 5 different RG is that it does not scale up easily in the case I have 10 tables for example. If I need to change every single RG it is going to be repetitive and not efficient. Also on my RG I have some icons that will trigger workflows and I would like to avoid creating X different workflows per icon. One of the icon is used to delete a row for example. It should be the same workflow for all the tables.

Could you detail a little bit more the solution please ? I am not sure how to reproduce it. It would help me a lot.
Thanks in advance.

A repeating group can only have a single content-type…

So if you only want to use a single RG then you’ll need to create a single datatype to use as its content type.

That datatype can then just link to the other 5 datatypes (with a field for each one), then inside the RG your text elements can use conditions to show the correct data:

i.e. if the current cell's RG_Datatype's Datatype 1 is not empty, text = current cell's RG_Datatype's Datatype 1's Text

That would be the basic idea…

Obviously if you plan to add additional datatypes (more than just the 5) in the future you’ll still need to do some manual modifications to your database (adding new fields to the RG datatype), so you might want to rethink your entire approach here entirely…

Without knowing your exact use-case I can’t really give any specific guidance, but I am wondering if you really need to have 5 separate datatypes at all?

Hi Adam,

Thanks a lot again for your support.

Here is my exact use case.
My app is designed to allow my users to monitor their contracts.
There are several tables this purpose:
Contract (one field is linked to the corporation and one to the contacts)
Corporation (one field is linked to the contacts and one to the locations)
Contact (one field is linked to location)
Location
I want my user to be able to see the database he has created for the monitoring of his contracts.
To do so, I have a visualization in the app to display tables from the database. He can add things (e.g: contracts, locations, contacts and corporations), edit things and delete things. I would like to have the exact same visualizations for the 4 tables meaning that if I do a change for one I will need to see the changes for the 4.

Of course for now my model is simple and I have only 4 tables to monitor but with times I will have more and more.

Hope it sounds clearer

Quentin

I can’t quite get my head around what you’re describing there (innately, I think you’re approaching this wrong… but I may just not understand what you’re trying to do)…

Can you give a more detailed explanation of what you’re trying to do here? Maybe an example of something similar?

Specifically I don’t know what you mean by “I would like to have the exact same visualizations for the 4 tables meaning that if I do a change for one I will need to see the changes for the 4.”

What do you mean by “changes”? Changes to what exactly (they are different datatypes, with different fields, so I don’t know what you’re intending to change, or how)?..

1 Like

I will need X different visualisations to display the X tables to my users. The visualisations must have the exact same formats (colors, borders, …) and each line - no matter what the data types is - will have the exact same icons for edition and deletion. Of course there are some differences and I have plan to create specific headers and content (only the last one will be in the RG) for the specific data types. Depending on which tab is selected on the app, the header and the content should update.

However, because all my tables will share some similarities (e.g.: the workflows and the formatting), I would like to use only 1 RG that contains the formatting and the icons. But of course this RG should be flexible enough to allow to have different datatypes selected.

Does it sound clearer ?


On this picture you’ll see the 4 different tables.
And on the right you can see 2 icons that should be shared for the 4 tables

If I understand correctly now, then the short answer is no… you can’t use a single repeating group for this (as they will have different datatypes AND different headers and internal elements etc…)… so you’ll need to have a separate RG for each one, and just show/hide them conditionally…

Of course, you can use Reusable elements within them (i.e. the delete and edit icons), and use custom states to control what they do when clicked.

1 Like

Ok thanks a lot.
As you can imagine my edit and delete icons will delete the corresponding data types depending on whose data types is selected. So would it be possible to pass a data type as an input of a reusable elements ?

Yes, as a custom state…

1 Like

@adamhholmes

I wonder if something like this could work. Hmm :thinking: Probably not worth the headache to do it, but I always like to stretch the perceived boundaries of Bubble.

What if you just send the repeating group a number, which is the count of items that you will send to it.

That way it can be dynamic. Then in a set state save the different type lists. Then you can display text conditionally by which list you are referring to.

Possible? Just not easy? Just a thought. :blush:

I use this type of thing all the time for using one ‘delete’ popup for all my types.

2 Likes

Thanks ! Sounds like my exact usecase.

However, I am not so sure about what you are describing here. I should save my different tables within a custom state ? And refer to the number using the current row index ?

1 Like

Yeah. Exactly. Current cells index and refer to your list that could be saved in a custom state. Not sure how performant it will be, but it might actually help because the repeating group will load the initial numbers quickly, then it will fill in the data for you. :man_shrugging:t2:

I dunno. It was just an idea I wanted to throw out there. @adamhholmes had some good ideas too. :+1:

Thanks a lot to both of you.
I think I will stick with the solution of using different RG. Not ideal but not that terrible too.
Not sure yet on how I will use the edit and delete icons as a reusable elements with a undefined data types but I will try it.

1 Like