Skip to content

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

Open
joshuaunity wants to merge 19 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 19 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

@nhoening nhoening left a comment

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.

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

joshuaunity commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

"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

Flix6x commented May 25, 2026

Copy link
Copy Markdown
Member

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

@nhoening nhoening left a comment

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.

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
Comment thread flexmeasures/ui/templates/assets/asset_new.html Outdated
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

joshuaunity commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

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

@nhoening nhoening left a comment

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.

I like the pagination!

I still have the main problem from last week: 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. You asked how that parent ID is known to the view, but we still need to use it in the call to the copy endpoint.

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.

Yes, that should be possible as it is the basic idea (we'll provide publlic templates for everybody). What would this refactoring include?

@joshuaunity

Copy link
Copy Markdown
Contributor Author

Yes, that should be possible as it is the basic idea (we'll provide publlic templates for everybody). What would this refactoring include?

The refactoring will include the ability to copy a public asset

…nt and parent asset IDs

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity

joshuaunity commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

@nhoening the latest commits does these things.

  • Copying an asset creates a new asset under the same account as the template
  • fixed the bug where copying any asset through this form uses the template parent asset
  • allow for copying of public assets
  • Set the default search keyword to "Template."

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
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