Skip to content

Commit

Permalink
fix(dashboard): separate display from actual option value (#1024) (#1025
Browse files Browse the repository at this point in the history
)

Signed-off-by: Thuan Vo <thvo@redhat.com>
(cherry picked from commit abd26e0)

Co-authored-by: Thuan Vo <thvo@redhat.com>
  • Loading branch information
mergify[bot] and Thuan Vo authored May 9, 2023
1 parent 796d0a5 commit 994e9e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/app/Dashboard/AddCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ interface PropsConfigFormProps {
onChange: (config: object) => void;
}

const PropsConfigForm = ({ onChange, ...props }: PropsConfigFormProps) => {
const PropsConfigForm: React.FC<PropsConfigFormProps> = ({ onChange, ...props }) => {
const { t } = useTranslation();
const handleChange = React.useCallback(
(k) => (e) => {
(k: string) => (e: unknown) => {
const copy = { ...props.config };
copy[k] = e;
onChange(copy);
Expand All @@ -479,7 +479,7 @@ const PropsConfigForm = ({ onChange, ...props }: PropsConfigFormProps) => {
);

const handleNumeric = React.useCallback(
(k) => (e) => {
(k: string) => (e: React.FormEvent<HTMLInputElement>) => {
const value = (e.target as HTMLInputElement).value;
const copy = { ...props.config };
copy[k] = value;
Expand All @@ -489,7 +489,7 @@ const PropsConfigForm = ({ onChange, ...props }: PropsConfigFormProps) => {
);

const handleNumericStep = React.useCallback(
(k, v) => (_) => {
(k: string, v: number) => (_: React.MouseEvent) => {
const copy = { ...props.config };
copy[k] = props.config[k] + v;
onChange(copy);
Expand Down Expand Up @@ -582,7 +582,7 @@ interface SelectControlProps {
selectedConfig: string | SelectOptionObject;
}

const SelectControl = ({ handleChange, control, selectedConfig }: SelectControlProps) => {
const SelectControl: React.FC<SelectControlProps> = ({ handleChange, control, selectedConfig }) => {
const addSubscription = useSubscriptions();

const [selectOpen, setSelectOpen] = React.useState(false);
Expand Down Expand Up @@ -638,10 +638,13 @@ const SelectControl = ({ handleChange, control, selectedConfig }: SelectControlP
{errored
? [<SelectOption key={0} value={`Load Error: ${options[0]}`} isPlaceholder isDisabled />]
: options.map((choice, idx) => {
if (control.extras && control.extras.displayMapper) {
choice = control.extras.displayMapper(choice);
}
return <SelectOption key={idx + 1} value={choice} />;
const display =
control.extras && control.extras.displayMapper ? control.extras.displayMapper(choice) : choice;
return (
<SelectOption key={idx + 1} value={choice}>
{display}
</SelectOption>
);
})}
</Select>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/Dashboard/Charts/mbean/MBeanMetricsChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export const MBeanMetricsChartCardDescriptor: DashboardCardDescriptor = {
name: 'CHART_CARD.PROP_CONTROLS.THEME.NAME',
key: 'themeColor',
values: ['blue', 'cyan', 'gold', 'gray', 'green', 'orange', 'purple'],
defaultValue: 'Blue',
defaultValue: 'blue',
description: 'CHART_CARD.PROP_CONTROLS.THEME.DESCRIPTION',
kind: 'select',
extras: {
Expand Down

0 comments on commit 994e9e8

Please sign in to comment.