Skip to content

Commit 4363da6

Browse files
committed
feat: add notice window when no spaces created
1 parent 801e623 commit 4363da6

File tree

1 file changed

+98
-57
lines changed

1 file changed

+98
-57
lines changed

nebulagraph-gephi-exchange.py

+98-57
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def query_nebulagraph(
262262
results.append(result)
263263
connection_pool.close()
264264
except Exception as e:
265-
st.warning(e)
265+
st.warning(e, icon="⚠️")
266266
return None
267267
return results
268268

@@ -342,6 +342,9 @@ def get_gephi_graph(g) -> None:
342342
if "queries" not in st.session_state:
343343
queries = persist("queries")
344344
st.session_state.queries = []
345+
if "connect_clicked" not in st.session_state:
346+
connect_clicked = persist("connect_clicked")
347+
st.session_state.connect_clicked = False
345348

346349
st.sidebar.markdown("---")
347350

@@ -350,12 +353,13 @@ def get_gephi_graph(g) -> None:
350353
"SHOW SPACES;", None, graphd_host, graphd_port, user, password
351354
)
352355
if results is None or len(results) == 0:
353-
st.warning("connect failed")
356+
st.warning("connect failed", icon="⚠️")
354357
st.stop()
355358
result: ResultSet = results[0]
356359
spaces_df = result_to_df(result)
357360
st.session_state.space_name_list = spaces_df["Name"].tolist()
358361
# st.sidebar.dataframe(st.session_state.space_name_list)
362+
st.session_state.connect_clicked = True
359363
persist("space_name")
360364
# clear all results
361365
st.session_state.results = None
@@ -376,56 +380,88 @@ def get_gephi_graph(g) -> None:
376380
]
377381
)
378382

