Skip to content

Feat: Add copy-existing-asset tab to asset creation flow#2195

Open
joshuaunity wants to merge 17 commits into
mainfrom
feat/asset-create-copy-tab-ui-flow
Open

Feat: Add copy-existing-asset tab to asset creation flow#2195
joshuaunity wants to merge 17 commits into
mainfrom
feat/asset-create-copy-tab-ui-flow

Conversation

@joshuaunity
Copy link
Copy Markdown
Contributor

Description

This PR adds a new "Copy an existing" tab to the asset creation page so users can create assets from templates instead of starting from scratch. It introduces searchable asset selection with filters (text, type, include public assets), a compact multi-column result layout, and a copy action wired to the existing API. On copy, the UI now shows progress and success/error toast messages, creates the new asset under the current parent asset, and redirects to the new asset page after success.

Look & Feel

image

Further Improvements

None

Related Items

This PR closes #2166

Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

…form

Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity self-assigned this May 22, 2026
@joshuaunity joshuaunity added the UI label May 22, 2026
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity requested a review from nhoening May 22, 2026 11:20
Copy link
Copy Markdown
Member

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

I tried this out, but then the copied asset was created under its original parent asset, rather than the asset named in the form URL (parent_asset_id)

The issue writes:

"The search form opens pre-set with "Template" in the text field and the checkbox for including public assets ticked."

That is not there yet. Please check that list again.

Finally, I found a corner case problem by accident: if an asset has external_id, remove it, as the ID is uniue per account. I got: failed to create asset: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "generic_asset_account_id_external_id_key" DETAIL: Key (account_id, external_id)=(2, )

Comment thread flexmeasures/ui/templates/assets/asset_new.html Outdated
Comment thread flexmeasures/ui/templates/assets/asset_new.html
Comment thread flexmeasures/ui/templates/assets/asset_new.html Outdated
Comment thread flexmeasures/ui/templates/assets/asset_new.html Outdated
@nhoening
Copy link
Copy Markdown
Member

I like the design, and the filtering by type makes sense, too!

Can you make each card's title a link to the asset, as well?

Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
@joshuaunity
Copy link
Copy Markdown
Contributor Author

joshuaunity commented May 25, 2026

"The search form opens pre-set with "Template" in the text field and the checkbox for including public assets ticked."

Regarding this, I forgot to mention that if the search field is set to "template", it immediately searches for assets named "template".

Would you rather it be a placeholder? So instead of the placeholder "Search asset..." we have "template," or you had something else in mind when you suggested this.

@joshuaunity
Copy link
Copy Markdown
Contributor Author

Finally, I found a corner case problem by accident: if an asset has external_id, remove it, as the ID is uniue per account. I got: failed to create asset: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "generic_asset_account_id_external_id_key" DETAIL: Key (account_id, external_id)=(2, )

Oh wow, that's a good catch. I'll fix that.

Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
…int conflicts

Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
…et creation script

Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
@joshuaunity
Copy link
Copy Markdown
Contributor Author

I tried this out, but then the copied asset was created under its original parent asset, rather than the asset named in the form URL (parent_asset_id)

Do you mean the parent asset shouldn't be NULL? cause we can't copy an asset under itself

@nhoening
Copy link
Copy Markdown
Member

I tried this out, but then the copied asset was created under its original parent asset, rather than the asset named in the form URL (parent_asset_id)

Do you mean the parent asset shouldn't be NULL? cause we can't copy an asset under itself

No I meant the copy asset was created as a sibling of the original asset, so it stayed under the parent of the original.

We need it to be a child of the form's parent_asset_id.

@nhoening
Copy link
Copy Markdown
Member

"The search form opens pre-set with "Template" in the text field and the checkbox for including public assets ticked."

Regarding this, I forgot to mention that if the search field is set to "template", it immediately searches for assets named "template".

Would you rather it be a placeholder? So instead of the placeholder "Search asset..." we have "template," or you had something else in mind when you suggested this.

My original ideas was indeed that that search happens on opening. Right now, a search also happens, without filters (sending much data).

