Skip to content

Commit

Permalink
Add ProviderConfigProperty types for numeric values
Browse files Browse the repository at this point in the history
Fixes keycloak#29511

Signed-off-by: Thomas Darimont <[email protected]>
  • Loading branch information
thomasdarimont authored Dec 16, 2024
1 parent 83bba0f commit 368c1f5
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
26 changes: 26 additions & 0 deletions js/apps/admin-ui/src/components/dynamic/IntComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useTranslation } from "react-i18next";
import { TextControl } from "@keycloak/keycloak-ui-shared";

import { convertToName } from "./DynamicComponents";
import { NumberComponentProps } from "./components";

export const IntComponent = ({
name,
label,
helpText,
...props
}: NumberComponentProps) => {
const { t } = useTranslation();

return (
<TextControl
name={convertToName(name!)}
type="number"
pattern="\d*"
label={t(label!)}
labelIcon={t(helpText!)}
data-testid={name}
{...props}
/>
);
};
25 changes: 25 additions & 0 deletions js/apps/admin-ui/src/components/dynamic/NumberComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useTranslation } from "react-i18next";
import { TextControl } from "@keycloak/keycloak-ui-shared";

import { convertToName } from "./DynamicComponents";
import { NumberComponentProps } from "./components";

export const NumberComponent = ({
name,
label,
helpText,
...props
}: NumberComponentProps) => {
const { t } = useTranslation();

return (
<TextControl
name={convertToName(name!)}
type="number"
label={t(label!)}
labelIcon={t(helpText!)}
data-testid={name}
{...props}
/>
);
};
11 changes: 11 additions & 0 deletions js/apps/admin-ui/src/components/dynamic/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@ import { StringComponent } from "./StringComponent";
import { TextComponent } from "./TextComponent";
import { UrlComponent } from "./UrlComponent";
import { UserProfileAttributeListComponent } from "./UserProfileAttributeListComponent";
import { IntComponent } from "./IntComponent";
import { NumberComponent } from "./NumberComponent";

export type ComponentProps = Omit<ConfigPropertyRepresentation, "type"> & {
isDisabled?: boolean;
isNew?: boolean;
stringify?: boolean;
};

export type NumberComponentProps = ComponentProps & {
min?: number;
max?: number;
};

type ComponentType =
| "String"
| "Text"
| "Integer"
| "Number"
| "boolean"
| "List"
| "Role"
Expand All @@ -46,6 +55,8 @@ export const COMPONENTS: {
String: StringComponent,
Text: TextComponent,
boolean: BooleanComponent,
Integer: IntComponent,
Number: NumberComponent,
List: ListComponent,
Role: RoleComponent,
Script: ScriptComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export interface ConfigPropertyRepresentation {
options?: string[];
secret?: boolean;
required?: boolean;
placeholder?: string;
}
1 change: 1 addition & 0 deletions js/libs/ui-shared/src/controls/TextControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type TextControlProps<
isDisabled?: boolean;
helperText?: string;
"data-testid"?: string;
type?: string;
};

export const TextControl = <
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
*/
public class ProviderConfigProperty {
public static final String BOOLEAN_TYPE="boolean";

/**
* Integral Value
*/
public static final String INTEGER_TYPE="Integer";

/**
* Arbitrary number, e.g. integral, floating-point.
*/
public static final String NUMBER_TYPE="Number";

public static final String STRING_TYPE="String";

/**
Expand Down

0 comments on commit 368c1f5

Please sign in to comment.