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

Feature: add commit filtering to the profiler #474

Merged
merged 2 commits into from
Apr 1, 2023
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
8 changes: 6 additions & 2 deletions src/adapter/adapter/profiler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { UpdateRects } from "./highlightUpdates";

export interface ProfilerState {
export interface RawTimelineFilterState {
filterCommitsUnder: number | false;
}
export type ProfilerState = {
isProfiling: boolean;
highlightUpdates: boolean;
pendingHighlightUpdates: Set<HTMLElement>;
updateRects: UpdateRects;
captureRenderReasons: boolean;
recordStats: boolean;
}
} & RawTimelineFilterState;

export function newProfiler(): ProfilerState {
return {
Expand All @@ -17,5 +20,6 @@ export function newProfiler(): ProfilerState {
captureRenderReasons: false,
isProfiling: false,
recordStats: false,
filterCommitsUnder: false,
};
}
2 changes: 2 additions & 0 deletions src/adapter/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Renderer } from "./renderer";
import { ID } from "../view/store/types";
import { createAdapter, InspectData, UpdateType } from "./adapter/adapter";
import { DEFAULT_FIlTERS, FilterState, RawFilterState } from "./adapter/filter";
import { RawTimelineFilterState } from "./adapter/profiler";
import { Options } from "preact";
import { createRenderer, RendererConfig } from "./shared/renderer";
import { setupOptionsV10 } from "./10/options";
Expand Down Expand Up @@ -43,6 +44,7 @@ export interface DevtoolEvents {
"start-highlight-updates": null;
"stop-highlight-updates": null;
"update-filter": RawFilterState;
"update-timeline-filter": RawTimelineFilterState;
"load-host-selection": null;
"inspect-host-node": null;
"view-source": ID;
Expand Down
105 changes: 105 additions & 0 deletions src/view/components/FilterPopup/FilterPopup.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
.filterBtnWrapper {
position: relative;
display: flex;
height: 100%;
align-items: center;
}

.filter {
position: absolute;
top: 90%;
right: -0.5rem;
border-top: none;
border: 0.0625rem solid var(--color-border);
background: var(--color-bg);
width: 12rem;
z-index: 10;
padding: 0.5rem 0.5rem 0.5rem 0.75rem;
}

.filter form {
margin: 0;
}

.filter label {
cursor: pointer;
}

.filterRow {
display: flex;
height: 1.375rem;
align-items: center;
}

.filterCheck {
width: 1.25rem;
display: flex;
flex: 0 0 auto;
justify-content: flex-start;
align-items: center;
}

.filterCheck svg {
width: 1.25rem;
}

.filterCheck input {
opacity: 0;
position: absolute;
left: 0;
}

.filterCheck input:checked + svg {
color: var(--color-selected-bg);
}

.filterValue {
text-align: left;
}

.filterValueText {
padding-left: 0.25rem;
font-size: 0.875rem;
}

.filterAdd {
display: flex;
align-items: center;
font-size: 0.875rem;
}

.filterName {
display: flex;
align-items: center;
width: 100%;
background: var(--color-props-input-bg);
border: none;
color: var(--color-text-input);
padding: 0.15rem 0.3rem;
font-size: 0.75rem;
}

.filterActions {
display: flex;
justify-content: space-between;
align-items: center;
}

.filterSubmitBtn {
display: block;
background: var(--color-selected-bg);
color: var(--color-selected-text);
border: none;
border-radius: 0.1875rem;
font-size: 0.875rem;
padding: 0.25rem 0.5rem;
}

.filterSubmitBtn svg {
margin-right: 0.25rem;
}

.filterInputNumber {
width: 3rem;
padding: 0.15rem;
}
106 changes: 106 additions & 0 deletions src/view/components/FilterPopup/FilterPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { h } from "preact";
import { ComponentChildren } from "preact";
import { Icon } from "../icons";
import s from "./FilterPopup.module.css";

export function FilterCheck({
checked,
label,
onInput,
}: {
checked: boolean;
onInput: (checked: boolean) => void;
label: string;
}) {
return (
<label class={s.filterRow}>
<span class={s.filterCheck}>
<input
type="checkbox"
checked={checked}
onInput={e => onInput((e.target as any).checked)}
/>
<Icon icon={checked ? "checkbox-checked" : "checkbox-unchecked"} />
</span>
<span class={`${s.filterValue} ${s.filterValueText}`}>{label}</span>
</label>
);
}

export function FilterNumber({
value,
label,
onInput,
units,
defaultValue,
}: {
value: number | false;
onInput: (value: number | false) => void;
label: string;
units?: string;
defaultValue: number;
}) {
const checked = value !== false;
return (
<label class={s.filterRow}>
<span class={s.filterCheck}>
<input
type="checkbox"
checked={checked}
onInput={e =>
onInput((e.target as any).checked ? defaultValue : (false as const))
}
/>
<Icon icon={checked ? "checkbox-checked" : "checkbox-unchecked"} />
</span>
<span class={`${s.filterValue} ${s.filterValueText}`}>
{label}{" "}
<input
type="number"
class={s.filterInputNumber}
value={checked ? value : defaultValue}
onInput={e => {
onInput((e.target as any).value);
}}
></input>{" "}
{units}
</span>
</label>
);
}

export function FilterPopup({
children,
onFiltersSubmit,
filterActions,
className,
}: {
children: ComponentChildren;
filterActions?: ComponentChildren;
onFiltersSubmit: () => void;
className?: string;
}) {
return (
<div class={`${s.filter} ${className}`} data-testid="filter-popup">
<form
onSubmit={e => {
e.preventDefault();
onFiltersSubmit();
}}
>
{children}
<div class={s.vSep} />
<div class={s.filterActions}>
{filterActions}
<button
type="submit"
class={s.filterSubmitBtn}
data-testid="filter-update"
>
Update
</button>
</div>
</form>
</div>
);
}
101 changes: 0 additions & 101 deletions src/view/components/elements/TreeBar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,107 +56,6 @@
color: var(--color-text-empty);
}

