Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Release to master-stable" #1835

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const App = () => {
const history = useHistory();
const chrome = useChrome();
useEffect(() => {
chrome.init();
return chrome.on(
'APP_NAVIGATION',
event => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/GeneralInfo/EditButton/EditButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';

import { usePermissionsWithContext } from '@redhat-cloud-services/frontend-components-utilities/RBACHook';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';

import { PencilAltIcon } from '@patternfly/react-icons';

Expand Down Expand Up @@ -46,7 +47,9 @@ EditButtonUnknownPermissions.propTypes = {
};

const EditButtonWrapper = ({ writePermissions, ...props }) => {
if (insights.chrome.isProd || writePermissions || permissionsCache) {
const { isProd } = useChrome();

if (isProd?.() || writePermissions || permissionsCache) {
return <InnerButton {...props} />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PencilAltIcon } from '@patternfly/react-icons';
import EditButton from './EditButton';

jest.mock('@redhat-cloud-services/frontend-components-utilities/RBACHook', () => ({
esModule: true,
__esModule: true,
usePermissionsWithContext: () => ({ hasAccess: false })
}));

Expand Down Expand Up @@ -39,21 +39,6 @@ describe('EditButton with no access', () => {
expect(wrapper.find('a')).toHaveLength(0);
});

it('render on production', () => {
const tmp = insights.chrome.isProd;
insights.chrome.isProd = true;

const wrapper = mount(<EditButton
onClick={onClick}
link={link}
/>);

expect(wrapper.find(PencilAltIcon)).toHaveLength(1);
expect(wrapper.find('a').props().href).toEqual('http://localhost:5000//some-link');

insights.chrome.isProd = tmp;
});

it('render when write permissions are set to true', () => {
const wrapper = mount(<EditButton
onClick={onClick}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { mount } from 'enzyme';
import { PencilAltIcon } from '@patternfly/react-icons';

import EditButton from './EditButton';

jest.mock('@redhat-cloud-services/frontend-components-utilities/RBACHook', () => ({
__esModule: true,
usePermissionsWithContext: () => ({ hasAccess: false })
}));

jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
__esModule: true,
default: () => ({
isProd: () => true
})
}));

describe('EditButton with no access', () => {
let onClick;
let link;

beforeEach(() => {
onClick = jest.fn();
link = 'some-link';
});

it('render on production', () => {
const wrapper = mount(<EditButton
onClick={onClick}
link={link}
/>);

expect(wrapper.find(PencilAltIcon)).toHaveLength(1);
expect(wrapper.find('a').props().href).toEqual('http://localhost:5000//some-link');
});
});
20 changes: 14 additions & 6 deletions src/components/InventoryDetail/ApplicationDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import React, { useState, useEffect, Suspense } from 'react';
import PropTypes from 'prop-types';
import { useSelector, useStore } from 'react-redux';
import { Tabs, Tab, Spinner, TabContent } from '@patternfly/react-core';
import { verifyCulledInsightsClient } from '../../Utilities/sharedFunctions';
import { getFact } from './helpers';
import { NotConnected } from '@redhat-cloud-services/frontend-components/NotConnected';

/**
* Component that renders tabs for each application detail and handles clicking on each item.
* @param {*} props onTabSelect can be used to notify parent component that detail has been selected.
*/
const ApplicationDetails = ({ onTabSelect, appList, activeApp, inventoryId, ...props }) => {
const ApplicationDetails = ({ onTabSelect, appList, activeApp, inventoryId, entity, ...props }) => {
const store = useStore();
const items = useSelector(({ entityDetails }) => {
return (entityDetails?.activeApps || appList || [])
Expand All @@ -31,6 +34,8 @@ const ApplicationDetails = ({ onTabSelect, appList, activeApp, inventoryId, ...p
}
}, [disabledApps]);

const isDisconnected = verifyCulledInsightsClient(getFact('per_reporter_staleness', entity));

return (
<React.Fragment>
<section className='pf-u-pr-lg pf-u-pl-lg pf-u-background-color-100-on-md'>
Expand Down Expand Up @@ -71,10 +76,12 @@ const ApplicationDetails = ({ onTabSelect, appList, activeApp, inventoryId, ...p
>
{item.name === currentApp && <Suspense fallback={Spinner}>
<section className='pf-c-page__main-section'>
<Cmp
inventoryId={inventoryId}
store={store}
/>
{isDisconnected && ['patch', 'vulnerabilities', 'advisor']
.includes(currentApp) ? <NotConnected/>
: <Cmp
inventoryId={inventoryId}
store={store}
/>}
</section>
</Suspense>}
</TabContent>
Expand All @@ -93,7 +100,8 @@ ApplicationDetails.propTypes = {
})),
onTabSelect: PropTypes.func,
activeApp: PropTypes.string.isRequired,
inventoryId: PropTypes.string.isRequired
inventoryId: PropTypes.string.isRequired,
entity: PropTypes.object
};

export default ApplicationDetails;
1 change: 1 addition & 0 deletions src/components/InventoryDetail/InventoryDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const InventoryDetail = ({
activeApp={activeApp}
appList={appList}
inventoryId={inventoryId}
entity={entity}
/>
)}
</>)
Expand Down
11 changes: 8 additions & 3 deletions src/routes/InventoryDetail.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useCallback } from 'react';
import React, { useEffect, useState, useCallback, useMemo } from 'react';
import PropTypes from 'prop-types';
import { useSelector, useStore, useDispatch } from 'react-redux';
import { useLocation, useParams, Link, useHistory } from 'react-router-dom';
Expand Down Expand Up @@ -75,6 +75,11 @@ const Inventory = () => {
const writePermissions = useWritePermissions();
const entityLoaded = useSelector(({ entityDetails }) => entityDetails?.loaded);
const entity = useSelector(({ entityDetails }) => entityDetails?.entity);
const cloudProvider = useSelector(({ systemProfileStore }) => systemProfileStore?.systemProfile?.cloud_provider);
const availableApps = useMemo(() => appList.map((app) => app.name === 'ros' ? {
...app,
isVisible: cloudProvider === 'aws'
} : app), [cloudProvider]);
const clearNotifications = () => dispatch(actions.clearNotifications());

useEffect(() => {
Expand All @@ -92,7 +97,7 @@ const Inventory = () => {
}

useEffect(() => {
insights?.chrome?.appObjectId?.(entity?.id);
chrome?.appObjectId?.(entity?.id);
}, [entity?.id]);

const onTabSelect = useCallback((_, activeApp, appName) => {
Expand Down Expand Up @@ -122,7 +127,7 @@ const Inventory = () => {
<BreadcrumbWrapper entity={entity} entityLoaded={entityLoaded} inventoryId={inventoryId}/>
}
activeApp={activeApp}
appList={appList}
appList={availableApps}
onTabSelect={onTabSelect}
/>
);
Expand Down
14 changes: 1 addition & 13 deletions src/store/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ function entitySelected(state, { payload }) {
};
}

function resourceOptTabVisibility(state, { payload }) {
return {
...state,
activeApps: state.activeApps?.map((entity) => entity.name === 'ros' ? ({
...entity,
isVisible: payload
}) : entity
)
};
}

function entityDeleted(state, { meta }) {
const selected = state.selected || (new Map());
meta.systems.forEach(id => selected.delete(id));
Expand Down Expand Up @@ -135,8 +124,7 @@ export const tableReducer = applyReducerHash(

export const entitesDetailReducer = () => applyReducerHash(
{
[INVENTORY_ACTION_TYPES.LOAD_ENTITY_FULFILLED]: entityLoaded,
[INVENTORY_ACTION_TYPES.LOAD_SYSTEM_PROFILE_FULFILLED]: resourceOptTabVisibility
[INVENTORY_ACTION_TYPES.LOAD_ENTITY_FULFILLED]: entityLoaded
},
defaultState
);
Expand Down