bcgov / PIMS

Property Inventory Management System
https://pims.gov.bc.ca
Apache License 2.0
42 stars 43 forks source link

PIMS-1741 Lookup Context #2469

Closed dbarkowsky closed 4 weeks ago

dbarkowsky commented 1 month ago
## 🎯 Summary [PIMS-1741](https://citz-imb.atlassian.net/browse/PIMS-1741?atlOrigin=eyJpIjoiZDhhYWUwZjJhZDVlNDY1MGIxZjdjNWJhZWY0Nzc1NzAiLCJwIjoiaiJ9)

Goal is to add a lookup context to the frontend that would reduce the number of joins needed in other database calls. Lookup context matches this interface:

export interface LookupAll {
  Risks: Partial<ProjectRisk>[];
  TimestampTypes: Partial<MetadataType>[];
  MonetaryTypes: Partial<MetadataType>[];
  NoteTypes: Partial<MetadataType>[];
  PropertyTypes: Partial<MetadataType>[];
  Tasks: Partial<Task>[];
  ProjectStatuses: Partial<ProjectStatus>[];
  ProjectTiers: Partial<TierLevel>[];
  ConstructionTypes: Partial<BuildingConstructionType>[];
  PredominateUses: Partial<BuildingPredominateUse>[];
  Classifications: Partial<PropertyClassification>[];
  Roles: Partial<Role>[];
  Agencies: Partial<Agency>[];
  AdministrativeAreas: Partial<AdministrativeArea>[];
  RegionalDistricts: Partial<RegionalDistrict>[];
}

This PR only adds the context for use. Will continue this ticket with a second PR that starts to swap out the joins for context usage.

Changes

Testing

If you navigate to /dev, there's a log that should print the context to the console.

🔰 Checklist

  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation where required.
  • I have tested my changes to the best of my ability.
  • My changes generate no new warnings.
github-actions[bot] commented 1 month ago

🚀 Deployment Information

The Express API Image has been built with the tag: 2469. Please make sure to utilize this specific tag when promoting these changes to the TEST and PROD environments during the API deployment. For more updates please monitor Image Tags Page on Wiki.

codeclimate[bot] commented 1 month ago

Code Climate has analyzed commit 28c639f4 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 95.4% (50% is the threshold).

This pull request will bring the total coverage in the repository to 94.5%.

View more on Code Climate.

GrahamS-Quartech commented 1 month ago

The context seems to work well. I think one thing that might be desirable to include in this is some functions for retrieving a lookup item by it's numeric id. There would be some upfront cost in collecting objects into a feasible format for this (probably organized into objects of form [primarykey]: { ...restOfRow } ), but past that initial cost we would then be able to retrieve anything in O(1) time. This would keep things super speedy when we go to use these in the tables.

EDIT: Went ahead and made a commit for this functionality. Let me know what you think.

dbarkowsky commented 1 month ago

@GrahamS-Quartech I like the way that works. Good idea. Testing out the context in practice with the AdministrativeAreaDetail, I have some errors where I think the context isn't finished populating by the time we're trying to retrieve data from it. Will continue to investigate, but I don't think we should merge this until it's working properly.

EDIT: Ok, think it's working now!