.filterBtnWrapper {
position: relative;
display: flex;
height: 100%;
align-items: center;
}

.filter {
position: absolute;
top: 90%;
right: -0.5rem;
border-top: none;
border: .0625rem solid var(--color-border);
background: var(--color-bg);
width: 12rem;
z-index: 10;
padding: 0.5rem 0.5rem 0.5rem 0.75rem;
}

.filter form {
margin: 0;
}

.filter label {
cursor: pointer;
}

.filterRow {
display: flex;
height: 1.375rem;
align-items: center;
}

.filterCheck {
width: 1.25rem;
display: flex;
flex: 0 0 auto;
justify-content: flex-start;
align-items: center;
}

.filterCheck svg {
width: 1.25rem;
}

.filterCheck input {
opacity: 0;
position: absolute;
left: 0;
}

.filterCheck input:checked + svg {
color: var(--color-selected-bg);
}

.filterValue {
text-align: left;
}

.filterValueText {
padding-left: .25rem;
font-size: .875rem;
}

.filterAdd {
display: flex;
align-items: center;
font-size: .875rem;
}

.filterName {
display: flex;
align-items: center;
width: 100%;
background: var(--color-props-input-bg);
border: none;
color: var(--color-text-input);
padding: 0.15rem 0.3rem;
font-size: .75rem;
}

.filterActions {
display: flex;
justify-content: space-between;
align-items: center;
}

.filterSubmitBtn {
display: block;
background: var(--color-selected-bg);
color: var(--color-selected-text);
border: none;
border-radius: 0.1875rem;
font-size: .875rem;
padding: 0.25rem 0.5rem;
}

.filterSubmitBtn svg {
margin-right: 0.25rem;
}

.removeWrapper {
width: 1.5rem;
display: flex;
Expand Down
Loading