From 277ce23218a3ed887c1d9572afd9eb60d5b6e25d Mon Sep 17 00:00:00 2001 From: Ross Perry Date: Thu, 29 Feb 2024 10:51:03 -0700 Subject: [PATCH] Handle empty cycles on portfolio summary (#4554) * refactors for empty cycles * precommit * documentation * formatting * documentation * documentation --------- Co-authored-by: Hannah Eslinger --- .../controllers/portfolio_summary_controller.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/seed/static/seed/js/controllers/portfolio_summary_controller.js b/seed/static/seed/js/controllers/portfolio_summary_controller.js index a0bf8ccc74..f3c81acab2 100644 --- a/seed/static/seed/js/controllers/portfolio_summary_controller.js +++ b/seed/static/seed/js/controllers/portfolio_summary_controller.js @@ -211,6 +211,11 @@ angular.module('BE.seed.controller.portfolio_summary', []) get_paginated_properties(page, per_page, cycle_priority[1], access_level_instance_id, false, property_ids).then((result1) => { properties = result1.results; + // if result0 returns fewer properties than result1, use result1 for ui-grid config + if (result1.pagination.num_pages > $scope.inventory_pagination.num_pages) { + baseline_first = !baseline_first + $scope.inventory_pagination = result1.pagination + } combined_result[cycle_priority[1].id] = properties; get_all_labels(); set_grid_options(combined_result); @@ -437,10 +442,14 @@ angular.module('BE.seed.controller.portfolio_summary', []) }; const combine_properties = (current, baseline) => { - // Given 2 properties, find non null values and combine into a single property + // Given 2 properties, find non null values and combine into a single property (favoring baseline if baseline_first) const [a, b] = baseline_first ? [baseline, current] : [current, baseline]; - const c = {}; - Object.keys(a).forEach((key) => c[key] = a[key] !== null ? a[key] : b[key]); + const c = {...b}; + Object.keys(a).forEach(key => { + if (a[key] !== null && a[key] !== undefined) { + c[key] = a[key] + } + }); return c; };