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

Inventory groups frontend edits #4820

Merged
merged 49 commits into from
Oct 4, 2024

Conversation

perryr16
Copy link
Contributor

@perryr16 perryr16 commented Sep 27, 2024

Any background context you want to provide?

What's this PR do?

  • Adds db constraint to inventory groups requiring unique name
  • Adds validation to group creation. The group and it's inventory must share an ALI.
  • Adds ability to choose an ALI if an empty group is created
  • Adds Group Map page
  • Adds temp partials and controllers for inventory group dashboard, systems & services, and meters
  • Various improvements

How should this be manually tested?

Sample test files
ali_tree_better_buildings_lite.xlsx
AH_BB_250props100_lat_long.xlsx
AH_BB_250props100_lat_long_diag.xlsx - Same properties, but properties lat has been updated

  • Upload property info with ALI and lat/long info to cycle 1. Upload 2nd file to cycle 2.
  • Go to Inventory List > Groups > Create Group > create 2 groups for 2 different leaf nodes node
  • Go to Inventory List > Select properties of a leaf node > Actions > Add to/Remove from Groups > Add button for the group with a matching ALI should be enabled, and the group with a mismatched ALI should be disabled
  • Select properties from different ALIs > Actions > Add to/Remove from Groups > should see a warning that the selected views do not meet group requirements. Create is disabled, all adds are disabled.
  • Go to Groups > click group name > navigate through Inventory Group Detail pages. The "Properties" and "Map" tab cycle dropdowns should update data to reflect cycle inventory

What are the relevant tickets?

Screenshots (if appropriate)

Screenshot 2024-10-01 at 9 54 05 AM
Screenshot 2024-10-01 at 9 53 24 AM
Screenshot 2024-10-01 at 9 55 57 AM
Screenshot 2024-10-01 at 9 54 22 AM

@perryr16 perryr16 added DO NOT MERGE Feature Add this label to new features. This will be reflected in the change log when generated. labels Sep 27, 2024
@perryr16 perryr16 changed the base branch from inventory_groups to develop September 27, 2024 17:04
@perryr16 perryr16 changed the base branch from develop to inventory_groups September 30, 2024 17:31
@perryr16 perryr16 force-pushed the inventory_groups-frontend-edits branch from 6304a41 to 8573e8a Compare September 30, 2024 20:44
@perryr16 perryr16 marked this pull request as ready for review October 1, 2024 18:38
Copy link
Contributor

@haneslinger haneslinger left a comment

Choose a reason for hiding this comment

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

Just reviewed things server side.

Comment on lines +37 to +39
property = models.ForeignKey(Property, on_delete=models.CASCADE, blank=True, null=True, related_name="group_mappings")
taxlot = models.ForeignKey(TaxLot, on_delete=models.CASCADE, blank=True, null=True, related_name="group_mappings")
group = models.ForeignKey(InventoryGroup, on_delete=models.CASCADE, related_name="group_mappings")
Copy link
Contributor

Choose a reason for hiding this comment

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

💯 💯 💯


class InventoryGroupSerializer(serializers.ModelSerializer):
inventory_type = ChoiceField(choices=VIEW_LIST_INVENTORY_TYPE)
member_list = serializers.SerializerMethodField()

Copy link
Contributor

Choose a reason for hiding this comment

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

you could replace L39-40 with this

Suggested change
access_level_instance_data = AccessLevelInstanceSerializer(many=False, read_only=True)

data = [InventoryGroupSerializer(q).data for q in groups]
group = InventoryGroup.objects.filter(organization_id=org.id, pk=pk).first()
data = InventoryGroupSerializer(group).data
# data = [InventoryGroupSerializer(q).data for q in group]
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

from seed.models import AccessLevelInstance


def access_level_filter(access_level_instance_id):
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi, treebeard has a built in function that's very similar. you might not need this.

Copy link
Contributor

Choose a reason for hiding this comment

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

there's for sure places in the code base where I should have used treebeard functions but rewrote them myself. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you elaborate on this? I was attempting to remove repetition when filtering for model instances within an ali. This pattern is used all over, and could be replaced by the filter in the above code, but I didn't want to make changes to dozens of files without approval.

self.model.objects.filter(
                    organization_id=self.get_organization(self.request),
                    property__access_level_instance__lft__gte=access_level_instance.lft,
                    property__access_level_instance__rgt__lte=access_level_instance.rgt,
                )

Copy link
Contributor

Choose a reason for hiding this comment

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

firstly, the code you quoted above cannot be replaced by this function. it's missing "property__".

Secondly, if you don't need the "property__", and are just looking for the tree under an ali, .get_descendants does that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, the function would need to accept a prefix argument.

