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

Sensors To Show Edit form #1212

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open

Sensors To Show Edit form #1212

wants to merge 50 commits into from

Conversation

joshuaunity
Copy link
Contributor

@joshuaunity joshuaunity commented Oct 16, 2024

Description

This PR introduces a feature that allows the sensors_to_show data for an asset to be edited directly from the UI via a form. This enhances the user experience by eliminating the need to modify the JSON directly.

Look & Feel

Screenshot from 2024-11-11 13-18-38

How to test

  1. Vist your assets page assets
  2. select any asset from the table
  3. Navigate to the edit asset modal on the left side of the screen
  4. scroll down and click on edit graph

Further Improvements

None

Related Items

This PR closes #1076


  • 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

Signed-off-by: joshuaunity <[email protected]>
@joshuaunity joshuaunity self-assigned this Oct 16, 2024
@joshuaunity joshuaunity changed the title chore: work in progress Sensors To Show Edit form Oct 16, 2024
@joshuaunity joshuaunity added the UI label Oct 16, 2024
@Flix6x
Copy link
Contributor

Flix6x commented Oct 28, 2024

The UX is amazing! ❤️

Please also show the entire asset ancestry for each sensor (like in the breadcrumb, including the organisation account) under an Asset property (next to ID and Unit), so they can be more easily distinguished. If it's trivial, let's also split off the account. For example,

ID: 79869
Unit: kW
Account: Seita
Asset: Some project > Baseline scenario > HQ > PV system

Where PV system is a child asset of HQ, which is a child asset of Baseline scenarios, which is a child asset of Some project, which is an asset belonging to the Seita account.

Hint: use this method to fetch the breadcrumb contents.

image

Copy link
Contributor

@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 have an issue with pre-existing data (in the sensors_to_show attribute) not being loaded into this UI.

Let me know if you can reproduce that.

flexmeasures/ui/templates/crud/asset.html Outdated Show resolved Hide resolved
@nhoening
Copy link
Contributor

I'd like the "Edit" button next to the graph title, not below. Ideally no button (clicking the title means editing) but next to it is also fine (under it eats a lot of vertical space)

@Flix6x
Copy link
Contributor

Flix6x commented Oct 28, 2024

I have an issue with pre-existing data (in the sensors_to_show attribute) not being loaded into this UI.

Let me know if you can reproduce that.

Just checking: if sensors_to_show is empty, by default the first 2 sensors of the asset are shown. That is not the situation you are encountering, right?

@joshuaunity
Copy link
Contributor Author

I have an issue with pre-existing data (in the sensors_to_show attribute) not being loaded into this UI.

Can you give some insight as to how this happened on your end?

@joshuaunity
Copy link
Contributor Author

I have an issue with pre-existing data (in the sensors_to_show attribute) not being loaded into this UI.

Let me know if you can reproduce that.

When you mean not loaded in the UI, do you mean in the edit form? or the graph/dashboard

@nhoening
Copy link
Contributor

The graph loaded them, but the edit form (the one from this PR) did not.

Copy link
Contributor

@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 tested again and indeed the existing graphs load in the form! :)

Some things I'd like:

  • Move the Edit button next to title
  • How do I add a new graph?
  • In the search, find sensors on the asset and public ones. I believe now it limits to the account of the user.

@joshuaunity
Copy link
Contributor Author

joshuaunity commented Oct 29, 2024

  • Move the Edit button next to title

I've moved the button, you can check it out

  • How do I add a new graph?

To add sensors to the graph you just fetch the sensors by clicking on the fetch sensors button and add the ones you want

  • In the search, find sensors on the asset and public ones. I believe now it limits to the account of the user.
    Currently, the API fetches all sensors by default. However, we’ve introduced a new feature to filter sensors by asset_id.

Should we modify the API by default to fetch only sensors from the specified asset (using the asset_id filter) and optionally include public sensors (using the include_public_assets filter)?

@joshuaunity
Copy link
Contributor Author

The UX is amazing! ❤️

