Skip to content
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

added "on" label to checkbox #28087

Merged
merged 1 commit into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions js/libs/ui-shared/src/user-profile/OptionsComponent.tsx
@@ -1,8 +1,12 @@
import { Checkbox, Radio } from "@patternfly/react-core";
import { Controller } from "react-hook-form";
import { Options, UserProfileFieldProps } from "./UserProfileFields";
import {
OptionLabel,
Options,
UserProfileFieldProps,
} from "./UserProfileFields";
import { UserProfileGroup } from "./UserProfileGroup";
import { fieldName, isRequiredAttribute } from "./utils";
import { fieldName, isRequiredAttribute, unWrap } from "./utils";

export const OptionComponent = (props: UserProfileFieldProps) => {
const { form, inputType, attribute } = props;
Expand All @@ -12,6 +16,10 @@ export const OptionComponent = (props: UserProfileFieldProps) => {
const options =
(attribute.validators?.options as Options | undefined)?.options || [];

const optionLabel = attribute.annotations?.[
"inputOptionLabels"
] as OptionLabel;

return (
<UserProfileGroup {...props}>
<Controller
Expand All @@ -25,7 +33,7 @@ export const OptionComponent = (props: UserProfileFieldProps) => {
key={option}
id={option}
data-testid={option}
label={option}
label={props.t(unWrap(optionLabel?.on || option))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to unWrap(label) here as well, or can we get away with:

Suggested change
label={props.t(unWrap(optionLabel?.on || option))}
label={props.t(optionLabel?.on ? unWrap(optionLabel.on) : option)}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can be a translation key, see the issue

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that using optionLabel?.on will look for a entry in inputOptionLabels for the key "on". My guess is that this should rather look for the key option.

Suggestion:

                label={props.t(unWrap(optionLabel?.[option] || option))}

value={option}
isChecked={field.value.includes(option)}
onChange={() => {
Expand Down
7 changes: 5 additions & 2 deletions js/libs/ui-shared/src/user-profile/SelectComponent.tsx
@@ -1,7 +1,11 @@
import { Select, SelectOption } from "@patternfly/react-core";
import { useState } from "react";
import { Controller, ControllerRenderProps } from "react-hook-form";
import { Options, UserProfileFieldProps } from "./UserProfileFields";
import {
OptionLabel,
Options,
UserProfileFieldProps,
} from "./UserProfileFields";
import { UserProfileGroup } from "./UserProfileGroup";
import {
UserFormFields,
Expand All @@ -10,7 +14,6 @@ import {
unWrap,
} from "./utils";

type OptionLabel = Record<string, string> | undefined;
export const SelectComponent = (props: UserProfileFieldProps) => {
const { t, form, inputType, attribute } = props;
const [open, setOpen] = useState(false);
Expand Down
2 changes: 2 additions & 0 deletions js/libs/ui-shared/src/user-profile/UserProfileFields.tsx
Expand Up @@ -54,6 +54,8 @@ export type UserProfileFieldProps = {
renderer?: (attribute: UserProfileAttributeMetadata) => ReactNode;
};

export type OptionLabel = Record<string, string> | undefined;

export const FIELDS: {
[type in InputType]: (props: UserProfileFieldProps) => JSX.Element;
} = {
Expand Down