zack commited on
Commit
5aa9199
·
1 Parent(s): 08156fb

🔧 Update custom node component

Browse files
frontend/src/components/Nodes/Custom.js CHANGED
@@ -1,5 +1,42 @@
1
  import React, { useCallback, useEffect, useRef, useState } from "react"
2
- // import { Handle, Position } from "react-flow-renderer"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import {TbResize} from 'react-icons/tb'
4
  import {BiCube, BiRefresh} from 'react-icons/bi'
5
  import {BsTrash} from 'react-icons/bs'
@@ -36,24 +73,13 @@ export default function CustomNodeIframe({id, data}){
36
  },
37
  });
38
 
39
- const isFetchable =useCallback(async () => {
40
- return fetch(data.host, {mode: 'no-cors'}).then((res) => {
41
- return true
42
- }).catch((err)=>{
43
- return false
44
- })
45
- }, [data.host])
46
-
47
  useEffect(() => {
48
  const fetched = setInterval(
49
  async () => {
50
- const fetch = await isFetchable()
51
- if (fetch){
52
- setReachable(true)
53
- clearInterval(fetched)
54
- }
55
  },1000)
56
- },[isFetchable])
57
 
58
 
59
  return (
@@ -64,7 +90,7 @@ export default function CustomNodeIframe({id, data}){
64
 
65
  <div className={` flex ${!collapsed ? '' : 'w-0 hidden'}`}>
66
  <div title="Adjust Node Size" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Violet rounded-xl" onClick={() => {setSizeAdjuster((size) => !size)}}><TbResize className="h-full w-full text-white p-1"/></div>
67
- <a href={data.host} target="_blank" rel="noopener noreferrer"><div title="Gradio Host Site" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Pink rounded-xl"><BiCube className="h-full w-full text-white p-1"/></div></a>
68
  <div title="Delete Node" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Red rounded-xl" onClick={() => {data.delete([{id}])}}><BsTrash className="h-full w-full text-white p-1"/></div>
69
  <div title="Refresh Node" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Orange rounded-xl" onClick={() => {setRefresh((old) => old++)}}><BiRefresh className="h-full w-full text-white p-1"/></div>
70
  </div>
@@ -75,7 +101,7 @@ export default function CustomNodeIframe({id, data}){
75
  <div id="draggable" className={`absolute h-full w-full ${data.colour} shadow-2xl rounded-xl -z-20`}></div>
76
  <iframe id="iframe"
77
  key={refresh}
78
- src={data.host}
79
  title={data.label}
80
  frameBorder="0"
81
  className=" p-[0.6rem] -z-10 h-full w-full ml-auto mr-auto overflow-y-scroll"/>
 
1
  import React, { useCallback, useEffect, useRef, useState } from "react"
2
+ import { Modal, Message } from 'semantic-ui-react';
3
+ import { useFetch } from '../../hooks/useFetch';
4
+ import Debug from '../../utilities/Debug';
5
+
6
+ /**
7
+ * Custom hook to check iframe reachability.
8
+ * @param {string} url - The URL to check for reachability.
9
+ * @returns {boolean} - True if reachable, false otherwise.
10
+ */
11
+ const useCheckReachability = (url) => {
12
+ const { data, error } = useFetch(url);
13
+ Debug.log('Checking reachability for:', url);
14
+ return { isReachable: !!data, error };
15
+ };
16
+
17
+ /**
18
+ * A component to render a debug message.
19
+ * @param {string} message - The debug message to display.
20
+ */
21
+ const DebugMessage = ({ message }) => {
22
+ useEffect(() => {
23
+ Debug.log(message);
24
+ }, [message]);
25
+
26
+ return null; // This component does not render anything.
27
+ };
28
+
29
+ /**
30
+ * A function to create a one-purpose utility.
31
+ * @param {Function} fn - The function to execute.
32
+ * @param {Array} args - The arguments to pass to the function.
33
+ * @returns {any} - The result of the function execution.
34
+ */
35
+ const executeUtility = (fn, ...args) => {
36
+ Debug.log('Executing utility function with args:', args);
37
+ return fn(...args);
38
+ };
39
+
40
  import {TbResize} from 'react-icons/tb'
41
  import {BiCube, BiRefresh} from 'react-icons/bi'
42
  import {BsTrash} from 'react-icons/bs'
 
73
  },
74
  });
75
 
 
 
 
 
 
 
 
 
76
  useEffect(() => {
77
  const fetched = setInterval(
78
  async () => {
79
+ setReachable(true)
80
+ clearInterval(fetched)
 
 
 
81
  },1000)
82
+ },[])
83
 
84
 
85
  return (
 
90
 
91
  <div className={` flex ${!collapsed ? '' : 'w-0 hidden'}`}>
92
  <div title="Adjust Node Size" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Violet rounded-xl" onClick={() => {setSizeAdjuster((size) => !size)}}><TbResize className="h-full w-full text-white p-1"/></div>
93
+ <a href={data.url} target="_blank" rel="noopener noreferrer"><div title="Gradio Host Site" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Pink rounded-xl"><BiCube className="h-full w-full text-white p-1"/></div></a>
94
  <div title="Delete Node" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Red rounded-xl" onClick={() => {data.delete([{id}])}}><BsTrash className="h-full w-full text-white p-1"/></div>
95
  <div title="Refresh Node" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Orange rounded-xl" onClick={() => {setRefresh((old) => old++)}}><BiRefresh className="h-full w-full text-white p-1"/></div>
96
  </div>
 
101
  <div id="draggable" className={`absolute h-full w-full ${data.colour} shadow-2xl rounded-xl -z-20`}></div>
102
  <iframe id="iframe"
103
  key={refresh}
104
+ src={data.url}
105
  title={data.label}
106
  frameBorder="0"
107
  className=" p-[0.6rem] -z-10 h-full w-full ml-auto mr-auto overflow-y-scroll"/>