-
Notifications
You must be signed in to change notification settings - Fork 24
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
Bug 2072797: Add duration to top consumers card #683
Merged
openshift-ci
merged 1 commit into
kubevirt-ui:main
from
pcbailey:add-duration-to-top-consumers-card
Jul 6, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ObjectEnum } from '@kubevirt-utils/utils/ObjectEnum'; | ||
|
||
export type DropdownProps = { | ||
dropdownLabel: string; | ||
}; | ||
|
||
abstract class DropdownEnum<T> extends ObjectEnum<T> { | ||
protected readonly dropdownLabel: string; | ||
|
||
protected constructor(value: T, { dropdownLabel }) { | ||
super(value); | ||
this.dropdownLabel = dropdownLabel; | ||
} | ||
|
||
getDropdownLabel = (): string => this.dropdownLabel; | ||
} | ||
|
||
export default DropdownEnum; |
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
43 changes: 43 additions & 0 deletions
43
...roverview/overview/components/MonitoringTab/top-consumers-card/utils/DurationDropdown.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as React from 'react'; | ||
|
||
import { Select, SelectOption, SelectVariant } from '@patternfly/react-core'; | ||
|
||
import DurationOption from './DurationOption'; | ||
|
||
export type DurationDropdownProps = { | ||
selectedDuration: string; | ||
selectHandler: (value: string) => void; | ||
}; | ||
|
||
const DurationDropdown: React.FC<DurationDropdownProps> = ({ selectedDuration, selectHandler }) => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
|
||
const onSelect = (event, durationOption: string) => { | ||
selectHandler(durationOption); | ||
setIsOpen(false); | ||
}; | ||
|
||
return ( | ||
<Select | ||
data-test-id="duration-select-dropdown" | ||
isOpen={isOpen} | ||
onToggle={() => setIsOpen(!isOpen)} | ||
onSelect={onSelect} | ||
selections={DurationOption.fromString(selectedDuration)?.getDropdownLabel()} | ||
variant={SelectVariant.single} | ||
> | ||
{DurationOption.getAll().map((durationOption) => { | ||
const dropdownLabel = durationOption.getDropdownLabel(); | ||
const durationValue = durationOption.getValue(); | ||
|
||
return ( | ||
<SelectOption data-test-id={durationValue} key={durationValue} value={dropdownLabel}> | ||
{dropdownLabel} | ||
</SelectOption> | ||
); | ||
})} | ||
</Select> | ||
); | ||
}; | ||
|
||
export default DurationDropdown; |
49 changes: 49 additions & 0 deletions
49
...steroverview/overview/components/MonitoringTab/top-consumers-card/utils/DurationOption.ts
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import DropdownEnum from '@kubevirt-utils/utils/dropdownEnum'; | ||
import { ObjectEnum } from '@kubevirt-utils/utils/ObjectEnum'; | ||
|
||
class DurationOption extends DropdownEnum<string> { | ||
static readonly FIVE_MIN = new DurationOption('5m', { | ||
dropdownLabel: '5 minutes', | ||
}); | ||
|
||
static readonly ONE_HOUR = new DurationOption('1h', { | ||
dropdownLabel: '1 hour', | ||
}); | ||
|
||
static readonly FOUR_HOURS = new DurationOption('4h', { | ||
dropdownLabel: '4 hours', | ||
}); | ||
|
||
static readonly ONE_DAY = new DurationOption('1d', { | ||
dropdownLabel: '1 day', | ||
}); | ||
|
||
private static readonly ALL = Object.freeze( | ||
ObjectEnum.getAllClassEnumProperties<DurationOption>(DurationOption), | ||
); | ||
|
||
static getAll = () => DurationOption.ALL; | ||
|
||
private static readonly stringMapper = DurationOption.ALL.reduce( | ||
(accumulator, durationOption: DurationOption) => ({ | ||
...accumulator, | ||
[durationOption.value]: durationOption, | ||
}), | ||
{}, | ||
); | ||
|
||
private static readonly dropdownLabelMapper = DurationOption.ALL.reduce( | ||
(accumulator, durationOption: DurationOption) => ({ | ||
...accumulator, | ||
[durationOption.dropdownLabel]: durationOption, | ||
}), | ||
{}, | ||
); | ||
|
||
static fromString = (source: string): DurationOption => DurationOption.stringMapper[source]; | ||
|
||
static fromDropdownLabel = (dropdownLabel: string): DurationOption => | ||
DurationOption.dropdownLabelMapper[dropdownLabel]; | ||
} | ||
|
||
export default DurationOption; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@pcbailey I feel like using
ObjectEnum
is a pain from the past that we should try to avoid at all cost.I do understand that you have portions of your feature relying on it, so IMO its ok to use it for porting features like the Virtualization dashboard. But I strongly recommend to move over to plain objects and hooks when implementing new features from now on.