This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #611 from eh-am/feat/add-single-view-ui
feat(frontend): add single view page
- Loading branch information
Showing
21 changed files
with
11,406 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: frontend | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
concurrency: | ||
# Cancel any running workflow for the same branch when new commits are pushed. | ||
# We group both by ref_name (available when CI is triggered by a push to a branch/tag) | ||
# and head_ref (available when CI is triggered by a PR). | ||
group: "frontend-${{ github.ref_name }}-${{ github.head_ref }}" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
type-check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.15.0 | ||
cache: yarn | ||
- run: yarn --frozen-lockfile | ||
- name: Run type-check | ||
run: yarn type-check | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.15.0 | ||
cache: yarn | ||
- run: yarn --frozen-lockfile | ||
- name: Run build | ||
run: yarn build | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.15.0 | ||
cache: yarn | ||
- run: yarn --frozen-lockfile | ||
- name: Run tests | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import './jquery-import'; | ||
import { Provider } from 'react-redux'; | ||
import store, { persistor } from './redux/store'; | ||
import '@webapp/../sass/profile.scss'; | ||
import '@szhsin/react-menu/dist/index.css'; | ||
import Notifications from '@webapp/ui/Notifications'; | ||
|
||
const root = ReactDOM.createRoot(document.getElementById('reactRoot')); | ||
root.render(<div></div>); | ||
import { SingleView } from './pages/SingleView'; | ||
|
||
const container = document.getElementById('reactRoot') as HTMLElement; | ||
const root = ReactDOM.createRoot(container); | ||
|
||
root.render( | ||
<Provider store={store}> | ||
<Notifications /> | ||
|
||
<SingleView /> | ||
</Provider> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('noop', () => { | ||
it('works', () => { | ||
expect(true).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useEffect } from 'react'; | ||
import { useAppDispatch } from '@webapp/redux/hooks'; | ||
import { reloadAppNames } from '@webapp/redux/reducers/continuous'; | ||
|
||
export function loadAppNames() { | ||
const dispatch = useAppDispatch(); | ||
|
||
useEffect(() => { | ||
async function run() { | ||
await dispatch(reloadAppNames()); | ||
} | ||
|
||
run(); | ||
}, [dispatch]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import $ from 'jquery'; | ||
interface WindowWithJquery { | ||
$: unknown; | ||
jQuery: unknown; | ||
} | ||
(window as unknown as WindowWithJquery).$ = $; | ||
(window as unknown as WindowWithJquery).jQuery = $; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
interface ExportDataProps { | ||
flamebearer: unknown; | ||
exportPNG: unknown; | ||
exportJSON: unknown; | ||
exportPprof: unknown; | ||
exportHTML: unknown; | ||
exportFlamegraphDotCom: unknown; | ||
exportFlamegraphDotComFn: unknown; | ||
} | ||
export default function (props: ExportDataProps) { | ||
return <></>; | ||
} |
10 changes: 10 additions & 0 deletions
10
public/app/overrides/components/TimelineChart/ContextMenu.plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface ContextMenuProps { | ||
click: { | ||
/** The X position in the window where the click originated */ | ||
pageX: number; | ||
/** The Y position in the window where the click originated */ | ||
pageY: number; | ||
}; | ||
timestamp: number; | ||
containerEl: HTMLElement; | ||
} |
41 changes: 41 additions & 0 deletions
41
public/app/overrides/components/TimelineChart/TimelineChartWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
// TooltipCallbackProps refers to the data available for the tooltip body construction | ||
interface TooltipCallbackProps { | ||
timeLabel: string; | ||
values: Array<{ | ||
closest: number[]; | ||
color: number[]; | ||
// TODO: remove this | ||
tagName: string; | ||
}>; | ||
// coordsToCanvasPos?: jquery.flot.axis['p2c']; | ||
coordsToCanvasPos?: unknown; | ||
canvasX?: number; | ||
} | ||
|
||
interface TimelineChartWrapperProps { | ||
id: string; | ||
timelineA: unknown; | ||
height: unknown; | ||
timezone: string; | ||
title: React.ReactNode; | ||
annotations: unknown; | ||
ContextMenu: unknown; | ||
selectionType: unknown; | ||
onSelect: (from: string, until: string) => void; | ||
onHoverDisplayTooltip?: React.FC<TooltipCallbackProps>; | ||
} | ||
export default function (props: TimelineChartWrapperProps) { | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
// Since this element is inside a <Box>, also make the box hidden | ||
useEffect(() => { | ||
const parentElement = ref.current?.parentElement?.parentElement; | ||
if (parentElement) { | ||
parentElement.style.display = 'none'; | ||
} | ||
}, [ref.current]); | ||
|
||
return <div ref={ref}></div>; | ||
} |
12 changes: 12 additions & 0 deletions
12
public/app/overrides/components/TimelineChart/Tooltip.plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// TooltipCallbackProps refers to the data available for the tooltip body construction | ||
export interface TooltipCallbackProps { | ||
timeLabel: string; | ||
values: Array<{ | ||
closest: number[]; | ||
color: number[]; | ||
// TODO: remove this | ||
tagName: string; | ||
}>; | ||
coordsToCanvasPos?: any; | ||
canvasX?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { App } from '@webapp/models/app'; | ||
import { Result } from '@webapp/util/fp'; | ||
import { z } from 'zod'; | ||
import type { ZodError } from 'zod'; | ||
import type { RequestError } from '@webapp/services/base'; | ||
import { parseResponse, request } from '@webapp/services/base'; | ||
|
||
const appNamesResponse = z.preprocess( | ||
(arg) => { | ||
if (!Array.isArray(arg)) { | ||
return []; | ||
} | ||
|
||
return arg; | ||
}, | ||
z.array(z.string()).transform((names) => { | ||
return names.map((name) => { | ||
return { | ||
name, | ||
spyName: 'gospy', | ||
units: 'unknown', | ||
}; | ||
}); | ||
}) | ||
); | ||
|
||
export async function fetchApps(): Promise< | ||
Result<App[], RequestError | ZodError> | ||
> { | ||
const response = await request('/pyroscope/label-values?label=__name__'); | ||
|
||
if (response.isOk) { | ||
return parseResponse(response, appNamesResponse); | ||
} | ||
|
||
return Result.err<App[], RequestError>(response.error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { Result } from '@webapp/util/fp'; | ||
import { | ||
Profile, | ||
Groups, | ||
FlamebearerProfileSchema, | ||
} from '@pyroscope/models/src'; | ||
import { z } from 'zod'; | ||
import type { ZodError } from 'zod'; | ||
import { buildRenderURL } from '@webapp/util/updateRequests'; | ||
import { Timeline, TimelineSchema } from '@webapp/models/timeline'; | ||
import { Annotation, AnnotationSchema } from '@webapp/models/annotation'; | ||
import type { RequestError } from '@webapp/services/base'; | ||
import { request } from '@webapp/services/base'; | ||
|
||
export interface RenderOutput { | ||
profile: Profile; | ||
timeline: Timeline; | ||
groups?: Groups; | ||
annotations: Annotation[]; | ||
} | ||
|
||
// Default to empty array if not present | ||
const defaultAnnotationsSchema = z.preprocess((a) => { | ||
if (!a) { | ||
return []; | ||
} | ||
return a; | ||
}, z.array(AnnotationSchema)); | ||
|
||
interface renderSingleProps { | ||
from: string; | ||
until: string; | ||
query: string; | ||
refreshToken?: string; | ||
maxNodes: string | number; | ||
} | ||
export async function renderSingle( | ||
props: renderSingleProps, | ||
controller?: { | ||
signal?: AbortSignal; | ||
} | ||
): Promise<Result<RenderOutput, RequestError | ZodError>> { | ||
const url = buildRenderURL(props); | ||
// TODO | ||
const response = await request(`/pyroscope/${url}&format=json`, { | ||
signal: controller?.signal, | ||
}); | ||
|
||
if (response.isErr) { | ||
return Result.err<RenderOutput, RequestError>(response.error); | ||
} | ||
|
||
const parsed = FlamebearerProfileSchema.merge( | ||
z.object({ | ||
timeline: TimelineSchema, | ||
annotations: defaultAnnotationsSchema, | ||
}) | ||
) | ||
.merge(z.object({ telemetry: z.object({}).passthrough().optional() })) | ||
.safeParse(response.value); | ||
|
||
if (parsed.success) { | ||
// TODO: strip timeline | ||
const profile = parsed.data; | ||
const { timeline, annotations } = parsed.data; | ||
|
||
return Result.ok({ | ||
profile, | ||
timeline, | ||
annotations, | ||
}); | ||
} | ||
|
||
return Result.err(parsed.error); | ||
} | ||
|
||
export type RenderDiffResponse = Profile; | ||
export interface RenderExploreOutput { | ||
profile: Profile; | ||
groups: Groups; | ||
} | ||
|
||
export async function renderDiff( | ||
props: unknown, | ||
controller?: { | ||
signal?: AbortSignal; | ||
} | ||
) { | ||
return Result.err<Profile, { message: string }>({ | ||
message: 'TODO: implement ', | ||
}); | ||
} | ||
export async function renderExplore( | ||
props: unknown, | ||
controller?: { | ||
signal?: AbortSignal; | ||
} | ||
) { | ||
return Result.err<RenderExploreOutput, { message: string }>({ | ||
message: 'TODO: implement ', | ||
}); | ||
} |
Oops, something went wrong.