-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add a modern web UI based on React, MaterialUI and Vite #2405
Conversation
d98417c
to
7658459
Compare
@heyman @KasimAhmic I know both of you suggested using Vite for this project, would either of you be able to assist in changing the Webpack code to Vite? As I mentioned, I am not at all familiar with the tool. I tried with the following config:
This unfortunately would not load any images properly (I even tried directly importing, such as they suggest here). I additionally couldn't seem to find any replacement in Vite for the Webpack Speaking of development - I propose in Webpack to use two different html files, one for developing using the Webpack dev server (it uses test data for the template arguments so we do not need to have a Locust server running) and one for production / developing with a Locust instance. Could the same be easily achieved in Vite? |
Checked out your code and got it working with the config below: import reactSwcPlugin from '@vitejs/plugin-react-swc';
import { defineConfig, splitVendorChunkPlugin } from 'vite';
import checkerPlugin from 'vite-plugin-checker';
import tsconfigPaths from 'vite-tsconfig-paths';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
reactSwcPlugin(),
tsconfigPaths(),
splitVendorChunkPlugin(),
checkerPlugin({
typescript: true,
eslint: {
lintCommand: 'eslint --ext .ts,.tsx',
},
}),
],
build: {
outDir: '../dist',
emptyOutDir: true,
},
server: {
port: 4000,
open: './dev.html'
},
}); Main changes are:
In addition to the config, I also moved the <script type="module" src="/src/index.tsx"></script> Because we specified the dev file in the server configuration, this should cover your use case of having two HTML files as I believe Vite will still use Regarding watch mode, Vite does have it built in. You can use it like so: And lastly, with regard to images, when loading images from the - <img height='52' src='/assets/logo.png' width='52' />
+ <img height='52' src='/logo.png' width='52' /> |
@cyberw There is one other thing that I believe is missing here. I believe for the UI to be properly bundled when |
Hey @KasimAhmic thanks so much for the assist! Looks like the
The images do work when running the dev server, however there seems to be an issue with how the assets are placed in the |
@andrewbaldwin44 Couple things
import reactSwcPlugin from '@vitejs/plugin-react-swc';
import { defineConfig, splitVendorChunkPlugin } from 'vite';
import checkerPlugin from 'vite-plugin-checker';
import tsconfigPaths from 'vite-tsconfig-paths';
// https://vitejs.dev/config/
export default defineConfig((config) => ({
plugins: [
reactSwcPlugin(),
tsconfigPaths(),
splitVendorChunkPlugin(),
checkerPlugin({
typescript: true,
eslint: {
lintCommand: 'eslint ./src/**/*.{ts,tsx}',
},
}),
],
server: {
port: 4000,
open: config.mode === 'production' ? './index.html' : './dev.html'
},
}));
|
I dont know the best way to do this off hand, and I'm kinda busy atm. Let me know if you're really stuck on it and I'll have a look. |
@andrewbaldwin44 For adding the files, you should just need to include them in
|
c0ac517
to
69ef885
Compare
Thanks everyone! @cyberw updated now with the missing "Message" column and the missing line in the Thanks @KasimAhmic you were correct, I have Flask configured to server assets from |
69ef885
to
c90f116
Compare
Cool stuff! Can you add a basic test case in test_web.py as well? And maybe have a look at the weird html escaping going on in your screenshot of the failures tab :) |
@cyberw Sure, I can add a test to ensure the correct behavior is happening with the |
You can add react testing in a later PR, that is fine. For test_web.py, a basic test that runs with |
@cyberw Updated now to support |
7573de5
to
abd1046
Compare
From a code perspective this looks really good, apart from the flake8 and black fails :) (I really should make them pre-commit checks) I think we should mention the availability of the modern UI explicitly in the manual. I’m thinking maybe as a note at the end of the web ui section of quickstart? And make it clear that it is experimental, and breaking changes may happen. Mark it experimental in the command line description too. |
Apologies for the failing pipeline, I committed the new tests a bit too quickly! The pipeline is passing now and I have added a line to the quick start guide mentioning the new web UI as well as a warning that this feature is experimental. |
Awesome stuff. I'll try it out in the coming days. |
6c85ee2
to
3b160dd
Compare
Couple things:
|
c9c4e91
to
c964c65
Compare
Hey guys, I have just pushed an update that should resolve all the comments posted above. I will still need some more time for getting the API logic working with RTK, I will need to look into it more next week |
tests on python 3.8 are flaky for some reason. you can ignore the build failure on 3.8 for now. |
Sorry for the delay everyone, all the comments are now resolved and I have replaced the API logic with RTK's |
Nice! Can you update the pr description? I think the following is no longer relevant and maybe there are other things to add.
|
Great stuff. I'm going to merge this tomorrow if nobody objects. Further improvements are of course very welcome later on. Especially a few UI test cases would be nice. Edit: Why wait until tomorrow? |
@cyberw Yes once this is merged I can open a PR for updating the HTML report and then a third PR to introduce a suite of tests using React testing library. From there I am happy to support with the community requested features, such as boolean custom arguments and having a tab for viewing the logs :) |
@mquinnfd Does your offer to implement poetry to build the frontend still stand? If so, I'm more interested now :) I've heard more good stuff about it (and the bad stuff I heard/inferred was maybe a little misguided). The one thing I want to make sure is that we dont lose the ability to do an editable install (-e) that can be used even outside the directory/venv (maybe PDM is better than poetry for that?) |
Changes Proposed
modern_ui
(--modern-ui
,LOCUST_MODERN_UI
). Whentrue
, will use the new frontendUIExtraArgOptions
returned as a dict. This is needed as otherwise the NamedTuple is returned as an Array when JSON stringified. This is tested and working in the old web uiFixes #2396
Demo
Light and dark mode:
Advanced options and custom arguments:
About Modal:
Running Test:
Exceptions:
Second Test Markers:
Class Picker:
Custom Shape:
Custom Shape with Class Picker:
Multiple Hosts:
Full Requests Statistics History:
With Workers:
With examples/extend_modern_web_ui.py