Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

feat(frontend): new app selector #712

Merged
merged 17 commits into from
May 30, 2023
Prev Previous commit
Next Next commit
poc
  • Loading branch information
eh-am committed May 24, 2023
commit 67b836a0c8476d024999ad015405db280815e939
6 changes: 2 additions & 4 deletions public/app/overrides/components/AppSelector/AppSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from '@pyroscope/webapp/javascript/components/AppSelector';
//import React, { useState, useEffect, useMemo } from 'react';
//import ModalWithToggle from '@webapp/ui/Modals/ModalWithToggle';
//import Input from '@webapp/ui/Input';
Expand All @@ -6,10 +7,6 @@
//import { Label, LabelString } from '@webapp/components/AppSelector/Label';
//import styles from './AppSelector.module.scss';

export default function AppSelector() {
return <div>hey</div>;
}

//interface AppSelectorProps {
// /** Triggered when an app is selected */
// onSelected: (name: string) => void;
Expand All @@ -20,6 +17,7 @@ export default function AppSelector() {
// selectedAppName: string;
//}
//
//
//const AppSelector = ({
// onSelected,
// selectedAppName,
Expand Down
76 changes: 76 additions & 0 deletions public/app/overrides/components/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react';
import 'react-dom';

import { useAppSelector, useAppDispatch } from '@webapp/redux/hooks';
import { Query, queryToAppName, queryFromAppName } from '@webapp/models/query';
import {
selectApps,
reloadAppNames,
selectQueries,
selectAppNamesState,
} from '@webapp/redux/reducers/continuous';
import { faSyncAlt } from '@fortawesome/free-solid-svg-icons/faSyncAlt';
import Button from '@webapp/ui/Button';
import LoadingSpinner from '@webapp/ui/LoadingSpinner';
import DateRangePicker from '@webapp/components/DateRangePicker';
import RefreshButton from '@webapp/components/RefreshButton';
import AppSelector from '@webapp/components/AppSelector';
// TODO
import styles from '../../../../node_modules/pyroscope-oss/webapp/javascript/components/Toolbar.module.css';

interface ToolbarProps {
/** callback to be called when an app is selected via the dropdown */
onSelectedApp: (name: Query) => void;

filterApp?: (names: string) => boolean;
}
function Toolbar({ onSelectedApp, filterApp = () => true }: ToolbarProps) {
const dispatch = useAppDispatch();
const appNamesState = useAppSelector(selectAppNamesState);
const apps = useAppSelector(selectApps).filter((a) => filterApp(a.name));
const appNames = apps.map((a) => a.name);
const { query } = useAppSelector(selectQueries);
const selectedAppName = queryToAppName(query).mapOr('', (q) =>
appNames.indexOf(q) !== -1 ? q : ''
);

const onSelected = (appName: string) => {
//const query = queryFromAppName(appName);
// onSelectedApp(query);
onSelectedApp(
'process_cpu:cpu:nanoseconds:cpu:nanoseconds{pyroscope_app="simple.golang.app"}'
);
};

const appNamesLoading =
appNamesState.type === 'reloading' ? (
<LoadingSpinner className={styles.appNamesLoading} />
) : null;

return (
<>
<div className="navbar">
<div className={styles.leftSide}>
<AppSelector
onSelected={onSelected}
apps={apps}
selectedAppName={selectedAppName}
/>
<Button
aria-label="Refresh Apps"
icon={faSyncAlt}
onClick={() => dispatch(reloadAppNames())}
className={styles.refreshAppsButton}
/>
{appNamesLoading}
</div>
<div className="navbar-space-filler" />
<RefreshButton />
&nbsp;
<DateRangePicker />
</div>
</>
);
}

export default Toolbar;
8 changes: 8 additions & 0 deletions scripts/webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ module.exports = {
__dirname,
'../../public/app/overrides/components/TimelineChart/ContextMenu.plugin'
),
//'@webapp/components/AppSelector': path.resolve(
// __dirname,
// '../../public/app/overrides/components/AppSelector/AppSelector'
//),
'@webapp/components/AppSelector/Label': path.resolve(
__dirname,
'../../public/app/overrides/components/AppSelector/Label'
),
'@webapp/components/Toolbar': path.resolve(
__dirname,
'../../public/app/overrides/components/Toolbar'
),
'@webapp/ui/Sidebar': path.resolve(
__dirname,
'../../public/app/overrides/ui/Sidebar'
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"@webapp/components/AppSelector/Label": [
"./public/app/overrides/components/AppSelector/Label"
],
"@webapp/components/Toolbar": [
"./public/app/overrides/components/Toolbar"
],
"@webapp/ui/Sidebar": ["./public/app/overrides/ui/Sidebar"],
"@webapp/util/baseurl": ["./public/app/overrides/util/baseurl"],

Expand Down