From 350b719db99095a7725e4914b76d5c0bb2c0880a Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Mon, 3 Apr 2023 17:19:52 +0800 Subject: [PATCH] feat: add a few default options in admin/Home (#39) --- tabby/admin/Home.py | 34 ++++++++++++++++++- tabby/admin/components/monaco/__init__.py | 12 ++++--- .../monaco/frontend/build/asset-manifest.json | 4 +-- .../monaco/frontend/build/index.html | 2 +- .../js/{main.15818978.js => main.c14dfe27.js} | 4 +-- ...CENSE.txt => main.c14dfe27.js.LICENSE.txt} | 0 .../components/monaco/frontend/src/Monaco.jsx | 22 +++++++----- 7 files changed, 60 insertions(+), 18 deletions(-) rename tabby/admin/components/monaco/frontend/build/static/js/{main.15818978.js => main.c14dfe27.js} (99%) rename tabby/admin/components/monaco/frontend/build/static/js/{main.15818978.js.LICENSE.txt => main.c14dfe27.js.LICENSE.txt} (100%) diff --git a/tabby/admin/Home.py b/tabby/admin/Home.py index c88130a..04db98b 100644 --- a/tabby/admin/Home.py +++ b/tabby/admin/Home.py @@ -16,5 +16,37 @@ st.set_page_config(page_title="Tabby Admin - Home") st.markdown("## Tabby") st.markdown(" ".join(map(make_badge_markdown, SERVICES))) +st.markdown("---") -monaco.st_monaco() +SNIPPETS = { + "Clear": "# Write some code ...", + "Fibonacci": "def fib(n):", + "Parse JSON": """def parse_json_lines(filename: str) -> List[Any]: + output = [] + with open(filename, "r", encoding="utf-8") as f: +""", + "Data ORM": """import birdchirp + +from birdchirp.model.chirp import chirp +from birdchirp.db.mysql import MysqlDb + +class User: + def __init__(self, user_id): + self.user_id = user_id + self.db = MysqlDb() + + def get_avatar""", +} + + +def code_editor(): + code = "" + cols = st.columns(len(SNIPPETS)) + for col, (k, v) in zip(cols, SNIPPETS.items()): + with col: + if st.button(k): + code = v + monaco.st_monaco(key="default", code=code) + + +code_editor() diff --git a/tabby/admin/components/monaco/__init__.py b/tabby/admin/components/monaco/__init__.py index 069d68c..f191080 100644 --- a/tabby/admin/components/monaco/__init__.py +++ b/tabby/admin/components/monaco/__init__.py @@ -30,8 +30,8 @@ else: # `declare_component` and call it done. The wrapper allows us to customize # our component's API: we can pre-process its input args, post-process its # output value, and add a docstring for users. -def st_monaco(tabby_server_url="http://localhost:5000", key=None): - _editor_func(tabby_server_url=tabby_server_url, key=key) +def st_monaco(key, tabby_server_url=None, code=None): + _editor_func(tabby_server_url=tabby_server_url, code=code, key=key) # Add some test code to play with the component while it's in development. @@ -40,5 +40,9 @@ def st_monaco(tabby_server_url="http://localhost:5000", key=None): if not _RELEASE: import streamlit as st - tabby_server_url = st.text_input("Tabby Server URL", value="http://localhost:5000") - st_monaco(tabby_server_url) + code = st.text_input("code") + set_code = st.button("Set code") + if set_code: + st_monaco(code=code, key="1") + else: + st_monaco(key="1") diff --git a/tabby/admin/components/monaco/frontend/build/asset-manifest.json b/tabby/admin/components/monaco/frontend/build/asset-manifest.json index dc397c1..65084e0 100644 --- a/tabby/admin/components/monaco/frontend/build/asset-manifest.json +++ b/tabby/admin/components/monaco/frontend/build/asset-manifest.json @@ -1,9 +1,9 @@ { "files": { - "main.js": "./static/js/main.15818978.js", + "main.js": "./static/js/main.c14dfe27.js", "index.html": "./index.html" }, "entrypoints": [ - "static/js/main.15818978.js" + "static/js/main.c14dfe27.js" ] } diff --git a/tabby/admin/components/monaco/frontend/build/index.html b/tabby/admin/components/monaco/frontend/build/index.html index 0d0d4ec..d31a3ad 100644 --- a/tabby/admin/components/monaco/frontend/build/index.html +++ b/tabby/admin/components/monaco/frontend/build/index.html @@ -1 +1 @@ -Streamlit Component
+Streamlit Component
diff --git a/tabby/admin/components/monaco/frontend/build/static/js/main.15818978.js b/tabby/admin/components/monaco/frontend/build/static/js/main.c14dfe27.js similarity index 99% rename from tabby/admin/components/monaco/frontend/build/static/js/main.15818978.js rename to tabby/admin/components/monaco/frontend/build/static/js/main.c14dfe27.js index f4f2716..a70d7cc 100644 --- a/tabby/admin/components/monaco/frontend/build/static/js/main.15818978.js +++ b/tabby/admin/components/monaco/frontend/build/static/js/main.c14dfe27.js @@ -1,2 +1,2 @@ -/*! For license information please see main.15818978.js.LICENSE.txt */ -!function(){var e={861:function(e,t,n){"use strict";var r=n(214),i={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},a={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},o={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},u={};function s(e){return r.isMemo(e)?o:u[e.$$typeof]||i}u[r.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},u[r.Memo]=o;var l=Object.defineProperty,c=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols,h=Object.getOwnPropertyDescriptor,d=Object.getPrototypeOf,p=Object.prototype;e.exports=function e(t,n,r){if("string"!==typeof n){if(p){var i=d(n);i&&i!==p&&e(t,i,r)}var o=c(n);f&&(o=o.concat(f(n)));for(var u=s(t),y=s(n),v=0;v