From c11ac78d84404c360058e50b1cfa29a592defca5 Mon Sep 17 00:00:00 2001 From: Djebran Lezzoum Date: Thu, 14 Dec 2023 11:19:52 +0100 Subject: [PATCH] fix(THEEDGE-3764): fixes LoadingCard component. A regression happened from latest changes when used in federated mode, preventing the model dialogs to open, as no way in federated mode to find the modelId. This PR revert the change related of using useParams function "Clickable" and add the full pathname to the url, also needed as in federated mode the path was truncated for example when used in edge-management app the path was "/edge/ipv4", with this change the path is correct and looks like "/edge/inventory/9ea55e32-6e30-4288-bf08-0a877c7fd306/ipv4" FIXES: https://issues.redhat.com/browse/THEEDGE-3764 --- .../__snapshots__/BiosCard.test.js.snap | 5 +- .../__snapshots__/CollectionCard.test.js.snap | 5 +- .../ConfigurationCard.test.js.snap | 137 ++++++---------- .../GeneralInformation.test.js | 4 +- .../GeneralInformation.test.js.snap | 154 +++++++++--------- .../InfrastructureCard.test.js.snap | 110 +++++-------- .../GeneralInfo/LoadingCard/LoadingCard.js | 12 +- .../__snapshots__/LoadingCard.test.js.snap | 15 +- .../OperatingSystemCard.test.js.snap | 5 +- .../__snapshots__/SystemCard.test.js.snap | 6 +- 10 files changed, 200 insertions(+), 253 deletions(-) diff --git a/src/components/GeneralInfo/BiosCard/__snapshots__/BiosCard.test.js.snap b/src/components/GeneralInfo/BiosCard/__snapshots__/BiosCard.test.js.snap index b2478e1c2..46a866e7f 100644 --- a/src/components/GeneralInfo/BiosCard/__snapshots__/BiosCard.test.js.snap +++ b/src/components/GeneralInfo/BiosCard/__snapshots__/BiosCard.test.js.snap @@ -1311,11 +1311,10 @@ exports[`BiosCard should render extra 1`] = ` value="1 tests" > 1 tests diff --git a/src/components/GeneralInfo/CollectionCard/__snapshots__/CollectionCard.test.js.snap b/src/components/GeneralInfo/CollectionCard/__snapshots__/CollectionCard.test.js.snap index 22d87d92c..9d3ce28e2 100644 --- a/src/components/GeneralInfo/CollectionCard/__snapshots__/CollectionCard.test.js.snap +++ b/src/components/GeneralInfo/CollectionCard/__snapshots__/CollectionCard.test.js.snap @@ -2839,11 +2839,10 @@ exports[`CollectionCard should render extra 1`] = ` value="1 tests" > 1 tests diff --git a/src/components/GeneralInfo/ConfigurationCard/__snapshots__/ConfigurationCard.test.js.snap b/src/components/GeneralInfo/ConfigurationCard/__snapshots__/ConfigurationCard.test.js.snap index fc5ab1213..fdf78fdfe 100644 --- a/src/components/GeneralInfo/ConfigurationCard/__snapshots__/ConfigurationCard.test.js.snap +++ b/src/components/GeneralInfo/ConfigurationCard/__snapshots__/ConfigurationCard.test.js.snap @@ -52,8 +52,7 @@ exports[`ConfigurationCard api should NOT call handleClick 1`] = ` >
1 package @@ -71,8 +70,7 @@ exports[`ConfigurationCard api should NOT call handleClick 1`] = ` >
1 service @@ -90,8 +88,7 @@ exports[`ConfigurationCard api should NOT call handleClick 1`] = ` >
1 process @@ -109,8 +106,7 @@ exports[`ConfigurationCard api should NOT call handleClick 1`] = ` >
1 enabled @@ -338,11 +334,10 @@ exports[`ConfigurationCard should not render hasPackages 1`] = ` value={1} > 1 service @@ -379,11 +374,10 @@ exports[`ConfigurationCard should not render hasPackages 1`] = ` value={1} > 1 process @@ -418,11 +412,10 @@ exports[`ConfigurationCard should not render hasPackages 1`] = ` value="1 enabled" > 1 enabled @@ -663,11 +656,10 @@ exports[`ConfigurationCard should not render hasProcesses 1`] = ` value={1} > 1 package @@ -703,11 +695,10 @@ exports[`ConfigurationCard should not render hasProcesses 1`] = ` value={1} > 1 service @@ -742,11 +733,10 @@ exports[`ConfigurationCard should not render hasProcesses 1`] = ` value="1 enabled" > 1 enabled @@ -989,11 +979,10 @@ exports[`ConfigurationCard should not render hasRepositories 1`] = ` value={1} > 1 package @@ -1029,11 +1018,10 @@ exports[`ConfigurationCard should not render hasRepositories 1`] = ` value={1} > 1 service @@ -1070,11 +1058,10 @@ exports[`ConfigurationCard should not render hasRepositories 1`] = ` value={1} > 1 process @@ -1316,11 +1303,10 @@ exports[`ConfigurationCard should not render hasServices 1`] = ` value={1} > 1 package @@ -1357,11 +1343,10 @@ exports[`ConfigurationCard should not render hasServices 1`] = ` value={1} > 1 process @@ -1396,11 +1381,10 @@ exports[`ConfigurationCard should not render hasServices 1`] = ` value="1 enabled" > 1 enabled @@ -1990,11 +1974,10 @@ exports[`ConfigurationCard should render correctly with data 1`] = ` value={1} > 1 package @@ -2030,11 +2013,10 @@ exports[`ConfigurationCard should render correctly with data 1`] = ` value={1} > 1 service @@ -2071,11 +2053,10 @@ exports[`ConfigurationCard should render correctly with data 1`] = ` value={1} > 1 process @@ -2110,11 +2091,10 @@ exports[`ConfigurationCard should render correctly with data 1`] = ` value="1 enabled" > 1 enabled @@ -2360,11 +2340,10 @@ exports[`ConfigurationCard should render enabled/disabled 1`] = ` value={1} > 1 package @@ -2400,11 +2379,10 @@ exports[`ConfigurationCard should render enabled/disabled 1`] = ` value={1} > 1 service @@ -2441,11 +2419,10 @@ exports[`ConfigurationCard should render enabled/disabled 1`] = ` value={1} > 1 process @@ -2480,11 +2457,10 @@ exports[`ConfigurationCard should render enabled/disabled 1`] = ` value="1 enabled / 1 disabled" > 1 enabled / 1 disabled @@ -2766,11 +2742,10 @@ exports[`ConfigurationCard should render extra 1`] = ` value={1} > 1 package @@ -2806,11 +2781,10 @@ exports[`ConfigurationCard should render extra 1`] = ` value={1} > 1 service @@ -2847,11 +2821,10 @@ exports[`ConfigurationCard should render extra 1`] = ` value={1} > 1 process @@ -2886,11 +2859,10 @@ exports[`ConfigurationCard should render extra 1`] = ` value="1 enabled" > 1 enabled @@ -2946,11 +2918,10 @@ exports[`ConfigurationCard should render extra 1`] = ` value="1 tests" > 1 tests diff --git a/src/components/GeneralInfo/GeneralInformation/GeneralInformation.test.js b/src/components/GeneralInfo/GeneralInformation/GeneralInformation.test.js index 366852a52..5f1675412 100644 --- a/src/components/GeneralInfo/GeneralInformation/GeneralInformation.test.js +++ b/src/components/GeneralInfo/GeneralInformation/GeneralInformation.test.js @@ -34,7 +34,6 @@ jest.mock( jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useLocation: () => location, - useParams: jest.fn(() => ({ modalId: 'running_processes' })), })); const location = {}; @@ -178,7 +177,7 @@ describe('GeneralInformation', () => { it('should open modal', () => { const store = mockStore(initialState); - + location.pathname = 'localhost:3000/example/running_processes'; const wrapper = mount( @@ -199,6 +198,7 @@ describe('GeneralInformation', () => { it('should open modal', () => { const store = mockStore(initialState); + location.pathname = 'localhost:3000/example/running_processes'; const wrapper = mount( diff --git a/src/components/GeneralInfo/GeneralInformation/__snapshots__/GeneralInformation.test.js.snap b/src/components/GeneralInfo/GeneralInformation/__snapshots__/GeneralInformation.test.js.snap index f9c594ee1..adf971aac 100644 --- a/src/components/GeneralInfo/GeneralInformation/__snapshots__/GeneralInformation.test.js.snap +++ b/src/components/GeneralInfo/GeneralInformation/__snapshots__/GeneralInformation.test.js.snap @@ -380,7 +380,7 @@ exports[`GeneralInformation custom components should not render BiosCardWrapper >
2 addresses @@ -398,7 +398,7 @@ exports[`GeneralInformation custom components should not render BiosCardWrapper >
2 addresses @@ -416,7 +416,7 @@ exports[`GeneralInformation custom components should not render BiosCardWrapper >
2 NICs @@ -1018,7 +1018,7 @@ exports[`GeneralInformation custom components should not render BiosCardWrapper >
1 package @@ -1036,7 +1036,7 @@ exports[`GeneralInformation custom components should not render BiosCardWrapper >
1 service @@ -1054,7 +1054,7 @@ exports[`GeneralInformation custom components should not render BiosCardWrapper >
1 process @@ -1072,7 +1072,7 @@ exports[`GeneralInformation custom components should not render BiosCardWrapper >
1 enabled @@ -1471,7 +1471,7 @@ exports[`GeneralInformation custom components should not render CollectionCardWr >
2 addresses @@ -1489,7 +1489,7 @@ exports[`GeneralInformation custom components should not render CollectionCardWr >
2 addresses @@ -1507,7 +1507,7 @@ exports[`GeneralInformation custom components should not render CollectionCardWr >
2 NICs @@ -2194,7 +2194,7 @@ exports[`GeneralInformation custom components should not render CollectionCardWr >
1 package @@ -2212,7 +2212,7 @@ exports[`GeneralInformation custom components should not render CollectionCardWr >
1 service @@ -2230,7 +2230,7 @@ exports[`GeneralInformation custom components should not render CollectionCardWr >
1 process @@ -2248,7 +2248,7 @@ exports[`GeneralInformation custom components should not render CollectionCardWr >
1 enabled @@ -2647,7 +2647,7 @@ exports[`GeneralInformation custom components should not render ConfigurationCar >
2 addresses @@ -2665,7 +2665,7 @@ exports[`GeneralInformation custom components should not render ConfigurationCar >
2 addresses @@ -2683,7 +2683,7 @@ exports[`GeneralInformation custom components should not render ConfigurationCar >
2 NICs @@ -4298,7 +4298,7 @@ exports[`GeneralInformation custom components should not render InfrastructureCa >
1 package @@ -4316,7 +4316,7 @@ exports[`GeneralInformation custom components should not render InfrastructureCa >
1 service @@ -4334,7 +4334,7 @@ exports[`GeneralInformation custom components should not render InfrastructureCa >
1 process @@ -4352,7 +4352,7 @@ exports[`GeneralInformation custom components should not render InfrastructureCa >
1 enabled @@ -4751,7 +4751,7 @@ exports[`GeneralInformation custom components should not render OperatingSystemC >
2 addresses @@ -4769,7 +4769,7 @@ exports[`GeneralInformation custom components should not render OperatingSystemC >
2 addresses @@ -4787,7 +4787,7 @@ exports[`GeneralInformation custom components should not render OperatingSystemC >
2 NICs @@ -5363,7 +5363,7 @@ exports[`GeneralInformation custom components should not render OperatingSystemC >
1 package @@ -5381,7 +5381,7 @@ exports[`GeneralInformation custom components should not render OperatingSystemC >
1 service @@ -5399,7 +5399,7 @@ exports[`GeneralInformation custom components should not render OperatingSystemC >
1 process @@ -5417,7 +5417,7 @@ exports[`GeneralInformation custom components should not render OperatingSystemC >
1 enabled @@ -5527,7 +5527,7 @@ exports[`GeneralInformation custom components should not render SystemCardWrappe >
2 addresses @@ -5545,7 +5545,7 @@ exports[`GeneralInformation custom components should not render SystemCardWrappe >
2 addresses @@ -5563,7 +5563,7 @@ exports[`GeneralInformation custom components should not render SystemCardWrappe >
2 NICs @@ -6250,7 +6250,7 @@ exports[`GeneralInformation custom components should not render SystemCardWrappe >
1 package @@ -6268,7 +6268,7 @@ exports[`GeneralInformation custom components should not render SystemCardWrappe >
1 service @@ -6286,7 +6286,7 @@ exports[`GeneralInformation custom components should not render SystemCardWrappe >
1 process @@ -6304,7 +6304,7 @@ exports[`GeneralInformation custom components should not render SystemCardWrappe >
1 enabled @@ -6703,7 +6703,7 @@ exports[`GeneralInformation custom components should render custom BiosCardWrapp >
2 addresses @@ -6721,7 +6721,7 @@ exports[`GeneralInformation custom components should render custom BiosCardWrapp >
2 addresses @@ -6739,7 +6739,7 @@ exports[`GeneralInformation custom components should render custom BiosCardWrapp >
2 NICs @@ -7348,7 +7348,7 @@ exports[`GeneralInformation custom components should render custom BiosCardWrapp >
1 package @@ -7366,7 +7366,7 @@ exports[`GeneralInformation custom components should render custom BiosCardWrapp >
1 service @@ -7384,7 +7384,7 @@ exports[`GeneralInformation custom components should render custom BiosCardWrapp >
1 process @@ -7402,7 +7402,7 @@ exports[`GeneralInformation custom components should render custom BiosCardWrapp >
1 enabled @@ -7801,7 +7801,7 @@ exports[`GeneralInformation custom components should render custom CollectionCar >
2 addresses @@ -7819,7 +7819,7 @@ exports[`GeneralInformation custom components should render custom CollectionCar >
2 addresses @@ -7837,7 +7837,7 @@ exports[`GeneralInformation custom components should render custom CollectionCar >
2 NICs @@ -8524,7 +8524,7 @@ exports[`GeneralInformation custom components should render custom CollectionCar >
1 package @@ -8542,7 +8542,7 @@ exports[`GeneralInformation custom components should render custom CollectionCar >
1 service @@ -8560,7 +8560,7 @@ exports[`GeneralInformation custom components should render custom CollectionCar >
1 process @@ -8578,7 +8578,7 @@ exports[`GeneralInformation custom components should render custom CollectionCar >
1 enabled @@ -8984,7 +8984,7 @@ exports[`GeneralInformation custom components should render custom Configuration >
2 addresses @@ -9002,7 +9002,7 @@ exports[`GeneralInformation custom components should render custom Configuration >
2 addresses @@ -9020,7 +9020,7 @@ exports[`GeneralInformation custom components should render custom Configuration >
2 NICs @@ -10649,7 +10649,7 @@ exports[`GeneralInformation custom components should render custom Infrastructur >
1 package @@ -10667,7 +10667,7 @@ exports[`GeneralInformation custom components should render custom Infrastructur >
1 service @@ -10685,7 +10685,7 @@ exports[`GeneralInformation custom components should render custom Infrastructur >
1 process @@ -10703,7 +10703,7 @@ exports[`GeneralInformation custom components should render custom Infrastructur >
1 enabled @@ -11102,7 +11102,7 @@ exports[`GeneralInformation custom components should render custom OperatingSyst >
2 addresses @@ -11120,7 +11120,7 @@ exports[`GeneralInformation custom components should render custom OperatingSyst >
2 addresses @@ -11138,7 +11138,7 @@ exports[`GeneralInformation custom components should render custom OperatingSyst >
2 NICs @@ -11721,7 +11721,7 @@ exports[`GeneralInformation custom components should render custom OperatingSyst >
1 package @@ -11739,7 +11739,7 @@ exports[`GeneralInformation custom components should render custom OperatingSyst >
1 service @@ -11757,7 +11757,7 @@ exports[`GeneralInformation custom components should render custom OperatingSyst >
1 process @@ -11775,7 +11775,7 @@ exports[`GeneralInformation custom components should render custom OperatingSyst >
1 enabled @@ -11892,7 +11892,7 @@ exports[`GeneralInformation custom components should render custom SystemCardWra >
2 addresses @@ -11910,7 +11910,7 @@ exports[`GeneralInformation custom components should render custom SystemCardWra >
2 addresses @@ -11928,7 +11928,7 @@ exports[`GeneralInformation custom components should render custom SystemCardWra >
2 NICs @@ -12615,7 +12615,7 @@ exports[`GeneralInformation custom components should render custom SystemCardWra >
1 package @@ -12633,7 +12633,7 @@ exports[`GeneralInformation custom components should render custom SystemCardWra >
1 service @@ -12651,7 +12651,7 @@ exports[`GeneralInformation custom components should render custom SystemCardWra >
1 process @@ -12669,7 +12669,7 @@ exports[`GeneralInformation custom components should render custom SystemCardWra >
1 enabled @@ -14341,7 +14341,7 @@ exports[`GeneralInformation should render correctly 1`] = ` >
2 addresses @@ -14359,7 +14359,7 @@ exports[`GeneralInformation should render correctly 1`] = ` >
2 addresses @@ -14377,7 +14377,7 @@ exports[`GeneralInformation should render correctly 1`] = ` >
2 NICs @@ -15064,7 +15064,7 @@ exports[`GeneralInformation should render correctly 1`] = ` >
1 package @@ -15082,7 +15082,7 @@ exports[`GeneralInformation should render correctly 1`] = ` >
1 service @@ -15100,7 +15100,7 @@ exports[`GeneralInformation should render correctly 1`] = ` >
1 process @@ -15118,7 +15118,7 @@ exports[`GeneralInformation should render correctly 1`] = ` >
1 enabled diff --git a/src/components/GeneralInfo/InfrastructureCard/__snapshots__/InfrastructureCard.test.js.snap b/src/components/GeneralInfo/InfrastructureCard/__snapshots__/InfrastructureCard.test.js.snap index 975c823d3..a06db08fe 100644 --- a/src/components/GeneralInfo/InfrastructureCard/__snapshots__/InfrastructureCard.test.js.snap +++ b/src/components/GeneralInfo/InfrastructureCard/__snapshots__/InfrastructureCard.test.js.snap @@ -254,11 +254,10 @@ exports[`InfrastructureCard should not render hasIPv4 1`] = ` value={1} > 1 address @@ -294,11 +293,10 @@ exports[`InfrastructureCard should not render hasIPv4 1`] = ` value={1} > 1 NIC @@ -580,11 +578,10 @@ exports[`InfrastructureCard should not render hasIPv6 1`] = ` value={1} > 1 address @@ -620,11 +617,10 @@ exports[`InfrastructureCard should not render hasIPv6 1`] = ` value={1} > 1 NIC @@ -907,11 +903,10 @@ exports[`InfrastructureCard should not render hasInterfaces 1`] = ` value={1} > 1 address @@ -948,11 +943,10 @@ exports[`InfrastructureCard should not render hasInterfaces 1`] = ` value={1} > 1 address @@ -1216,11 +1210,10 @@ exports[`InfrastructureCard should not render hasType 1`] = ` value={1} > 1 address @@ -1257,11 +1250,10 @@ exports[`InfrastructureCard should not render hasType 1`] = ` value={1} > 1 address @@ -1297,11 +1289,10 @@ exports[`InfrastructureCard should not render hasType 1`] = ` value={1} > 1 NIC @@ -1565,11 +1556,10 @@ exports[`InfrastructureCard should not render hasVendor 1`] = ` value={1} > 1 address @@ -1606,11 +1596,10 @@ exports[`InfrastructureCard should not render hasVendor 1`] = ` value={1} > 1 address @@ -1646,11 +1635,10 @@ exports[`InfrastructureCard should not render hasVendor 1`] = ` value={1} > 1 NIC @@ -2323,11 +2311,10 @@ exports[`InfrastructureCard should render correctly with data 1`] = ` value={1} > 1 address @@ -2364,11 +2351,10 @@ exports[`InfrastructureCard should render correctly with data 1`] = ` value={1} > 1 address @@ -2404,11 +2390,10 @@ exports[`InfrastructureCard should render correctly with data 1`] = ` value={1} > 1 NIC @@ -3011,11 +2996,10 @@ exports[`InfrastructureCard should render enabled/disabled 1`] = ` value={1} > 1 address @@ -3052,11 +3036,10 @@ exports[`InfrastructureCard should render enabled/disabled 1`] = ` value={1} > 1 address @@ -3092,11 +3075,10 @@ exports[`InfrastructureCard should render enabled/disabled 1`] = ` value={1} > 1 NIC @@ -3419,11 +3401,10 @@ exports[`InfrastructureCard should render extra 1`] = ` value={1} > 1 address @@ -3460,11 +3441,10 @@ exports[`InfrastructureCard should render extra 1`] = ` value={1} > 1 address @@ -3500,11 +3480,10 @@ exports[`InfrastructureCard should render extra 1`] = ` value={1} > 1 NIC @@ -3560,11 +3539,10 @@ exports[`InfrastructureCard should render extra 1`] = ` value="1 tests" > 1 tests diff --git a/src/components/GeneralInfo/LoadingCard/LoadingCard.js b/src/components/GeneralInfo/LoadingCard/LoadingCard.js index 9eba4fa2f..5803b10ab 100644 --- a/src/components/GeneralInfo/LoadingCard/LoadingCard.js +++ b/src/components/GeneralInfo/LoadingCard/LoadingCard.js @@ -17,7 +17,7 @@ import { Skeleton, SkeletonSize, } from '@redhat-cloud-services/frontend-components/Skeleton'; -import { Link, useParams } from 'react-router-dom'; +import { Link, useLocation } from 'react-router-dom'; const valueToText = (value, singular, plural) => { if ((value || value === 0) && singular) { @@ -34,14 +34,20 @@ const valueToText = (value, singular, plural) => { }; export const Clickable = ({ value, target, plural, singular, onClick }) => { - const { modalId } = useParams(); + const { pathname } = useLocation(); + // const { modalId } = useParams(); is causing regression when using LoadingCard derived components in Federated mode + const modalId = pathname.split('/').pop(); useEffect(() => { if (target === modalId) { onClick({ value, target }); } }, [modalId, target]); - return {valueToText(value, singular, plural)}; + return ( + + {valueToText(value, singular, plural)} + + ); }; Clickable.propTypes = { diff --git a/src/components/GeneralInfo/LoadingCard/__snapshots__/LoadingCard.test.js.snap b/src/components/GeneralInfo/LoadingCard/__snapshots__/LoadingCard.test.js.snap index ed96e6d38..0a488d4af 100644 --- a/src/components/GeneralInfo/LoadingCard/__snapshots__/LoadingCard.test.js.snap +++ b/src/components/GeneralInfo/LoadingCard/__snapshots__/LoadingCard.test.js.snap @@ -40,11 +40,10 @@ exports[`LoadingCard Clickable should render - 0 value 1`] = ` value={0} > None @@ -92,11 +91,10 @@ exports[`LoadingCard Clickable should render - no data 1`] = ` onClick={[MockFunction]} > Not available @@ -447,11 +445,10 @@ exports[`LoadingCard Loading card render 1`] = ` value="some value" > some value diff --git a/src/components/GeneralInfo/OperatingSystemCard/__snapshots__/OperatingSystemCard.test.js.snap b/src/components/GeneralInfo/OperatingSystemCard/__snapshots__/OperatingSystemCard.test.js.snap index 07652f687..582fdfb8c 100644 --- a/src/components/GeneralInfo/OperatingSystemCard/__snapshots__/OperatingSystemCard.test.js.snap +++ b/src/components/GeneralInfo/OperatingSystemCard/__snapshots__/OperatingSystemCard.test.js.snap @@ -3234,11 +3234,10 @@ exports[`OperatingSystemCard should render extra 1`] = ` value="1 tests" > 1 tests diff --git a/src/components/GeneralInfo/SystemCard/__snapshots__/SystemCard.test.js.snap b/src/components/GeneralInfo/SystemCard/__snapshots__/SystemCard.test.js.snap index 47dcf199c..e8a30130a 100644 --- a/src/components/GeneralInfo/SystemCard/__snapshots__/SystemCard.test.js.snap +++ b/src/components/GeneralInfo/SystemCard/__snapshots__/SystemCard.test.js.snap @@ -4013,8 +4013,7 @@ Array [ >
2 identifiers @@ -5142,8 +5141,7 @@ Array [ >