diff --git a/ui/package.json b/ui/package.json index 119722ba5..2f1d4f2d2 100644 --- a/ui/package.json +++ b/ui/package.json @@ -1,6 +1,6 @@ { - "name": "smuiii", - "version": "0.1.0", + "name": "btp-manager-ui", + "version": "0.0.1", "private": true, "dependencies": { "@reduxjs/toolkit": "^2.2.3", diff --git a/ui/src/components/CreateBindingForm.tsx b/ui/src/components/CreateBindingForm.tsx index 60a378842..41dc9b1c7 100644 --- a/ui/src/components/CreateBindingForm.tsx +++ b/ui/src/components/CreateBindingForm.tsx @@ -36,71 +36,94 @@ function CreateBindingForm(props: any) { createdBinding.service_instance_id = props.instanceId ?? "" setLoading(true) - if (props.buttonPressed) { - axios - .put(api("service-bindings") + "/" + createdBinding.id, { - name: createdBinding.name, - service_instance_id: createdBinding.service_instance_id, - secret_name: createdBinding.secret_name, - secret_namespace: createdBinding.secret_namespace - }, { - params: { - sm_secret_name: props.secret.name, - sm_secret_namespace: props.secret.namespace + axios + .post(api("service-bindings"), { + name: createdBinding.name, + service_instance_id: createdBinding.service_instance_id, + secret_name: createdBinding.secret_name, + secret_namespace: createdBinding.secret_namespace + }, { + params: + { + sm_secret_name: props.secret!!.name, + sm_secret_namespace: props.secret!!.namespace } - }) - .then((response) => { - props.onCreate(response.data); - setError(undefined); - setLoading(false); - }) - .catch((error: ApiError) => { - setLoading(false); - setError(error); - setSuccess(""); - }); - } else { - axios - .post(api("service-bindings"), { - name: createdBinding.name, - service_instance_id: createdBinding.service_instance_id, - secret_name: createdBinding.secret_name, - secret_namespace: createdBinding.secret_namespace - }, { - params: - { - sm_secret_name: props.secret!!.name, - sm_secret_namespace: props.secret!!.namespace - } - }) - .then((response) => { - - // propagate the created binding - props.onCreate(response.data); - - // reset binding - const binding = new ServiceInstanceBinding() - binding.name = props.instanceName - binding.secret_name = props.instanceName + suffix - binding.secret_namespace = "default" - - setSuccess("Item with id " + response.data.name + " created."); - setCreatedBinding(binding); - setError(undefined); - setLoading(false); - }) - .catch((error: ApiError) => { - setLoading(false); - setError(error); - setSuccess(""); - }); - } + }) + .then((response) => { + + // propagate the created binding + props.onCreate(response.data); + + // reset binding + const binding = new ServiceInstanceBinding() + binding.name = props.instanceName + binding.secret_name = props.instanceName + suffix + binding.secret_namespace = "default" + + setSuccess("Item with id " + response.data.name + " created."); + setCreatedBinding(binding); + setError(undefined); + setLoading(false); + }) + .catch((error: ApiError) => { + setLoading(false); + setError(error); + setSuccess(""); + }); e.preventDefault(); e.stopPropagation(); return false; } + const handleSecretRestore = (e: any): boolean => { + e.preventDefault(); + + if (e.nativeEvent.submitter.localName === "ui5-multi-input") { + e.preventDefault() + return false; + } + + createdBinding.service_instance_id = props.instanceId ?? "" + + setLoading(true) + if (props.buttonPressed) { + axios + .put(api("service-bindings") + "/" + createdBinding.id, { + name: createdBinding.name, + service_instance_id: createdBinding.service_instance_id, + secret_name: createdBinding.secret_name, + secret_namespace: createdBinding.secret_namespace + }, { + params: { + sm_secret_name: props.secret.name, + sm_secret_namespace: props.secret.namespace + } + }) + .then((response) => { + const binding = new ServiceInstanceBinding() + binding.name = props.instanceName + binding.secret_name = props.instanceName + suffix + binding.secret_namespace = "default" + + props.onSecretRestore(); + + setSuccess("Item with id " + response.data.name + " updated."); + setCreatedBinding(binding); + setError(undefined); + setLoading(false); + }) + .catch((error: ApiError) => { + setLoading(false); + setError(error); + setSuccess(""); + }); + } + + e.preventDefault(); + return false; + } + useEffect(() => { setLoading(true) if (!Ok(props.instanceId)) { @@ -131,7 +154,7 @@ function CreateBindingForm(props: any) { setCreatedBinding(createdBinding) } - }, [createdBinding, props.instanceId, props.instanceName, props.onCreate, props.secret]); + }, [createdBinding, suffix, props.instanceId, props.instanceName, props.onCreate, props.secret, props.binding, props.buttonPressed]); const renderData = () => { @@ -146,7 +169,7 @@ function CreateBindingForm(props: any) { if (props.buttonPressed) { return ( + onSubmit={handleSecretRestore}> diff --git a/ui/src/components/ServiceBindingsList.tsx b/ui/src/components/ServiceBindingsList.tsx index c8fa4d0b2..48163d60d 100644 --- a/ui/src/components/ServiceBindingsList.tsx +++ b/ui/src/components/ServiceBindingsList.tsx @@ -23,7 +23,14 @@ const ServiceBindingsList = forwardRef((props: any, ref) => { const newbindings = new ServiceInstanceBindings(); newbindings.items = bindings?.items ?? []; setServiceInstanceBindings(newbindings); - } + }, + + refresh() { + console.log(bindings) + const newbindings = new ServiceInstanceBindings(); + newbindings.items = bindings?.items ?? []; + setServiceInstanceBindings(newbindings); + } })); diff --git a/ui/src/components/ServiceInstancesDetailsView.tsx b/ui/src/components/ServiceInstancesDetailsView.tsx index 55d0fcdfd..ee73e60d4 100644 --- a/ui/src/components/ServiceInstancesDetailsView.tsx +++ b/ui/src/components/ServiceInstancesDetailsView.tsx @@ -16,7 +16,7 @@ const ServiceInstancesDetailsView = forwardRef((props: any, ref) => { const [error] = useState(); const [instance, setInstance] = useState(); - const [binding, setBinding] = useState(); + const [binding, setBinding] = useState(new ServiceInstanceBinding()); const [secretRestoreButtonPressed, setSecretRestoreButtonPressed] = useState(false); const dialogRef = useRef(null); const listRef = useRef(null); @@ -35,6 +35,11 @@ const ServiceInstancesDetailsView = forwardRef((props: any, ref) => { setSecretRestoreButtonPressed(pressed) } + function onSecretRestore() { + // @ts-ignore + listRef.current.refresh() + } + useEffect(() => { setLoading(true); if (!Ok(props.instance)) { @@ -86,7 +91,7 @@ const ServiceInstancesDetailsView = forwardRef((props: any, ref) => { - onBindingAdded(binding)} instanceId={props.instance.id} instanceName={props.instance.name} buttonPressed={secretRestoreButtonPressed}/> + onBindingAdded(binding)} instanceId={props.instance.id} instanceName={props.instance.name} buttonPressed={secretRestoreButtonPressed} onSecretRestore={onSecretRestore} />