Merge ~caleb-ellis/maas:machine-truncation-2.6 into maas:master

Proposed by Caleb Ellis
Status: Merged
Approved by: Caleb Ellis
Approved revision: 2241cbe331554d97ebe6a4fa81c6e78045e3372a
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~caleb-ellis/maas:machine-truncation-2.6
Merge into: maas:master
Diff against target: 169 lines (+81/-15)
3 files modified
src/maasserver/static/js/angular/directives/machines_table.js (+31/-9)
src/maasserver/static/js/angular/directives/tests/test_machines_table.js (+30/-0)
src/maasserver/static/partials/machines-table.html (+20/-6)
Reviewer Review Type Date Requested Status
Steve Rydz (community) Approve
Adam Collard (community) Needs Information
MAAS Lander Approve
Review via email: mp+373912@code.launchpad.net

Commit message

Forward port machine list truncation from 2.6 branch.

Description of the change

## Done
- Copy+pasted the machine list truncation work from the 2.6 branch to here. This adds the "Show all..." functionality and simultaneously fixes the error where machines wouldn't load (likely fixed by `MachinesManager.clear()` being removed)

## QA
- Check that the machine list truncation works like in 2.6 i.e. a maximum of 5 machines show per group by default, clicking "Show all..." shows all. Test it out in grouping by status, grouping my owner, and no grouping.
- Go to a KVM details page and check that the machine list displays correctly there too.
- Go to any page that isn't the machine list and refresh the app. Navigate back to the machine list and check that the machines load in correctly.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b machine-truncation-2.6 lp:~caleb-ellis/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 2241cbe331554d97ebe6a4fa81c6e78045e3372a

review: Approve
Revision history for this message
Adam Collard (adam-collard) wrote :

What's the rationale for this? I know we did it for 2.6, but do we want it in 2.7?

review: Needs Information
Revision history for this message
Steve Rydz (steverydz) wrote :

LGTM +1

review: Approve
Revision history for this message
Caleb Ellis (caleb-ellis) wrote :

To reiterate what was said on IRC - this branch improves first load performance on the machine list a lot by removing vs-repeat. It also solves the problem of having to reload the machine data every time a user navigates to the machine list. While we would have liked to have moved to React by now it just simply won't happen this cycle, so I've opted to pull in this stop-gap performance fix from 2.6.

Relevant performance discussions:
https://github.com/canonical-web-and-design/MAAS-squad/issues/1314
https://docs.google.com/document/d/18kE1XU56odpf_ZOWgiSaYPjLcmPfZy_AiK8ZiRn1mW8/edit

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/static/js/angular/directives/machines_table.js b/src/maasserver/static/js/angular/directives/machines_table.js
2index 0cd2753..7405028 100644
3--- a/src/maasserver/static/js/angular/directives/machines_table.js
4+++ b/src/maasserver/static/js/angular/directives/machines_table.js
5@@ -74,15 +74,6 @@ function maasMachinesTable(
6 NodeStatus.EXITING_RESCUE_MODE,
7 NodeStatus.TESTING
8 ];
9-
10- // This is an performance optimisation to unblock initial rendering,
11- // otherwise when there are many machines, due to numerous nested
12- // ng-repeats the initial digest cycle is slow and the UI is
13- // blocked on first navigation.
14- if (angular.isDefined($scope.loading)) {
15- MachinesManager.clear();
16- $scope.metadata = MachinesManager.getMetadata();
17- }
18 const machines = MachinesManager.getItems();
19
20 // Scope variables.
21@@ -97,6 +88,29 @@ function maasMachinesTable(
22 machineActions: GeneralManager.getData("machine_actions")
23 };
24
25+ $scope.DISPLAY_LIMIT = 5;
26+ $scope.displayLimits = {};
27+ const groupLabels = [
28+ "Failed",
29+ "New",
30+ "Commissioning",
31+ "Testing",
32+ "Ready",
33+ "Allocated",
34+ "Deploying",
35+ "Deployed",
36+ "Rescue mode",
37+ "Releasing",
38+ "Broken",
39+ "Other"
40+ ];
41+
42+ $scope.getLimit = group => $scope.displayLimits[group.label];
43+
44+ $scope.loadAll = selectedGroup => {
45+ $scope.displayLimits[selectedGroup.label] = undefined;
46+ };
47+
48 $scope.statusMenuActions = [
49 "commission",
50 "acquire",
51@@ -480,6 +494,9 @@ function maasMachinesTable(
52 ]
53 }
54 ];
55+ groupLabels.forEach(label => {
56+ $scope.displayLimits[label] = $scope.DISPLAY_LIMIT;
57+ });
58 return;
59 }
60
61@@ -500,6 +517,9 @@ function maasMachinesTable(
62 });
63
64 $scope.groupedMachines = groupedByOwner;
65+ groupedByOwner.forEach(owner => {
66+ $scope.displayLimits[owner.label] = $scope.DISPLAY_LIMIT;
67+ });
68 return;
69 }
70
71@@ -509,6 +529,7 @@ function maasMachinesTable(
72 machines: $scope.table.filteredMachines
73 }
74 ];
75+ $scope.displayLimits["none"] = $scope.DISPLAY_LIMIT;
76 return;
77 };
78
79@@ -517,6 +538,7 @@ function maasMachinesTable(
80 $scope.table.machines,
81 $scope.search
82 );
83+ $scope.displayLimits["none"] = $scope.DISPLAY_LIMIT;
84 };
85
86 // When the list of filtered machines change update the all checkbox.
87diff --git a/src/maasserver/static/js/angular/directives/tests/test_machines_table.js b/src/maasserver/static/js/angular/directives/tests/test_machines_table.js
88index 1d47339..d8403cd 100644
89--- a/src/maasserver/static/js/angular/directives/tests/test_machines_table.js
90+++ b/src/maasserver/static/js/angular/directives/tests/test_machines_table.js
91@@ -1083,4 +1083,34 @@ barbaz`); // Has to be formatted this way for tooltip
92 expect(scope.getArchitectureText("i386/generic")).toBe("i386");
93 });
94 });
95+
96+ describe("display limits", () => {
97+ it("returns the default display limit for the group", () => {
98+ const directive = compileDirective();
99+ const scope = directive.isolateScope();
100+
101+ scope.groupByLabel = "status";
102+ const group = {
103+ label: "Allocated",
104+ machines: []
105+ };
106+ scope.$digest();
107+
108+ expect(scope.getLimit(group)).toEqual(scope.DISPLAY_LIMIT);
109+ });
110+
111+ it("sets the groups display limit to undefined", () => {
112+ const directive = compileDirective();
113+ const scope = directive.isolateScope();
114+
115+ scope.groupByLabel = "status";
116+ const group = {
117+ label: "New",
118+ machines: []
119+ };
120+ scope.loadAll(group);
121+
122+ expect(scope.getLimit(group)).toEqual(undefined);
123+ });
124+ });
125 });
126diff --git a/src/maasserver/static/partials/machines-table.html b/src/maasserver/static/partials/machines-table.html
127index c925b57..5f8c4a9 100644
128--- a/src/maasserver/static/partials/machines-table.html
129+++ b/src/maasserver/static/partials/machines-table.html
130@@ -99,12 +99,13 @@
131 <th class="p-table__col--storage u-align--right" role="columnheader"></th>
132 </tr>
133 </thead>
134- <tbody vs-repeat data-ng-if="!closedGroups.includes(group.label)">
135- <tr class="p-table__row" data-ng-repeat="node in group.machines | nodesFilter:search | orderBy:table.predicate:table.reverse track by node.system_id"
136- data-ng-class="{ 'table--error': machineHasError({ $machine: node }),
137- 'is-active': node.$selected,
138- 'is-grouped': group.label !== 'none'
139- }"
140+ <tbody data-ng-if="!closedGroups.includes(group.label)">
141+ <tr class="p-table__row"
142+ ng-class="{
143+ 'table--error': machineHasError({ $machine: node }),
144+ 'is-active': node.$selected,
145+ 'is-grouped': group.label !== 'none'}"
146+ ng-repeat="node in group.machines | limitTo:getLimit(group) | nodesFilter:search | orderBy:table.predicate:table.reverse track by node.system_id"
147 tabindex="0"
148 >
149 <td class="p-table__col--name p-double-row" aria-label="FQDN" data-ng-if="table.column === 'fqdn' || table.column === 'ip_address'">
150@@ -449,6 +450,19 @@
151 </span>
152 </td>
153 </tr>
154+ <tr data-ng-if="group.machines && group.machines.length > getLimit(group)">
155+ <td colspan="12">
156+ <div class="p-table__group-label" style="padding: .25rem 0 .3rem">
157+ <a class="p-muted-text" data-ng-click="loadAll(group)">
158+ <span>Show all</span>
159+ <span data-ng-if="group.label === 'none'">machines&hellip;</span>
160+ <span data-ng-if="group.label === 'No owner'">unowned&hellip;</span>
161+ <span data-ng-if="groupByLabel === 'owner' && group.label !== 'No owner'">owned by {$ group.label $}&hellip;</span>
162+ <span data-ng-if="groupByLabel === 'status'">{$ group.label | lowercase $}&hellip;</span>
163+ </a>
164+ </div>
165+ </td>
166+ </tr>
167 </tbody>
168 </table>
169 <div class="p-strip" data-ng-if="search && !loading && !table.filteredMachines.length">

Subscribers

People subscribed via source and target branches