From 4f0d943e044c8a43ab9d22317209a46fb8a4e34b Mon Sep 17 00:00:00 2001 From: ewandor Date: Sat, 3 May 2025 21:24:39 +0200 Subject: [PATCH] Updating Foreign key to new CrudForm standard --- .../crud/components/widgets/foreign-key.tsx | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/gui/rpk-gui/src/lib/crud/components/widgets/foreign-key.tsx b/gui/rpk-gui/src/lib/crud/components/widgets/foreign-key.tsx index 263df08..cc2ccd6 100644 --- a/gui/rpk-gui/src/lib/crud/components/widgets/foreign-key.tsx +++ b/gui/rpk-gui/src/lib/crud/components/widgets/foreign-key.tsx @@ -6,7 +6,7 @@ import ClearIcon from '@mui/icons-material/Clear'; import EditIcon from '@mui/icons-material/Edit'; import NoteAddIcon from '@mui/icons-material/NoteAdd'; import React, { useState, useEffect, useContext, Fragment } from "react"; -import { useList, useOne } from "@refinedev/core"; +import { useForm, useList, useOne } from "@refinedev/core"; import { ResourceContext } from "../../contexts/ResourceContext"; import { CrudForm } from "../crud-form"; @@ -103,7 +103,7 @@ const RealAutocomplete = - - void } -const FormContainer = (props: FormContainerProps) => { - const { schemaName, resourceBasePath, resource, uiSchema = {}, id = undefined, onSuccess } = props; +const FormContainerEdit = (props: FormContainerProps) => { + const { schemaName, resourceBasePath, resource, uiSchema = {}, id, onSuccess } = props; + const { onFinish, query, formLoading } = useForm({ + resource: `${resourceBasePath}/${resource}`, + action: "edit", + id: id, + }); + + if (formLoading || query?.data === undefined) { + return + } return ( - onSuccess(data)} /> + { + onFinish(data); + onSuccess(data); + }} /> + + ) +} + +const FormContainerNew = (props: FormContainerProps) => { + const { schemaName, resourceBasePath, resource, uiSchema = {}, onSuccess } = props; + const { onFinish } = useForm({ + resource: `${resourceBasePath}/${resource}`, + action: "create" + }); + + return ( + + { + onFinish(data); + onSuccess(data); + }} /> ) }