-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #733 from yaacov/hide-vm-list-columns-for-251
[V2.5.1] Hide new columns in vm list for release 2.5.1
- Loading branch information
Showing
7 changed files
with
75 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 71 additions & 22 deletions
93
...odules/Providers/views/details/tabs/VirtualMachines/components/VMConcernsCellRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,90 @@ | ||
import React from 'react'; | ||
import { TableCell } from 'src/modules/Providers/utils'; | ||
|
||
import { Concern } from '@kubev2v/types'; | ||
import { | ||
BlueInfoCircleIcon, | ||
RedExclamationCircleIcon, | ||
YellowExclamationTriangleIcon, | ||
} from '@openshift-console/dynamic-plugin-sdk'; | ||
import { Stack, StackItem } from '@patternfly/react-core'; | ||
import { Button, Flex, FlexItem, Label, Popover, Stack, StackItem } from '@patternfly/react-core'; | ||
|
||
import { VMCellProps } from './VMCellProps'; | ||
|
||
const statusIcons = { | ||
Critical: <RedExclamationCircleIcon />, | ||
Information: <BlueInfoCircleIcon />, | ||
Warning: <YellowExclamationTriangleIcon />, | ||
}; | ||
|
||
const categoryWeights = { | ||
Critical: 1, | ||
Warning: 2, | ||
Information: 3, | ||
type ConcernCategories = { | ||
category: 'Critical' | 'Information' | 'Warning'; | ||
label: string; | ||
}; | ||
|
||
export const VMConcernsCellRenderer: React.FC<VMCellProps> = ({ data }) => { | ||
const groupedConcerns = groupConcernsByCategory(data?.vm?.concerns); | ||
|
||
return ( | ||
<TableCell> | ||
<Stack> | ||
{data?.vm?.concerns | ||
?.sort((a, b) => categoryWeights[a.category] - categoryWeights[b.category]) | ||
?.map((c) => { | ||
return ( | ||
<StackItem key={c.label}> | ||
{statusIcons?.[c.category]} {c.label} | ||
</StackItem> | ||
); | ||
})} | ||
</Stack> | ||
<Flex spaceItems={{ default: 'spaceItemsNone' }}> | ||
{['Critical', 'Information', 'Warning'].map((category) => ( | ||
<FlexItem key={category}> | ||
<ConcernPopover category={category} concerns={groupedConcerns[category] || []} /> | ||
</FlexItem> | ||
))} | ||
</Flex> | ||
</TableCell> | ||
); | ||
}; | ||
|
||
const groupConcernsByCategory = (concerns: Concern[]): Record<string, ConcernCategories[]> => { | ||
return ( | ||
concerns?.reduce((acc, concern) => { | ||
acc[concern.category] = (acc[concern.category] || []).concat(concern); | ||
return acc; | ||
}, {}) || {} | ||
); | ||
}; | ||
|
||
const ConcernPopover: React.FC<{ | ||
category: string; | ||
concerns: ConcernCategories[]; | ||
}> = ({ category, concerns }) => { | ||
if (concerns.length < 1) return <></>; | ||
|
||
return ( | ||
<Popover | ||
aria-label={`${category} popover`} | ||
headerContent={<div>{category} Concerns</div>} | ||
bodyContent={<ConcernList concerns={concerns} />} | ||
footerContent={`Total: ${concerns.length}`} | ||
> | ||
<Button variant="link" className="forklift-page-provider-vm_concern-button"> | ||
<ConcernLabel category={category} count={concerns.length} /> | ||
</Button> | ||
</Popover> | ||
); | ||
}; | ||
|
||
const ConcernList: React.FC<{ concerns: ConcernCategories[] }> = ({ concerns }) => ( | ||
<Stack> | ||
{concerns.map((c) => ( | ||
<StackItem key={c.category}> | ||
{statusIcons[c.category]} {c.label} | ||
</StackItem> | ||
))} | ||
</Stack> | ||
); | ||
|
||
const ConcernLabel: React.FC<{ category: string; count: number }> = ({ category, count }) => ( | ||
<Label variant="outline" color={categoryColors[category]} icon={statusIcons[category]}> | ||
{count} | ||
</Label> | ||
); | ||
|
||
const statusIcons = { | ||
Critical: <RedExclamationCircleIcon />, | ||
Information: <BlueInfoCircleIcon />, | ||
Warning: <YellowExclamationTriangleIcon />, | ||
}; | ||
|
||
const categoryColors = { | ||
Critical: 'red', | ||
Information: 'blue', | ||
Warning: 'orange', | ||
}; |