I played around with .get_descendants() and it's not quite right. .get_descendants() returns descendants of the node, but not the current node. So to get current and descendants, there are 4 db queries, while the original only uses 2. Let me know if you have a more elegant solution :)

access_level_instance = AccessLevelInstance.objects.get(pk=access_level_id)
current_and_descendants = AccessLevelInstance.objects.filter(id=access_level_id) | access_level_instance.get_descendants()
groups = groups.filter(access_level_instance__in=current_and_descendants)

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, you're right. Maybe get_tree()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.get_tree returns the entire tree, sisters, aunts, ... everything

Copy link
Contributor

Choose a reason for hiding this comment

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

even if you pass the current node as an arg? Its a class method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, thats perfect!

seed/views/v3/access_levels.py Show resolved Hide resolved
Base automatically changed from inventory_groups to inventory-groups-develop October 3, 2024 17:19
Ross Perry added 3 commits October 4, 2024 11:34
cleanup

cleanup

cleanup

broken

ali typo

meters page functional
@haneslinger haneslinger merged commit f149a57 into inventory-groups-develop Oct 4, 2024
9 checks passed
@haneslinger haneslinger deleted the inventory_groups-frontend-edits branch October 4, 2024 22:54
haneslinger added a commit that referenced this pull request Dec 11, 2024
* Added inventory groups

* fixed formatting

* Add in AH

* Groups Details page

* Lint

* rp edits

* fix migrations

* add group buttons to inv detail

* groups to look like labels/dcs

* least common ancestor

* add all alis to group modal

* move lowest common to org view

* development

* migration

* member list default

* optimize lowest_common

* functional pre same node constraint

* validate inventorygroup for name and org

* fe error handling on group create

* mapping constraint, inventory and group must share ali

* precommit

* overhaul of the serializer and member list

* add and remove button bugs

* precommit

* merge conflicts

* merge conflicts

