Skip to content

Commit

Permalink
Expose tab config
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbaldwin44 committed Aug 19, 2024
1 parent 34a82fa commit 15ee0a0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
24 changes: 12 additions & 12 deletions locust/webui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The Locust UI is used for viewing stats, reports, and information on your curren

**Using the Locust UI as a library should be considered an experimental feature**

The Locust UI may be extended to fit your needs. If you only need limited extensibility, you may do so in your Locustfile, see the [extend_web_ui example](https://github.com/locustio/locust/blob/master/examples/extend_web_ui.py).
The Locust UI may be extended to fit your needs. If you only need limited extensibility, you may do so in your Locustfile, see the [extend_web_ui example](https://github.com/locustio/locust/blob/master/examples/extend_web_ui.py).

However, you may want to further extend certain functionalities. To do so, you may replace the default Locust UI with your own React application. Start by installing the locust-ui in your React application:
```sh
Expand Down Expand Up @@ -66,7 +66,7 @@ For Locust to be able to pass data to your React frontend, place the following s

To load the favicon, place the link in your head:
```html
<link rel="icon" href="./assets/favicon.ico" />
<link rel="icon" href="./assets/favicon.png" />
```

Lastly, you must configure Locust to point to your own React build output. To achieve this, you can use the flag `--build-path` and provide the **absolute** path to your build directory.
Expand Down Expand Up @@ -108,14 +108,17 @@ function App() {

The `tabs` prop allows for complete control of which tabs are rendered. You can then customize which base tabs are shown or where your new tab should be placed:
```js
import LocustUi, { baseTabs } from "locust-ui";
import LocustUi, { tabConfig } from "locust-ui";

const tabs = [...baseTabs];
tabs.splice(2, 0, {
title: "Custom Tab",
key: "custom-tab",
component: MyCustomTab,
});
const tabs = [
tabConfig.stats,
tabConfig.charts,
{
title: "Custom Tab",
key: "custom-tab",
component: MyCustomTab,
},
]

function App() {
return (
Expand Down Expand Up @@ -164,6 +167,3 @@ function App() {
tabs={/* Optional array of tabs that will take precedence over extendedTabs */}
/>
```



30 changes: 21 additions & 9 deletions locust/webui/src/components/Tabs/Tabs.constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,59 @@ import SwarmRatios from 'components/SwarmRatios/SwarmRatios';
import WorkersTable from 'components/WorkersTable/WorkersTable';
import { LOG_VIEWER_KEY } from 'constants/logs';
import { IRootState } from 'redux/store';
import { ITab } from 'types/tab.types';

export const baseTabs = [
{
export const tabConfig = {
stats: {
component: StatsTable,
key: 'stats',
title: 'Statistics',
},
{
charts: {
component: SwarmCharts,
key: 'charts',
title: 'Charts',
},
{
failures: {
component: FailuresTable,
key: 'failures',
title: 'Failures',
},
{
exceptions: {
component: ExceptionsTable,
key: 'exceptions',
title: 'Exceptions',
},
{
ratios: {
component: SwarmRatios,
key: 'ratios',
title: 'Current Ratio',
},
{
reports: {
component: Reports,
key: 'reports',
title: 'Download Data',
},
{
logs: {
component: LogViewer,
key: LOG_VIEWER_KEY,
title: 'Logs',
},
{
workers: {
component: WorkersTable,
key: 'workers',
title: 'Workers',
shouldDisplayTab: (state: IRootState) => state.swarm.isDistributed,
},
};

export const baseTabs: ITab[] = [
tabConfig.stats,
tabConfig.charts,
tabConfig.failures,
tabConfig.exceptions,
tabConfig.ratios,
tabConfig.reports,
tabConfig.logs,
tabConfig.workers,
];
5 changes: 2 additions & 3 deletions locust/webui/src/hooks/useCreateTheme.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { useMemo } from 'react';
import { Theme } from '@mui/material/styles';

import { THEME_MODE } from 'constants/theme';
import { useSelector } from 'redux/hooks';
import createTheme from 'styles/theme';

export default function useCreateTheme(extendedTheme?: Theme) {
export default function useCreateTheme() {
const isDarkMode = useSelector(({ theme: { isDarkMode } }) => isDarkMode);

const theme = useMemo(
() => createTheme(isDarkMode ? THEME_MODE.DARK : THEME_MODE.LIGHT, extendedTheme),
() => createTheme(isDarkMode ? THEME_MODE.DARK : THEME_MODE.LIGHT),
[isDarkMode],
);

Expand Down
3 changes: 2 additions & 1 deletion locust/webui/src/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export { default as useFetchExceptions } from 'hooks/useFetchExceptions';
export { default as useFetchTasks } from 'hooks/useFetchTasks';
export { default as useFetchStats } from 'hooks/useFetchStats';
export { default as Navbar } from 'components/Layout/Navbar/Navbar';
export { default as useTheme } from 'hooks/useTheme';
export { default as useCreateTheme } from 'hooks/useCreateTheme';
export { tabConfig } from 'components/Tabs/Tabs.constants';
export { store as locustStore } from 'redux/store';

export type { IRootState } from 'redux/store';
Expand Down
4 changes: 2 additions & 2 deletions locust/webui/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import useLogViewer from 'components/LogViewer/useLogViewer';
import SwarmForm from 'components/SwarmForm/SwarmForm';
import Tabs from 'components/Tabs/Tabs';
import { SWARM_STATE } from 'constants/swarm';
import useCreateTheme from 'hooks/useCreateTheme';
import useFetchExceptions from 'hooks/useFetchExceptions';
import useFetchStats from 'hooks/useFetchStats';
import useFetchTasks from 'hooks/useFetchTasks';
import useTheme from 'hooks/useTheme';
import { IRootState } from 'redux/store';
import { ITab } from 'types/tab.types';
import { SwarmState } from 'types/ui.types';
Expand All @@ -28,7 +28,7 @@ function Dashboard({ swarmState, tabs, extendedTabs }: IDashboard) {
useFetchTasks();
useLogViewer();

const { theme } = useTheme();
const theme = useCreateTheme();

return (
<ThemeProvider theme={theme}>
Expand Down

0 comments on commit 15ee0a0

Please sign in to comment.