Please also show the entire asset ancestry for each sensor (like in the breadcrumb, including the organisation account) under an Asset property (next to ID and Unit), so they can be more easily distinguished. If it's trivial, let's also split off the account. For example,

ID: 79869
Unit: kW
Account: Seita
Asset: Some project > Baseline scenario > HQ > PV system

Where PV system is a child asset of HQ, which is a child asset of Baseline scenarios, which is a child asset of Some project, which is an asset belonging to the Seita account.

Hint: use this method to fetch the breadcrumb contents.

image

ok, so you suggest the fetch sensor card should show these instead right

@nhoening
Copy link
Contributor

To add sensors to the graph

No I meant to add a new graph - I did not see how to do that, maybe I overlooked it

Maybe the API should by default search for sensors on that asset and public ones, not optionally. We can see how well that works ẃhen we use it.

For Felix' request, maybe we want that breadcrumb in the search results as well as in the graph cards.

@Flix6x
Copy link
Contributor

Flix6x commented Oct 29, 2024

For Felix' request, maybe we want that breadcrumb in the search results as well as in the graph cards.

Yes, exactly.

@nhoening nhoening added this to the 0.24.0 milestone Oct 31, 2024
@nhoening
Copy link
Contributor

In your screen-video I still see a call to the sensor API when you add a graph on the left, at the 4s mark. (I can't see your mouse pointer though, so I am assuming). But it is difficult to tell what happens. I looked at the code for renderData() and I don't know why the right side gets shown when we click "Add Graph" and hidden when "Remove" a graph. I would just not do anything with the right side when we change something on the left side. Make them more independent.

Thanks for addressing the smaller items. Here are some things I just found:

  • The function renderData() (and the variable dataList) also have too simple names (and also the comment above the function is not adding anything: "Function to render the data list"). Is this about the data in the graph card?
  • Same goes for filterData() - be less generic, so the code is more readable (also to yourself in a few weeks :)
  • If all that renderData() is doing is to render the sensors on the graph card, then I don't think the try/catch blocks you use when you call it make sense. You show a toast saying "Failed to save changes" - but we are not saving any data to the DB right?
  • This text ("sensorsContent") should probably not be there?

@joshuaunity
Copy link
Contributor Author

joshuaunity commented Nov 19, 2024

In your screen-video I still see a call to the sensor API when you add a graph on the left, at the 4s mark. (I can't see your mouse pointer though, so I am assuming). But it is difficult to tell what happens.

I clicked on "Add Graph". When we spoke, you said that when the add graph is clicked, it should add a blank graph, and should also pre-select that graph. When a graph is selected(it shows the border), it fetches the available sensors so the user can add them instead of having to click on the card manually after "Add graph" to see the available sensors to add.

@joshuaunity
Copy link
Contributor Author

If all that renderData() is doing is to render the sensors on the graph card, then I don't think the try/catch blocks you use when you call it make sense. You show a toast saying "Failed to save changes" - but we are not saving any data to the DB right?

This is correct we initially where, but now we don't anymore, I will refactor that

@nhoening
Copy link
Contributor

Thanks. I see the appeal but I would suggest to get rid of that for now. It can be confusing and add too many API calls.
If we find later that it would be really useful to add that, we can do that, and then do it due to experience with the UI.

@joshuaunity
Copy link
Contributor Author

joshuaunity commented Nov 19, 2024

Thanks. I see the appeal but I would suggest to get rid of that for now. It can be confusing and add too many API calls. If we find later that it would be really useful to add that, we can do that, and then do it due to experience with the UI.

Ok, so I should seize rendering that part(the right part) but leave the border highlight.

Also when I click on another card that should still render the right side right?

@nhoening
Copy link
Contributor

Thanks. I see the appeal but I would suggest to get rid of that for now. It can be confusing and add too many API calls. If we find later that it would be really useful to add that, we can do that, and then do it due to experience with the UI.

Ok, so I should seize rendering that part(the right part) but leave the border highlight.

Also when I click on another card that should still render the right side right?

Why? I would leave the right side as-is.

@joshuaunity
Copy link
Contributor Author

Thanks. I see the appeal but I would suggest to get rid of that for now. It can be confusing and add too many API calls.
If we find later that it would be really useful to add that, we can do that, and then do it due to experience with the UI.

Wait, which of the comments was this reply for?

@nhoening
Copy link
Contributor

nhoening commented Nov 20, 2024

About this one, which described automated updates to the sensor list on the right due to changes on the left:

" When a graph is selected(it shows the border), it fetches the available sensors so the user can add them instead of having to click on the card manually after "Add graph" to see the available sensors to add."

Copy link
Contributor

@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 like the code!
But I know how I'd love it.

flexmeasures/ui/templates/crud/asset.html Outdated Show resolved Hide resolved
documentation/views/asset-data.rst Show resolved Hide resolved
documentation/views/asset-data.rst Outdated Show resolved Hide resolved
flexmeasures/ui/templates/crud/asset.html Outdated Show resolved Hide resolved
flexmeasures/ui/static/css/flexmeasures.css Show resolved Hide resolved
flexmeasures/ui/templates/crud/asset.html Outdated Show resolved Hide resolved
flexmeasures/ui/templates/crud/asset.html Show resolved Hide resolved
flexmeasures/ui/templates/crud/asset.html Show resolved Hide resolved
flexmeasures/ui/templates/crud/asset.html Outdated Show resolved Hide resolved
flexmeasures/ui/templates/crud/asset.html Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

This is working pretty sweet now.

Just a few comments, and one serious (but easily fixable) bug.

A question about sensor search: you use pagination, but if the sensor one wants is not on the first page, there is no way to get to the second page.
I don't believe we should add pagination here right now. Maybe we should remove the pagination for now?

Also, there is no way to do a search without entering a keyword or unit. Maybe we could start the dialogue with an initial complete search?

col.classList.add("col-12", "mb-1");

const sensorsUnits = [];
const newItem = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment here, because a reader might not know why you do this. I believe you are handling both newer and older formats of sensors_to_show data here, right?

Should we still make an issue for the API always returning the latest format, as we discussed?

<label for="sensors_to_show" class="col-sm-6 control-label">Sensor Graphs: </label>

<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#sensorsToShowForm">
Edit Graph
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, "Edit Graphs"

</div>

<div class="col-4">
<select class="form-select" aria-label="Default select example"
Copy link
Contributor

Choose a reason for hiding this comment

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

In one of the last commits, you removed id="unitsSelect" from this select tag, which stopped the sensor search from working. Adding it back fixed it for me.
So please add it back :)

</div>

<div class="col-4">
<select class="form-select" aria-label="Default select example"
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess "Default select example" does not need to be here?

</div>
<h5 class="card-title pt-2"><b> Sensors: </b></h5>
<div>
${sensorsContent.length > 0 ? sensorsContent.join("") : "<i>Add sensors on the right side</i>"}
Copy link
Contributor

Choose a reason for hiding this comment

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

As without sensors, the graph is not shown, this should also be rendered in yellow (as the warning about differing units)

<button class="btn btn-danger btn-sm me-2" onclick="removeGraph(${index})">Remove</button>
<button class="btn btn-secondary btn-sm me-2" onclick="moveGraphUp(${index})" ${index === 0 ? "disabled" : ""}>Move Up</button>
<button class="btn btn-secondary btn-sm" onclick="moveGraphDown(${index})" ${index === data.length - 1 ? "disabled" : ""}>Move Down</button>
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not work perfectly yet.

  • I have three graphs.
  • The second graph cannot move down, even if it is not last.
  • I move the first downwards (to 2nd position), then it has the same problem.

sensorsUnits.push(sensorData.unit);

return `
<div class="p-1 mb-3 border-bottom border-secondary">
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it visually a bit confusing that this "X" icon is top of the span. It sits almost within the text, so the second row of text can be mistaken as a different thing, especially if there is only one sensor.

I could improve it by adding it as first element to the div and adding float: right; - but maybe you have a better idea.

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.

Support better editing of sensors_to_show
3 participants