2021-11-08 09:46:03 +00:00
|
|
|
import React from "react";
|
|
|
|
import type { ConfigPropertyRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/authenticatorConfigInfoRepresentation";
|
|
|
|
|
|
|
|
import { COMPONENTS, isValidComponentType } from "./components";
|
|
|
|
|
|
|
|
type DynamicComponentProps = {
|
|
|
|
properties: ConfigPropertyRepresentation[];
|
2021-11-09 18:27:25 +00:00
|
|
|
selectedValues?: string[];
|
|
|
|
parentCallback?: (data: string[]) => void;
|
2021-11-08 09:46:03 +00:00
|
|
|
};
|
|
|
|
|
2022-02-16 14:53:45 +00:00
|
|
|
export const DynamicComponents = ({
|
|
|
|
properties,
|
|
|
|
...rest
|
|
|
|
}: DynamicComponentProps) => (
|
2021-11-08 09:46:03 +00:00
|
|
|
<>
|
|
|
|
{properties.map((property) => {
|
|
|
|
const componentType = property.type!;
|
2022-02-21 16:30:57 +00:00
|
|
|
if (isValidComponentType(componentType)) {
|
2021-11-08 09:46:03 +00:00
|
|
|
const Component = COMPONENTS[componentType];
|
2022-02-16 14:53:45 +00:00
|
|
|
return <Component key={property.name} {...property} {...rest} />;
|
2021-11-08 09:46:03 +00:00
|
|
|
} else {
|
|
|
|
console.warn(`There is no editor registered for ${componentType}`);
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
);
|