-
Notifications
You must be signed in to change notification settings - Fork 64
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
Resource tab optimization #1435
Changes from 30 commits
360e920
b060909
f66ace8
0f725de
41b0aa2
c16159d
d6a7d8e
862b09e
9f9fa98
990535d
ffc7b1f
0c28d0d
cb55806
7e5812f
56c9b9b
ee2e804
4a47bd5
c1dc3ec
704fdde
17edc4d
3575e61
8269f05
9c3a67f
a1edabf
e4a4a8a
5588d18
8445da6
4d12d28
f8d09f8
b33a445
f972f94
4eb549f
b2f87ed
327f6e3
80a28e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||
import React, { useEffect } from 'react'; | ||||||||||
import React, { useEffect, useState } from 'react'; | ||||||||||
import PropTypes from 'prop-types'; | ||||||||||
import { useSelector, useDispatch } from 'react-redux'; | ||||||||||
import { useLocation, useHistory } from 'react-router-dom'; | ||||||||||
|
@@ -14,11 +14,14 @@ const ApplicationDetails = ({ onTabSelect, appList, ...props }) => { | |||||||||
const history = useHistory(); | ||||||||||
const dispatch = useDispatch(); | ||||||||||
const searchParams = new URLSearchParams(search); | ||||||||||
const items = useSelector(({ entityDetails }) => entityDetails?.activeApps); | ||||||||||
const items = useSelector(({ entityDetails }) => entityDetails?.activeApps.filter(({ isVisible }) => isVisible !== false)); | ||||||||||
const activeApp = useSelector(({ entityDetails }) => entityDetails?.activeApp); | ||||||||||
const disabledApps = useSelector(({ systemProfileStore }) => systemProfileStore?.disabledApps); | ||||||||||
const defaultApp = activeApp?.appName || appList?.find(({ pageId, name }) => items?.[0]?.name === ( | ||||||||||
pageId || name))?.name || items?.[0]?.name; | ||||||||||
const applications = appList || items; | ||||||||||
let applications = appList || items; | ||||||||||
const [activeTabs, setActiveTabs] = useState(applications); | ||||||||||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified to directly assign to default state
Suggested change
|
||||||||||
|
||||||||||
useEffect(() => { | ||||||||||
/** | ||||||||||
* Initialize first inventory detail type | ||||||||||
|
@@ -29,6 +32,16 @@ const ApplicationDetails = ({ onTabSelect, appList, ...props }) => { | |||||||||
} | ||||||||||
}, []); | ||||||||||
|
||||||||||
useEffect(() => { | ||||||||||
const filteredResult = disabledApps && disabledApps.length && applications.filter(app => app.name !== disabledApps[0]); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified with safe accessor, using
Suggested change
|
||||||||||
if (filteredResult !== 0 && typeof filteredResult !== undefined) { | ||||||||||
setActiveTabs(filteredResult); | ||||||||||
} | ||||||||||
else { | ||||||||||
setActiveTabs(applications); | ||||||||||
} | ||||||||||
}, [disabledApps]); | ||||||||||
|
||||||||||
return ( | ||||||||||
<React.Fragment> | ||||||||||
{ | ||||||||||
|
@@ -37,7 +50,7 @@ const ApplicationDetails = ({ onTabSelect, appList, ...props }) => { | |||||||||
{...props} | ||||||||||
activeKey={ defaultApp } | ||||||||||
onSelect={ (event, item) => { | ||||||||||
const activeItem = applications.find(oneApp => oneApp.name === item); | ||||||||||
const activeItem = activeTabs.find(oneApp => oneApp.name === item); | ||||||||||
if (onTabSelect) { | ||||||||||
onTabSelect(event, item, activeItem); | ||||||||||
} else { | ||||||||||
|
@@ -50,7 +63,7 @@ const ApplicationDetails = ({ onTabSelect, appList, ...props }) => { | |||||||||
isFilled | ||||||||||
className="ins-c-inventory-detail__app-tabs" | ||||||||||
> | ||||||||||
{ applications.map((item, key) => ( | ||||||||||
{ activeTabs && activeTabs.length && activeTabs.map((item, key) => ( | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified with safe accessor
Suggested change
|
||||||||||
<Tab key={ key } eventKey={ item.name } title={ item.title }></Tab> | ||||||||||
)) } | ||||||||||
</Tabs> | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,4 @@ export const CLEAR_FILTERS = 'CLEAR_FILTERS'; | |
export const TOGGLE_TAG_MODAL = 'TOGGLE_TAG_MODAL'; | ||
export const CONFIG_CHANGED = 'CONFIG_CHANGED'; | ||
export const TOGGLE_DRAWER = 'TOGGLE_INVENTORY_DRAWER'; | ||
export const SET_ROS_TAB_VISBILITY = 'SET_ROS_TAB_VISBILITY'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this const |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,6 +193,11 @@ export const deleteEntity = (systems, displayName) => ({ | |
} | ||
}); | ||
|
||
// export const setRosTabVisibility = (shouldShowRosTab) => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for commented out code |
||
// type: SET_ROS_TAB_VISBILITY, | ||
// payload: shouldShowRosTab | ||
// }); | ||
|
||
export const configChanged = (config) => ({ | ||
type: CONFIG_CHANGED, | ||
payload: config | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import { INVENTORY_ACTION_TYPES, ACTION_TYPES, SELECT_ENTITY, SET_INVENTORY_FILTER, SET_PAGINATION } from './action-types'; | ||
import { | ||
INVENTORY_ACTION_TYPES, | ||
ACTION_TYPES, | ||
SELECT_ENTITY, | ||
SET_INVENTORY_FILTER, | ||
SET_PAGINATION | ||
} from './action-types'; | ||
import systemProfileStore from './systemProfileStore'; | ||
import { | ||
ComplianceTab, | ||
|
@@ -64,6 +70,7 @@ function entityLoaded(state) { | |
(!insights.chrome.isProd || (insights.chrome.isProd && insights?.chrome?.isBeta())) && { | ||
title: 'Resource Optimization', | ||
name: 'ros', | ||
isVisible: false, | ||
component: RosTab | ||
} | ||
].filter(Boolean) | ||
|
@@ -95,6 +102,17 @@ 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)); | ||
|
@@ -105,11 +123,7 @@ function entityDeleted(state, { meta }) { | |
}; | ||
} | ||
|
||
function onEntitiesLoaded(state, { payload, meta }) { | ||
if (meta?.lastDateRequest < state?.lastDateRequest) { | ||
return state; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rvsia this was added to prevent race conditions, right? I don't think we can remove this. |
||
|
||
function onEntitiesLoaded(state, { payload }) { | ||
return { | ||
...state, | ||
rows: mergeArraysByKey([state.rows, payload.results.map(result => { | ||
|
@@ -160,7 +174,8 @@ export const tableReducer = applyReducerHash( | |
|
||
export const entitesDetailReducer = () => applyReducerHash( | ||
{ | ||
[INVENTORY_ACTION_TYPES.LOAD_ENTITY_FULFILLED]: entityLoaded | ||
[INVENTORY_ACTION_TYPES.LOAD_ENTITY_FULFILLED]: entityLoaded, | ||
[INVENTORY_ACTION_TYPES.LOAD_SYSTEM_PROFILE_FULFILLED]: resourceOptTabVisibility | ||
}, | ||
defaultState | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,8 +45,14 @@ export function calculateInterfaces(interfaces) { | |
|
||
export function onSystemProfile(state, { payload: { results } }) { | ||
const systemProfile = (results && results[0] && results[0].system_profile) || {}; | ||
const cloudProviderObj = (results && results[0] && (typeof results[0].system_profile.cloud_provider !== 'undefined')) | ||
&& results[0].system_profile.cloud_provider; | ||
return { | ||
...state, | ||
disabledApps: [ | ||
...(cloudProviderObj === 'aws' || cloudProviderObj === 'test cloud provider') ? [] : ['ros'] | ||
// ...(cloudProviderObj === 'aws' || cloudProviderObj === 'azure') ? ['ros'] : [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we actually want this code to present and the one above not, right? |
||
], | ||
systemProfile: { | ||
loaded: true, | ||
...systemProfile, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add another guard in here