* Fix `hiredis` not found error (#4821)

Fix hiredis not found error

* navigation bugs

* navigation bugs

* troubleshooting

* id bug

* migration order

precommit

* lint

* fix tests

* integrate with develop

fix frontend tests

lint

* fix tests, simplify migration, formatting

precommit

* lint

* dry mapping presave

* group meters page

cleanup

cleanup

cleanup

broken

ali typo

meters page functional

* fix test

---------

Co-authored-by: Elizabeth <ebeers86@gmail.com>
Co-authored-by: Hannah Eslinger <heslinge@nrel.gov>
Co-authored-by: Ross Perry <ross.perry@rosss-mbp-2.lan>
Co-authored-by: Ross Perry <ross.perry@Rosss-MBP-2.home>
Co-authored-by: Ross Perry <ross.perry@Rosss-MacBook-Pro-2.local>
Co-authored-by: Alex Swindler <alex.swindler@nrel.gov>
kflemin added a commit that referenced this pull request Dec 13, 2024
* Inventory groups (#4726)

* Added inventory groups

* fixed formatting

* Add in AH

* Groups Details page

* Lint

* rp edits

* migration

* migration order

precommit

* lint

* fix tests

---------

Co-authored-by: Hannah Eslinger <heslinge@nrel.gov>
Co-authored-by: Ross Perry <ross.perry@rosss-mbp-2.lan>
Co-authored-by: Ross Perry <ross.perry@Rosss-MBP-2.home>

* Inventory groups frontend edits (#4820)

* Added inventory groups

* fixed formatting

* Add in AH

* Groups Details page

* Lint

* rp edits

* fix migrations

* add group buttons to inv detail

* groups to look like labels/dcs

* least common ancestor

* add all alis to group modal

* move lowest common to org view

* development

* migration

* member list default

* optimize lowest_common

* functional pre same node constraint

* validate inventorygroup for name and org

* fe error handling on group create

* mapping constraint, inventory and group must share ali

* precommit

* overhaul of the serializer and member list

* add and remove button bugs

* precommit

* merge conflicts

* merge conflicts

* Fix `hiredis` not found error (#4821)

Fix hiredis not found error

* navigation bugs

* navigation bugs

* troubleshooting

* id bug

* migration order

precommit

* lint

* fix tests

* integrate with develop

fix frontend tests

lint

* fix tests, simplify migration, formatting

precommit

* lint

* dry mapping presave

* group meters page

cleanup

cleanup

cleanup

broken

ali typo

meters page functional

* fix test

---------

Co-authored-by: Elizabeth <ebeers86@gmail.com>
Co-authored-by: Hannah Eslinger <heslinge@nrel.gov>
Co-authored-by: Ross Perry <ross.perry@rosss-mbp-2.lan>
Co-authored-by: Ross Perry <ross.perry@Rosss-MBP-2.home>
Co-authored-by: Ross Perry <ross.perry@Rosss-MacBook-Pro-2.local>
Co-authored-by: Alex Swindler <alex.swindler@nrel.gov>

* Add various inventory group features (#4837)

* descendant tree endpoint

* refactor group merges

---------

Co-authored-by: Ross Perry <ross.perry@Rosss-MacBook-Pro-2.local>

* Systems and services fe edits (#4860)

* Init systems and services

* Add Create Service UI and API

* create factories for groups and systems

* system test

* systems uigrids functional

documentation

* partial for system table

* Add connection type to meters

* refactor modal

* building update endpoint

* system endpoints

* service crud functional

precommit

* service sad path tests

error catching

service tests

* system sad path tests

* front end error handling

* Add meter import to sytems (#4857)

* Fix rollup table (#4835)

* default to float data type for axis data if data_type is not set on the selected column

---------

Co-authored-by: kflemin <2205659+kflemin@users.noreply.github.com>

* More cts fixes (#4830)

Co-authored-by: Katherine Fleming <2205659+kflemin@users.noreply.github.com>

* Init system meter upload

* Lock sass dependency and enforce Node v20 (#4855)

* use node version 20 for unittests

---------

Co-authored-by: Caleb Rutan <crutan@users.noreply.github.com>
Co-authored-by: kflemin <2205659+kflemin@users.noreply.github.com>
Co-authored-by: Alex Swindler <Alex.Swindler@nrel.gov>
Co-authored-by: Ross Perry <ross.perry@Rosss-MacBook-Pro-2.local>
Co-authored-by: Ross Perry <perryr16@gmail.com>

* fix test conflict

---------

Co-authored-by: Hannah Eslinger <heslinge@nrel.gov>
Co-authored-by: Ross Perry <ross.perry@Rosss-MacBook-Pro-2.local>
Co-authored-by: Caleb Rutan <crutan@users.noreply.github.com>
Co-authored-by: kflemin <2205659+kflemin@users.noreply.github.com>
Co-authored-by: Alex Swindler <Alex.Swindler@nrel.gov>

* Updates to meter connection modal (#4868)

* Add modal to update meter connections

* Create update system meter connection endpoint

* modal development

* hookup group meter update

* Fix tests

* add config to serailized meter

* precommit

* comments

* fix test

* Add dashbard endpoint

* group header styling

* readable keys

* sort options

precommit

precommit

* migration

* precommit

* fix test

* hookup group meter delete

---------

Co-authored-by: Hannah Eslinger <heslinge@nrel.gov>
Co-authored-by: Ross Perry <ross.perry@Rosss-MacBook-Pro-2.local>

* Systems and services improvements (#4879)

* systen service modal mods

* update meter enums

* property display field

* alphabetical actions

* nav error and modal arrangement

* precommit

* unit refactors

* precommit

* fix tests

---------

Co-authored-by: Ross Perry <ross.perry@Rosss-MacBook-Pro-2.local>

* Redo group meter creation (#4889)

* Make create group meters modal

* Remove add meter button from systems and services page

* Init Group meter readings upload

* Fix dupe error

* Fix small things

* Make little UI fixes

* Add import/export to dashboard

* Remove meter attched to other services from groups meter/meterreading list

* Format

* Format

* Format

* linter

* translations and cleanup

* lint

* precommit

* dismiss action

* Fix meter usage

* Add message to mismatched meter readings

* Fix docker

* styles & linter

styles & linter

* fix group meter usage test

---------

Co-authored-by: Ross Perry <ross.perry@Rosss-MacBook-Pro-2.local>
Co-authored-by: kflemin <2205659+kflemin@users.noreply.github.com>

* fix migration order

* Format

* precommit

* add service options to modal when meter already configured

* fix meter import tz issue

* lint

* add description text to group meters page

* make-aware for meter reading query

* precommit

* small bugs

lint

* adding missing migration

* precommit

---------

Co-authored-by: ebeers-png <53191386+ebeers-png@users.noreply.github.com>
Co-authored-by: Ross Perry <ross.perry@rosss-mbp-2.lan>
Co-authored-by: Ross Perry <ross.perry@Rosss-MBP-2.home>
Co-authored-by: Ross Perry <perryr16@gmail.com>
Co-authored-by: Elizabeth <ebeers86@gmail.com>
Co-authored-by: Ross Perry <ross.perry@Rosss-MacBook-Pro-2.local>
Co-authored-by: Alex Swindler <alex.swindler@nrel.gov>
Co-authored-by: Caleb Rutan <crutan@users.noreply.github.com>
Co-authored-by: kflemin <2205659+kflemin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Add this label to new features. This will be reflected in the change log when generated.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants