From cc7488bc15e335956dea4ab49c60a6e879696058 Mon Sep 17 00:00:00 2001 From: Kia Lam Date: Mon, 23 Aug 2021 15:06:36 -0400 Subject: [PATCH 1/2] Disable checkbox for instances with node type control. --- .../Instances/InstanceListItem.js | 2 +- .../Instances/InstanceListItem.test.js | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.js b/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.js index 442f3b464f..60b6e9e505 100644 --- a/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.js +++ b/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.js @@ -108,7 +108,7 @@ function InstanceListItem({ rowIndex, isSelected, onSelect, - disable: false, + disable: instance.node_type === 'control', }} dataLabel={t`Selected`} /> diff --git a/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.test.js b/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.test.js index 0b660da15c..681dfd9482 100644 --- a/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.test.js +++ b/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.test.js @@ -38,6 +38,33 @@ const instance = [ managed_by_policy: true, node_type: 'hybrid', }, + { + id: 2, + type: 'instance', + url: '/api/v2/instances/1/', + related: { + jobs: '/api/v2/instances/1/jobs/', + instance_groups: '/api/v2/instances/1/instance_groups/', + }, + uuid: '00000000-0000-0000-0000-000000000001', + hostname: 'awx-control', + created: '2020-07-14T19:03:49.000054Z', + modified: '2020-08-12T20:08:02.836748Z', + capacity_adjustment: '0.40', + version: '13.0.0', + capacity: 10, + consumed_capacity: 0, + percent_capacity_remaining: 60.0, + jobs_running: 0, + jobs_total: 68, + cpu: 6, + memory: 2087469056, + cpu_capacity: 24, + mem_capacity: 1, + enabled: true, + managed_by_policy: true, + node_type: 'control', + }, ]; describe('', () => { @@ -167,6 +194,24 @@ describe('', () => { ); }); + test('should disable checkbox', async () => { + const onSelect = jest.fn(); + await act(async () => { + wrapper = mountWithContexts( + + + {}} + /> + +
+ ); + }); + expect(wrapper.find('Td').first().prop('select').disable).toEqual(true); + }); + test('should display instance toggle', () => { expect(wrapper.find('InstanceToggle').length).toBe(1); }); From cde0df937f703d85ae5e92540f92f36bf6f5a189 Mon Sep 17 00:00:00 2001 From: Kia Lam Date: Thu, 26 Aug 2021 12:47:43 -0400 Subject: [PATCH 2/2] Filter out instances with node_type equal to 'control'. --- .../InstanceGroup/Instances/InstanceList.js | 23 +++++++++++++------ .../Instances/InstanceListItem.js | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/awx/ui/src/screens/InstanceGroup/Instances/InstanceList.js b/awx/ui/src/screens/InstanceGroup/Instances/InstanceList.js index c8cf075436..94e8327fca 100644 --- a/awx/ui/src/screens/InstanceGroup/Instances/InstanceList.js +++ b/awx/ui/src/screens/InstanceGroup/Instances/InstanceList.js @@ -90,9 +90,14 @@ function InstanceList() { useCallback( () => Promise.all( - selected.map((instance) => - InstanceGroupsAPI.disassociateInstance(instanceGroupId, instance.id) - ) + selected + .filter((s) => s.node_type !== 'control') + .map((instance) => + InstanceGroupsAPI.disassociateInstance( + instanceGroupId, + instance.id + ) + ) ), [instanceGroupId, selected] ), @@ -107,9 +112,11 @@ function InstanceList() { useCallback( async (instancesToAssociate) => { await Promise.all( - instancesToAssociate.map((instance) => - InstanceGroupsAPI.associateInstance(instanceGroupId, instance.id) - ) + instancesToAssociate + .filter((i) => i.node_type !== 'control') + .map((instance) => + InstanceGroupsAPI.associateInstance(instanceGroupId, instance.id) + ) ); fetchInstances(); }, @@ -187,7 +194,9 @@ function InstanceList() { verifyCannotDisassociate={false} key="disassociate" onDisassociate={handleDisassociate} - itemsToDisassociate={selected} + itemsToDisassociate={selected.filter( + (s) => s.node_type !== 'control' + )} modalTitle={t`Disassociate instance from instance group?`} />, ]} diff --git a/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.js b/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.js index 60b6e9e505..d3891e3755 100644 --- a/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.js +++ b/awx/ui/src/screens/InstanceGroup/Instances/InstanceListItem.js @@ -106,7 +106,7 @@ function InstanceListItem({