I don't know if users will really get it (might have to tweak that UX later a bit), but we believe that the main the use case for the copy-asset feature is that usually you copy pre-made templates .

Comment thread flexmeasures/api/common/utils/api_utils.py Outdated
Comment thread flexmeasures/api/common/schemas/assets.py Outdated
Comment thread flexmeasures/ui/templates/assets/asset_new.html
@joshuaunity
Copy link
Copy Markdown
Contributor Author

My original ideas was indeed that that search happens on opening. Right now, a search also happens, without filters (sending much data).

I don't know if users will really get it (might have to tweak that UX later a bit), but we believe that the main the use case for the copy-asset feature is that usually you copy pre-made templates .

Okay, what's the preferred approach? Should I keep the "template" input, even though it often returns no results? I think fetching data without an initial search is acceptable, as the page renders quickly and the card design is simple to maintain performance.

@joshuaunity
Copy link
Copy Markdown
Contributor Author

We need it to be a child of the form's parent_asset_id.

Could you share how the "parent_asset_id" in the form is populated, and what use case(s) trigger its usage? For me i it returns an empty value.

@Flix6x
Copy link
Copy Markdown
Member

Flix6x commented May 25, 2026

Could you share how the "parent_asset_id" in the form is populated, and what use case(s) trigger its usage? For me i it returns an empty value.

I think this happens when in the asset context view you click on "Create new child asset."

joshuaunity and others added 5 commits May 29, 2026 07:47
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
…deserialization

Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
…straint conflicts

Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity requested a review from nhoening June 1, 2026 11:25
Copy link
Copy Markdown
Member

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

Some comments inline, but one of my original problems is still there: the copied asset is created as a sibling of the original asset, so it stays under the parent of the original. We need the parent to be the asset of the currently shown page.

Also, I tested copying a public asset, and got an error that I am not allowed to do that. Can you ask Copilot to tell us why, then we can make a decision what we want to do about it.

Comment thread flexmeasures/ui/templates/assets/asset_new.html Outdated
// Ensure stable ordering across pages to avoid page-overlap duplicates.
params.set("sort_by", "id");
params.set("sort_dir", "asc");
params.set("all_accessible", "true");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a ite admin, I am now seeing way too many assets. So I would actually use my initial plan to not show everything right away.

  • Either we paginate, but that would be some UX work.
  • Or we do not query on opening, but tell the user to select some filter. Maybe even a suggestion: a link ("Search template assets") which fills in "Template" in the text field and hits Enter

Either would be fine with me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we currently have pagination, but i implemented an infinite scroll, so as you scroll down, it fetches more. its liek an auto pagaintion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So i can reduce the items per page, but for the infinite scroll to still work well, i need to reduce how many items are rendered per row.

Do you prefer the infinite scroll to stay, or would you prefer button navigations

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mh, a senior UX person would probably advise to stick with one way to do it, and we already went with buttons in other views. Let's do that.

Yeah, the initial number is really high, 10 should suffice.

And is that link idea possible? I would like to guide the user to this Template idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe even a suggestion: a link ("Search template assets") which fills in "Template" in the text field and hits Enter

For this, what is the template idea? is it mock data or an actual asset template?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We will later add some example templates with "Template" in the name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, that means with this implemented it will intentionally be an empty search result.

Comment thread flexmeasures/ui/templates/assets/asset_new.html
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
@joshuaunity
Copy link
Copy Markdown
Contributor Author

@copilot, look into why copying public assets fails

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity
Copy link
Copy Markdown
Contributor Author

joshuaunity commented Jun 2, 2026

Also, I tested copying a public asset, and got an error that I am not allowed to do that. Can you ask Copilot to tell us why, then we can make a decision what we want to do about it.

i tested myself, and this happens when no parent or account is set. The current logic doesn't allow for that, as the defaults of these two parameters hinder the asset from being copied. That is, it defaults to the copied asset's parent and account. In the case of a public asset, both are None.

Do you think we should still allow a public asset to be copied? The logic could be refactored. Or you want to keep it as is and we return a proper message.

@joshuaunity joshuaunity requested a review from nhoening June 4, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to create assets by copying public assets

3 participants