zack commited on
Commit
f96cac1
1 Parent(s): e6949ce

:sparkles: Update modal and navbar components

Browse files
frontend/src/components/Modal/importer.js CHANGED
@@ -7,12 +7,14 @@ import { useState } from 'react'
7
  import { BsSearch } from 'react-icons/bs';
8
 
9
  export default function Import(props) {
10
- const [tab, setTab] = useState("gradio")
11
  const [subTab, setSubTab] = useState(0)
12
  const [embedUrl, setEmbedUrl] = useState("");
13
  const [vmid, setVmid] = useState('');
14
  const [node, setNode] = useState('');
15
  const [iframeSrc, setIframeSrc] = useState("");
 
 
16
 
17
  const handleSubmit = async (e) => {
18
  e.preventDefault();
@@ -21,27 +23,27 @@ export default function Import(props) {
21
  props.onAddEmbed({ url: iframeSrc, type: 'embed' });
22
  };
23
 
24
- // const handleProxmoxSubmit = async (e) => {
25
- // e.preventDefault();
26
- // const requestData = { vmid, node };
27
- // fetch("http://localhost:2000/api/proxmox/vnc", {
28
- // method: "POST",
29
- // headers: { 'Content-Type': 'application/json' },
30
- // body: JSON.stringify(requestData)
31
- // })
32
- // .then(response => response.json())
33
- // .then(data => {
34
- // if(data.iframe_src) {
35
- // setIframeSrc(data.iframe_src);
36
- // props.onAddEmbed({ url: data.iframe_src, type: 'embed' });
37
- // } else {
38
- // console.error("Failed to get iframe source URL");
39
- // }
40
- // })
41
- // .catch(error => {
42
- // console.error("Error fetching iframe source URL:", error);
43
- // });
44
- // };
45
 
46
  return (<div>
47
  <Modal
@@ -128,8 +130,17 @@ export default function Import(props) {
128
  <Shared type="streamlit" textHandler={props.textHandler} appendHandler={props.appendHandler} handelError={props.handelError} catch={props.catch} />
129
  </div>
130
  }
 
 
131
  {tab === "IframeURL" && (
132
  <form onSubmit={handleSubmit}>
 
 
 
 
 
 
 
133
  <input
134
  type="text"
135
  placeholder="Enter iframe link here..."
 
7
  import { BsSearch } from 'react-icons/bs';
8
 
9
  export default function Import(props) {
10
+ // const [tab, setTab] = useState("gradio")
11
  const [subTab, setSubTab] = useState(0)
12
  const [embedUrl, setEmbedUrl] = useState("");
13
  const [vmid, setVmid] = useState('');
14
  const [node, setNode] = useState('');
15
  const [iframeSrc, setIframeSrc] = useState("");
16
+ const [tab, setTab] = useState('')
17
+
18
 
19
  const handleSubmit = async (e) => {
20
  e.preventDefault();
 
23
  props.onAddEmbed({ url: iframeSrc, type: 'embed' });
24
  };
25
 
26
+ const handleProxmoxSubmit = async (e) => {
27
+ e.preventDefault();
28
+ const requestData = { vmid, node };
29
+ fetch("http://localhost:2000/api/proxmox/vnc", {
30
+ method: "POST",
31
+ headers: { 'Content-Type': 'application/json' },
32
+ body: JSON.stringify(requestData)
33
+ })
34
+ .then(response => response.json())
35
+ .then(data => {
36
+ if (data.iframe_src) {
37
+ setIframeSrc(data.iframe_src);
38
+ props.onAddEmbed({ url: data.iframe_src, type: 'embed' });
39
+ } else {
40
+ console.error("Failed to get iframe source URL");
41
+ }
42
+ })
43
+ .catch(error => {
44
+ console.error("Error fetching iframe source URL:", error);
45
+ });
46
+ };
47
 
48
  return (<div>
49
  <Modal
 
130
  <Shared type="streamlit" textHandler={props.textHandler} appendHandler={props.appendHandler} handelError={props.handelError} catch={props.catch} />
131
  </div>
132
  }
133
+
134
+ // Update the form to include a title input
135
  {tab === "IframeURL" && (
136
  <form onSubmit={handleSubmit}>
137
+ <input
138
+ type="text"
139
+ placeholder="Enter iframe title here..."
140
+ value={iframeTitle}
141
+ onChange={(e) => setIframeTitle(e.target.value)}
142
+ className="input"
143
+ />
144
  <input
145
  type="text"
146
  placeholder="Enter iframe link here..."
frontend/src/components/Navagation/navbar.js CHANGED
@@ -23,7 +23,8 @@ export default class Navbar extends Component{
23
  emoji : props.emoji || [],
24
  mode : false,
25
  modal : false,
26
- error : false
 
27
  }
28
 
29
  }
@@ -33,10 +34,6 @@ export default class Navbar extends Component{
33
 
34
  }
35
 
36
- /**
37
- * Asynchronously call the Flask api server every second to check if there exist a gradio application info
38
- * @return null
39
- */
40
  fetch_classes = async () => {
41
  try {
42
  setInterval( async () => {
@@ -54,9 +51,6 @@ export default class Navbar extends Component{
54
  }
55
  }
56
 
57
- /**
58
- * Append new node from the user
59
- */
60
  appendStreamNode = async (type) => {
61
  const pattern = {
62
  local : new RegExp('^https?://(localhost)(:[0-9]+)?(/)?$'),
@@ -88,13 +82,9 @@ export default class Navbar extends Component{
88
  }).catch((err)=> this.setState({'text': '','name' : '', 'error' : true,}))
89
  }
90
 
91
- /**
92
- * Render a tab for the Proxmox VNC that can be dragged into React Flow
93
- */
94
  renderProxmoxVncTab = () => {
95
- // Assuming the Proxmox VNC tab information is stored in the state
96
  const { proxmoxVncInfo } = this.state;
97
- if (!proxmoxVncInfo) return null; // If no Proxmox VNC info, don't render anything
98
 
99
  return (
100
  <li onDragStart={(event) => this.onDragStart(event, 'proxmoxVNC', proxmoxVncInfo, -1)}
@@ -108,22 +98,11 @@ export default class Navbar extends Component{
108
  );
109
  }
110
 
111
- /**
112
- * error check the user input
113
- * @param {*} bool boolean of the current state of the modal
114
- */
115
  handelModal = (bool) => {
116
  this.setState({'error' : !bool ? false : this.state.error ,
117
  'modal' : bool})
118
  }
119
 
120
- /**
121
- * when dragged get all the information needed
122
- * @param {*} event
123
- * @param {*} nodeType string 'custom' node type
124
- * @param {*} item object information returned from the api
125
- * @param {*} index current index
126
- */
127
  onDragStart = (event, nodeType, item, index) => {
128
  event.dataTransfer.setData('application/reactflow', nodeType);
129
  event.dataTransfer.setData('application/style', JSON.stringify({colour : this.state.colour[index], emoji : this.state.emoji[index] }))
@@ -131,12 +110,6 @@ export default class Navbar extends Component{
131
  event.dataTransfer.effectAllowed = 'move';
132
  };
133
 
134
- /**
135
- * droped event that occurs when the user drops the Tab within the tash div.
136
- * The function just deletes all nodes within React-Flow enviorment related,
137
- * and remove it from the api.
138
- * @param {*} e drop event
139
- */
140
  onDragDrop = (e) => {
141
  e.preventDefault();
142
  var item = JSON.parse(e.dataTransfer.getData('application/item'));
@@ -146,20 +119,12 @@ export default class Navbar extends Component{
146
 
147
  }
148
 
149
- /**
150
- * update the tabs within the navbar
151
- * @param {*} e current menu
152
- * @param {*} d integer variable of the diffence between the current menu and new menu updated ment
153
- */
154
  handelTabs = async (e, d) => {
155
- // if less then 0 we must remove colour's and emoji's
156
- // get index of the object
157
- // remove
158
  var c = []
159
  var j = []
160
  if (d.length - e.length === 0) return
161
  else if(d.length - e.length < 0){
162
- var a = this.state.menu.filter(item => e.includes(item)) // get the items not in menu anymore
163
  c = this.state.colour
164
  j = this.state.emoji
165
  for(var k=0; k < d.length; k++){
@@ -168,7 +133,6 @@ export default class Navbar extends Component{
168
  }
169
  this.setState({'colour' : c, 'emoji' : j})
170
  }else{
171
- //append new colours
172
  for(var i =0; i < d.length; i++){
173
  c.push(random_colour(i === 0 ? null : c[i-1]));
174
  j.push(random_emoji(i === 0 ? null : c[i-1]));
@@ -184,28 +148,14 @@ export default class Navbar extends Component{
184
  this.setState({'error' : boolean})
185
  }
186
 
187
- /**
188
- * handel navagation open and close function
189
- */
190
  handelNavbar = () => {
191
  this.setState({'open' : !this.state.open})
192
  }
193
 
194
- /**
195
- *
196
- * @param {*} e : event type to get the target value of the current input
197
- * @param {*} type : text | name string that set the changed value of the input to the current value
198
- */
199
  updateText = (e, type) => {
200
  this.setState({[`${type}`] : e.target.value })
201
  }
202
 
203
- /**
204
- *
205
- * @param {*} item : object infomation from the flask api
206
- * @param {*} index : current index with in the list
207
- * @returns div component that contians infomation of gradio
208
- */
209
  subComponents(item, index){
210
 
211
  return(<>
@@ -262,4 +212,3 @@ export default class Navbar extends Component{
262
  </div>)
263
  }
264
  }
265
-
 
23
  emoji : props.emoji || [],
24
  mode : false,
25
  modal : false,
26
+ error : false,
27
+ proxmoxVncInfo: null // Added missing state for Proxmox VNC info
28
  }
29
 
30
  }
 
34
 
35
  }
36
 
 
 
 
 
37
  fetch_classes = async () => {
38
  try {
39
  setInterval( async () => {
 
51
  }
52
  }
53
 
 
 
 
54
  appendStreamNode = async (type) => {
55
  const pattern = {
56
  local : new RegExp('^https?://(localhost)(:[0-9]+)?(/)?$'),
 
82
  }).catch((err)=> this.setState({'text': '','name' : '', 'error' : true,}))
83
  }
84
 
 
 
 
85
  renderProxmoxVncTab = () => {
 
86
  const { proxmoxVncInfo } = this.state;
87
+ if (!proxmoxVncInfo) return null;
88
 
89
  return (
90
  <li onDragStart={(event) => this.onDragStart(event, 'proxmoxVNC', proxmoxVncInfo, -1)}
 
98
  );
99
  }
100
 
 
 
 
 
101
  handelModal = (bool) => {
102
  this.setState({'error' : !bool ? false : this.state.error ,
103
  'modal' : bool})
104
  }
105
 
 
 
 
 
 
 
 
106
  onDragStart = (event, nodeType, item, index) => {
107
  event.dataTransfer.setData('application/reactflow', nodeType);
108
  event.dataTransfer.setData('application/style', JSON.stringify({colour : this.state.colour[index], emoji : this.state.emoji[index] }))
 
110
  event.dataTransfer.effectAllowed = 'move';
111
  };
112
 
 
 
 
 
 
 
113
  onDragDrop = (e) => {
114
  e.preventDefault();
115
  var item = JSON.parse(e.dataTransfer.getData('application/item'));
 
119
 
120
  }
121
 
 
 
 
 
 
122
  handelTabs = async (e, d) => {
 
 
 
123
  var c = []
124
  var j = []
125
  if (d.length - e.length === 0) return
126
  else if(d.length - e.length < 0){
127
+ var a = this.state.menu.filter(item => e.includes(item))
128
  c = this.state.colour
129
  j = this.state.emoji
130
  for(var k=0; k < d.length; k++){
 
133
  }
134
  this.setState({'colour' : c, 'emoji' : j})
135
  }else{
 
136
  for(var i =0; i < d.length; i++){
137
  c.push(random_colour(i === 0 ? null : c[i-1]));
138
  j.push(random_emoji(i === 0 ? null : c[i-1]));
 
148
  this.setState({'error' : boolean})
149
  }
150
 
 
 
 
151
  handelNavbar = () => {
152
  this.setState({'open' : !this.state.open})
153
  }
154
 
 
 
 
 
 
155
  updateText = (e, type) => {
156
  this.setState({[`${type}`] : e.target.value })
157
  }
158
 
 
 
 
 
 
 
159
  subComponents(item, index){
160
 
161
  return(<>
 
212
  </div>)
213
  }
214
  }