383+
float_window_css = """
384+
<style>
385+
.floating-window {
386+
position: absolute;
387+
z-index: 1;
388+
left: -20px;
389+
top: -10px;
390+
right: -20px;
391+
bottom: 0.1px;
392+
background-color: rgba(25, 49, 75, 0.30);
393+
padding: 10px;
394+
border: 1px solid #48494D;
395+
border-radius: 10px;
396+
min-height: 720px;
397+
backdrop-filter: blur(5px);
398+
}
399+
.text-container {
400+
position: absolute;
401+
z-index: 1;
402+
left: 50%;
403+
top: 50%;
404+
transform: translate(-50%, -50%);
405+
background-color: #0E1118;
406+
padding: 20px 2px;
407+
border: 0px solid #48494D;
408+
border-radius: 10px;
409+
min-height: 60px;
410+
min-width: 300px;
411+
white-space: nowrap;
412+
# box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
413+
}
414+
</style>
415+
416+
"""
417+
nebula_logo_svg = """<img
418+
src="https://raw.githubusercontent.com/nebula-contrib/nebulagraph-docker-ext/main/nebulagraph.svg"
419+
alt=" "
420+
style="height: 16px; width: auto;">"""
421+
float_window_css_no_space = float_window_css.replace(
422+
"backdrop-filter: blur(5px);", "").replace(
423+
"min-height: 60px;",
424+
"min-height: 124px;"
425+
).replace(
426+
"min-width: 300px;",
427+
"min-width: 440px;"
428+
)
429+
430+
float_window_html = f"""
431+
<div class="floating-window">
432+
<div class="text-container">
433+
<p style=
434+
"position: absolute;
435+
top: 50%; left: 50%;
436+
transform: translate(-50%, -50%);
437+
color: #FAFAFA;
438+
">
439+
🔗  Connect to <span> </span>{nebula_logo_svg} <span style="color: #009EFF;"><strong>Nebula</strong></span>Graph first.
440+
</p>
441+
</div>
442+
</div>
443+
"""
444+
445+
float_window_html_no_space = float_window_html.replace(
446+
"Graph first.",
447+
f"Graph done !<br/>"
448+
f"🔎  Opps... no graph spaces found. <br/>"
449+
f"<span style='color: #88846F;'>💡  Try creating one from {nebula_logo_svg} "
450+
f"Studio's starter dataset.</span>").replace(
451+
"🔗", "✅")
452+
453+
379454
with tab_query:
380-
if len(st.session_state.space_name_list) == 0:
455+
if st.session_state.connect_clicked:
456+
if len(st.session_state.space_name_list) == 0:
381457
# floating window before login
458+
st.markdown(
459+
float_window_css_no_space + float_window_html_no_space,
460+
unsafe_allow_html=True,
461+
)
462+
else:
382463
st.markdown(
383-
"""
384-
<style>
385-
.floating-window {
386-
position: absolute;
387-
z-index: 1;
388-
left: -20px;
389-
top: -10px;
390-
right: -20px;
391-
bottom: 0.1px;
392-
background-color: rgba(25, 49, 75, 0.30);
393-
padding: 10px;
394-
border: 1px solid #48494D;
395-
border-radius: 10px;
396-
min-height: 720px;
397-
backdrop-filter: blur(5px);
398-
}
399-
.text-container {
400-
position: absolute;
401-
z-index: 1;
402-
left: 300px;
403-
top: 300px;
404-
right: 300px;
405-
bottom: 300px;
406-
background-color: #0E1118;
407-
padding: 10px;
408-
border: 0px solid #48494D;
409-
border-radius: 10px;
410-
min-height: 20px;
411-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
412-
}
413-
</style>
414-
<div class="floating-window">
415-
<div class="text-container">
416-
<p style=
417-
"position: absolute;
418-
top: 50%; left: 50%;
419-
transform: translate(-50%, -50%);
420-
color: #FAFAFA;
421-
">
422-
🔗  Connect to <span> </span>
423-
<img src="https://raw.githubusercontent.com/nebula-contrib/nebulagraph-docker-ext/main/nebulagraph.svg" alt=" " style="height: 16px; width: auto;">
424-
<span style="color: #009EFF;"><strong>Nebula</strong></span>Graph first.
425-
</p>
426-
</div>
427-
</div>
428-
""",
464+
float_window_css + float_window_html,
429465
unsafe_allow_html=True,
430466
)
431467

@@ -460,11 +496,16 @@ def get_gephi_graph(g) -> None:
460496
)
461497

462498
with buttons:
463-
space_name = st.selectbox(
464-
"Graph Space",
465-
st.session_state.space_name_list,
466-
key="space_name",
467-
)
499+
try:
500+
space_name = st.selectbox(
501+
"Graph Space",
502+
st.session_state.space_name_list,
503+
key="space_name",
504+
)
505+
except Exception as e:
506+
st.warning("Failed to get spaces, reload and reconnect, please.",
507+
icon="😵‍💫")
508+
st.stop()
468509

469510
if st.button(
470511
"Execute",
@@ -482,7 +523,7 @@ def get_gephi_graph(g) -> None:
482523
)
483524

484525
if results is None or len(results) == 0:
485-
st.warning("query failed")
526+
st.warning("query failed", icon="⚠️")
486527
st.stop()
487528
st.session_state.results = results
488529

@@ -515,7 +556,7 @@ def get_gephi_graph(g) -> None:
515556
for result in st.session_state.results:
516557
if result.error_code() != 0:
517558
st.markdown("---")
518-
st.warning(result.error_msg())
559+
st.warning(result.error_msg(), icon="⚠️")
519560
st.stop()
520561

521562
if st.session_state.excuted_clicked:
@@ -616,7 +657,7 @@ def get_gephi_graph(g) -> None:
616657
hide_index=True,
617658
)
618659
except Exception as e:
619-
st.warning(e)
660+
st.warning(e, icon="⚠️")
620661
# df table end
621662

622663

0 commit comments

Comments
 (0)