-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Integrate FastHTML replacing FastAPI and React #81
base: master
Are you sure you want to change the base?
Conversation
b7cde84
to
e0c22bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some initial comments. As the PR is still WIP anyway, I've mostly only looked at the greater ideas, and not too much into the details yet. (Except for the comment about OOB swaps :p )
capella_model_explorer/icons.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make more sense to store all these icons as individual *.svg
files and serve them somewhere below /static
. This allows the browser to cache the files and optimize rendering, since it knows that they must look the same (in the absence of CSS shenanigans, that is). It also makes the licensing situation a bit clearer, as there can be individual license notices attached to each file. Plus, it slightly improves server performance as well, as there's no longer the need to construct several intermediate objects over and over just to show a static image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about having .svg
files instead of py components for SVGs.
Do not want to do that because we depend on Tailwind CSS utility classes which will be listed in the class
(respectively FastHTML's cls
) attribute of the <svg>
tags sent to the client instead of attrs of the <svg>
tag itself.
With external .svg
file we would have final values for colors. A solution with string replacements after the reading of SVG files is sth. I do not really want to implement.
We want to be able to configure colors
<svg stroke="black"> <!-- light theme -->
<svg stroke="white"> <!-- dark theme -->
Example pseudo-code of current implementation:
constants.py
STROKE_ACCENT: t.Final[dict[str, str]] = {
"dark": "white",
"light": "black"
}
icons.py
from fasthtml import svg
import constants as c
THEME: str = "dark"
def icon() -> t.Any:
return fh.Svg(
svg.Path(...),
cls=f"stroke-{c.STROKE_ACCENT[THEME]}""
)
I am open for discussion. It has for sure benefits when dealing with .svg
files which can easily be edited/ downloaded etc..
ft.Div(model_element["uuid"], cls="text-xs text-sky-700") | ||
if state.show_uuids | ||
else None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, we'll probably want to make this a client- (or session-) specific setting that's configurable via some settings UI.
capella_model_explorer/main.py
Outdated
"w-full", | ||
), | ||
hx_trigger="load", | ||
hx_get="/rendered-template", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we know the template and element IDs at this point, we can easily just pass them along here as part of this request, instead of storing them in the state module.
This would also work well together with an OOB breadcrumb swap initiated by /rendered-template
itself (as detailed in another comment), these IDs would just have to be passed down into the breadcrumbs component then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
8e79d21
to
2391551
Compare
ed5cec4
to
cd465d0
Compare
6d7bbb9
to
0134fe1
Compare
Please add a way to disable that. uvicorn's live reloading feature injects a websocket connection that reloads the page automatically. Problem with that is that it also tries to reload the page when that websocket connection breaks, for example due to the server going down. This reload then of course fails, because the server is down now, and just shows an error page. So the effect is that you can't just keep an old version of a page opened in the background. I want to be able to do just that, for example to compare against a newer template version, or just to look at the current DOM and make template changes without constantly being thrown around in the page inspector due to the reloads. Also, the feature should be disabled when deploying the docker image to e.g. the Collab Manager, where the templates are immutable anyway. |
6b86c3c
to
cdd0938
Compare
This introduces a major change by replacing the FastAPI backend and React frontend with FastHTML. The integration involves reusing existing code where possible, but also includes significant rewrites that affect the application's behavior. This update aims to enhance performance and streamline the development process. This commit also introduces project management tool which replaces the Makefile with a Python CLI tool. The tool manages the project, including building the Docker image, running the app in a container, and running the app locally. The tool also builds the Tailwind CSS stylesheet. The app always runs with hot template reloading enabled. In development mode, it also runs with hot code reloading. After cloning the project, one can get further information by running: ```bash cme -h cme run -h cme build -h ``` Co-authored-by: Martin Lehmann <[email protected]>
cdd0938
to
d4c4c78
Compare
fh.HighlightJS(langs=["python"]), | ||
fh.Link( | ||
rel="stylesheet", | ||
href=f"{ROUTE_PREFIX}/static/css/main-{cme.__version__}.min.css", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add hash as ?v=HASH
to URL so that the CSS is always reloaded when the input.css
is changed (especially when in local-dev
, where the app version is stable)
Note, that it is sometimes needed to empty cache and hard reload the app in the | ||
browser, when styles are not applied correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this, when we serve the main-vx.y.z..min.css
with a ?v=HASH
query parameter.
This introduces several major changes by
The project can be managed including
New is also a hot template reloading, which is enabled per default.
In development mode, it also runs with hot code reloading.
The FastHTML integration involves reusing existing code where possible, but also includes significant rewrites that affect the application's behavior. This update aims to enhance performance and streamline the development process.
Open issues/ topics
ROUTE_PREFIX
work for static filesdocker
must set tool versions via three--build-arg
specsdiagramViewer.js
work (scaling must be fixed for diagrams with a height which is greater than the width)README.md
/CONTRIBUTING.md
!
) that this PR introduces breaking changes.Integration in Capella Collaboration Manager
MODEL_ENTRYPOINT
-->CME_MODEL
andROUTE_PREFIX
-->CME_ROUTE_PREFIX
Align this with main contributor @MoritzWeber0 of https://github.com/DSD-DBS/capella-collab-manager.gitCME_LIVE_MODE=0
in the tool config