Reset region and Account when switching inventory (#54287)

This commit is contained in:
Phillip Burch 2020-01-08 16:37:37 -06:00 committed by GitHub
parent 303e4842ea
commit e1e1d964c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -28,6 +28,8 @@ interface WaffleInventorySwitcherProps {
changeNodeType: (nodeType: InfraNodeType) => void;
changeGroupBy: (groupBy: InfraSnapshotGroupbyInput[]) => void;
changeMetric: (metric: InfraSnapshotMetricInput) => void;
changeAccount: (id: string) => void;
changeRegion: (name: string) => void;
}
const getDisplayNameForType = (type: InventoryItemType) => {
@ -39,6 +41,8 @@ export const WaffleInventorySwitcher: React.FC<WaffleInventorySwitcherProps> = (
changeNodeType,
changeGroupBy,
changeMetric,
changeAccount,
changeRegion,
nodeType,
}) => {
const [isOpen, setIsOpen] = useState(false);
@ -49,12 +53,14 @@ export const WaffleInventorySwitcher: React.FC<WaffleInventorySwitcherProps> = (
closePopover();
changeNodeType(targetNodeType);
changeGroupBy([]);
changeAccount('');
changeRegion('');
const inventoryModel = findInventoryModel(targetNodeType);
changeMetric({
type: inventoryModel.metrics.defaultSnapshot as InfraSnapshotMetricType,
});
},
[closePopover, changeNodeType, changeGroupBy, changeMetric]
[closePopover, changeNodeType, changeGroupBy, changeMetric, changeAccount, changeRegion]
);
const goToHost = useCallback(() => goToNodeType('host' as InfraNodeType), [goToNodeType]);
const goToK8 = useCallback(() => goToNodeType('pod' as InfraNodeType), [goToNodeType]);

View file

@ -23,12 +23,21 @@ export const SnapshotToolbar = () => (
<EuiFlexGroup alignItems="center" justifyContent="spaceBetween" gutterSize="m">
<EuiFlexItem grow={false}>
<WithWaffleOptions>
{({ changeMetric, changeNodeType, changeGroupBy, nodeType }) => (
{({
changeMetric,
changeNodeType,
changeGroupBy,
changeAccount,
changeRegion,
nodeType,
}) => (
<WaffleInventorySwitcher
nodeType={nodeType}
changeNodeType={changeNodeType}
changeMetric={changeMetric}
changeGroupBy={changeGroupBy}
changeAccount={changeAccount}
changeRegion={changeRegion}
/>
)}
</WithWaffleOptions>