added params to config giving users context (#28769)

fixes: #28616

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2024-04-30 14:05:29 +02:00 committed by GitHub
parent db6f35696c
commit 878be98122
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,6 +11,7 @@ import { useAlerts } from "../components/alert/Alerts";
import { DynamicComponents } from "../components/dynamic/DynamicComponents";
import { useRealm } from "../context/realm-context/RealmContext";
import { useFetch } from "../utils/useFetch";
import { useParams } from "../utils/useParams";
import { PAGE_PROVIDER, TAB_PROVIDER } from "./PageList";
import { toPage } from "./routes";
@ -31,6 +32,7 @@ export const PageHandler = ({
const [realm, setRealm] = useState<RealmRepresentation>();
const { addAlert, addError } = useAlerts();
const [id, setId] = useState(idAttribute);
const params = useParams();
useFetch(
async () =>
@ -51,11 +53,13 @@ export const PageHandler = ({
);
const onSubmit = async (component: ComponentRepresentation) => {
if (component.config)
if (component.config || params) {
component.config = Object.assign(component.config || {}, params);
Object.entries(component.config).forEach(
([key, value]) =>
(component.config![key] = Array.isArray(value) ? value : [value]),
);
}
try {
const updatedComponent = {
...component,