Skip to content
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

[Report][Modern-UI] HTML report is blank #2609

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/web_ui_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

For more information, see https://docs.locust.io/en/stable/extending-locust.html#authentication
"""
from locust import HttpUser, events
from locust import HttpUser, events, task

import json
import os
Expand All @@ -16,7 +16,9 @@


class LocustHttpUser(HttpUser):
pass
@task
def example(self):
self.client.get("/")


class AuthUser(UserMixin):
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion locust/webui/dist/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="theme-color" content="#000000" />

<title>Locust</title>
<script type="module" crossorigin src="/assets/index-af38c28c.js"></script>
<script type="module" crossorigin src="/assets/index-ad6f2665.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
2 changes: 1 addition & 1 deletion locust/webui/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="theme-color" content="#000000" />

<title>Locust</title>
<script type="module" crossorigin src="/assets/index-af38c28c.js"></script>
<script type="module" crossorigin src="/assets/index-ad6f2665.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
1 change: 1 addition & 0 deletions locust/webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"echarts": "^5.4.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.12",
"react-markdown": "^9.0.0",
"react-redux": "^8.0.5",
"vite": "^4.5.1",
Expand Down
12 changes: 12 additions & 0 deletions locust/webui/src/components/FallbackRender/FallbackRender.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function FallbackRender({ error }: { error: { message?: string } }) {
return (
<div role='alert'>
<p>Something went wrong</p>
{error.message && <pre style={{ color: 'red' }}>{error.message}</pre>}
If the issue persists, please consider opening an{' '}
<a href='https://github.com/locustio/locust/issues/new?assignees=&labels=bug&projects=&template=bug.yml'>
issue
</a>
</div>
);
}
56 changes: 31 additions & 25 deletions locust/webui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { combineReducers, configureStore } from '@reduxjs/toolkit';
import Auth from 'auth';
import ReactDOM from 'react-dom/client';
import { ErrorBoundary } from 'react-error-boundary';
import { Provider } from 'react-redux';

import App from 'App';
import FallbackRender from 'components/FallbackRender/FallbackRender';
import { swarmTemplateArgs } from 'constants/swarm';
import theme from 'redux/slice/theme.slice';
import { store } from 'redux/store';
Expand All @@ -14,30 +16,34 @@ import { updateArraysAtProps } from 'utils/object';

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);

if (window.authArgs) {
const authStore = configureStore({
reducer: combineReducers({ theme }),
});
function componentToRender() {
if (window.authArgs) {
const authStore = configureStore({
reducer: combineReducers({ theme }),
});

root.render(
<Provider store={authStore}>
<Auth />
</Provider>,
);
} else if ((swarmTemplateArgs as IReportTemplateArgs).isReport) {
const reportProps = {
...(swarmTemplateArgs as IReportTemplateArgs),
charts: swarmTemplateArgs.history?.reduce(
(charts, { currentResponseTimePercentiles, ...history }) =>
updateArraysAtProps(charts, { ...currentResponseTimePercentiles, ...history }),
{} as ICharts,
) as ICharts,
};
root.render(<Report {...reportProps} />);
} else {
root.render(
<Provider store={store}>
<App />
</Provider>,
);
return (
<Provider store={authStore}>
<Auth />
</Provider>
);
} else if ((swarmTemplateArgs as IReportTemplateArgs).isReport) {
const reportProps = {
...(swarmTemplateArgs as IReportTemplateArgs),
charts: swarmTemplateArgs.history?.reduce(
(charts, { currentResponseTimePercentiles, ...history }) =>
updateArraysAtProps(charts, { ...currentResponseTimePercentiles, ...history }),
{} as ICharts,
) as ICharts,
};
return <Report {...reportProps} />;
} else {
return (
<Provider store={store}>
<App />
</Provider>
);
}
}

root.render(<ErrorBoundary fallbackRender={FallbackRender}>{componentToRender()}</ErrorBoundary>);
2 changes: 2 additions & 0 deletions locust/webui/src/redux/store.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { configureStore } from '@reduxjs/toolkit';

import { api } from 'redux/api/swarm';
import rootReducer from 'redux/slice/root.slice';

export const store = configureStore({
reducer: rootReducer,
middleware: getDefaultMiddleware => getDefaultMiddleware().concat(api.middleware),
});

export type { IRootState, Action } from 'redux/slice/root.slice';
Expand Down
7 changes: 7 additions & 0 deletions locust/webui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3724,6 +3724,13 @@ react-dom@^18.2.0:
loose-envify "^1.1.0"
scheduler "^0.23.0"

react-error-boundary@^4.0.12:
version "4.0.12"
resolved "https://registry.yarnpkg.com/react-error-boundary/-/react-error-boundary-4.0.12.tgz#59f8f1dbc53bbbb34fc384c8db7cf4082cb63e2c"
integrity sha512-kJdxdEYlb7CPC1A0SeUY38cHpjuu6UkvzKiAmqmOFL21VRfMhOcWxTCBgLVCO0VEMh9JhFNcVaXlV4/BTpiwOA==
dependencies:
"@babel/runtime" "^7.12.5"

react-is@^16.13.1, react-is@^16.7.0:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
Expand Down
Loading